IBM T30 ACPID event handler script

Sunday, 08/02/2009 ≅20:14 ©brainycat
#!/bin/bash

# cat@brainycat.com
# Wed Jan 28 08:08:47 PST 2009

# event handlers for IBM T30 and related laptops.
# volume, brightness, status LEDs and keyboard illumination already supported
# borrowed heavily from http://www.thinkwiki.org/wiki/How_to_configure_acpid

case "$4" in
  00001003)
	#logger "found hotkey FN+F3"
	# turn the LCD on/off
	monitorStatus=`xset -display :0.0 -q | grep 'Monitor'`
	if [ "$monitorStatus" == "  Monitor is On" ]
	  then
  	    # Wed Jan 28 12:43:44 PST 2009
	    # it's responding to FN+F3 to turn light off, but it won't turn back on unless you change virtual terms. This is from X or terminal. Logs do not show the turn on event. WTF?!?!?!
	    # After rebooting, it's not responding to FN+F3 at all. Logs show the event is being treated as "light on" again. WTF?!?!?!
	    logger "light off"
	    /usr/sbin/radeontool light off
	  else
	    logger "light on"
	    /usr/sbin/radeontool light on
	fi
    ;;
  00001004)
	#logger "found hotkey FN+F4"
	# suspend the OS to RAM
	# both the blackjack USB modem and Option GTMax were unable to logon to network after this. Appropriate /devs existed.
	/sbin/rmmod uhci_hcd
	/sbin/sync
	/sbin/hwclock
	FGCONSOLE=`fgconsole`
	chvt 6
	/usr/sbin/radeontool light off
	killall kppp
	sleep 5 && echo -n "mem" > /sys/power/state
	# OS is on RAM at this point
	# following commands will be run upon restoration
	/sbin/hwclock --adjust
	/sbin/hwclock --hctosys
	modprobe uhci_hcd
	radeontool light on
	chvt $FGCONSOLE
    ;;
  00001007)
	#logger "found hotkey FN+F7"
	/usr/bin/xrandr --output VGA 0 --auto
    ;;
  0000100c)
	#logger "found hotkey FN+F12"
	# suspend the OS to DISK
	/sbin/rmmod uhci_hcd
	/sbin/sync
	/sbin/hwclock
	FGCONSOLE=`fgconsole`
	chvt 6
	/usr/sbin/radeontool light off
	killall kppp
	sleep 5 && echo -n "disk" > /sys/power/state
	# OS is on RAM at this point
	# following commands will be run upon restoration
	/sbin/hwclock --adjust
	/sbin/hwclock --hctosys
	modprobe uhci_hcd
	radeontool light on
	chvt $FGCONSOLE
    ;;
  00001014)
	#logger "found hotkey FN+SPACE"
    ;;
  00001018)
	#logger "found hotkey THINKPAD"
	# SVideo out?? xrandr
    ;;
  *)
    logger "ACPI group $1 / action $2 is not defined"
    ;;
esac