--- /dev/null
+#!/bin/bash
+debug=0
+
+Exit(){
+ if ((${debug}));then echo "Restoring default speed and exiting.";fi
+ SetCPUSpeed ${DefaultMaxCPUSpeed}
+ rm /var/run/Temp2Hz.pid
+ exit
+}
+
+GetTemp(){
+ Temp=$(/usr/bin/sensors|sed -n 's/Package id 0: +\(.*\)°C .*/\1/p')
+ if ((${debug}));then echo -n "Current Condition: ${Temp}°C ";fi
+}
+
+CheckTemp(){
+for index in $(echo -e $(echo "${!CPUSpeeds[@]}"|sed 's/ /\\n/g')|sort -r);do
+ if (( $(echo ${Temp}$(echo $index|sed 's/over_/>/;s/under_/</')|bc -l) ));then
+ if [ ${CurMaxCPUSpeed} != ${CPUSpeeds[${index}]} ]; then
+ SetCPUSpeed ${CPUSpeeds[${index}]}
+ fi
+ return
+ fi
+done
+}
+
+GetCurMaxSpeed(){
+CurMaxCPUSpeed=$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq)
+if ((${debug}));then echo "@${CurMaxCPUSpeed}Hz";fi
+}
+
+SetCPUSpeed(){
+ for file in /sys/devices/system/cpu/cpufreq/policy*;do
+ echo $1 > ${file}/scaling_max_freq
+ if ((${debug}));then echo "$1 Requested: ${file}/scaling_max_freq set to $(cat ${file}/scaling_max_freq)";fi
+ done
+}
+
+
+Main(){
+trap Exit SIGINT SIGUSR1
+echo -n $$ >/var/run/Temp2Hz.pid
+GetCurMaxSpeed
+DefaultMaxCPUSpeed=${CurMaxCPUSpeed}
+if ((${debug}));then echo "Default scaling_max_freq recorded as ${DefaultMaxCPUSpeed}";fi
+
+declare -A CPUSpeeds
+
+################ Config Section ################
+CPUSpeeds[over_90]=800000
+CPUSpeeds[over_85]=1300000
+CPUSpeeds[over_70]=1800000
+CPUSpeeds[over_55]=2300000
+CPUSpeeds[over_45]=2800000
+CPUSpeeds[under_45]=${CurMaxCPUSpeed}
+TempPollPeriod=15
+################################################
+
+
+##Main loop
+while GetTemp;do
+ GetCurMaxSpeed
+ CheckTemp
+ a=1;until [ $a -gt ${TempPollPeriod} ] ;do sleep 1;((a++));done
+done
+}
+
+KillMain(){
+ MainPID=$(/bin/cat /var/run/Temp2Hz.pid)
+ if ps -A|awk '{print $1}'|grep -q ${MainPID};then /bin/kill -USR1 ${MainPID};fi
+ for a in {0..5};do if ps -A|awk '{print $1}'|grep -q ${MainPID};then sleep 1;fi;done
+ if ps -A|awk '{print $1}'|grep -q ${MainPID};then echo "Stopping forcefully...";/usr/bin/killall -SIGKILL Temp2Hz.sh;fi
+}
+
+case $1 in
+ start )
+ Main
+ ;;
+ stop )
+ KillMain
+ ;;
+ * )
+ echo "Usage: $0 [start|stop]"
+ ;;
+esac
+