summaryrefslogtreecommitdiff
path: root/packages/slugos-init/files/initscripts/zleds
blob: b6d2f1600b88146665f85a71f90a6bdfcdafb6eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/sh
#
# This script is executed at the start and end of each run-level
# transition.  It is the first 'stop' script and the last 'start'
# script.
#
# 'stop'  sets the correct colour power LED to flash between the
#         two colours of the previous and next runlevel.
# 'start' sets the LED to steady
#
# The 'ready' led is used for the indication of state, except that
# if a 'status' led is used ready+status is set in place of !ready.
#
# For NSLU2:
#
# 'amber' is used for run levels S (from /linuxrc), 0 (halt),
#         1 (single user) and 6 (reboot).  halt and reboot do not
#         terminate therefore the LED remains flashing until the
#         kernel terminates.
#
# 'green' is used for run levels 2-5 - the normal user run levels.
#
# state outputs 's' (for 'system') or 'u' (for user) to distinguish
# the required colours.
#
# NOTE: this will change
state(){
	case "$1" in
	S|0|1|6) echo s;;
	2|3|4|5) echo u;;
	N)       echo s;;
	*)       echo "led change: $runlevel: runlevel unknown" >&2
		 echo s;;
	esac
}

# Make the named LED do something
flash(){
	echo timer >/sys/class/leds/"$1"/trigger
	echo 200 >/sys/class/leds/"$1"/frequency
}
on(){
	echo none >/sys/class/leds/"$1"/trigger
	echo 100 >/sys/class/leds/"$1"/brightness
}
off(){
	echo none >/sys/class/leds/"$1"/trigger
	echo 0 >/sys/class/leds/"$1"/brightness
}

test -d /sys/class/leds/ready && case "$1" in
start)	if test -d /sys/class/leds/status
	then
		case "$(state "$runlevel")" in
		s)	on status
			on ready;;
		u)	off status
			on ready;;
		esac
	else
		on ready
	fi;;
stop)	if test -d /sys/class/leds/status
	then
		case "$(state "$previous")$(state "$runlevel")" in
		ss)	flash status
			flash ready;;
		su|us)	flash status
			on ready;;
		uu)	off status
			flash ready;;
		esac
	else
		flash ready
	fi;;
*)	echo "led change: $1: command ignored" >&2;;
esac

exit 0