#!/bin/ksh

# Component: web
#
# Description:
#  Control script of web component
#

#--- INIT ------------------------------
#needs $HOME
. $HOME/etc/ctrl.main.shi

[ -f $HOME/etc/setenv.sh ] && . $HOME/etc/setenv.sh

JAVACOMPS="applets archive cases dotcom prior qr scheduler servlets classes art billing qc pref main download info imadmin iface help cd checkintegrity libs services"

#--- MAIN ------------------------------

check_action_ $1
if [ 0 -eq $? ]; then
	if [ "shell" != "$1" -a "crontab" != "$1" ]; then
		echo "#SUBCTRLLIST"
                echo "# these scripts will be iterated through by ~/etc/rc"
	fi
	for comp in $JAVACOMPS; do
		if [ "shell" == "$1" ]; then
			echo "# --- $comp/ctrl ---"

                        typeset -u upperCompName
                        upperCompName=$comp

			cat <<-EOI
${upperCompName}_HOME=$HOME/component/$comp
			EOI

			[ ! -x $WEB_HOME/$comp/ctrl ] && continue
			Assign=$( $WEB_HOME/$comp/ctrl shell )
			Err=$?

			if [ 0 -eq $Err ]; then
				if [ -n "$Assign" ] ; then
					cat <<-EOI
						$Assign
					EOI
					echo
				fi
			else
				echo "# $Assign"

			fi
			echo
		elif [ "crontab" == "$1" ]; then
			echo "# >>> >>> web/$comp/ctrl $1 >>>"
			[ -x $WEB_HOME/$comp/ctrl ] && $WEB_HOME/$comp/ctrl crontab
		else 
			## Rename lefover directory
			[ -d $HOME/component/$comp -a ! -L $HOME/component/$comp ] && mv $HOME/component/$comp $HOME/component/${comp}.$$
			[ ! -e $HOME/component/$comp -o -h $HOME/component/$comp ] && ln -sfn web/$comp $HOME/component/$comp
			[ -x $WEB_HOME/$comp/ctrl ] && echo "$WEB_HOME/$comp/ctrl"
		fi
		echo
	done

else
	echo "--- Component web [ctrl $$]: Bad command: $1" >&2
	exit 1
fi
