-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautofan-2.2.2.sh
257 lines (232 loc) · 9.18 KB
/
autofan-2.2.2.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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/bin/bash
##############################################################
## Thank you very much for your support! It's very impotant!##
## ##
## Nicehash donate: 3JKA47P98c9JGCy3GN7qXFC2FzeuJmXuph ##
## Zec donate: t1fP9jWyqFEni2p4i9t3byqtimsMKv1y95T ##
## ETH donate: 0xe835a7d5605a370e4750279b28f9ce0926061ea2 ##
##############################################################
DELAY=30
MIN_SPEED=20
MIN_TEMP=60
MAX_TEMP=70
MIN_COEF=80
MAX_COEF=110
MINER_STOP=0
CRITICAL_TEMP_MINER_STOP=90
PL_LIMIT=1
CRITICAL_TEMP_PL=75
VERSION="2.2.2"
s_name="autofan.sh"
CONF_FILE="/home/user/autofan.conf"
export DISPLAY=:0
red=$(tput setf 4)
green=$(tput setf 2)
reset=$(tput sgr0)
function set_var {
read -p "Enter DELAY (current $DELAY): "
[ ! -z "${REPLY##*[!0-9]*}" ] && DELAY=$REPLY
echo -n -e "${red}DELAY=$DELAY${reset}\n"
read -p "Enter MIN_SPEED (current $MIN_SPEED): "
[ ! -z "${REPLY##*[!0-9]*}" ] && MIN_SPEED=$REPLY
echo -n -e "${red}MIN_SPEED=$MIN_SPEED${reset}\n"
read -p "Enter MIN TEMP (current $MIN_TEMP): "
[ ! -z "${REPLY##*[!0-9]*}" ] && MIN_TEMP=$REPLY
echo -n -e "${red}MIN_TEMP=$MIN_TEMP${reset}\n"
read -p "Enter MAX TEMP (current $MAX_TEMP): "
[ ! -z "${REPLY##*[!0-9]*}" ] && MAX_TEMP=$REPLY
echo -n -e "${red}MAX_TEMP=$MAX_TEMP${reset}\n"
read -p "Enter MIN_COEF (current $MIN_COEF): "
[ ! -z "${REPLY##*[!0-9]*}" ] && MIN_COEF=$REPLY
echo -n -e "${red}MIN_COEF=$MIN_COEF${reset}\n"
read -p "Enter MAX_COEF (current $MAX_COEF): "
[ ! -z "${REPLY##*[!0-9]*}" ] && MAX_COEF=$REPLY
echo -n -e "${red}MAX_COEF=$MAX_COEF${reset}\n"
read -p "Switch on MINER_STOP (1-YES/0-NO, current state $MINER_STOP): "
[ ! -z "${REPLY##*[!0-9]*}" ] && [[ $REPLY < 2 ]] && MINER_STOP=$REPLY
echo -n -e "${red}MINER_STOP=$MINER_STOP${reset}\n"
if [[ $MINER_STOP == 1 ]]; then
read -p "Enter CRITICAL_TEMP_MINER_STOP (current $CRITICAL_TEMP_MINER_STOP): "
[ ! -z "${REPLY##*[!0-9]*}" ] && CRITICAL_TEMP_MINER_STOP=$REPLY
echo -n -e "${red}CRITICAL_TEMP_MINER_STOP=$CRITICAL_TEMP_MINER_STOP${reset}\n"
fi
read -p "Switch on PL_LIMIT (1-YES/0-NO, current state $PL_LIMIT): "
[ ! -z "${REPLY##*[!0-9]*}" ] && [[ $REPLY < 2 ]] && PL_LIMIT=$REPLY
echo -n -e "${red}PL_LIMIT=$PL_LIMIT${reset}\n"
if [[ $PL_LIMIT == 1 ]]; then
read -p "Enter CRITICAL_TEMP_PL (current $CRITICAL_TEMP_PL): "
[ ! -z "${REPLY##*[!0-9]*}" ] && CRITICAL_TEMP_PL=$REPLY
echo -n -e "${red}CRITICAL_TEMP_PL=$CRITICAL_TEMP_PL${reset}\n"
fi
echo "Creating config..."
[ ! -f $CONF_FILE ] && touch $CONF_FILE
echo -n > $CONF_FILE
echo -e "DELAY=$DELAY\nMIN_SPEED=$MIN_SPEED\nMIN_TEMP=$MIN_TEMP\nMAX_TEMP=$MAX_TEMP\nMIN_COEF=$MIN_COEF\nMAX_COEF=$MAX_COEF\nMINER_STOP=$MINER_STOP\nCRITICAL_TEMP_MINER_STOP=$CRITICAL_TEMP_MINER_STOP\nPL_LIMIT=$PL_LIMIT\nCRITICAL_TEMP_PL=$CRITICAL_TEMP_PL" >> /home/user/autofan.conf
echo "${green}[Status]: ${reset}Config created."
}
function check_run {
if [ ! -f "/home/user/xinit.user.sh" ]; then
touch /home/user/xinit.user.sh
chmod +x /home/user/xinit.user.sh
echo -e "#!/bin/bash\nscreen -dmS autofan /home/user/$s_name -r" >> /home/user/xinit.user.sh
echo -n -e "${green}[Status]: ${reset}File xinit.user.sh created.\n"
else
if grep -q "screen -dmS autofan /home/user/$s_name -r" /home/user/xinit.user.sh; then
echo -n -e "${green}[Status]: ${reset}Autorun switched on.\n"
else
echo -e "screen -dmS autofan /home/user/$s_name -r" >> /home/user/xinit.user.sh
echo -n -e "${green}[Status]: ${reset}Autorun created.\n"
fi
fi
}
function safe_mode {
if [[ $1 == 1 ]]; then miner start; echo "${green}[Status]: ${reset} Miner started."
elif [[ $1 == 2 ]]; then miner stop; echo "${red}Critical temperature! Miner STOPPED!${reset}"
fi
}
function clock_limit_mode {
gpu_info=`nvidia-smi --query-gpu=power.min_limit,power.limit --format=csv,noheader,nounits -i $i`
pl_min=`awk -F', ' '{print $1}' <<< $gpu_info`
pl_cur=`awk -F', ' '{print $2}' <<< $gpu_info`
echo "${green}GPU${i}${reset} Minimal possible PL: $pl_min, curent PL: $pl_cur"
new_pl=$(( `sed 's/\.[0-9]*//' <<< $pl_cur`-5 ))
#cur_pl=`sed 's/\.[0-9]*//' <<< $pl_cur`
if [ `sed 's/\.[0-9]*//' <<< $pl_min` -lt $new_pl ]
then
echo "${green}GPU${i}-> ${reset}setting PL to $new_pl"
nvidia-smi -i $i -pl $new_pl > /dev/null
else echo "${red}GPU${i}: ${reset}already done or PL too low."
fi
}
function auto_fan {
CARDS_NUM=`nvidia-smi -L | wc -l`
echo "Found ${CARDS_NUM} GPU(s)"
echo -e -n "${green}Current AUTOFAN settings:${reset}\nDELAY=$DELAY\nMIN_SPEED=$MIN_SPEED\nMIN_TEMP=$MIN_TEMP\nMAX_TEMP=$MAX_TEMP\nMIN_COEF=$MIN_COEF\nMAX_COEF=$MAX_COEF\nMINER_STOP=$MINER_STOP\nCRITICAL_TEMP_MINER_STOP=$CRITICAL_TEMP_MINER_STOP\nPL_LIMIT=$PL_LIMIT\nCRITICAL_TEMP_PL=$CRITICAL_TEMP_PL\n"
sleep 2
while true
do
[[ -e $CONF_FILE ]] && . $CONF_FILE
echo -n -e "${green}$(date +"%d/%m/%y %T")${reset}\n"
for ((i=0; i<$CARDS_NUM; i++))
do
GPU_TEMP=`nvidia-smi -i $i --query-gpu=temperature.gpu --format=csv,noheader`
if [[ $GPU_TEMP -le $MIN_TEMP ]]
then
FAN_SPEED=$(($GPU_TEMP * ($MIN_COEF-($MIN_TEMP - $GPU_TEMP) * 2)/100))
[[ $FAN_SPEED -le $MIN_SPEED ]] && FAN_SPEED=$MIN_SPEED
GPU_TEMP_ALL=`nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader`
GPU_TEMP_ALL=(${GPU_TEMP_ALL//\n/ })
for gpu_count in "${GPU_TEMP_ALL[@]}"
do
[[ "$gpu_count" > $MIN_TEMP ]] && MINER_STOP=0 && break
done
[[ $MINER_STOP == 1 ]] && ! screen -ls | grep -q "miner" && safe_mode 1
MINER_STOP=1
elif [[ $GPU_TEMP > $MIN_TEMP ]] && [[ $GPU_TEMP < $MAX_TEMP ]]
then
FAN_SPEED=$(( $GPU_TEMP *(($GPU_TEMP - $MIN_TEMP) * 4 + $MIN_COEF)/100 ))
elif [[ $GPU_TEMP -ge $MAX_TEMP ]]
then
FAN_SPEED=$(( $GPU_TEMP *(($GPU_TEMP - $MAX_TEMP) * 4 + $MAX_COEF)/100 ))
fi
[[ $GPU_TEMP -ge $CRITICAL_TEMP_MINER_STOP && $MINER_STOP == 1 ]] && safe_mode 2
[[ $GPU_TEMP -ge $CRITICAL_TEMP_PL && $PL_LIMIT == 1 ]] && clock_limit_mode $i
[[ $FAN_SPEED -gt 100 ]] && FAN_SPEED=100
nvidia-settings -a [gpu:$i]/GPUFanControlState=1 -a [fan:$i]/GPUTargetFanSpeed=$FAN_SPEED > /dev/null &
echo "GPU${i} ${GPU_TEMP}°C -> ${FAN_SPEED}%"
done
sleep $DELAY
done
}
function ghost_run {
read -p "Run script in GHOST mode? (y/n) "
if [[ $REPLY = "y" ]] ;then
session_count=`screen -ls autofan | grep autofan | wc -l`
if [[ $session_count > 0 ]]; then
echo -e "${red}AUTOFAN is already running${reset}"
echo -e "Run autofan.sh -c to see the current status"
else
echo "Your choice is ${green}[YES]${reset}."
screen -dmS autofan /home/user/$s_name -r && echo -n -e "${green}[Status]: ${reset}Script started in GHOST mode.\n"
fi
elif [[ $REPLY = "n" ]] ; then
echo "Your choice is ${red}[NO]${reset}."
read -p "Run script in default mode? (y/n) "
if [[ $REPLY = "y" ]] ; then $s_name -r
else echo "Your choice is ${red}[NO]${reset}. See your later.."; exit
fi
else
echo "${red}[FAIL] ${reset} Please, make a choice."
ghost_run
fi
}
function selfupdate {
echo "${green}[Status]:${reset} Checking..."
new_version=`wget -q -O- https://raw.githubusercontent.com/Steambot33/HiveOS-NVIDIA-GPU-autofan-2.0/master/version | head`
if [[ $new_version != $VERSION ]]
then
echo "${green}NEW VERSION $new_version ${reset}"
read -p "Continue update? (y/n)"
if [[ $REPLY = "y" ]]
then
mv autofan.sh autofan.sh.old
if wget -q https://raw.githubusercontent.com/Steambot33/HiveOS-NVIDIA-GPU-autofan-2.0/master/autofan.sh
then
rm autofan.sh.old
chmod +x autofan.sh
echo "${green}[Status]:${reset} The script updated."
echo "${green}[Status]:${reset} Restart script! (autofan.sh -k and autofan.sh -g)"
else
echo "${red}[ FAIL ]{reset}"
mv autofan.sh.old autofan.sh
fi
else echo "Your choice is ${red}[NO]${reset}."
fi
else echo "${green}[Status]:${reset}You use actual version $new_version"
fi
}
[[ -e $CONF_FILE ]] && . $CONF_FILE
case $1 in
-r)
auto_fan
;;
-s)
set_var
;;
-g)
ghost_run
;;
-u)
selfupdate
;;
-c)
if screen -ls | grep -q "autofan"; then
echo "${green}[Status]:${reset} The script is running."
else echo "${green}[Status]:${reset} The script is ${red}NOT${reset} running."
fi
echo -e -n "${green}Current AUTOFAN settings:${reset}\nDELAY=$DELAY\nMIN_SPEED=$MIN_SPEED\nMIN_TEMP=$MIN_TEMP\nMAX_TEMP=$MAX_TEMP\nMIN_COEF=$MIN_COEF\nMAX_COEF=$MAX_COEF\nMINER_STOP=$MINER_STOP\nCRITICAL_TEMP_MINER_STOP=$CRITICAL_TEMP_MINER_STOP\nPL_LIMIT=$PL_LIMIT\nCRITICAL_TEMP_PL=$CRITICAL_TEMP_PL\n"
CARDS_NUM=`nvidia-smi -L | wc -l`
echo "Found ${CARDS_NUM} GPU(s):"
while true
do
echo -n -e "${green}$(date +"%d/%m/%y %T")${reset}\n"
for ((i=0; i<$CARDS_NUM; i++))
do
GPU_TEMP_C=`nvidia-smi -i $i --query-gpu=temperature.gpu --format=csv,noheader`
GPU_FAN_C=`nvidia-smi -i $i --query-gpu=fan.speed --format=csv,noheader`
echo "GPU${i} ${GPU_TEMP_C}°C - ${GPU_FAN_C}"
done
sleep $DELAY
done
;;
-k)
pkill $s_name
;;
*)
echo -n -e "${green}HiveOS autofan script for NVIDIA GPU.${reset} v.${VERSION}\n"
set_var
check_run
ghost_run
;;
esac
exit