-include README.md
-
+recursive-include extra *
 
+++ /dev/null
-# motionEye, the motion frontend #\r
-\r
-**motionEye **is a web-based user interface for [motion](http://www.lavrsen.dk/foswiki/bin/view/Motion).\r
-\r
-## Requirements ##\r
-\r
- * a machine running Linux\r
- * python 2.6+\r
- * tornado 3.1+\r
- * jinja2\r
- * PIL\r
- * pycurl\r
- * motion\r
- * ffmpeg\r
- * v4l-utils\r
-\r
-## Installation ##\r
-\r
- 1. download the latest version from [bitbucket](https://bitbucket.org/ccrisan/motioneye/downloads) (use the *Tags* tab).\r
- 2. extract the archive to a directory of your choice (e.g. your home directory):\r
- \r
-        cd /home/user\r
-        tar zxvf ccrisan-motioneye-xyz.tar.gz\r
-        mv ccrisan-motioneye-xyz motioneye\r
- \r
- 3. create a `settings.py` file using the default template file (the default settings should do for now):\r
-\r
-        cd motioneye \r
-        cp settings_default.py settings.py\r
- \r
- 4. motionEye can be run directly from the extracted directory; no root privileges are required:\r
- \r
-        ./motioneye.py\r
- \r
- 5. point your favourite browser to <http://localhost:8765>\r
 
--- /dev/null
+**motionEye** is a web-based frontend for `motion <http://www.lavrsen.dk/foswiki/bin/view/Motion>`_.\r
 
--- /dev/null
+#!/bin/sh -e
+#
+# /etc/init.d/motioneye: Start the motionEye server
+#
+### BEGIN INIT INFO
+# Provides:      motioneye
+# Required-Start: $local_fs $syslog $remote_fs
+# Required-Stop: $remote_fs
+# Default-Start:  2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Start the motionEye server
+# Description: Start the motionEye server
+### END INIT INFO
+
+NAME="motioneye"
+PATH_BIN="/bin:/usr/bin:/sbin:/usr/sbin"
+DAEMON="/usr/bin/meyectl"
+PIDFILE="/var/run/$NAME.pid"
+DESC="motionEye server"
+USER="motion"
+OPTIONS="startserver -c /etc/motioneye/motioneye.conf -l"
+
+. /lib/lsb/init-functions
+
+test -x $DAEMON || exit 0
+
+RET=0
+
+case "$1" in
+    start)
+        log_daemon_msg "Starting $DESC"
+        if start-stop-daemon --start --oknodo --exec $DAEMON -b --chuid $USER -- $OPTIONS; then
+            log_end_msg 0
+        else
+            log_end_msg 1
+            RET=1
+        fi
+        ;;
+
+    stop)
+        log_daemon_msg "Stopping $DESC"
+        if start-stop-daemon --stop --oknodo --exec $DAEMON --retry 5; then
+            log_end_msg 0
+        else
+            log_end_msg 1
+            RET=1
+        fi
+        ;;
+
+    restart)
+        log_action_begin_msg "Restarting $DESC"
+        if $0 stop && $0 start; then
+            log_action_end_msg 0
+        else
+            log_action_cont_msg "(failed)"
+            RET=1
+        fi
+        ;;
+
+    status)
+        status_of_proc $DAEMON $NAME
+        ;;
+
+    *)
+        echo "Usage: /etc/init.d/$NAME {start|stop|restart|status}"
+        RET=1
+        ;;
+esac
+
+exit $RET
+
 
--- /dev/null
+[Unit]
+Description=motionEye Server
+
+[Service]
+ExecStart=/usr/local/bin/meyectl startserver -c /etc/motioneye/motioneye.conf
+Restart=on-abort
+
+[Install]
+WantedBy=multi-user.target
 
 
 
 def configure_logging(cmd, log_to_file=False):
-    format = '%(asctime)s: [{cmd}] %(levelname)s: %(message)s'.format(cmd=cmd)
+    if log_to_file or cmd != 'motioneye':
+        format = '%(asctime)s: [{cmd}] %(levelname)s: %(message)s'.format(cmd=cmd)
+        
+    else:
+        format = '%(levelname)s: %(message)s'.format(cmd=cmd)
 
     for h in logging.getLogger().handlers:
         logging.getLogger().removeHandler(h)
             action='store_true', dest='debug')
     parser.add_argument('-h', help='print this help and exit',
             action='help', default=argparse.SUPPRESS)
+    parser.add_argument('-l', help='log to file instead of standard error',
+            action='store_true', dest='log_to_file')
     parser.add_argument('-v', help='print program version and exit',
             action='version', default=argparse.SUPPRESS)
 
 
     
     options = parse_options(parser, args)
     
-    meyectl.configure_logging('relayevent')
+    meyectl.configure_logging('relayevent', options.log_to_file)
     meyectl.configure_tornado()
 
     logging.debug('hello!')
 
     
     options = parse_options(parser, args)
     
-    meyectl.configure_logging('sendmail')
+    meyectl.configure_logging('sendmail', options.log_to_file)
     meyectl.configure_tornado()
 
     logging.debug('hello!')
 
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-import argparse
 import atexit
 import datetime
 import logging
     
     options = parse_options(parser, args)
     
-    meyectl.configure_logging('motioneye', options.background)
+    meyectl.configure_logging('motioneye', options.background or options.log_to_file)
     meyectl.configure_tornado()
 
     if command == 'start':
 
     
     options = parse_options(parser, args)
     
-    meyectl.configure_logging('webhook')
+    meyectl.configure_logging('webhook', options.log_to_file)
     meyectl.configure_tornado()
 
     logging.debug('hello!')
 
 
-# Always prefer setuptools over distutils
+import os.path
+
 from setuptools import setup
-# To use a consistent encoding
 from codecs import open
-from os import path
 
-here = path.abspath(path.dirname(__file__))
+import motioneye
+
 
-with open(path.join(here, 'README.md'), encoding='utf-8') as f:
+here = os.path.abspath(os.path.dirname(__file__))
+name = 'motioneye'
+version = motioneye.VERSION
+
+with open(os.path.join(here, 'README.rst'), encoding='utf-8') as f:
     long_description = f.read()
 
-setup(
-    name='motioneye',
 
-    version='0.25.2',
+setup(
+    name=name,
+    version=version,
 
     description='motionEye server',
     long_description=long_description,
 
     license='GPLv3',
 
-    # See https://pypi.python.org/pypi?%3Aaction=list_classifiers
     classifiers=[
         'Development Status :: 3 - Beta',
 
 
     package_data={
         'motioneye': [
-            'static/*',
+            'static/*.*',
             'static/*/*',
             'templates/*'
         ]
     },
 
-    data_files=[],
+    data_files=[
+        (os.path.join('share/%s' % name, root), [os.path.join(root, f) for f in files])
+                for (root, dirs, files) in os.walk('extra')
+    ],
 
     entry_points={
         'console_scripts': [
-            'motioneye=motioneye.motioneye:main',
+            'meyectl=motioneye.meyectl:main',
         ],
-    },
+    }
 )
-