luci-mod-system: flash.js: fix mtdname on download
[project/luci.git] / modules / luci-base / root / etc / init.d / ucitrack
1 #!/bin/sh /etc/rc.common
2
3 START=80
4 USE_PROCD=1
5
6 . "$IPKG_INSTROOT/usr/share/libubox/jshn.sh"
7
8 register_init() {
9 local config="$1"
10 local init="$2"
11 shift; shift
12
13 if [ -x "$init" ] && "$init" enabled && ! grep -sqE 'USE_PROCD=.' "$init"; then
14 logger -t "ucitrack" "Setting up /etc/config/$config reload trigger for non-procd $init"
15 procd_add_config_trigger "config.change" "$config" "$init" "$@"
16 fi
17 }
18
19 register_trigger() {
20 local file="$1"
21
22 local config init exec affects affected
23 local prev
24
25 json_set_namespace config prev
26 json_init
27 json_load_file "${file}" >/dev/null 2>&1
28 json_get_var config 'config'
29 json_get_var init 'init'
30 json_get_var exec 'exec'
31 json_get_values affects 'affects'
32 json_cleanup
33 json_set_namespace "$prev"
34
35 if [ -n "$init" ]; then
36 register_init "$config" "/etc/init.d/$init" "reload"
37 fi
38
39 if [ -n "$exec" ]; then
40 case "$exec" in
41 /etc/init.d/*)
42 set -- $exec
43 register_init "$config" "$@"
44 ;;
45 *)
46 logger -t "ucitrack" "Setting up non-init /etc/config/$config reload handler: $exec"
47 procd_add_config_trigger "config.change" "$config" $exec
48 ;;
49 esac
50 fi
51
52 for affected in $affects; do
53 logger -t "ucitrack" "Setting up /etc/config/$affected reload dependency on /etc/config/$config"
54 procd_add_config_trigger "config.change" "$config" \
55 ubus call service event \
56 "$(printf '{"type":"config.change","data":{"package":"%s"}}' $affected)"
57 done
58 }
59
60 service_triggers() {
61 local config="$1"
62
63 local file
64
65 for file in /usr/share/ucitrack/*.json; do
66 [ -f "$file" ] || continue
67 register_trigger "$file"
68 done
69 }