Created
January 20, 2013 18:08
-
-
Save ignisf/4580372 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# Refactored from Ubuntu's hdparm script | |
# It isn't safe to set an APM policy by default on Firewire or USB devices. | |
# See https://bugs.launchpad.net/bugs/515023. | |
has_apm() | |
{ | |
hdparm -i $dev 2> /dev/null | grep -q 'AdvancedPM=yes' | |
} | |
hdparm_is_on_battery() { | |
on_ac_power 2>/dev/null | |
[ $? -eq 1 ] | |
} | |
cancel_hdparm_apm() | |
{ | |
for dev in /dev/sd? /dev/hd? ; do | |
if [ -b $dev ] && has_apm $dev ; then | |
hdparm -B 254 $dev | |
hdparm -S 0 $dev | |
fi | |
done | |
} | |
start_hdparm_apm() | |
{ | |
for dev in /dev/sd? /dev/hd? ; do | |
if [ -b $dev ] && has_apm $dev ; then | |
hdparm -B 1 $dev | |
hdparm -S 24 $dev | |
fi | |
done | |
} | |
resume_hdparm_apm() | |
{ | |
if hdparm_is_on_battery ; then | |
start_hdparm_apm | |
else | |
cancel_hdparm_apm | |
fi | |
} | |
case "$1" in | |
true) #powersaving on | |
resume_hdparm_apm | |
;; | |
false) # powersaving off | |
cancel_hdparm_apm | |
;; | |
thaw|resume|post) # resume pm | |
resume_hdparm_apm | |
;; | |
*) | |
exit 254 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment