#!/bin/ksh
#--------------------------------------------------------------------------------
#	Licensed Program Product:
#		VisualAge for Smalltalk for HP-UX
#
#	(C) COPYRIGHT International Business Machines Corp. 1995, 2001
#	All Rights Reserved
#
#	US Government Users Restricted Rights - Use, duplication or
#	disclosure restricted by GSA ADP Schedule Contract with
#	IBM Corp. and its licensors.
#
#	Changes:
#	2000.03.30 GWC - Initial V5.5 from V5.0
#	2000.09.25 GWC - V5.5.1 from V5.5
#	2001.04.25 GWC - V5.5.2 from V5.5.1
#
#	Generated   InstallScriptsEtc  (4/26/01 1:04:14 PM)
#--------------------------------------------------------------------------------

#--------------------------------------------------------------------------------
#	Directory Structure of cd
#	{cd}
#		nls
#		bitmaps	
#		{unix}	[this is where the setup script is]
#			bin
#
#	Where {unix} -> = install_a, install_h, install_s
#--------------------------------------------------------------------------------


#--------------------------------------------------------------------------------
# 	Verify superuser authority. It is not necessary for the user to
#	actually *be* 'root'.  It is only necessary that they have
#	root-like authority.
#--------------------------------------------------------------------------------
touchfile=/a.$$.tmp
touch $touchfile 2>/dev/null
if [  $? -ne 0  ] ; then
	echo "ERROR: You must have root authority to run this program."
	exit 1
fi
rm $touchfile

#--------------------------------------------------------------------------------
# Script var summary:
#
#	IMAGE				- the name of the Smalltalk icx file. (WITH the .icx,
#									but WITHOUT any leading path information.
#									Example:  setup.icx
#
#	LINKDIR			- the directory in which we create a complete
#									shadow of the CD tree using symbolic links.
#									All filename and directory name spellings and
#									case will be correct in this shadow tree.
#
#	MOUNTDIR		- the root directory of the installation CD
#
#	NAMESFILE		- The temporary file used to build the shadow
#									tree in LINKDIR
#--------------------------------------------------------------------------------


