aboutsummaryrefslogtreecommitdiff
path: root/utils/ap51-flash/files/ap51-flash.init
blob: 7969385b857588913ffbaee0c29319bad7e68fcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh /etc/rc.common
# Copyright (C) 2010 OpenWrt.org

START=20

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 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)"
	   	if ! pgrep "^.[ ]*$PID "; then
	   		rm "/var/run/$NAME.sh-$ifname.pid"
		fi
		if find /var/run/ -name "$NAME.sh-$ifname.pid"; then
			echo "Can't start more than one ap51-flash for interface $ifname!"
			return 0
		fi
		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
}

start() {
	config_load ap51-flash
	config_foreach start_daemon flash
}

stop() {
	# Terminating all ap51-flash processes
	echo "WARNING: Going to teminate all ap51-flash processes! (hope you made sure that they're not flashing right now)"
	echo "OR you can stop this with Ctrl+c within 10 seconds"
	sleep 10
	find /var/run/ -name "$NAME.sh-*.pid" -exec start-stop-daemon -K -s TERM -p '{}' -n "$NAME.sh" \; -exec rm -f '{}' \;
	find /var/run/ -name "$NAME.sh-*.pid" -exec start-stop-daemon -K -s TERM -p '{}' -n "$NAME" \; -exec rm -f '{}' \;
}