-
Notifications
You must be signed in to change notification settings - Fork 0
/
cm3-lite.sh
executable file
·97 lines (79 loc) · 1.43 KB
/
cm3-lite.sh
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
AUTHOR='Akgnah <[email protected]>'
VERSION='0.10'
#
# taco-fan install script
#
cat > /usr/bin/taco-cm3-lite.sh << \EOF
#!/bin/bash
AUTHOR='Akgnah <[email protected]>'
VERSION='0.10'
#
# Taco cm3 fan
#
BASE_PATH=/sys/class/gpio
TEMP_FILE=/sys/class/thermal/thermal_zone0/temp
FAN=22
LOW=0
HIGH=1
export_pin() {
if [[ ! -e $BASE_PATH/gpio$1 ]]; then
echo "$1" > $BASE_PATH/export
fi
}
unexport_pin() {
if [[ -e $BASE_PATH/gpio$1 ]]; then
echo "$1" > $BASE_PATH/unexport
fi
}
set_mode() {
export_pin $1
echo "out" > $BASE_PATH/gpio$1/direction
echo "$2" > $BASE_PATH/gpio$1/value
if [[ "$3" == "clean" ]]; then
unexport_pin $1
fi
}
turn_on() {
set_mode $FAN $HIGH
}
turn_off() {
set_mode $FAN $LOW clean
}
trap turn_off SIGINT
function get_temp() {
if [[ "$(cat $TEMP_FILE)" -gt "50000" ]]; then
turn_on
else
turn_off
fi
}
if [[ $1 == "on" ]]; then
turn_on
else
turn_off
exit 0
fi
for (( ; ; ))
do
sleep 30s
get_temp
done
exit 0
EOF
chmod +x /usr/bin/taco-cm3-lite.sh
cat > /lib/systemd/system/taco-cm3-lite.service << EOF
[Unit]
Description=Taco cm3 fan
[Service]
ExecStart=/usr/bin/taco-cm3-lite.sh on
ExecStop=/usr/bin/taco-cm3-lite.sh off
Type=simple
[Install]
WantedBy=multi-user.target
EOF
systemctl enable taco-cm3-lite.service
if [ -d /run/systemd/system ]; then
systemctl --system daemon-reload > /dev/null || true
fi
systemctl start taco-cm3-lite.service > /dev/null