~ubuntu-branches/ubuntu/quantal/pm-utils/quantal-proposed

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
#!/bin/sh
# vim:noexpandtab
# Simple powersave script
#
# Copyright 2006 Red Hat, Inc.
#
# Based on work from:
#    Bill Nottingham <notting@redhat.com>
#    Peter Jones <pjones@redhat.com>
#    David Zeuthen <davidz@redhat.com>
#    Richard Hughes <richard@hughsie.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

export STASHNAME=pm-powersave
. "@PM-UTILS-LIBDIR@/pm-functions"

remove_powersave_lock() {
    release_lock "${STASHNAME}.lock"
}

help() {
    cat <<EOF
$0: Valid options are:
false or ac = turn powersaving features off.
true or battery = turn powersaving features on.
help = get detailed help.

EOF
if [ "$1" = "--help" ]; then
    cat <<EOF
The rest of this help message displays the variables
that can be used to tune the powersave hooks.  
You can change these variables using pm-utils config files.
(see the pm-utils README for more information)

EOF
else
    echo "You can get more detailed information by running pm-powersave --help"
fi
}

lock_and_load() {
# take the powersave lock.
# ensure it gets released no matter how we exit.
    try_lock "${STASHNAME}.lock" || exit 1
    trap remove_powersave_lock 0
    mkdir -p "${STORAGEDIR}"
    rm -f "${INHIBIT}"
    
    load_hook_blacklist
    
    init_logfile "${PM_LOGFILE}"
}

_on_ac_power() {
    on_ac_power
    case $? in
        # If on_ac_power can't determine AC power state (255), assume it's a desktop.
        0|255) return 0 ;;
        1) return 1 ;;
    esac
}

case $1 in
    true|battery) lock_and_load && run_hooks power true;;
    false|ac) lock_and_load && run_hooks power false;;
    --help) help && run_hooks power help;;
    '') lock_and_load; _on_ac_power && run_hooks power false || run_hooks power true;;
    *) help && exit 1;;
esac