#!/bin/sh
#
# Provided by Sun Microsystems Inc. September 1997.

clear

echo "JavaWorkshop - WorkShop Visual integration files can be installed either
for single user or for entire site. For single user installation, the
integration files are installed in the user home directory, in this
case only this user can use WorkShop Visual from JavaWorkshop. If JWS-visu
integration is desired for the entire site, then the integration 
files will be installed in the JavaWorkshop installation directory."

echo "Note: For full site installation, you may need to run this 
script as super user"

echo ""
echo "Please select how you prefer to install the integration files:"
echo "       Enter '1' for single user installation"
echo "       Enter '2' for full site installation"

ARC=`uname -p`
case $ARC in
i?86)
    ARC=intel ;;
esac

while :
do
	echo "Please enter your choice '1' or '2'  :"
	read ans
	case "$ans" in
		1) clear
			echo "Proceeding installation for user -" $USER
			JWS_DIR=$HOME/.jws2.0
		break;;
		2) clear
			echo "Please enter installation path for JavaWorkshop"
			echo "If you have installed JavaWorkshop in /opt then"
			echo "the path is /opt/SUNWjws/Java-WorkShop2.0/JWS"
			echo ""
			while :
			do
				echo "If /opt/SUNWjws/Java-WorkShop2.0/JWS is correct, enter '1'"
				echo "otherwise enter the full path : "
				read jws_path
				case "$jws_path" in
					1) JWS_DIR=/opt/SUNWjws/Java-WorkShop2.0/JWS 
					;;
					*) JWS_DIR=$jws_path 
					;;
				esac
				if  test -x $JWS_DIR/$ARC-S2/bin/jws 
				then
					clear
					echo "$JWS_DIR/$ARC-S2/bin/jws found."
					echo "Proceeding for full site installation"
					break 
				else
					clear
					echo "$JWS_DIR/$ARC-S2/bin/jws not found."
					echo " Please enter the correct path"
					echo ""
				fi
			done
		break ;;
		*) echo "$(ans)? Please answer 1 or 2" ;;
	esac
done

# See if visuroot can be execd from the current dir, 
# if not from the commandline substitute visuroot instead of jws_intg_install
# and execute it
if test -x ./visuroot
then
	PRODROOT=`./visuroot`
else
	CMD=$0
	dd=`echo $CMD | sed s/jws_intg_install/visuroot/g`
	if test ! -x $dd
	then
        echo "Cannot execute $dd, try changing directory to"
		echo "\${VISUROOT}/bin and execute this script from"
		echo "the current directory - ./jws_intg_install"
		exit 1
	fi

	PRODROOT=`$dd`
fi

JWS_XD_CLASS_DIR=$PRODROOT/lib/jws_intg/classes
echo ""
echo ""

INTG_TOP_DIR=$JWS_DIR/PlugIns
INTG_CLASS_DIR=$INTG_TOP_DIR/classes
INTG_BIN_DIR=$INTG_TOP_DIR/xd/bin

# Check to see if the required directories are present

# Check if ~/.jws2.0 is present, if not create it
if test ! -d $JWS_DIR
then
	if mkdir $JWS_DIR
	then
		echo "Created" $JWS_DIR
	else
		echo "For full site installation, run this script as super user"
		echo "Please check for right permissions and rerun this script"
		exit 1
	fi
fi

# Create $JWS_DIR/PlugIns, if not present
if test ! -d $INTG_TOP_DIR
then
	if mkdir $INTG_TOP_DIR
	then
		echo "Created" $INTG_TOP_DIR
	else
		echo "For full site installation, run this script as super user"
		echo "Please check for right permissions and rerun this script"
		exit 1
	fi
fi

# Create $JWS_DIR/PlugIns/classes, if not present
if test ! -d $INTG_TOP_DIR/classes
then
	if mkdir $INTG_TOP_DIR/classes
	then
		echo "Created" $INTG_TOP_DIR/classes
	else
		echo "For full site installation, run this script as super user"
		echo "Please check for right permissions and rerun this script"
		exit 1
	fi
fi

# Create $JWS_DIR/PlugIns/xd, if not present
if test ! -d $INTG_TOP_DIR/xd
then
	if mkdir $INTG_TOP_DIR/xd
	then
		echo "Created" $INTG_TOP_DIR/xd
	else
		echo "For full site installation, run this script as super user"
		echo "Please check for right permissions and rerun this script"
		exit 1
	fi
