#!/bin/sh
#
# chkconfig: - 20 90
# description: Starts and stops "laptop-mode" - tweaks system behavior
#              to extend battery life.
#
# config:  /etc/laptop-mode/laptop-mode.conf

test -f /usr/sbin/laptop_mode || exit 0

# Enable laptop mode when the system is booted when running on battery.

case $1 in
  start)
    echo -n "Initializing laptop mode..."
    touch /var/run/laptop-mode-enabled
    # Run it with "force" so that syslog.conf and hdparm settings
    # are set correctly at system bootup.
    /usr/sbin/laptop_mode auto force > /dev/null
    echo "done."
    exit 0
    ;;

  restart|reload|force-reload)
    set -e
    echo -n "Restarting laptop mode..."
    $0 stop > /dev/null
    $0 start > /dev/null
    echo "done."
    exit 0
    ;;
  stop)
    echo -n "Stopping laptop mode..."
    rm -f /var/run/laptop-mode-enabled
    if ! ( /usr/sbin/laptop_mode stop > /dev/null ) ; then
    	echo "failed."
	exit 1
    fi
    echo "done."
    exit 0
    ;;
  *)
      echo "Usage: $0 {stop|start|restart|reload|force-reload}" >&2
      exit 1
    ;;
esac

