#!/bin/sh
#  script for qtsmbstatusd
#

# For LSB
### BEGIN INIT INFO
# Provides:          qtsmbstatusd
# Required-Start:    $remote_fs $syslog samba
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: start qtsmbstatusd server at boot time
# Description:       QtSmbstatus is a graphical user interface for smbstatus
### END INIT INFO

NAME=qtsmbstatusd

# see if qtsmbstatusd is running
pid=`ps ax | awk '{print $1,$5}' | grep $NAME | awk '{print $1}' | awk '{print $1}'`

# get locale
default_locale=en_US.UTF-8
if [ -f /etc/default/locale ]; then
        # Debian systems
        system_locale=`grep -re "LANG=" /etc/default/locale | awk 'BEGIN { FS = "[\"]" } { print $2 }'`
fi

if [ -z $system_locale ]; then system_locale=$default_locale; fi

# Start or stop the qtsmbstatusd server
case $1 in
	start | restart | reload | force-reload)
		export LANG=$system_locale
		if test "$pid" != ""; then
			kill $pid
			if /usr/bin/qtsmbstatusd -d; then
			echo "qtsmbstatusd server restarted."
			fi
		else
		if /usr/bin/qtsmbstatusd -d; then
			echo "qtsmbstatusd server started."
			fi
		fi
		;;
	stop)
		if test "$pid" != ""; then
		  kill -3 $pid
		fi
		echo "qtsmbstatusd server stopped"
		;;

	status)
		if test "$pid" != ""; then
			echo "qtsmbstatusd : server is running."
		else
			echo "qtsmbstatusd : server is not running."
		fi
		;;

	*)
		echo "Usage: qtsmbstatusd {start|stop|reload|restart|status|force-reload}"
		exit 1
		;;
esac

exit 0
