#!/bin/bash
#
# acpiinfo.sh - Simple script to output some basic ACPI information.
#
# Copyright (C) 2002 Oskar Andreasson
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
# USA



#
# AC Power
#
echo "AC Power"
count=0
for adapter in /proc/acpi/ac_adapter/* ; do
	count=$(($count+1))
	status=`cat $adapter/state | tr -s " " | cut -d " " -f 2`
	echo "AC state:	$status"
done

#
# Battery
#
echo "Battery status"
count=0
for battery in /proc/acpi/battery/* ; do
	count=$(($count+1))
	left=`cat $battery/state |grep "remaining capacity"| tr -s " "|cut -d " " -f 3`
	max=`cat $battery/info |grep "last full capacity"| tr -s " "|cut -d " " -f 4`
	if [ ! $left == "" ] ; then
		percentage=`echo "scale=2; $left/$max" | bc`
		echo "Battery $count: 	$percentage"
	fi
done

#
# Fans status
#
echo "Fan status"
count=0
for fan in /proc/acpi/fan/* ; do
	count=$(($count+1))
	status=`cat $fan/state | grep "status" | tr -s " " | cut -d " " -f 2`
	echo "Fan $count: 		$status"
done

#
# CPU status
#
echo "CPU status"
count=0
for cpu in /proc/acpi/processor/* ; do
	count=$(($count+1))
	getstate=`cat $cpu/throttling |grep "active state" | tr -s " " | cut -d " " -f 3`
	perc=`cat $cpu/throttling | grep "$getstate\:" | tr -s " " | cut -d " " -f 3`
	if [ $perc == "00%" ] ; then
		perc="100%"
	fi
	echo "CPU $count throttling: 	$perc"
	
	perfstate=`cat $cpu/performance | grep "active state" | tr -s " " | cut -d " " -f 3`
	perf=`cat $cpu/performance | grep "$perfstate\:" | tr -s " " | cut -d " " -f 3-`
	echo "CPU $count Performance:	$perf"
done

echo "Thermal status"
count=0
for thermal in /proc/acpi/thermal_zone/* ; do
	count=$(($count+1))
	temperature=`cat $thermal/temperature | grep temperature | tr -s " " | cut -d " " -f 2-`
	echo "Thermometer $count:	$temperature"
done


