#!/bin/sh

# Copyright (c) 2001 Massachusetts Institute of Technology
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this package; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.

set -e

. /usr/share/debconf/confmodule

CONFFILE=/etc/apm/apmd_proxy.conf

if [ -e "${CONFFILE}" ]; then
    # Determine whether the file is under debconf control.
    # Otherwise it has been hand-modified by the user and we
    # shouldn't change it.
    db_get apmd/etc-apmd-md5 || true
    MD5="${RET}"
    [ "${MD5}" = "$(md5sum < "${CONFFILE}")" ] || exit 0

    # Read the values from the config file and save them in the
    # debconf database.  This preserves them upon reconfiguration or
    # reinstallation.
    . "${CONFFILE}" || true
    if [ -n "${SUSPEND_ON_AC+foo}" ]; then
	db_set apmd/suspend-on-ac "${SUSPEND_ON_AC}" || true
    fi
    if [ -n "${HDPARM_DRIVE+foo}" ]; then
	db_set apmd/hdparm-drive "${HDPARM_DRIVE}" || true
    fi
    if [ -n "${HDPARM_SPINDOWN+foo}" ]; then
	db_set apmd/hdparm-spindown "${HDPARM_SPINDOWN}" || true
    fi
fi

db_beginblock || true

db_input medium apmd/suspend-on-ac || true
db_go || true

db_input medium apmd/hdparm-drive || true
db_go || true

db_get apmd/hdparm-drive || true
if [ "${RET}" != "none" ]; then
    db_input medium apmd/hdparm-spindown || true
    db_go || true
fi

db_endblock || true
