missing optional parameters for restart and boot functions
[openwrt-10.03/.git] / package / base-files / files / etc / rc.common
index 7180b0f7fa9188c05a94d33881c0668060b89a6d..6b3c213a1d81a38b34cbfc2a50b8002e7e182b3c 100755 (executable)
@@ -3,8 +3,6 @@
 
 . $IPKG_INSTROOT/etc/functions.sh
 
-START=50
-
 start() {
        return 0
 }
@@ -18,12 +16,13 @@ reload() {
 }
 
 restart() {
-       stop
-       start
+       trap '' TERM
+       stop "$@"
+       start "$@"
 }
 
 boot() {
-       start
+       start "$@"
 }
 
 shutdown() {
@@ -33,12 +32,19 @@ shutdown() {
 disable() {
        name="$(basename "${initscript}")"
        rm -f "$IPKG_INSTROOT"/etc/rc.d/S??$name
+       rm -f "$IPKG_INSTROOT"/etc/rc.d/K??$name
 }
 
 enable() {
        name="$(basename "${initscript}")"
        disable
-       ln -s "/etc/init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}"
+       [ "$START" ] && ln -s "/etc/init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}"
+       [ "$STOP"  ] && ln -s "/etc/init.d/$name" "$IPKG_INSTROOT/etc/rc.d/K${STOP}${name##K[0-9][0-9]}"
+}
+
+enabled() {
+       name="$(basename "${initscript}")"
+       [ -x "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" ]
 }
 
 depends() {
@@ -61,23 +67,26 @@ EOF
 }
 
 initscript="$1"
-action="$2"
+[ "$#" -ge 1 ] && shift
+action="$1"
+[ "$#" -ge 1 ] && shift
 
 . "$initscript"
 
 cmds=
 for cmd in $EXTRA_COMMANDS; do
-       cmds="${cmds:+$cmds$N}$cmd) $cmd;;"
+       cmds="${cmds:+$cmds$N}$cmd) $cmd \"\$@\";;"
 done
 eval "case \"\$action\" in
-       start) start;;
-       stop) stop;;
-       reload) reload || restart;;
-       restart) restart;;
-       boot) boot;;
-       shutdown) shutdown;;
-       enable) enable;;
-       disable) disable;;
+       start) start \"\$@\";;
+       stop) stop \"\$@\";;
+       reload) reload \"\$@\" || restart \"\$@\";;
+       restart) restart \"\$@\";;
+       boot) boot \"\$@\";;
+       shutdown) shutdown \"\$@\";;
+       enable) enable \"\$@\";;
+       enabled) enabled \"\$@\";;
+       disable) disable \"\$@\";;
        $cmds
        *) help;;
 esac"