3
# Laptop mode tools module: start and stop programs
7
if [ x$CONTROL_START_STOP = x1 ] ; then
9
# Undo the previous state.
11
if [ -f /var/run/laptop-mode-tools/start-stop-undo-actions ] ; then
12
cat /var/run/laptop-mode-tools/start-stop-undo-actions | \
13
while read SCRIPT STARTSTOPACTION ; do
14
$SCRIPT $STARTSTOPACTION
19
# Apply the new state, if LMT is enabled.
21
if [ "$STATE" = "enabled" ]; then
22
# Empty undo file first. We write the actions we take
23
# into this file, so that we can undo them at the
24
# next state change. Note: we actually
25
# write the actions to the file in reverse order,
26
# so we can execute the commands easily afterwards.
27
echo > /var/run/laptop-mode-tools/start-stop-undo-actions
30
if [ $ON_AC -eq 1 ] ; then
31
if [ "$ACTIVATE" -eq 1 ] ; then
32
START_STOP_DIR_PREFIX=/etc/laptop-mode/lm-ac
33
START_SERVICES="$LM_AC_START"
34
STOP_SERVICES="$LM_AC_STOP"
36
START_STOP_DIR_PREFIX=/etc/laptop-mode/nolm-ac
37
START_SERVICES="$NOLM_AC_START"
38
STOP_SERVICES="$NOLM_AC_STOP"
41
START_STOP_DIR_PREFIX=/etc/laptop-mode/batt
42
START_SERVICES="$BATT_START"
43
STOP_SERVICES="$BATT_STOP"
45
START_DIR="$START_STOP_DIR_PREFIX"-start
46
STOP_DIR="$START_STOP_DIR_PREFIX"-stop
47
if [ -d "$STOP_DIR" ] ; then
48
for SCRIPT in "$STOP_DIR"/* ; do
49
if [ -e "$SCRIPT" ] ; then
50
$LM_VERBOSE && echo "Stopping $SCRIPT" >> $OUTPUT
52
# Dereference any links. When people configure
53
# the directories with links and then they remove
54
# links while laptop mode is active, the "undo"
55
# will fail if we don't dereference the links
56
# before storing them.
57
LINKTARGET=`readlink -f "$SCRIPT"`
58
sed -i "1i $LINKTARGET start" /var/run/laptop-mode-tools/start-stop-undo-actions
62
if [ -d "$START_DIR" ] ; then
63
for SCRIPT in "$START_DIR"/* ; do
64
if [ -e "$SCRIPT" ] ; then
65
$LM_VERBOSE && echo "Starting $SCRIPT" >> $OUTPUT
67
LINKTARGET=`readlink -f "$SCRIPT"`
68
sed -i "1i $LINKTARGET stop" /var/run/laptop-mode-tools/start-stop-undo-actions
74
echo "START_SERVICES = $START_SERVICES" >> $OUTPUT
75
echo "STOP_SERVICES = $STOP_SERVICES" >> $OUTPUT
76
if [ "$START_SERVICES" != "" -o "$STOP_SERVICES" != "" ] ; then
77
echo "Starting/stopping services" >> $OUTPUT
79
# Determine how we can start/restart services.
80
if ( which invoke-rc.d > /dev/null ) ; then
81
# Debian uses invoke-rc.d
83
INITSCRIPT=laptop-mode
84
elif ( which service > /dev/null ) ; then
87
INITSCRIPT=laptop-mode
89
# Any other -- we start the init script it ourselves.
91
# Try non-link directories first, then try links. This helps if one of
92
# the locations is linked to another, which is the case on some distros.
93
if [ -d /etc/rc.d/init.d -a ! -L /etc/rc.d/init.d ] ; then
94
INIT_D=/etc/rc.d/init.d
95
elif [ -d /etc/rc.d -a ! -L /etc/rc.d -a ! -d /etc/rc.d/init.d ] ; then
97
elif [ -d /etc/init.d -a ! -L /etc/init.d ] ; then
99
elif [ -d /etc/rc.d/init.d ] ; then
100
INIT_D=/etc/rc.d/init.d
101
elif [ -d /etc/rc.d ] ; then
103
elif [ -d /etc/init.d ] ; then
106
$LM_VERBOSE && echo "Cannot determine location of init scripts." >> $OUTPUT
113
for SERVICE in $STOP_SERVICES ; do
114
$LM_VERBOSE && echo "Stopping service $SERVICE." >> $OUTPUT
116
sed -i "1i $RCPROG$SERVICE start" /var/run/laptop-mode-tools/start-stop-undo-actions
118
for SERVICE in $START_SERVICES ; do
119
$LM_VERBOSE && echo "Starting service $SERVICE." >> $OUTPUT
120
$RCPROG$SERVICE start
121
sed -i "1i $RCPROG$SERVICE stop" /var/run/laptop-mode-tools/start-stop-undo-actions