#!/bin/sh

lsmod | grep -q -e "k.temp"
if [ $? -ne 0 ]; then
  modprobe coretemp   # CHANGE THE MODULE IF NEEDED
fi

sensors -A  | tr -s " " > /tmp/CPUtemp.txt

THRMFILE="/sys/class/thermal/thermal_zone0/temp"
if [ -e $THRMFILE ]; then
  TEMP=`cat $THRMFILE`
  TEMP=${TEMP%???}
  echo "THRM Temp: " $TEMP C >> /tmp/CPUtemp.txt
  echo >> /tmp/CPUtemp.txt
fi

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor | grep -q ondemand
if [ $? -eq 0 ]; then
  echo -n "OnDemand CPU Scaling: on" >> /tmp/CPUtemp.txt
else
  echo -n "OnDemand CPU Scaling: off" >> /tmp/CPUtemp.txt 
fi

FREQ=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq`
if [ -n "$FREQ" ]; then
  echo >> /tmp/CPUtemp.txt
  echo -n "Current CPU Frequency: " >> /tmp/CPUtemp.txt
  echo -n ${FREQ%???} MHz >> /tmp/CPUtemp.txt
fi

export DIALOG='
<window title=" ">
<vbox>
  <frame CPUtemp>
    <text><input file>/tmp/CPUtemp.txt</input></text>
  </frame>
  <hbox>
    <button><label>OK</label></button>
    <button><label>Help</label></button>
  </hbox>
</vbox>
</window>'
  
I=$IFS; IFS=""
for STATEMENTS in  $(gtkdialog3 --program DIALOG); do
  eval $STATEMENTS
done
IFS=$I

[ "$EXIT" = "OK" ] && exit

export DIALOG='
<window title=" ">
<vbox>
  <frame CPUtemp>
    <text><input file>/usr/local/bin/CPUtemp.hlp</input></text>
  </frame>
  <hbox>
    <button><label>OK</label></button>
  </hbox>
</vbox>
</window>'
  
I=$IFS; IFS=""
for STATEMENTS in  $(gtkdialog3 --program DIALOG); do
  eval $STATEMENTS
done
IFS=$I
