base-files: add a generic wps button handler
[librecmc/librecmc.git] / target / linux / lantiq / base-files / etc / hotplug.d / button / 10-generic.sh
1 #!/bin/sh
2
3 [ "${ACTION}" = "released" ] || exit 0
4
5 . /lib/functions.sh
6
7 logger "$BUTTON pressed for $SEEN seconds"
8
9 local rfkill_state=0
10
11 wifi_rfkill_set() {
12         uci set wireless.$1.disabled=$rfkill_state
13 }
14
15 wifi_rfkill_check() {
16         local disabled
17         config_get disabled $1 disabled
18         [ "$disabled" = "1" ] || rfkill_state=1
19 }
20
21 case "${BUTTON}" in
22         reset)
23                 if [ "$SEEN" -lt 1 ]
24                 then
25                         echo "REBOOT" > /dev/console
26                         sync
27                         reboot
28                 elif [ "$SEEN" -gt 5 ]
29                 then
30                         echo "FACTORY RESET" > /dev/console
31                         firstboot && reboot &
32                 fi
33                 ;;
34
35         wps)
36                 for dir in /var/run/hostapd-*; do
37                         [ -d "$dir" ] || continue
38                         hostapd_cli -p "$dir" wps_pbc
39                 done
40                 ;;
41
42         rfkill)
43                 config_load wireless
44                 config_foreach wifi_rfkill_check wifi-device
45                 config_foreach wifi_rfkill_set wifi-device
46                 uci commit wireless
47                 wifi up
48                 ;;
49
50         *)
51                 logger "unknown button ${BUTTON}"
52                 ;;
53 esac