c59e155eccdba0d52535ad94a762fc28b1cd4889
[librewrt/.git] / apply-hotspot.sh
1 #!/bin/sh
2 #
3 # Hotspot apply handler.
4
5 reload_hotspot() {
6         echo '@TR<<Exporting>> @TR<<hotspot settings>> ...'
7         [ -e /bin/save_hotspot ] && {
8                 /bin/save_hotspot >&- 2>&-
9         }
10         (
11         config_cb() {
12                 [ "$1" = "chillispot" ] && service_cfg="$2"
13         }
14         config_load "hotspot"
15         config_get_bool test "$service_cfg" enable 0
16         chilli_init="/etc/init.d/chilli"
17         [ -e $chilli_init ] && {
18                 if [ "1" = "$test" ]; then
19                         echo '@TR<<Reloading>> @TR<<hotspot settings>> ...'
20                         $chilli_init enable >&- 2>&-
21                         $chilli_init stop  >&- 2>&-
22                         $chilli_init start >&- 2>&-
23                 else
24                         echo '@TR<<Stopping>> @TR<<hotspot>> ...'
25                         $chilli_init stop  >&- 2>&-
26                         $chilli_init disable >&- 2>&-
27                 fi
28         }
29         )
30 }
31
32 [ -f /tmp/.uci/hotspot ] && {
33         # save settings
34         echo "@TR<<Committing>> $package ..."
35         uci_commit "hotspot"
36         reload_hotspot
37         # and do not save it twice
38         rm -f /tmp/.uci/hotspot 2>/dev/null
39 }