3687c2d5b47a59b1abcb605909777170a6b4e21a
[openwrt/openwrt.git] / target / linux / ar71xx / base-files / etc / uci-defaults / 04_led_migration
1 #!/bin/sh
2 #
3 # Copyright (C) 2013 OpenWrt.org
4 #
5
6 LED_OPTIONS_CHANGED=0
7
8 . /lib/functions.sh
9
10 do_led_update_sysfs()
11 {
12 local cfg=$1; shift
13 local tuples="$@"
14 local sysfs
15 local name
16
17 config_get sysfs $cfg sysfs
18 config_get name $cfg name
19
20 [ -z "$sysfs" ] && return
21
22 for tuple in $tuples; do
23 local old=${tuple%=*}
24 local new=${tuple#*=}
25 local new_sysfs
26
27 new_sysfs=$(echo ${sysfs} | sed "s/${old}/${new}/")
28
29 [ "${new_sysfs}" == "${sysfs}" ] && continue
30
31 uci set system.${cfg}.sysfs="${new_sysfs}"
32 LED_OPTIONS_CHANGED=1
33
34 logger -t led-migration "sysfs option of LED \"${name}\" updated to ${new_sysfs}"
35 done;
36 }
37
38 migrate_leds()
39 {
40 config_load system
41 config_foreach do_led_update_sysfs led "$@"
42 }
43
44 . /lib/ar71xx.sh
45
46 board=$(ar71xx_board_name)
47
48 case "$board" in
49 *)
50 ;;
51 esac
52
53 [ "$LED_OPTIONS_CHANGED" == "1" ] && uci commit system
54
55 exit 0