#!/bin/bash
#
# wltool       Userspace tool that helps setting kernel s3_sleep
#              parameters during boot based on a model specific
#              whitelist.
#
# chkconfig: 2345 90 10
# description: Userspace tool that helps setting kernel s3_sleep
#              parameters during boot based on a model specific
#              whitelist.
#
### BEGIN INIT INFO
# Provides: wltool
# Default-Start: 2 3 4 5
# Short-Description: Helps out setting s3_sleep during boot
# Description: Userspace tool that helps setting kernel s3_sleep 
#              during boot based on a model specific whitelist.
### END INIT INFO

#Servicename
SERVICE=wltool

# Source function library.
. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/$SERVICE ]; then
	. /etc/sysconfig/$SERVICE
fi

# If acpi isn't used, don't try to run wltool (aka don't print
# useless error messages).
if ! [ -d /proc/acpi ]; then
       	exit 0
fi

if [ "$FORCE" = "y" ]; then
	OPTIONS="--force --acpi_sleep=$ACPI_SLEEP $UNSAFE"
fi

RETVAL=0

case "$1" in
	start)
	gprintf "Starting %s: " "$SERVICE"
	if ! [ -e /proc/sys/kernel/acpi_video_flags ]; then
		failure
		echo
		gprintf "You need kernel 2.6.17 or newer with acpi enabled!\n"
		exit 1
	fi
	RETVAL=$?
	/usr/sbin/wltool --quiet $OPTIONS
	success
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$SERVICE
	;;
    	stop)
	gprintf "Stopping %s: " "$SERVICE"
	RETVAL=$?
	success
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$SERVICE
	;;
	status)
	if [ -e /var/lock/subsys/$SERVICE ]; then
		gprintf "$SERVICE has been initialized.\n"
	else
		gprintf "$SERVICE hasn't been initialized\n"
	fi
	;;
	restart|reload)
	$0 stop
	$0 start
	;;
	*)
	gprintf "Usage: %s {start|status|stop}\n" "$SERVICE"
	exit 1
esac

exit $RETVAL
