-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththermal.sh
More file actions
executable file
·48 lines (37 loc) · 1.18 KB
/
Copy paththermal.sh
File metadata and controls
executable file
·48 lines (37 loc) · 1.18 KB
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
#!/usr/bin/env bash
alertLevel="$1"
# load in defaults from config
scriptRoot=$(dirname "$0")
configFile="$scriptRoot/config.sh"
if [[ -f "$configFile" ]]; then
source "$configFile"
if [[ -z "$alertLevel" ]]; then
alertLevel="$THERMAL_ALERT"
fi
fi
# loop over all thermal zones
while read -r mcFile; do
# we need something to work with
if [[ -z "$mcFile" ]]; then
continue;
fi
# each zone has two files we use:
# "./temp" <int> zone temp (milli-celsius)
# "./type" <string> zone title
titleFile=$(echo "$mcFile" | sed 's/temp/type/')
title=$( < "$titleFile")
mc=$( < "$mcFile")
# calculate Celcius and Fahrenheit
c=$(echo "scale=1 ; $mc / 1000.0" | bc -l)
f=$(echo "scale=1 ; $c * 9 / 5 + 32" | bc -l)
hot=$(echo "$c >= $alertLevel" | bc -l)
echo "$title: $c C ($f F)"
# if we have reached our alert threshold, mark it as active
if [[ -n "$alertLevel" ]] && [[ "$hot" -gt 0 ]]; then
alertActive=1
fi
done <<< $(find /sys/class/thermal/*/* -path '*/thermal_*' -name 'temp')
# we exit with a status code of 1 to indicate alert level has been reached
if [[ "$alertActive" -eq 1 ]]; then
exit 1
fi