#!/bin/sh
#
# ThinkPad Configuration Tools for Linux initscript
#
# This script is part of the tpctl package

# Don't use set -e; check return status instead

. /lib/lsb/init-functions

# $1 EXITSTATUS
# [$2 MESSAGE]
log_action_end_msg_and_exit()
{
	log_action_end_msg "$1" ${2:+"$2"}
	exit $1
}

PATH=/bin:/sbin:/usr/bin:/usr/sbin
TPCTL=/usr/bin/tpctl
unset PSL

[ -r /etc/default/tpctl ] && . /etc/default/tpctl

test -x "$TPCTL" || exit 0

start()
{
	[ "$PSL" ] || return 0
	tpctl --quiet --psl="$PSL" > /dev/null
}

stop()
{
	[ "$PSL" ] || return 0
	tpctl --quiet --psl=- > /dev/null
}

case "$1" in
start)
	log_action_begin_msg "Preparing ThinkPad for use"
	start
	log_action_end_msg_and_exit "$?"
	;;
stop)
	log_action_begin_msg "Preparing ThinkPad for shutdown"
	stop
	log_action_end_msg_and_exit "$?"
	;;
restart|force-reload)
	log_action_begin_msg "Preparing ThinkPad for use"
	stop || :
	start
	log_action_end_msg_and_exit "$?"
	;;
*)
	echo "Usage: /etc/init.d/tpctl {start|stop|restart|force-reload}" >&2
	exit 3
	;;
esac
