#!/bin/bash

. /usr/lib/rc/functions
. /etc/rc/hdparm.conf

case "$1" in
    start)
        if cat /proc/cmdline | grep -qF nohdparm; then
            stat_busy "hdparm disabled"
            stat_die
        fi

        for device in /dev/hd* /dev/sd* /dev/cdrom*; do
            [ -e "$device" ] || continue
            case "${device}" in
                *[0-9]) continue ;;
                /dev/hd*)   extra_args="$pata_all_args" ;;
                /dev/sd*)   extra_args="$sata_all_args" ;;
                *)          extra_args="" ;;
            esac

            device_args="${device##*/}_args"
            stat_busy "Running hdparm on $device"
            hdparm ${!device_args} $extra_args $all_args $device >/dev/null
            rc=$?
            (( rc || $? )) && stat_die
            stat_done
        done
        add_daemon hdparm
        ;;
    *)
        echo "usage: $0 {start}"
        exit 1
        ;;
esac
