#!/bin/bash
#
# TP Probe v.0.2 alpha
# by 31d1 2005
djbidi@gmail.com
#
# displays (somewhat accurate) hardware sensor readouts on some current macs.
#
# seems to work on new Powerbooks, ibooks, and PowerMacs
# does NOT seems to work on G4 Powermacs, or G4 Titanium Powerbooks
# help
if [ "$1" == "-h" ]
then
basename=`echo $0 | sed 's/.*\///'`
echo "usage: $basename [option|regex]"
echo " regex - display only matching lines"
echo " -h - display this message"
exit
fi
# get data
sensors=`ioreg -n IOHWSensor | awk '/location/ || /current-value/ || /"type"/' | sed -e 's/[^"]*"//' -e 's/" =//' -e 's/location//' -e 's/type//' -e 's/"//g' | awk '{ if ((NR % 3) == 0) print $0; else printf $0 " " }'`
# temperatures require strange manipulation
temps=`echo "$sensors" | grep 'temperature' | awk '{ for(i=1;i<5;i++) if ($i=="current-value") $(i+1)=((( (($(i+1) / 2^13) - ($(i+1) / 2^13) % 1 ) / 2^3) - .5)" C\t"); print $0 }' | sed -e 's/current-value //' -e 's/temperature//'`
# the rest merely need to be divided by 2^16
therest=`echo "$sensors" | grep -v 'temperature' | awk '{ for(i=1;i<5;i++) if ($i=="current-value") $(i+1)=(substr((($(i+1)/2^16)"\t"),1,8)); print $0 }' | sed -e 's/current-value //'`
# optionally display Machine Name and Type
if [ "$1" == "-l" ]
then
system_profiler SPHardwareDataType | awk '/Machine Name/ || /Machine Model/ || /CPU Type/' | sed 's/[^:]*: //' | awk '{printf $0 " " }'
machine
echo -e "\n$temps\n$therest"
exit
fi
# grep for $1 or display all
if [ "$1" ]
then
echo -e "$temps\n$therest" | grep "$*"
else
echo -e "$temps\n$therest"
fi