base-files: add leds migration
[openwrt/openwrt.git] / package / base-files / files / lib / functions / migrations.sh
1 #!/bin/sh
2
3 . /lib/functions.sh
4
5 migrate_led_sysfs() {
6 local cfg="$1"; shift
7 local tuples="$@"
8 local sysfs
9 local name
10
11 config_get sysfs ${cfg} sysfs
12 config_get name ${cfg} name
13
14 [ -z "${sysfs}" ] && return
15
16 for tuple in ${tuples}; do
17 local old=${tuple%=*}
18 local new=${tuple#*=}
19 local new_sysfs
20
21 new_sysfs=$(echo ${sysfs} | sed "s/${old}/${new}/")
22
23 [ "${new_sysfs}" = "${sysfs}" ] && continue
24
25 uci set system.${cfg}.sysfs="${new_sysfs}"
26
27 logger -t led-migration "sysfs option of LED \"${name}\" updated to ${new_sysfs}"
28 done;
29 }
30
31 migrate_leds() {
32 config_load system
33 config_foreach migrate_led_sysfs led "$@"
34 }
35
36 migrations_apply() {
37 local realm="$1"
38 [ -n "$(uci changes ${realm})" ] && uci -q commit ${realm}
39 }