#!/bin/ksh
#
# Component: viewer
#
# Description:
#  Control script of component viewer
#

#--- INIT ------------------------------
#needs $HOME

. $HOME/etc/ctrl.main.shi

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


#--- FUNC ------------------------------

do_shell_()
{
	cat <<-EndOfInlineData
		VIEWER_HOME=$HOME/component/viewer
	EndOfInlineData
	
}

do_start_()
{
	if [ ! -d "${PLUGINS_DATA}" ] ; then
		# download and plugins would also create if not yet exists
		mkdir "${PLUGINS_DATA}" 2>/dev/null
	fi

	if [ ! -d "${PLUGINS_DATA}/x64" ] ; then
		# plugins would also create if not yet exists
		mkdir "${PLUGINS_DATA}/x64" 2>/dev/null
	fi

	for f in "${VIEWER_HOME}/plugins.std"/* ; do
		# we don't want to link the x64 directory
		[[ "$f" == */plugins\.std/x64 ]] && continue;
		ln -sf $f "${PLUGINS_DATA}/"
	done
	
	for f in "${VIEWER_HOME}/plugins.std/x64"/* ; do 
		ln -sf $f "${PLUGINS_DATA}/x64/"
	done
	
} #do_start_()

#
# List files/tables to be backed up grouped by categories
#
# output lines should be in '<category> <type> <names>' format
#
#do_listbackup_()
#{
#	cat <<-EOFLISTBACKUP
#		data.plugins FILE ${DATA#$HOME/}/plugins
#		data.plugins.x64 FILE ${DATA#$HOME/}/plugins/x64
#	EOFLISTBACKUP
#}

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

check_action_ $1
if [ 0 = $? ]; then
	do_$1_

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

fi
