-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfanctrl
executable file
·137 lines (127 loc) · 3.48 KB
/
fanctrl
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
# Description: Fan Control
# Destination: /usr/local/bin/fanctrl
if [[ -f "/etc/opt/board.txt" ]]; then
. /etc/opt/board.txt
else
echo -e "Your board is not supported."
exit 0
fi
if [[ "$USER" == "root" ]]; then
:;
else
if [[ `command -v sudo` ]]; then
if [[ $EUID -ne 0 ]]; then
sudo "$0" "$@"
exit
fi
else
echo "Please run this as root or with sudo privileges."
exit 0
fi
fi
if [[ -f "/etc/default/fanctrl" ]]; then
. /etc/default/fanctrl
else
echo 'POINT="55000"' | tee /etc/default/fanctrl
sleep .25
. /etc/default/fanctrl
fi
warning (){
WARNING_MSG="Argument is not supported."
echo -e "$WARNING_MSG"
exit 0
}
check (){
if [[ "$BOARD" == "bananapicm4" ]]; then
X=`echo $POINT | sed 's/...$//'`
Y="5"
echo -e "Current trip points: ${POINT}, $(($X+$Y))000"
else
echo -e "Current trip point: $POINT"
fi
}
run (){ # run script
if [[ "$BOARD" == "bananapicm4" ]]; then
if [[ -f "/sys/devices/virtual/thermal/thermal_zone0/trip_point_3_temp" ]]; then
echo "$POINT" | tee /sys/devices/virtual/thermal/thermal_zone0/trip_point_3_temp
if [[ -f "/sys/devices/virtual/thermal/thermal_zone0/trip_point_4_temp" ]]; then
X=`echo $POINT | sed 's/...$//'`
Y="5"
echo "$(($X+$Y))000" | tee /sys/devices/virtual/thermal/thermal_zone0/trip_point_4_temp
fi
else
echo -e "Trip point missing."
exit 0
fi
fi
if [[ "$BOARD" == "odroidn2l" || "$BOARD" == "odroidn2plus" ]]; then
if [[ -f "/sys/devices/virtual/thermal/thermal_zone0/trip_point_3_temp" ]]; then
echo "$POINT" | tee /sys/devices/virtual/thermal/thermal_zone0/trip_point_3_temp
else
echo -e "Trip point missing."
exit 0
fi
fi
if [[ "$BOARD" == "odroidxu4" ]]; then
TZONE0="/sys/devices/virtual/thermal/thermal_zone0/trip_point_0_temp"
TZONE1="/sys/devices/virtual/thermal/thermal_zone1/trip_point_0_temp"
TZONE2="/sys/devices/virtual/thermal/thermal_zone2/trip_point_0_temp"
TZONE3="/sys/devices/virtual/thermal/thermal_zone3/trip_point_0_temp"
TZONE4="/sys/devices/virtual/thermal/thermal_zone4/trip_point_0_temp"
if [[ -f "$TZONE0" ]] && [[ -f "$TZONE1" ]] && [[ -f "$TZONE2" ]] && [[ -f "$TZONE3" ]] && [[ -f "$TZONE4" ]]; then
echo "$POINT" | tee /sys/devices/virtual/thermal/thermal_zone{0,1,2,3,4}/trip_point_0_temp
sleep .50
# tap trip points twice
echo "$POINT" | tee /sys/devices/virtual/thermal/thermal_zone{0,1,2,3,4}/trip_point_0_temp > /dev/null 2>&1
else
echo -e "Trip point missing."
exit 0
fi
fi
}
temperature (){
echo 'POINT="'"${X}000"'"' | tee /etc/default/fanctrl > /dev/null 2>&1
source /etc/default/fanctrl
sleep .25
fanctrl run
}
update (){
if [[ `curl -I https://github.com 2>&1 | grep 'HTTP/2 200'` ]]; then
echo -en "Updating fanctrl script"
if [[ `command -v fanctrl` ]]; then
mv -f /usr/local/bin/fanctrl /usr/local/bin/fanctrl.orig
fi
wget -cq https://raw.githubusercontent.com/pyavitz/scripts/master/fanctrl -P /usr/local/bin
chmod +x $(command -v fanctrl)
if [[ `command -v fanctrl` ]]; then
echo -e " [done]"
rm -f /usr/local/bin/fanctrl.orig
else
echo -e " [fail]"
mv -f /usr/local/bin/fanctrl.orig /usr/local/bin/fanctrl
fi
fanctrl
else
echo -e "This script requires an internet connection to update."
exit 0
fi
}
if [ $# -eq 0 ]; then
>&2 echo -e "Arguments: 65 60 55 50 45 40 35 30 25 check run update"
exit 1
fi
case $1 in
65|60|55|50|45|40|35|30|25|check|run|update)
;;
*)
echo -e "Arguments: 65 60 55 50 45 40 35 30 25 check run update" >&2
exit 1
esac
FANCTRL=`echo $1`
$FANCTRL 2>/dev/null
if [[ "$1" =~ ^[0-9]+$ ]]; then
X="$1"
temperature
fi
exit 0