All pastes #764796 Raw Edit

Mine

public text v1 · immutable
·published 2007-11-07 15:57 UTC
rendered paste body
#!/bin/bash


SYNC=/bin/sync
HWCLOCK=/sbin/hwclock
CONSOLE=/usr/bin/fgconsole
CHVT=/usr/bin/chvt
MODPROBE=/sbin/modprobe
DATE=/bin/date
LSMOD=/sbin/lsmod
CAT=/bin/cat
CPUFREQ=/usr/bin/cpufreq-set
HDPARM=/sbin/hdparm
ETHTOOL=/usr/sbin/ethtool

arg_group=${1/\/*/}
arg_action=${1/*\//}
arg_device=$2
arg_parameter1=$3
arg_parameter2=$4

logger "ACPI lid event: $1; $2; $3; $4" 

GOVERNOR=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)

# 
# If lid is open, do not do anything
#  
if [ "$1" == "button/lid" ] && grep -q open /proc/acpi/button/lid/LID/state; then
	logger "ACPI lid event while lid open. Ignored.";
	exit 0;
fi;

$HWCLOCK --localtime --systohc

# 
# change to console (otherwise fglrx is screwed up)
FGCONSOLE=$($CONSOLE)
$CHVT 1

#
# register battery usage stats
FILENAME=$($DATE +'%FT%R')
FILENAME="/tmp/battery-data/$FILENAME"
echo "modules:" >> "$FILENAME"
$LSMOD >> "$FILENAME"
echo "before:" >> "$FILENAME"
$DATE +'%s' >> "$FILENAME"
$CAT /sys/devices/platform/smapi/BAT0/remaining_capacity >> "$FILENAME"

#
# flush disk cache, if suspend2ram hangs 
$SYNC

# a bit of powersaving
# disable wake-on-lan -- maybe not necessary when disabled in BIOS?
$ETHTOOL -s eth0 wol d 
#
# This doubles the power drain on 2.6.17-r5
$MODPROBE -r ehci_hcd

# good night
echo -n "mem" > /sys/power/state

# Restore USB2.0
$MODPROBE ehci_hcd

echo "after:" >> "$FILENAME"
$DATE +'%s' >> "$FILENAME"
$CAT /sys/devices/platform/smapi/BAT0/remaining_capacity >> "$FILENAME"

# readjust the clock
$HWCLOCK --hctosys --localtime

#
# force HD APM off (almost)
$HDPARM -B200 /dev/sda

# 
# change back to whichever console we had (fglrx hack)
$CHVT "$FGCONSOLE"

echo "$GOVERNOR" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor