ee64ca2c5891ba6b546ef7856f090f54c7b72a0e
[openwrt/svn-archive/archive.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 wndr3700)
50 migrate_leds "wndr3700:=netgear:"
51 ;;
52
53 wnr2000)
54 migrate_leds "wnr2000:=netgear:"
55 ;;
56
57 *)
58 ;;
59 esac
60
61 [ "$LED_OPTIONS_CHANGED" == "1" ] && uci commit system
62
63 exit 0