#!/bin/sh
#
# Init file for HPTools server daemon
#
# chkconfig: on 103 103
# description: HPTools server daemon
#
# processname: sutd
# pidfile: /var/run/sutd.pid

RETVAL=0
prog="sut"

# Some functions to make the below more readable
HPTOOLSD=/opt/sut/bin/sut
PID_FILE=/var/run/sutd.pid

# Create a symlink to SUT binary so sut commands can be run without
# providing the full path to the binary

# Detect if OS is Ubuntu
if [ -f /etc/os-release ]; then
	. /etc/os-release
	IS_UBUNTU=false
	if echo "$ID" | grep -qi ubuntu; then
		IS_UBUNTU=true
	else
		IS_UBUNTU=false
	fi
else
	IS_UBUNTU=false
fi

# Create a symlink to SUT binary so sut commands can be run without
# providing the full path to the binary

if $IS_UBUNTU; then
	ln -sf /opt/sut/bin/sut ./debian/sut/usr/bin/sut > /dev/null 2>&1 || true
else
	ln -sf /opt/sut/bin/sut /bin/sut 2>/dev/null || true
fi

start()
{
        OPTIONS="-installer -start"
        echo -n $"Starting $prog"
        $HPTOOLSD $OPTIONS > /dev/null 2>&1
        RETVAL=$?
        echo
}

stop()
{
        echo -n $"Stopping $prog"
        OPTIONS="-installer -stop"
        $HPTOOLSD $OPTIONS > /dev/null 2>&1
        RETVAL=$?
        echo
}

case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        *)
                echo $"Usage: $0 {start|stop}"
                RETVAL=1
esac
exit $RETVAL
