add uci led support
[openwrt/svn-archive/archive.git] / package / base-files / files / etc / init.d / led
1 #!/bin/sh /etc/rc.common
2 # (C) 2008 openwrt.org
3
4 . /etc/functions.sh
5
6 START=60
7
8 load_led() {
9 local name
10 local sysfs
11 local trigger
12 local dev
13 local mode
14 local default
15
16 config_get name $1 name
17 config_get sysfs $1 sysfs
18 config_get trigger $1 trigger
19 config_get dev $1 dev
20 config_get mode $1 mode
21 config_get default $1 default
22
23 [ -e /sys/class/leds/${sysfs}/brightness -a -n "$name" ] && {
24 logger "setting up led : $name"
25 [ -n "$default" ] && {
26 [ $default -eq 1 ] &&
27 echo 1 >/sys/class/leds/${sysfs}/brightness \
28 || echo 0 >/sys/class/leds/${sysfs}/brightness
29 }
30 [ -z "$trigger" ] && trigger=none
31 echo $trigger > /sys/class/leds/${sysfs}/trigger
32 [ "$trigger" == "netdev" -a -n "$dev" ] && {
33 [ -z "$mode" ] && mode=link
34 echo $dev > /sys/class/leds/${sysfs}/device_name
35 echo $mode > /sys/class/leds/${sysfs}/mode
36 }
37 }
38 }
39
40 start() {
41 [ -e /sys/class/leds/ ] && {
42 config_load system
43 config_foreach load_led led
44 }
45 }