[packages] ap51-flash: update ap51-flash and add loop option
[openwrt/svn-archive/archive.git] / utils / ap51-flash / files / ap51-flash.init
index ec5bb9e7fe0e2b9133bf4a085d2da688fb1fda41..1633ac4034e822dfaa514e9c4fa0def19c43536b 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/sh /etc/rc.common
-# Copyright (C) 2007 OpenWrt.org
+# Copyright (C) 2010 OpenWrt.org
 
 START=20
 
@@ -8,22 +8,23 @@ NAME=ap51-flash
 start_daemon() {
        local cfg="$1"
 
+       config_get_bool loop "$cfg" loop
        config_get ifname "$cfg" ifname
        config_get rootfs "$cfg" rootfs
        config_get kernel "$cfg" kernel
-       config_get ubntimg "$cfg" ubntimg
-       if [ -n "$ifname" -a -n "$rootfs" -a -n "$kernel" ]; then
-               [ -n "`ls /var/run/$NAME-$ifname.pid 2> /dev/null`" ] && {
+       config_get ubnt "$cfg" ubnt
+       [ "$loop" != "1" ] && loop=0
+       if [ -n "$ifname" -a -n "$rootfs" -a -n "$kernel" ] || \
+          [ -n "$ifname" -a -n "$ubnt" ]; then
+               PID="`cat /var/run/$NAME.sh-$ifname.pid 2> /dev/null`"
+               [ -z "`ps | grep "^.[ ]*$PID "`" ] && \
+                       rm /var/run/$NAME.sh-$ifname.pid
+               [ -n "`ls /var/run/$NAME.sh-$ifname.pid 2> /dev/null`" ] && {
                        echo "Can't start more than one ap51-flash for interface $ifname!"
                        return 0
                }
-               start-stop-daemon -S -b -m -p /var/run/$NAME-$ifname.pid -n $NAME -x /usr/sbin/$NAME -- $ifname $rootfs $kernel
-       elif [ -n "$ifname" -a -n "$ubntimg" ]; then
-               [ -n "`ls /var/run/$NAME-$ifname-ubnt.pid 2> /dev/null`" ] && {
-                       echo "Can't start more than one ap51-flash (ubnt) for interface $ifname!"
-                       return 0
-               }
-               start-stop-daemon -S -b -m -p /var/run/$NAME-$ifname-ubnt.pid -n $NAME -x /usr/sbin/$NAME -- $ifname $ubntimg
+               start-stop-daemon -S -b -m -p /var/run/$NAME.sh-$ifname.pid -n $NAME.sh \
+                       -x /usr/lib/ap51-flash/$NAME.sh -- "$loop" "$ifname" "$rootfs" "$kernel" "$ubnt"
        fi
 }
 
@@ -38,6 +39,10 @@ stop() {
        echo "OR you can stop this with Ctrl+c within 10 seconds"
        sleep 10
        local pidfile
+       for pidfile in `ls /var/run/${NAME}.sh-*.pid 2> /dev/null`; do
+               start-stop-daemon -K -s TERM -p "${pidfile}" -n "${NAME}.sh" >/dev/null
+               rm -f "${pidfile}"
+       done
        for pidfile in `ls /var/run/${NAME}-*.pid 2> /dev/null`; do
                start-stop-daemon -K -s TERM -p "${pidfile}" -n "${NAME}" >/dev/null
                rm -f "${pidfile}"