4 # utilities to manipulate the settings of the system leds
6 # load the utility functions unless this script is being called
7 # just to load its own functions.
11 . /etc/default/functions;;
15 # led_set led-dir off|on|slow|fast|panic|blink|flash|*
16 # set the given LED (expressed as a directory) to the
21 # expect led-dir state
31 esac >"$1/brightness";;
33 slow|fast|panic|blink|flash)
50 esac >"$1/delay_off";;
52 *) echo -n "$setting";;
55 echo "leds: $1: no such directory" >&2
61 # sysled [boot] system|user|singleuser|shutdown [error|panic|*]
62 # set the system LEDs to indicate the given boot state, the function
63 # will temporarily mount sysfs is necessary (using /mnt)
65 # the cases for two LEDs (ready+status)
68 # expect dir [boot](system|user) [error|panic]
70 error) ready=fast; status=off;;
71 panic) ready=fast; status=fast;;
73 bootsystem) ready=slow; status=slow;;
74 system) ready=on; status=on;;
75 bootuser) ready=on; status=slow;;
76 user) ready=user; status=off;;
77 bootsingleuser) ready=on; status=slow;;
78 singleuser) ready=user; status=user;;
79 bootshutdown) ready=on; status=slow;;
80 shutdown) ready=slow; status=on;;
84 led_set "$1/$ready_led_name" "$ready"
85 led_set "$1/$status_led_name" "$status"
88 # the cases for one LED (just ready)
91 # expect dir [boot](system|user) [error|panic]
96 bootsystem) ready=flash;;
98 bootuser) ready=slow;;
100 bootsingleuser) ready=flash;;
101 singleuser) ready=blink;;
102 bootshutdown) ready=slow;;
103 shutdown) ready=blink;;
107 led_set "$1/$ready_led_name" "$ready"
110 # the cases for one blue flashing LED (just power)
113 # expect dir [boot](system|user) [error|panic]
118 bootsystem) power=off;; # blinking
119 system) power=off;; # blinking
122 bootsingleuser) power=off;; # blinking
123 singleuser) power=off;; # blinking
124 bootshutdown) power=off;; # blinking
125 shutdown) power=off;; # blinking
129 led_set "$1/$power_led_name" "$power"
133 local mp st boot isst
145 system|user|singleuser|shutdown) :;;
146 *) echo "sysled: unknown option '$1'" >&2
147 echo " usage: sysled [boot] system|user|singleuser|shutdown [error|panic|*]" >&2
151 if test ! -d "$mp/class/leds" && mount -t sysfs sysfs /mnt
156 # check for the 'ready' LED - otherwise check for a 'power' LED
157 if test -d "$mp/class/leds/$ready_led_name"
159 if test -d "$mp/class/leds/$status_led_name"
161 sysled_readystatus "$mp/class/leds" $boot"$@"
163 sysled_ready "$mp/class/leds" $boot"$@"
166 if test -d "$mp/class/leds/$power_led_name"
168 sysled_power "$mp/class/leds" $boot"$@"
173 test "$mp" = /mnt && umount /mnt
180 # does nothing if there is no beep executable, is very
181 # quiet in the presence of errors
183 local arg devices module
185 test "$1" = beep && shift
188 devices=`ls -d /sys/class/input/event*`
189 for device in $devices
191 module=`egrep PHYSDEVDRIVER $device'/uevent' | cut -d '=' -f 2`
192 if test "$module" = "ixp4xx-beeper";
194 devnode=`echo "$device" | cut -d '/' -f 5`
195 arg="-e /dev/input/"$devnode
199 /bin/beep $arg "$@" 2>/dev/null
207 # leds <led> off|on|slow|fast|panic|blink|flash|user|*
208 # leds [boot] system|user|singleuser|shutdown [error|panic|*]
210 echo "leds: change the setting of the LEDs" >&2
212 echo " leds [boot] system|user|singleuser|shutdown [error|panic|*]" >&2
213 echo " set leds during system boot to indicate a particular boot" >&2
214 echo " state. 'boot' means that the system is transitioning to" >&2
215 echo " the new state. 'error' or 'panic' means a (potentially)" >&2
216 echo " recoverable error or an unrecoverable error ('panic') has" >&2
218 echo " <led> off|on|slow|fast|panic|blink|flash" >&2
219 echo " set the named led to the given display." >&2
220 echo " beep {args}" >&2
221 echo " if possible cause the machine to emit a beep" >&2
224 # Define the LED names based on kernel version.
225 version=$(uname -r | cut -c -6)
226 if [ "$version" \< "2.6.25" ]; then
227 status_led_name="status"
228 ready_led_name="ready"
229 power_led_name="power"
233 status_led_name="none"
234 ready_led_name="none"
235 power_led_name="dsmg600:green:power"
238 status_led_name="none"
239 ready_led_name="fsg:blue:sync"
240 power_led_name="none"
243 status_led_name="none"
244 ready_led_name="none"
245 power_led_name="nas100d:blue:power"
248 status_led_name="nslu2:red:status"
249 ready_led_name="nslu2:green:ready"
250 power_led_name="none"
255 # the real command, if required
257 boot|system|user|singleuser|shutdown)
265 leds) # just load the functions
268 *) led_set /sys/class/leds/"$@"