-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathledctl
57 lines (37 loc) · 1.41 KB
/
ledctl
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
#!/bin/sh
leds=$(ls /sys/class/leds) # Find avaliable leds
################################################
if [ "$1" = -l ]; then #Check for list command.
echo $leds
exit 1
fi
################################################
if [ -z $1 ]; then #Check if user inputted any led data.
echo "Please select LED. To see all avaliable LEDs run: ledctl -l"
exit 1
fi
################################################
if [ -z $2 ]; then #Check if state exists
echo "Please choose state: on or off."
exit 1
fi
################################################
if [ -e /sys/class/leds/$1 ]; then #Check if spcified led exists.
echo 'Led exists.'
if [ "$2" == 'on' ] && [ -e /sys/class/leds/$1 ]; then #Check if args are valid and write data
ledstate=1
echo $ledstate >/sys/class/leds/$1/brightness
echo "Set "$1" state to "$2"."
elif [ "$2" == 'off' ] && [ -e /sys/class/leds/$1 ]; then #Check if args are valid and write data
ledstate=0
echo $ledstate >/sys/class/leds/$1/brightness
echo "Set "$1" state to "$2"."
else
echo "Please choose state: on or off."
exit 1
fi
else
echo 'Led selection is invalid. Run ledcontrol -l to see avaliable leds.'
exit 1
fi
################################################