Skip to content

Instantly share code, notes, and snippets.

@ignisf
Created January 20, 2013 18:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ignisf/4580372 to your computer and use it in GitHub Desktop.
Save ignisf/4580372 to your computer and use it in GitHub Desktop.
#! /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