#!/bin/sh
# 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

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 -f /lib/lsb/init-functions || exit 1
. /lib/lsb/init-functions

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

case "$1" in
  start)
    log_begin_msg "Checking battery state..."
    if [ x"`echo /proc/acpi/ac_adapter/*`" != x"/proc/acpi/ac_adapter/*" ]; then 
	/etc/acpi/power.sh
    fi
    # Source everything in /etc/acpi/start.d/
    for SCRIPT in /etc/acpi/start.d/*.sh; do
	if [ -f "$SCRIPT" ] ; then
  	  . $SCRIPT
  	fi
    done
    log_end_msg 0
    ;;
  stop)
    log_begin_msg "Disabling power management..."
    if [ x"`echo /proc/acpi/ac_adapter/*`" != x"/proc/acpi/ac_adapter/*" ]; then
	/etc/acpi/power.sh stop
    fi
    log_end_msg 0
    ;;
  restart|force-reload)
    # Doesn't make sense for that package
    ;;
  *)
  ;;
esac
        

