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.

44 lines
1.4 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. if ! pgrep "^.[ ]*$PID "; then
  17. rm "/var/run/$NAME.sh-$ifname.pid"
  18. fi
  19. if find /var/run/ -name "$NAME.sh-$ifname.pid"; then
  20. echo "Can't start more than one ap51-flash for interface $ifname!"
  21. return 0
  22. fi
  23. start-stop-daemon -S -b -m -p "/var/run/$NAME.sh-$ifname.pid" -n $NAME.sh \
  24. -x /usr/lib/ap51-flash/$NAME.sh -- "$loop" "$ifname" "$rootfs" "$kernel" "$ubnt"
  25. fi
  26. }
  27. start() {
  28. config_load ap51-flash
  29. config_foreach start_daemon flash
  30. }
  31. stop() {
  32. # Terminating all ap51-flash processes
  33. echo "WARNING: Going to teminate all ap51-flash processes! (hope you made sure that they're not flashing right now)"
  34. echo "OR you can stop this with Ctrl+c within 10 seconds"
  35. sleep 10
  36. find /var/run/ -name "$NAME.sh-*.pid" -exec start-stop-daemon -K -s TERM -p '{}' -n "$NAME.sh" \; -exec rm -f '{}' \;
  37. find /var/run/ -name "$NAME.sh-*.pid" -exec start-stop-daemon -K -s TERM -p '{}' -n "$NAME" \; -exec rm -f '{}' \;
  38. }