#!/bin/sh # # This is the laptop mode tools polling daemon. It is used by the module # battery-level-polling to periodically let laptop mode tools run and check # the battery levels. # This copy was modified to call laptop_mode only when the battery is # very low. Calling laptop_mode every few minutes does not save much # power, lets not do any reads or writes to the disk until it's time. BAT="BAT0" # ACPI battery to monitor LIMIT="200" # Alarm if battery level drops below this value (in mAh/mWh) INTERVAL="150" # Seconds between each battery level check HIBERNATE="/usr/sbin/pm-hibernate" # Command to execute on low BAT level #HIBERNATE="/usr/sbin/laptop_mode auto" # Command to execute on low BAT level while ( true ) ; do sleep $INTERVAL # Don't terminate during the call to laptop_mode; wait until afterwards # to keep a stable situation. MUSTQUIT=0 trap 'MUSTQUIT=1' TERM QUIT STATE=$(/bin/sed -ne "/charging state:/{s/^charging state:[ ]*\([a-zA-Z]*\)$/\1/p;q}" /proc/acpi/battery/$BAT/state) BATTERY=$(/bin/sed -ne "/remaining capacity:/{s/^remaining capacity:[ ]*\([0-9]*\) m[WA]h$/\1/p;q}" /proc/acpi/battery/$BAT/state) if [ "$BATTERY" -lt "$LIMIT" ] && [ "$STATE" = "discharging" ]; then exec "$HIBERNATE" fi if [ $MUSTQUIT -eq 1 ] ; then exit 0 fi trap - TERM done