File: apm.event

package info (click to toggle)
longrun 0.9-21
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 148 kB
  • ctags: 67
  • sloc: ansic: 466; sh: 104; makefile: 64
file content (99 lines) | stat: -rw-r--r-- 1,985 bytes parent folder | download | duplicates (4)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/sh

# Longrun setup in response to apm 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
}

# Is APM available

apm_available || exit 0

# Source the default values

if [ -e "$DEFAULTS" ]; then
    . "$DEFAULTS"
fi

# Should we go on?

[ "$LONGRUN_ENABLE" = "1" ] || exit 0

# Check the APM kernel driver version, to see if we
# understand the content of /proc/apm. Then, get the
# remaining battery charge from /proc/apm.

# See /usr/src/linux/arch/i386/kernel/apm.c

APM_VERSION=`cat /proc/apm | cut -d " " -f 1`

if [ "$APM_VERSION" = "1.16" ] ; then
    REMAINING_POWER=`cat /proc/apm | cut -d " " -f 7 | tr -d "%"`
else
    REMAINING_POWER=-1
fi

# Is longrun available

[ -x "$LONGRUN_BIN" ] || exit 0

# Act depending on the APM event

case "$1,$2" in

    change,power|resume,*|start,*)
        if `on_ac_power` ; then

            set_longrun "on ac" "$PERFORMANCE" "performance"

        elif [ "$REMAINING_POWER" -eq -1 -o \
               "$REMAINING_POWER" -gt "$BATTERY_THRESHOLD" ] ; then

            set_longrun "on battery" "$ECONOMY" "economy"

        else

            set_longrun "on battery" "$LOW_BATTERY" "economy"

        fi
        ;;

    change,battery)
        if `on_ac_power` ; then

            set_longrun "on ac" "$PERFORMANCE" "performance"

        elif [ "$REMAINING_POWER" -gt "$BATTERY_THRESHOLD" ] ; then

            set_longrun "on battery" "$ECONOMY" "economy"

        else

            set_longrun "on battery" "$LOW_BATTERY" "economy"

        fi
        ;;

esac