#--------------------------------------------------------------------------------
#	Get/Set the CD-ROM drive mount point.
#	
#	If exactly one parameter is passed in, then it will be used
#		as the mount point.  Otherwise we will use our parent
#		directory. [Relative to where this script was started from.]
#--------------------------------------------------------------------------------
if [  $# -eq 1  ] ; then
	MOUNTDIR=$1
else
	MOUNTDIR=`(cd ..; pwd)`       
fi

IMAGE=setup.icx
LINKDIR=/tmp/vastcd-5.5.2 
NAMESFILE=/tmp/f$$.tmp	# tmpfile for link names

# -- remove any existing version of the namesfile
trap "rm -rf $NAMESFILE $BINDIR ; exit" INT QUIT TERM EXIT


#--------------------------------------------------------------------------------
#	Function: 	strip_iso9660
#		calls:		
#	Convert filenames by clipping off the ;# and .# suffixes
#--------------------------------------------------------------------------------
function strip_iso9660
{
	typeset -l lcname
	lcname=$1
	lcname=${lcname%\;*}
	lcname=${lcname%\.}
	echo $lcname
} 

#--------------------------------------------------------------------------------
#	Function: 	makelinks
#		calls:		strip_iso9660
#
#	Create link tree under $PWD from $MOUNTDIR 
#--------------------------------------------------------------------------------
function makelinks
{
   while read name
	 do
	   linkname=`strip_iso9660 $name`
	   if [ -d $MOUNTDIR/$name ]
		 then
			   mkdir $linkname                 2>/dev/null
		 else
			   ln -s $MOUNTDIR/$name $linkname 2>/dev/null
	   fi
	 done
}

#--------------------------------------------------------------------------------
#	Function: 	dolink
#		calls:		makelinks
#
# 	Perform some checks, then create a tree of links 
# 	under $LINKDIR which maps onto $MOUNTDIR. We do
# 	this to get around the different CDROM device driver conventions
#	on various platforms.  For example, an ISO 9660 CD created on our
#	windows machine will look different on the unix platforms:
# 
#			Windows 	AIX				Solaris			HP
#			-------------	------------		------------		------------
# dir		MYDIR		mydir			mydir			MYDIR
# file	FOO.TXT	foo.txt			foo.txt			FOO.TXT;1
# file	FOO			foo.				foo.				FOO.;1
# 
# In the linking process we will consistenly use lowercase file and
#		directory names without any of the added '.' or ';1' noise.
#--------------------------------------------------------------------------------
function dolink    
{
	# Always recreate the link tree, just for safety.
	if [ -d $LINKDIR ] ; then
			rm -rf $LINKDIR
	fi
	print "\nMaking link directory: $LINKDIR\c"
	/bin/mkdir $LINKDIR
	if [ $? -ne 0 ]       # bail out if directory couldn't be made
	then 
		print ""
		print "Press return to continue...\c"
		read PAUSEKEY
		exit 1
	fi
	chmod 755 $LINKDIR
	
	print "\nStarting linkage process...\c"

	cd $MOUNTDIR
	# filter out files having a dot prefix... just in case.
	# Also, filter out the client directory since we are
	#	no longer zipping the client subdirectories.
	find . \
		\( -name client -o -name CLIENT \) -prune \
		-o ! -name ".*" -print > $NAMESFILE  

	# Also map the license directory for our client installs.
	find . \
		\( -name 'try.*' -o -name 'license.*' -o  -name 'TRY.*' -o -name 'LICENSE.*' \) \
		-print >> $NAMESFILE  


	print "\nMaking the symbolic links...\c"
	cd $LINKDIR
	
	# make sure that the path between cwd and license exists.
	mkdir client
	mkdir client/base-manager-srt
	mkdir client/base-manager-srt/common_all
	mkdir client/base-manager-srt/common_all/license
	makelinks < $NAMESFILE

	print "\nMapping completed.\n"
	rm $NAMESFILE
}

#--------------------------------------------------------------------------------
#	Function: 	set_default_locale
#		
#	Circumvent LANG=C 
#--------------------------------------------------------------------------------
function set_default_locale
{
	if [ X$LANG = X ] || [ $LANG = C ] 
	then
		loc=`locale -a | grep -i en_us | head -1`
		export LANG=$loc
	fi
}

#--------------------------------------------------------------------------------
#	Function: 	vacd_install
#		calls:		set_default_locale
#
#	Exec VisualAge for Smalltalk Installer
#--------------------------------------------------------------------------------
function vacd_install
{
	#
	# - - - Note: We will be running directly from the LINKDIR shadow tree.
	#
	
	#
	# - - - Workaround for CommonPrinting run-time bug.
	#
	export XPPATH=.
	
	#
	# - - - Start the installer app
	#
	set_default_locale
	
	#
	# - - - Assumption: our bin directory ({cd}/install_?/bin) is first in $PATH
	#
	# - - - Also, do not exec 'es' -- we need "trap" to run on EXIT
	#
	# - - - Send stdout and stderr to a file.
	# - - - Pass in the mount dir as a parameter in case the
	#			install code needs to find the CDROM itself.
	es -mcd -no_break -i$IMAGE -z.us.$MOUNTDIR >/tmp/vastInstall-output 2>&1
}


#-----------------------------------------------------------
#	Function: 	show_vastcd_prolog
#		calls:		
#-----------------------------------------------------------
function show_vastcd_prolog 
{
clear
print "
VisualAge for Smalltalk Install
--------------------------------------

This utility will create links for all files under the mounted 
directory:  $MOUNTDIR 
in the directory named:  $LINKDIR 

If the mounted device is a CDROM, then the link names
will be derived from the ISO 9660 CDROM file names
as follows:

	1. strip the ISO 9660 filename extensions 
	2. convert filenames to lowercase 

The link tree will not be deleted by this program. To delete the link tree,
execute:

	rm -rf $LINKDIR

After the link tree is created, the VisualAge for Smalltalk Installer
will run.

Enter c to continue or anything else to quit: \c"

read ANSWER
case $ANSWER in 
c|C) ;;
  *) print "\nBye.\n"
	 exit 1
	 ;;
esac
}

#------------------------------------------------------------
# HPUX
#
# Main Program Starts Here...
#------------------------------------------------------------
#
# - - - Setup platform-specific:
#         *) shared library search path,
#         *) executable search path,
#         *) cdrom install source directory.
#
dtlib=/usr/dt/lib
x11lib=/usr/lib/X11
dtbin=/usr/dt/bin
x11bin=/usr/bin/X11

export SHLIB_PATH=$LINKDIR/install_h/bin:$SHLIB_PATH:$dtlib:$x11lib
show_vastcd_prolog
export PATH=$LINKDIR/install_h/bin:$PATH:$dtbin:$x11bin

clear
print "
VisualAge for Smalltalk Install
--------------------------------------"

dolink
chmod -R a+x $LINKDIR/install_h

print "Installer startup..."
cd $LINKDIR/install_h
vacd_install
