vdr/vdr/debian vdr.init

Tobias Grimm pkg-vdr-dvb-changes@lists.alioth.debian.org
Thu, 06 May 2004 19:46:29 +0000


Update of /cvsroot/pkg-vdr-dvb/vdr/vdr/debian
In directory haydn:/tmp/cvs-serv12196

Modified Files:
	vdr.init 
Log Message:
added code for dynamic [commands|reccmds].conf creation

Index: vdr.init
===================================================================
RCS file: /cvsroot/pkg-vdr-dvb/vdr/vdr/debian/vdr.init,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- vdr.init	27 Apr 2004 00:52:41 -0000	1.13
+++ vdr.init	6 May 2004 19:46:27 -0000	1.14
@@ -7,6 +7,8 @@
 NAME=vdr
 DESC="Linux Video Disk Recorder"
 
+CMDHOOKSDIR="/usr/share/vdr/command-hooks"
+
 # Defaults - don't touch, edit /etc/default/vdr
 
 ENABLED=0
@@ -19,20 +21,6 @@
 
 VERSION=`/usr/bin/$DAEMON -V 2>/dev/null | grep '^vdr[- ]' | sed -e 's/.*(\(.*\)).*/\1/'`
 
-startvdr() 
-{
-    start-stop-daemon --start --quiet \
-	--exec /usr/sbin/runvdr -- $DAEMON \
-	-v $VIDEO_DIR -c $CFG_DIR $OPTIONS \
-	$PLUGINS &
-} 
-
-stopvdr()
-{
-    killall -q -TERM runvdr
-    killall -q -TERM $DAEMON
-}
-
 getplugins ()
 {
     local plugin_order
@@ -85,10 +73,86 @@
     #echo
 }
 
+writewarning ()
+{
+echo -e \
+"#\n"\
+"# WARNING: Do not edit this file! It is automatically generated by the\n"\
+"#          vdr init-script. If you want to define some custom commands,\n"\
+"#          put them in a file called $1.<name>.conf and restart vdr.\n"\
+"#          All $1.*.conf files will be concatenated to this file.\n"\
+"#\n"\
+"# WARNUNG: Ändern Sie nicht diese Datei! Diese Datei wird automatisch vom\n"\
+"#          vdr init-Skript generiert. Wenn Sie eigene Kommandos definieren\n"\
+"#          möchten, so schreiben Sie diese in eine Datei mit dem Namen\n"\
+"#          $1.<name>.conf und starten Sie vdr erneut. Alle\n"\
+"#          $1.*.conf -Dateien werden zu dieser Datei zusammengefügt.\n"\
+"#\n\n\n"
+}
+
+# merges single <cmdtype>.<name>.conf files into one <cmdtype>.conf using
+# the order defined in order.<cmdtype>.conf
+mergecommands ()
+{
+    local cmd
+    local cmds
+    local cmdsorder
+    local line
+    local cmdtype
+    local cmdfile
+    local ordered_cmds
+    
+    cmdtype=$1
+    cmdfile="$CFG_DIR/$cmdtype.conf"
+
+    writewarning $cmdtype > "$cmdfile"
+
+    cmdsorder=( `cat $CFG_DIR/command-hooks/order.$cmdtype.conf | sed "s/#.*$//"` )
+    cmds=(`find $CMDHOOKSDIR -follow -name "$cmdtype.*.conf" || true`)
+    
+    # first the ordered commands:
+    for cmd in ${cmdsorder[@]}; do
+        for (( line=0 ; line<${#cmds[@]} ; line++ )); do
+            if echo "${cmds[$line]}" | grep "$cmd">/dev/null 2>&1 ; then
+                ordered_cmds=( "${ordered_cmds[@]}" "${cmds[$line]}" )
+                unset cmds[$line]
+		cmds=( "${cmds[@]}" )
+		break
+            fi
+        done
+    done
+    # then the remaining unordered commands:
+    ordered_cmds=( "${ordered_cmds[@]}" "${cmds[@]}" )
+
+    # concatenate all commands
+    for cmd in ${ordered_cmds[@]}; do
+	if [ "$cmd" != "" ]; then
+	    cat "$cmd" >> "$cmdfile"
+	    echo "" >> "$cmdfile"
+	fi
+    done 
+}
+
+startvdr() 
+{
+    getplugins
+    mergecommands "commands"
+    mergecommands "reccmds"
+    start-stop-daemon --start --quiet \
+	--exec /usr/sbin/runvdr -- $DAEMON \
+	-v $VIDEO_DIR -c $CFG_DIR $OPTIONS \
+	$PLUGINS &
+} 
+
+stopvdr()
+{
+    killall -q -TERM runvdr
+    killall -q -TERM $DAEMON
+}
+
 case "$1" in
   start)
 	 echo -n "Starting $DESC: $NAME"
-    getplugins
 	 startvdr
 	 echo "."
 	 ;;
@@ -101,7 +165,6 @@
 	 echo -n "Restarting $DESC: $NAME"
 	 stopvdr
 	 sleep 4
-	 getplugins
 	 startvdr
 	 echo "."
 	 ;;