tpfan/tpfan

100 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
if [ -f /etc/tpfan.conf ]
then
. /etc/tpfan.conf
else
echo "This script needs /etc/tpfan.conf to operate."
exit 1
fi
sens(){
temp=$(expr $1 / 1000)
if [ "$temp" -lt "$low" ]
then
export state=low
export color="$cyan"
elif [ "$temp" -lt "$high" ]
then
export state=mid
export color="$green"
elif [ "$temp" -lt "$extreme" ]
then
export state=high
export color="$red"
else
export state=extreme
export color="$red"
fi
show "$temp°C"
}
show(){
if [ -z $quiet ]
then
echo -e "${color}$1${nc}"
fi
}
correct(){
sens $1
case "$state" in
low)
export lv=$slow
show "System determined cool." ;;
mid)
export lv=$med
show "System determined normal." ;;
high)
export lv=$fast
show "System determined hot." ;;
extreme)
export lv=$max
show "System determined in danger." ;;
esac
if [ -z "$mon" ]
then
if [ "$UID" -ne "0" ]
then
export color="$red"
show "Not running as root, no corrective action taken."
elif [ ! -z "$corr" ]
then
echo "level $lv" > /proc/acpi/ibm/fan
show "Fan speed set to $lv."
fi
fi
show "Current fan speed: $(cat $fan) RPM."
}
usage(){
show "A simple fan control script for the ThinkPad x220."
show "Currently available options:"
show "- monitor: Monitor the fan speed and temperature."
show "- correct: Take corrective action on the fan speed."
exit 0
}
case "$1" in
m*) export mon=on ;;
c*) export corr=on ;;
s*) export quiet=on ;;
*) usage ;;
esac
while true
do
clear
for i in $(cat $sens)
do
sens $i
done
export color="$nc"
show ----
avg=$(expr \( $(echo $(cat $sens) | sed "s/\ /\ +\ /g") \) / ${#arr[@]})
correct $avg
sleep $slp
done