You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.5 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2010 OpenWrt.org
  3. START=20
  4. NAME=ap51-flash
  5. start_daemon() {
  6. local cfg="$1"
  7. config_get_bool loop "$cfg" loop
  8. config_get ifname "$cfg" ifname
  9. config_get rootfs "$cfg" rootfs
  10. config_get kernel "$cfg" kernel
  11. config_get ubnt "$cfg" ubnt
  12. [ "$loop" != "1" ] && loop=0
  13. if [ -n "$ifname" -a -n "$rootfs" -a -n "$kernel" ] || \
  14. [ -n "$ifname" -a -n "$ubnt" ]; then
  15. PID="`cat /var/run/$NAME.sh-$ifname.pid 2> /dev/null`"
  16. [ -z "`ps | grep "^.[ ]*$PID "`" ] && \
  17. rm /var/run/$NAME.sh-$ifname.pid
  18. [ -n "`ls /var/run/$NAME.sh-$ifname.pid 2> /dev/null`" ] && {
  19. echo "Can't start more than one ap51-flash for interface $ifname!"
  20. return 0
  21. }
  22. start-stop-daemon -S -b -m -p /var/run/$NAME.sh-$ifname.pid -n $NAME.sh \
  23. -x /usr/lib/ap51-flash/$NAME.sh -- "$loop" "$ifname" "$rootfs" "$kernel" "$ubnt"
  24. fi
  25. }
  26. start() {
  27. config_load ap51-flash
  28. config_foreach start_daemon flash
  29. }
  30. stop() {
  31. # Terminating all ap51-flash processes
  32. echo "WARNING: Going to teminate all ap51-flash processes! (hope you made sure that they're not flashing right now)"
  33. echo "OR you can stop this with Ctrl+c within 10 seconds"
  34. sleep 10
  35. local pidfile
  36. for pidfile in `ls /var/run/${NAME}.sh-*.pid 2> /dev/null`; do
  37. start-stop-daemon -K -s TERM -p "${pidfile}" -n "${NAME}.sh" >/dev/null
  38. rm -f "${pidfile}"
  39. done
  40. for pidfile in `ls /var/run/${NAME}-*.pid 2> /dev/null`; do
  41. start-stop-daemon -K -s TERM -p "${pidfile}" -n "${NAME}" >/dev/null
  42. rm -f "${pidfile}"
  43. done
  44. }