#!/bin/bash # # /etc/acpi/action.sh (2004.01.17) # called by acpid for all events # Christopher Knoerle # Tomasz Sterna for Compaq TC1000 # # This works with gentoo-sources, ac-sources, mm-sources on my # HP Compaq nx9000 Laptop. For more information have a look at # http://cknoerle.homelinux.org/nx9000/ # The latest version is available from # http://cknoerle.homelinux.org/nx9000/stuff/acpi/ # This should be placed in /etc/acpi/action.sh and should be called by acpid. # To make this happen you need the acpid installed and running. # acpid can be obtained from http://acpid.sourceforge.net # For this to work you need only one event handler in /etc/acpi/event # It should contain something like the following: # # event=.* # action=/etc/acpi/action.sh %e # Modified to work on my Compaq TC1000 # For more information see # let's set some paths LOGGER="/usr/bin/logger -t acpid" # logs to syslog - an echo logs to /var/log/acpid XGAMMA="/usr/X11R6/bin/xgamma" XSET="/usr/X11R6/bin/xset" HDPARM="/sbin/hdparm" LONGRUN="/usr/sbin/longrun" SCALING_GOVERNOR="/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" BATTERY="CMB0" AC_ADAPTER="AC" BAT_STATE="/proc/acpi/battery/$BATTERY/state" BAT_INFO="/proc/acpi/battery/$BATTERY/info" BAT_ALARM="/proc/acpi/battery/$BATTERY/alarm" BAT_ALR=`awk '/warning/ { print $4 }' $BAT_INFO 2>/dev/null || echo "300"` BAT_LOW=`awk '/low/ { print $4 }' $BAT_INFO 2>/dev/null || echo "150"` AC_STATE="/proc/acpi/ac_adapter/$AC_ADAPTER/state" # if we didn't know about an event # log to /var/log/acpid to do something like 'grep #### /var/log/acpid' :-) no_action () { echo "#### NO ACTION FOR EVENT: $*" exit 1 } # AC Adapter plugged in acad_in () { $LOGGER "AC Adapter plugged IN" #if ps -A | grep -q X #then # $XGAMMA -d :0.0 -gamma 1.0 # set gamma in X to 100% # $XSET -d :0.0 dpms 0 0 600 # shutdown display after 600s #fi $LONGRUN -f performance # select performance longrun profile echo -n performance > $SCALING_GOVERNOR # set performance cpufreq profile swapon -a # enable all swap $HDPARM -S 240 /dev/hda > /dev/null 2>&1 # spindown after 20min $HDPARM -B 255 /dev/hda > /dev/null 2>&1 # disable drive's APM } # AC Adapter plugged out acad_out () { $LOGGER "AC Adapter plugged OUT" #if ps -A | grep -q X #then # $XGAMMA -d :0.0 -gamma 0.7 # set gamma in X to 70% # $XSET -d :0.0 dpms 0 0 120 # shutdown display after 120s #fi $LONGRUN -f economy # select economy longrun profile echo -n powersave > $SCALING_GOVERNOR # set powersaving cpufreq profile swapoff -a # disable all swap to decrease disk activity $HDPARM -S 4 /dev/hda > /dev/null 2>&1 # spindown after 20s $HDPARM -B 1 /dev/hda > /dev/null 2>&1 # enable drives's APM } # state of battery changed # shutdown if battery capacity is low battery () { if grep -q discharging $BAT_STATE >/dev/null 2>&1 then if ((`awk '/remaining/ { print $3 }' $BAT_STATE` < $BAT_LOW)) then $LOGGER "battery capacity critically low" btn_pwr elif ((`awk '/remaining/ { print $3 }' $BAT_STATE` < $BAT_ALR)) then $LOGGER "battery capacity less than $BAT_ALR mWh" #echo $BAT_LOW > $BAT_ALARM # start beep'ing with delay 5 sec #$BEEP -f 1500 -r 100 -d 5000 & echo "MEEEP! MEEEEP!" fi fi } # powerbutton pressed # if kde is running try to show dialog - else shutdown immediately btn_pwr () { $LOGGER "Powerbutton pressed" if test -f $KDEDIR/bin/dcop && $KDEDIR/bin/dcop kdesktop > /dev/null 2>&1 then $LOGGER "KDE running: asking user what to do" dcop --all-sessions ksmserver ksmserver logout 1 2 0 && exit 0 else $LOGGER "shutdown initiated" /sbin/init 0 fi } # system startup system_startup () { #test for ac if grep -q 'off-line' "$AC_STATE" then acad_out else acad_in fi } # let's see which event occured and what action to take :-) # have a look at /var/log/acpid to see what your events look like # and adjust accordingly case "$*" in ac_adapter\ $AC_ADAPTER\ 00000080\ 00000000) acad_out ;; ac_adapter\ $AC_ADAPTER\ 00000080\ 00000001) acad_in ;; battery\ $BATTERY\ 00000080\ 00000001) battery ;; button?power\ PWRF\ 00000080\ ????????) # the last eight digits count the times the button was pressed btn_pwr ;; startup) # system startup system_startup ;; *) no_action ;; esac # EOF