#!/bin/sh
# Default acpi script that takes an entry for all actions

set $*

group=${1/\/*/}
action=${1/*\//}
STATE=`cat /proc/acpi/ac_adapter/ADP1/state |awk {'print $2'}`
LID=`cat /proc/acpi/button/lid/LID0/state |awk {'print $2'}` 	

case "$group" in
	button)
		case "$action" in
			power)	logger "ACPI action $action started"
				/sbin/init 0
				;;
			sleep)	logger "ACPI action $action started"
				#ifconfig eth0 down
				echo 4 > /proc/acpi/sleep
				;;
			lid)	logger "ACPI action ${action} $LID"
				if [ $STATE == "off-line" ]; then
					if [ $LID == "closed" ]; then
						/usr/bin/setterm -blank 1 -powersave on -powerdown 2
					else
						/usr/bin/setterm -blank 2 -powersave on -powerdown 4
					fi

				fi
				;;
			*)	logger "ACPI action $action is not defined"
				;;
		esac
		;;
	ac_adapter)
		case "$action" in
			ac_adapter) logger "ACPI action $action $STATE"
				if [ $STATE == "off-line" ]; then
					/root/bin/laptop-mode.sh start
					logger "ACPI action ${action}: laptop-mode started"
				else
					/root/bin/laptop-mode.sh stop
					logger "ACPI action ${action}: laptop-mode stopped"
				fi
				;;
			*)	logger "ACPI action $action is not defined"
				;;
		esac
		;;
	battery)
		case "$action" in
			battery) logger "ACPI action $action started"
				BAT=`acpi |awk {'print $4'} |sed -e "s/%,//g"`
				if [ $BAT -le 4 ] && [ "$STATE" != "on-line" ]; then
					logger "ACPI action $action: batery low"
					#ifconfig eth0 down
					echo 4 > /proc/acpi/sleep
				fi
				;;
			*)	logger "ACPI action $action is not defined"
				;;
		esac
		;;
	*)
		logger "ACPI group $group / action $action is not defined"
		;;
esac
