#!/bin/bash

LIST_HD=$(grep '^hd.:' /var/log/dmesg|\
	grep -ivE '(CD.*ROM|FLOPPY|TAPE|STATUS)'|cut -d: -f1|sort|uniq)
arg="$1"

acon_hdtimeout=241	# 30-minute disk spindown
acoff_hdtimeout=12	# 1-minute disk spindown

apmstat=`cat /proc/apm`
set $apmstat
case "$4" in
0x01)
	# AC online
	hdtimeout=$acon_hdtimeout
	;;
0x00|0x02)
	# AC offline
	hdtimeout=$acoff_hdtimeout
	;;
*)
	hdtimeout=$acoff_hdtimeout
	;;
esac

for i in $LIST_HD;do
	hdparm -S $hdtimeout /dev/$i
done

# don't exit, since this is run with "."
