blob: d43ea35051ce5498147c4d58ae5dd43a5b84c36a [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001. /lib/functions.sh
2
3migrate_led_sysfs() {
4 local cfg="$1"; shift
5 local tuples="$@"
6 local sysfs
7 local name
8
9 config_get sysfs ${cfg} sysfs
10 config_get name ${cfg} name
11
12 [ -z "${sysfs}" ] && return
13
14 for tuple in ${tuples}; do
15 local old=${tuple%=*}
16 local new=${tuple#*=}
17 local new_sysfs
18
19 new_sysfs=$(echo ${sysfs} | sed "s/${old}/${new}/")
20
21 [ "${new_sysfs}" = "${sysfs}" ] && continue
22
23 uci set system.${cfg}.sysfs="${new_sysfs}"
24
25 logger -t led-migration "sysfs option of LED \"${name}\" updated to ${new_sysfs}"
26 done;
27}
28
29remove_devicename_led_sysfs() {
30 local cfg="$1"; shift
31 local exceptions="$@"
32 local sysfs
33 local name
34 local new_sysfs
35
36 config_get sysfs ${cfg} sysfs
37 config_get name ${cfg} name
38
39 # only continue if two or more colons are present
40 echo "${sysfs}" | grep -q ":.*:" || return
41
42 for exception in ${exceptions}; do
43 # no change if exceptions provided as argument are found for devicename
44 echo "${sysfs}" | grep -q "^${exception}:" && return
45 done
46
47 new_sysfs=$(echo ${sysfs} | sed "s/^[^:]*://")
48
49 uci set system.${cfg}.sysfs="${new_sysfs}"
50
51 logger -t led-migration "sysfs option of LED \"${name}\" updated to ${new_sysfs}"
52}
53
54migrate_leds() {
55 config_load system
56 config_foreach migrate_led_sysfs led "$@"
57}
58
59remove_devicename_leds() {
60 config_load system
61 config_foreach remove_devicename_led_sysfs led "$@"
62}
63
64migrations_apply() {
65 local realm="$1"
66 [ -n "$(uci changes ${realm})" ] && uci -q commit ${realm}
67}