#! /bin/sh
### BEGIN INIT INFO
# Provides:          phidgetsbcwebif_ua
# Required-Start:    $remote_fs $all
# Required-Stop:     $remote_fs
# Should-Start:      phidget22networkserver phidgetwebservice
# Should-Stop:       phidget22networkserver phidgetwebservice
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Runs User Applications
# Description:       Starts / Stops Applications setup
#					 via the PhidgetSBC web interface.
### END INIT INFO

PATH=/sbin:/bin:/usr/bin
WEBIFCONFIGSCRIPT=/lib/webif/config.sh

# Exit if the package is not installed
[ -f "$WEBIFCONFIGSCRIPT" ] || exit 0

. /lib/init/vars.sh
. /lib/lsb/init-functions
. /lib/webif/config.sh

# Start all init scripts in $SBC_CONFIGDIR/init.d
# executing them in numerical order.
#
start() {
	for i in $SBC_CONFIGDIR/init.d/S??* ;do

		 # Ignore dangling symlinks (if any).
		 [ ! -f "$i" ] && continue

		 case "$i" in
		*.sh)
			# Source shell script for speed.
			(
			trap - INT QUIT TSTP
			set start
			. $i
			)
			;;
		*)
			# No sh extension, so fork subprocess.
			$i start
			;;
		esac
	done
}

# Stop all init scripts in $SBC_CONFIGDIR/init.d
# executing them in numerical order.
#
stop() {
	for i in $SBC_CONFIGDIR/init.d/S??* ;do

		 # Ignore dangling symlinks (if any).
		 [ ! -f "$i" ] && continue

		 case "$i" in
		*.sh)
			# Source shell script for speed.
			(
			trap - INT QUIT TSTP
			set stop
			. $i
			)
			;;
		*)
			# No sh extension, so fork subprocess.
			$i stop
			;;
		esac
	done
}

case "$1" in
  start)
	start
	;;
  restart|reload|force-reload)
	stop
	start
	;;
  stop)
	stop
	;;
  *)
	echo "Usage: phidgetsbcwebif_ua {start|stop|restart}" >&2
	exit 3
	;;
esac
