vdr/vdr/debian commands-loader.sh plugin-loader.sh changelog rules vdr.init

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


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

Modified Files:
	changelog rules vdr.init 
Added Files:
	commands-loader.sh plugin-loader.sh 
Log Message:
extracted functions from vdr.init to separate files

Index: changelog
===================================================================
RCS file: /cvsroot/pkg-vdr-dvb/vdr/vdr/debian/changelog,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- changelog	6 May 2004 14:22:45 -0000	1.10
+++ changelog	6 May 2004 21:06:56 -0000	1.11
@@ -19,6 +19,7 @@
 
   * Tobias Grimm <vdr@e-tobi.net>
     - added automatic loading of plugins in init script from c't vdr
+    - added dynamic generation of reccmds.conf and commands.conf from c't vdr
 
  -- Thomas Schmidt <thomas.schmidt@in.stud.tu-ilmenau.de>  Sat, 24 Apr 2004 12:04:41 +0200
 

--- NEW FILE: plugin-loader.sh ---
#
# This file is called by /etc/init.d/vdr
#

VERSION=`/usr/bin/$DAEMON -V 2>/dev/null | grep '^vdr[- ]' | sed -e 's/.*(\(.*\)).*/\1/'`

getplugins ()
{
    local plugin_order
    local installed_plugins
    local ordered_plugins
    local plugin
    local i
    local arguments


    echo -ne "\nSearching for plugins:"

    # find installed plugins
    installed_plugins=( `find $PLUGIN_DIR -maxdepth 1 -name "$PLUGIN_PREFIX*.so.$VERSION" -printf "%f " | sed "s/$PLUGIN_PREFIX\([^\.]\+\)\.so\.$VERSION/\1/g"` )
    
    if [ -r $PLUGIN_ORDER_FILE ]; then
	# load plugin order
	plugin_order=( `cat $PLUGIN_ORDER_FILE | sed "s/#.*$//"` )

	# move ordered plugins to list of ordered plugins
	for plugin in ${plugin_order[@]}; do
	    for (( i=0 ; i<${#installed_plugins[@]} ; i++ )); do
        	if [ "$plugin" == "-${installed_plugins[$i]}" ]; then
			 unset installed_plugins[$i]
		    installed_plugins=( "${installed_plugins[@]}" )
			 break
			fi
        	if [ "$plugin" == "${installed_plugins[$i]}" ]; then
		    ordered_plugins=( "${ordered_plugins[@]}" "$plugin" )
		    unset installed_plugins[$i]
		    installed_plugins=( "${installed_plugins[@]}" )
		    break
        	fi
    	    done
	done
    fi

    # append unordered to ordered plugins
    ordered_plugins=( "${ordered_plugins[@]}" "${installed_plugins[@]}" )

    # add the command line arguments for each plugin
    for plugin in ${ordered_plugins[@]}; do
        echo -n " $plugin"
        PLUGINS="$PLUGINS -P $plugin"
        if [ -r "$PLUGIN_CFG_DIR/plugin.$plugin.conf" ] ; then
            arguments=( `cat $PLUGIN_CFG_DIR/plugin.$plugin.conf | sed "s/#.*$//"` )
            PLUGINS="$PLUGINS ${arguments[*]}\""
        fi
    done
    #echo
}

Index: vdr.init
===================================================================
RCS file: /cvsroot/pkg-vdr-dvb/vdr/vdr/debian/vdr.init,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- vdr.init	6 May 2004 19:46:27 -0000	1.14
+++ vdr.init	6 May 2004 21:06:56 -0000	1.15
@@ -7,7 +7,7 @@
 NAME=vdr
 DESC="Linux Video Disk Recorder"
 
-CMDHOOKSDIR="/usr/share/vdr/command-hooks"
+CMDHOOKSDIR="/usr/share/vdr/command-hooks" # should this be in /etc/default/vdr?
 
 # Defaults - don't touch, edit /etc/default/vdr
 
@@ -19,119 +19,8 @@
 
 test -x /usr/sbin/runvdr || exit 0
 
-VERSION=`/usr/bin/$DAEMON -V 2>/dev/null | grep '^vdr[- ]' | sed -e 's/.*(\(.*\)).*/\1/'`
-
-getplugins ()
-{
-    local plugin_order
-    local installed_plugins
-    local ordered_plugins
-    local plugin
-    local i
-    local arguments
-
-
-    echo -ne "\nSearching for plugins:"
-
-    # find installed plugins
-    installed_plugins=( `find $PLUGIN_DIR -maxdepth 1 -name "$PLUGIN_PREFIX*.so.$VERSION" -printf "%f " | sed "s/$PLUGIN_PREFIX\([^\.]\+\)\.so\.$VERSION/\1/g"` )
-    
-    if [ -r $PLUGIN_ORDER_FILE ]; then
-	# load plugin order
-	plugin_order=( `cat $PLUGIN_ORDER_FILE | sed "s/#.*$//"` )
-
-	# move ordered plugins to list of ordered plugins
-	for plugin in ${plugin_order[@]}; do
-	    for (( i=0 ; i<${#installed_plugins[@]} ; i++ )); do
-        	if [ "$plugin" == "-${installed_plugins[$i]}" ]; then
-			 unset installed_plugins[$i]
-		    installed_plugins=( "${installed_plugins[@]}" )
-			 break
-			fi
-        	if [ "$plugin" == "${installed_plugins[$i]}" ]; then
-		    ordered_plugins=( "${ordered_plugins[@]}" "$plugin" )
-		    unset installed_plugins[$i]
-		    installed_plugins=( "${installed_plugins[@]}" )
-		    break
-        	fi
-    	    done
-	done
-    fi
-
-    # append unordered to ordered plugins
-    ordered_plugins=( "${ordered_plugins[@]}" "${installed_plugins[@]}" )
-
-    # add the command line arguments for each plugin
-    for plugin in ${ordered_plugins[@]}; do
-        echo -n " $plugin"
-        PLUGINS="$PLUGINS -P $plugin"
-        if [ -r "$PLUGIN_CFG_DIR/plugin.$plugin.conf" ] ; then
-            arguments=( `cat $PLUGIN_CFG_DIR/plugin.$plugin.conf | sed "s/#.*$//"` )
-            PLUGINS="$PLUGINS ${arguments[*]}\""
-        fi
-    done
-    #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 
-}
+. /usr/lib/vdr/plugin-loader.sh
+. /usr/lib/vdr/commands-loader.sh
 
 startvdr() 
 {

--- NEW FILE: commands-loader.sh ---
#
# This file is called by /etc/init.d/vdr
#

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 
}

Index: rules
===================================================================
RCS file: /cvsroot/pkg-vdr-dvb/vdr/vdr/debian/rules,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- rules	6 May 2004 21:03:30 -0000	1.14
+++ rules	6 May 2004 21:06:56 -0000	1.15
@@ -109,9 +109,13 @@
 	cp debian/order.commands.conf $(CURDIR)/debian/vdr/etc/vdr/command-hooks/
 	cp debian/order.recmds.conf $(CURDIR)/debian/vdr/etc/vdr/command-hooks/
 
-	# install custom commands files:
+	# install custom commands files
 	cp debian/commands.custom.conf $(CURDIR)/debian/vdr/usr/share/vdr/command-hooks/
 	cp debian/reccmds.custom.conf $(CURDIR)/debian/vdr/usr/share/vdr/command-hooks/
+	
+	# install helper files for vdr.init
+	cp debian/plugin-loader.sh $(CURDIR)/debian/vdr/usr/lib/vdr
+	cp debian/commands-loader.sh $(CURDIR)/debian/vdr/usr/lib/vdr
 
 	# config files
 	install -m 644 ca.conf diseqc.conf keymacros.conf sources.conf svdrphosts.conf $(CURDIR)/debian/vdr/etc/vdr/