#!/bin/bash

# PowerManagement Control Script
# This script will be called on certain events from a
# powermanagement daemon with two arguments. The first
# argument contains the command and the second the
# currently active power source.
#
# arg $1: powersave     minimum power consumption
#         performance   maximum performance
#         sleep         prepare for sleep
#         wakeup        recovering from sleep
#
# arg $2: ac            running on ac power
#         battery       running on battery
#
# Options for this scripts will be kept in the central
# configuration file ../config. Variables for each script
# will be introduced by a special unique prefix.

# name        : hdsetup
# prefix      : HD_
# author      : Matthias Grimm <joker@cymes.de>
# description : Set harddisk spin-down timeouts
# requirements: hdparm and sync in path
# limitations : work only with IDE harddisks
#               controls only a single harddisk
#
# --- end of public part -- don't change below this line ---

PATH=/bin:/sbin:/usr/bin:/usr/sbin

# source configuration
. config

case "$1" in
  powersave)
    hdparm $HD_options -S $(($HD_timeout/5)) $HD_device
    ;;
  performance)
    hdparm $HD_options -S 0 $HD_device
    ;;
  sleep)
    sync
    ;;
  wakeup)
    ;;
esac

exit 0
