Package: motion
Version: 3.2.9-7
Tags: patch
Severity: important

--- Please enter the report below this line. ---

Hello,

I just installed this version and I saw that after the install, the camera was 
on by default (thanks
to the webcam led).

This bothered me and I thought that there should be a way to disable the daemon 
via a configuration
file in /etc/default/ (update-rc.d is not a reasonable way to do this).

Why not start? Because:
- by default, you get video "access" to the station (security risk)
- motion is perfectly usable as a motion detector and, most importantly, this 
is one of the foremost
advertised features


Also, the script sources /lib/lsb/init-functions, but never uses the functions 
from there, so I
thought it would be nice to fix that.


Please see the attached patch with the following changes:
- allow motion to be disabled via /etc/default/motion (in its absence, the 
daemon starts, maybe
should be the other way around? what about upgrades?)
- a default /etc/default/motion file with the daemon disabled
- use lsb functions providing a nice output on boot :-)



Although this *looks* a big change, I think it can be safely be prepared for 
lenny, especially if
the daemon is delivered /enabled/ (opposed to the current patch).




--- System information. ---
Architecture: amd64
Kernel:       Linux 2.6.25-2-amd64

Debian Release: lenny/sid
  900 testing         snapshot.debian.net
  900 testing         security.debian.org
  900 testing         ftp.ro.debian.org
   10 unstable        ftp.ro.debian.org
    1 experimental    ftp.ro.debian.org

--- Package information. ---
Depends                                   (Version) | Installed
===================================================-+-======================
libavcodec51                  (>= 0.svn20080206-8)  | 0.svn20080206-14
 OR libavcodec-unstripped-51   (>= 0.svn20080206-8) |
libavformat52                 (>= 0.svn20080206-8)  | 0.svn20080206-14
 OR libavformat-unstripped-52  (>= 0.svn20080206-8) |
libavutil49                   (>= 0.svn20080206-8)  | 0.svn20080206-14
 OR libavutil-unstripped-49    (>= 0.svn20080206-8) |
libc6                                    (>= 2.7-1) | 2.7-15
libjpeg62                                           | 6b-14
libmysqlclient15off                   (>= 5.0.27-1) | 5.0.51a-15
libpq5                               (>= 8.3~beta1) | 8.3.4-2
debconf                                   (>= 0.5)  | 1.5.22
 OR debconf-2.0                                     |
adduser                                             | 3.110
debconf                                             | 1.5.22



-- 
Regards,
EddyP
=============================================
"Imagination is more important than knowledge" A.Einstein
diff --git a/default/motion b/default/motion
new file mode 100644
index 0000000..f638fd0
--- /dev/null
+++ b/default/motion
@@ -0,0 +1,2 @@
+# set to 'yes' to enable the motion daemon
+start_motion_daemon=no
diff --git a/init.d/motion b/init.d/motion
index 73e9484..83b7dff 100755
--- a/init.d/motion
+++ b/init.d/motion
@@ -20,6 +20,7 @@ NAME=motion
 PATH_BIN=/bin:/usr/bin:/sbin:/usr/sbin
 DAEMON=/usr/bin/motion
 PIDFILE=/var/run/$NAME.pid
+DEFAULTS=/etc/default/$NAME
 
 ENV="env -i LANG=C PATH=$PATH_BIN"
 
@@ -27,43 +28,76 @@ ENV="env -i LANG=C PATH=$PATH_BIN"
 
 test -x $DAEMON || exit 0
 
+RET=0
+
+[ -r "$DEFAULTS" ] && . "$DEFAULTS" || start_motion_daemon=yes
+
+
+check_daemon_enabled () {
+    if [ "$start_motion_daemon" = "yes" ] ; then
+        return 0
+    else
+        log_warning_msg "Not starting $NAME daemon, disabled via /etc/default/$NAME"
+        return 1
+    fi
+
+}
+
+
 case "$1" in
   start)
-    echo "Starting motion detection : $NAME"
-    start-stop-daemon --start --exec $DAEMON -b --chuid motion || true
+    if check_daemon_enabled ; then
+        log_daemon_msg "Starting motion detection daemon : $NAME"
+        if start-stop-daemon --start --oknodo --exec $DAEMON -b --chuid motion ; then
+            log_end_msg 0
+        else
+            log_end_msg 1
+            RET=1
+        fi
+    fi
     ;;
 
   stop)
-    echo "Stopping motion detection : $NAME"
-    start-stop-daemon --stop --oknodo --exec $DAEMON --retry 30
+    log_daemon_msg "Stopping motion detection daemon: $NAME"
+    if start-stop-daemon --stop --oknodo --exec $DAEMON --retry 30 ; then
+        log_end_msg 0
+    else
+        log_end_msg 1
+        RET=1
+    fi
     ;;
 
   reload-config)
-    echo "Reloading $NAME configuration"
-    start-stop-daemon --stop --signal HUP --exec $DAEMON
+    log_daemon_msg "Reloading $NAME configuration"
+    if start-stop-daemon --stop --signal HUP --exec $DAEMON ; then
+        log_end_msg 0
+    else
+        log_end_msg 1
+        RET=1
+    fi
     ;;
 
   restart-motion)
-    echo "Restarting $NAME"
-    $0 stop
-    $0 start
+    if check_daemon_enabled ; then
+        log_action_begin_msg "Restarting $NAME"
+        if $0 stop && $0 start ; then
+            log_action_end_msg 0
+        else
+            log_action_cont_msg "(failed)"
+            RET=1
+        fi
+    fi
     ;;
 
   restart|force-reload)
     $0 restart-motion
-    exit $?
     ;;
 
   *)
     echo "Usage: /etc/init.d/$NAME {start|stop|reload-config|restart|force-reload}"
-    exit 1
+    RET=1
     ;;
 esac
 
-if [ $? -eq 0 ]; then
-	echo .
-	exit 0
-else
-	echo failed
-	exit 0
-fi
+
+exit $RET

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to