#!/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
		DESKTOPAPPS_HOME=$HOME/component/desktopapps
		DOWNLOAD_HTDOCS=$HOME/htdocs/download
	EndOfInlineData

}

do_start_()
{
    [ -h "${DOWNLOAD_HTDOCS}" ] && rm "${DOWNLOAD_HTDOCS}"
    [ ! -d "${DOWNLOAD_HTDOCS}" ] && mkdir "${DOWNLOAD_HTDOCS}"

	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

        for f in "${DESKTOPAPPS_HOME}"/*; do
            [[ "$f" == */ctrl ]] && continue
            ln -sfn $f "${DOWNLOAD_HTDOCS}/"
        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
