1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#!/bin/sh
# Longrun setup in response to acpi events
#
# Do not make changes to this file, use /etc/default/longrun to tune
# this script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
LONGRUN_BIN=/usr/bin/longrun
DEFAULTS=/etc/default/longrun
# Default values - overiden by /etc/default/longrun
LONGRUN_ENABLE="0"
PERFORMANCE="0 100"
ECONOMY="0 70"
LOW_BATTERY="0 0"
BATTERY_THRESHOLD="10"
DEBUG="0"
# longrun settings update function
set_longrun () {
[ "$DEBUG" -eq 1 ] && logger -t longrun "$1; perf. window: $2; flag: $3"
"$LONGRUN_BIN" -s $2
"$LONGRUN_BIN" -f $3
}
# Source the default values
if [ -e "$DEFAULTS" ]; then
. "$DEFAULTS"
fi
# Should we go on?
[ "$LONGRUN_ENABLE" = "1" ] || exit 0
# Calculate the remaining power (as a percentage) from
# iterating over the battery info and state files in
# /proc/acpi/battery/*/{info,state} if available.
LAST_FULL_CAPACITY=0
REMAINING_CAPACITY=0
for battery in /proc/acpi/battery/* ; do
if [ -d "$battery" ]; then
LAST_FULL_CAPACITY=$(($LAST_FULL_CAPACITY + `awk '/last full/ {print $4}' $battery/info`))
REMAINING_CAPACITY=$(($REMAINING_CAPACITY + `awk '/remaining/ {print $3}' $battery/state`))
fi
done
if [ "$LAST_FULL_CAPACITY" -gt 0 ] ; then
REMAINING_POWER=$((100*$REMAINING_CAPACITY/$LAST_FULL_CAPACITY))
else
REMAINING_POWER=-1
fi
# Is longrun available
[ -x "$LONGRUN_BIN" ] || exit 0
# Can take different actions based on the ACPI event
# that triggered the script, but for now all events
# require the same action.
case "$1" in
*)
if `on_ac_power` ; then
set_longrun "on ac" "$PERFORMANCE" "performance"
elif [ "$REMAINING_POWER" -eq -1 ] || \
[ "$REMAINING_POWER" -gt "$BATTERY_THRESHOLD" ] ; then
set_longrun "on battery" "$ECONOMY" "economy"
else
set_longrun "on battery" "$LOW_BATTERY" "economy"
fi
;;
esac
|