#!/bin/bash
# INIT script to check whether we're on batteries, and so start with laptop 
# mode etc enabled.

### BEGIN INIT INFO
# Provides:          acpi-support
# Required-Start:    $local_fs $remote_fs
# Required-Stop:     $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start some power management scripts
### END INIT INFO

# Adding smgl stuff..
PROGRAM=/etc/acpi/power.sh
RUNLEVEL=3
. /etc/init.d/smgl_init

test -f /usr/share/acpi-support/power-funcs || exit 0

# BUGS: unless we start *really* late, we have no way of throttling 
# xscreensaver, since it won't be there to command.
. /usr/share/acpi-support/power-funcs

test -d /var/lib/acpi-support || exit 0

# Changing to support SMGL init way to do things...

function start() {
    echo "Checking battery state..."
    if [ x"`echo /proc/acpi/ac_adapter/*`" != x"/proc/acpi/ac_adapter/*" ]; then 
	$PROGRAM
    fi
    # Source everything in /etc/acpi/start.d/
    for SCRIPT in /etc/acpi/start.d/*.sh; do
	if [ -f "$SCRIPT" ] ; then
  	  . $SCRIPT
  	fi
    done
    echo "Done..."
}

function stop() {
    echo "Disabling power management..."
    if [ x"`echo /proc/acpi/ac_adapter/*`" != x"/proc/acpi/ac_adapter/*" ]; then
	$PROGRAM stop
    fi
    echo "Done..."
}

function restart() {
    echo "Unsupported..."
}
