#!/bin/bash

# (c) 2005 Marcus Habermehl <bmh1980de@yahoo.de>
# (c) 2004 Vajna Miklos <vmiklos@frugalware.org>
# functions for Frugalware
# distributed under GPL License

TEXTDOMAIN=functions
TEXTDOMAINDIR=/lib/initscripts/messages

hint()
{
	echo -e "\e[01;33m>>\e[0m $1"
}

msg()
{
	echo -ne "\e[01;36m::\e[0m \e[01m$1\e[0m"
}

ok()
{
	if [[ "$(echo $LANG | cut -d _ -f 1)" == "de" ]] ; then
		cols=$(($(tput cols) - 14))
	else
		cols=$(($(tput cols) - 10))
	fi

	case $1 in
		0|997) retval=32m ;;
		999)   retval=33m ;;
		*)     retval=31m ;;
	esac

	if (( $1 == 0 )) ; then
		retmsg=$"   OK   "
	elif (( $1 == 997 )) ; then
		retmsg=$"   ON   "
	elif (( $1 == 998 )) ; then
		retmsg=$"  OFF   "
	elif (( $1 == 999 )) ; then
		retmsg=$"SKIPPING"
	else
		retmsg=$" FAILED "
	fi

	echo -ne $'\e['$cols$'G\e[01m[\e[01;'$retval
	echo -n "$retmsg"
	echo -e '\e[0;39m\e[01m]\e[0m'
}

rc_exec()
{
	if declare -f rc_$1 > /dev/null && \
	echo "${actions[*]} help" | grep -q $1 ; then
		rc_$1
	else
		rc_help && exit 1
	fi
}

rc_help()
{
	actions=$(echo ${actions[*]} | tr ' ' '|')
	msg $"Please use $0 $actions"
	ok 1
}

rc_restart()
{
	rc_stop && sleep 1 && rc_start
}

rc_status()
{
	status_msg
	if [[ "$(eval $pid)" == "" ]] ; then
		ok 998
		exit 1
	else
		ok 997
		exit 0
	fi
}

start_msg()
{
	if [ ! -z "${daemon}" ] ; then
		msg $"Starting $daemon"
	else
		msg "$@"
	fi
}

status_msg()
{
	if [ ! -z "${daemon}" ] ; then
		msg $"$daemon is"
	else
		msg "$@"
	fi
}

stop_msg()
{
	if [ ! -z "${daemon}" ] ; then
		msg $"Stopping $daemon"
	else
		msg "$@"
	fi
}

# backward compatibility
start()
{
	msg "$1"
}

stop()
{
	msg "$1"
}

# vim: ft=sh