fi

# Create $JWS_DIR/PlugIns/xd/bin, if not present
if test ! -d $INTG_TOP_DIR/xd/bin
then
	if mkdir $INTG_TOP_DIR/xd/bin
	then
		echo "Created" $INTG_TOP_DIR/xd/bin
	else
		echo "For full site installation, run this script as super user"
		echo "Please check for right permissions and rerun this script"
		exit 1
	fi
fi

# Copy class files into $JWS_DIR/PlugIns/classes
if cp $JWS_XD_CLASS_DIR/TranslatorFactory_xd.class $INTG_TOP_DIR/classes
then
	echo "Copied TranslatorFactory_xd.class"
else
	echo "For full site installation, run this script as super user"
	echo "Please check for right permissions and rerun this script"
	exit 1
fi
if cp $JWS_XD_CLASS_DIR/Translator_xd.class $INTG_TOP_DIR/classes
then
	echo "Copied Translator_xd.class"
else
	echo "For full site installation, run this script as super user"
	echo "Please check for right permissions and rerun this script"
	exit 1
fi
if cp $JWS_XD_CLASS_DIR/XdGeneratedFiles.class $INTG_TOP_DIR/classes
then
	echo "Copied XdGeneratedFiles.class"
else
	echo "For full site installation, run this script as super user"
	echo "Please check for right permissions and rerun this script"
	exit 1
fi
if cp $JWS_XD_CLASS_DIR/TF_xd_msg.properties $INTG_TOP_DIR/classes
then
	echo "Copied TF_xd_msg.properties"
else
	echo "For full site installation, run this script as super user"
	echo "Please check for right permissions and rerun this script"
	exit 1
fi

#Create translate_xd file in $INTG_BIN_DIR and provide execute permissions

VISU_INTG_BIN_FILE=$INTG_BIN_DIR/translate_xd

touch $VISU_INTG_BIN_FILE
echo "#!/bin/sh" > $VISU_INTG_BIN_FILE
echo "" >> $VISU_INTG_BIN_FILE
echo "BIN_DIR=$PRODROOT/bin" >> $VISU_INTG_BIN_FILE
echo "" >> $VISU_INTG_BIN_FILE

echo "exec \$BIN_DIR/visu \${1+\"\$@\"}"  >> $VISU_INTG_BIN_FILE

chmod +x $VISU_INTG_BIN_FILE

echo "Created $VISU_INTG_BIN_FILE"

#
# Create JavaWorkshop toolbar integration properties file
#

TOOLBAR_INTG_DIR=$INTG_TOP_DIR/toolbar
TOOLBAR_FILE=$TOOLBAR_INTG_DIR/visu.properties
JWS_XD_TOOLBAR_IMAGE=$PRODROOT/lib/jws_intg/toolbar/visu.gif

# Create $JWS_DIR/PlugIns/toolbar, if not present
if test ! -d $TOOLBAR_INTG_DIR
then
	if mkdir $TOOLBAR_INTG_DIR
	then
		echo "Created" $TOOLBAR_INTG_DIR
	else
		echo "For full site installation, run this script as super user"
		echo "Please check for right permissions and rerun this script"
		exit 1
	fi
fi

if cp $JWS_XD_TOOLBAR_IMAGE $TOOLBAR_INTG_DIR
then
	echo "Copied visu.gif"
else
	echo "For full site installation, run this script as super user"
	echo "Please check for right permissions and rerun this script"
	exit 1
fi


echo "#" > $TOOLBAR_FILE
echo "# JWS Toolbar properties for visu PlugIn" >> $TOOLBAR_FILE
echo "#" >> $TOOLBAR_FILE

echo "" >> $TOOLBAR_FILE
echo "toolbar.properties.version=1.0" >> $TOOLBAR_FILE
echo "label=visu" >> $TOOLBAR_FILE
echo "up_image=file:$TOOLBAR_INTG_DIR/visu.gif" >> $TOOLBAR_FILE
echo "tooltip=WorkShop Visual GUI builder" >> $TOOLBAR_FILE
echo "footerhelp=Launch WorkShop Visual GUI builder" >> $TOOLBAR_FILE
echo "action=$PRODROOT/bin/visu" >> $TOOLBAR_FILE

echo "Created $TOOLBAR_FILE"

# Inform sucessful installation
echo ""
echo "JavaWorkshop - visu Integration files installed sucessfuly "
echo ""
echo "Restart JavaWorkshop."
