#! /bin/sh

### BEGIN INIT INFO
# Provides:          bcdi
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Serveur Bcdi
### END INIT INFO



# This file was automatically customized by dh-make on Thu, 28 Sep 2006 17:34:49 +0200

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bcdiserv/prog/ConsBcdi
RUNNER=/usr/bcdiserv/prog/consolebcdi
NAME=kwartz-bcdi
DESC=kwartz-bcdi

CHR="chroot /home/kwartz/chroot/bcdi"

test -x $DAEMON || exit 0
test -x $RUNNER || exit 0

if [ "$LANG" = "fr_FR.UTF-8" ]; then
	cp "$RUNNER" "$RUNNER.kwartz"
else 
	iconv -f UTF-8 -t iso-8859-1 -o "$RUNNER.kwartz" "$RUNNER"
fi
chown gestbcdi: "$RUNNER.kwartz"
chmod --reference="$RUNNER" "$RUNNER.kwartz"

set -e

case "$1" in
  start)

	# correction des droits dans Prog
	chmod -R +x /usr/bcdiserv/prog

	# correction des droits dans Data
	chown gestbcdi:gestbcdi /usr/bcdiserv/Data/* || true
	chmod 0775 /usr/bcdiserv/Data || true


    $CHR "$RUNNER.kwartz" start 

	;;
  stop)

    $CHR "$RUNNER.kwartz" stop 

	;;
  #reload)
	#
	#	If the daemon can reload its config files on the fly
	#	for example by sending it SIGHUP, do it here.
	#
	#	If the daemon responds to changes in its config file
	#	directly anyway, make this a do-nothing entry.
	#
	# echo "Reloading $DESC configuration files."
	# start-stop-daemon --stop --signal 1 --quiet --pidfile \
	#	/var/run/$NAME.pid --exec $DAEMON
  #;;
  restart|force-reload)
	#
	#	If the "reload" option is implemented, move the "force-reload"
	#	option to the "reload" entry above. If not, "force-reload" is
	#	just the same as "restart".
	#

	$CHR "$RUNNER.kwartz" restart 

	;;
  *)
	N=/etc/init.d/$NAME
	# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
