
# WPINSTALL - WordPerfect installation script (START)
# SCCS Version Information
# @(#) account.h 1.1 7/9/93 19:42:37


if [ "$1" = "-x" ]
then
	echo ==================== wpinstall =============================
	set -x
	DEBUG="-x"
	shift
fi

# page break
pgbreak()
{
	echo
	echo -------------------------------------------------------------------------------
	echo
}

clean_up()
{
	if [ "$LNKDIR" != "" ]
	then
		cd /tmp
		rm -f /tmp/instdir /tmp/lnkdir /tmp/tardir
		rm -rf $LNKDIR &
	fi
	exit $*
}

tar_completed()
{
	ls $tardir/install/dir* $tardir/install/perms* > TMPTMP 2> /dev/null
	if [ ! -f TMPTMP ]
	then
		echo "     ERROR: No permissions on the installation files and directories."
		clean_up 1
	fi
	if [ ! -s TMPTMP ]
	then
		doneyet='n'
	elif [ ! -f $tardir/install/installloop ]
	then
		doneyet='n'
	fi
	rm -f TMPTMP

	if [ "$Pflg" = 'P' ]
	then
		if [ ! -d $tardir/_P ]
		then
			doneyet='n'
		fi
		ls $tardir/install/prsinfo.* > TMPTMP 2> /dev/null
		if [ ! -s TMPTMP ]
		then
			doneyet='n'
		fi
		rm -f TMPTMP
	fi

	if [ "$Tflg" = 'T' ]
	then
		if [ ! -f $tardir/install/trsinfo.wp ]
		then
			doneyet='n'
		fi
		if [ ! -f $tardir/_T/trs.wp -a ! -f $tardir/_T/trs.wpgg ]
		then
			doneyet='n'
		fi
	fi

	if [ \( "$Aflg" = 'A' -o "$NOflg" = 'N' \) -a \( -d $tardir/_W -o -d $tardir/_O  \) ]
	then
		ls $tardir/*/oftcp* $tardir/*/xoffice $tardir/*/xofficeaa $tardir/*/xofficeaagg $tardir/*/office $tardir/*/officeaa $tardir/*/officeaagg $tardir/*/adunix* $tardir/*/xwp $tardir/*/xwpaa $tardir/*/xwpaagg 2> /dev/null > TMPTMP
		if [ ! -s TMPTMP ]
		then
			doneyet='n'
		fi
	fi
	rm -f TMPTMP
}

is_tar_needed()
{
	tar_completed
	if [ "$doneyet" = 'n' ]
	then
		echo
		echo "                       Corel Installation Program"
		echo
		echo "     To make installation of WordPerfect 6.0 easier, the installation"
		echo "     program will store the device name you use to load the product files."
		echo
		doneyet='y'
		perform_tar
	fi
}

tar_mesg()
{
	echo
	if [ "$1" = 0 ]						# initial install
	then
		INSTTYPE="install"
	else								# partial install (-a option)
		INSTTYPE="reinstall"
	fi
echo "     If you are ${INSTTYPE}ing from tape, insert the media into the drive"
echo "     and press Enter."
echo
echo "     NOTE: To terminate the Installation Program, type Q and press Enter."
echo
echo "     Once the files have been loaded, type C and press Enter"
echo "     to continue with the ${INSTTYPE}ation."
echo

}

copy_to_temp()
{
	echo
	echo "     Copying files from $1 to $2"
	(cd $1; tar cf - *) | (cd $2; tar xf -)
}

perform_tar()		# Copy the contents of the media to the tar directory
{
	olddir=`pwd`	# here's where we started.
	mydevice=????
	if [ -f .wpdevice ]
	then
		mydevice=`cat .wpdevice`
	fi
	cd $tardir

	tmprsp='n'
	while [ "$tmprsp" != 'y' -a "$tmprsp" != 'Y' ]
	do
		echo "     The current default device on your system is: $mydevice"
		echo
		echo "     Press Enter to use the default device displayed above or type a"
		echo "     different device and press Enter.  If you have already extracted"
		echo "     the files from the media, you may also enter the directory where"
		echo $NL "     the files are located and press Enter: $NL1"

		read response

		if [ "$response" != "" ]
		then
			mydevice=$response
			echo $mydevice > $olddir/.wpdevice
		fi

		if [ "$mydevice" = "????" ]
		then
			echo
			echo "$mydevice is an invalid device."
			sleep 1
			continue
		fi
							# is this a device name?
		if [ `echo ${mydevice} | sed 's|/dev/||g'` = "$mydevice" ]
		then				# no
			SVtardir=$tardir	# save off .../WPTEMP dir
			tardir=${mydevice}
			tar_completed
			if [ "$doneyet" = 'n' ]
			then			# missing some files still
				echo
				echo "     Unable to locate the WordPerfect files at this location."
				doneyet='y'
				sleep 4
				pgbreak
				continue
			fi
			copy_to_temp $tardir $SVtardir	# copy files to temp area
			tardir="$SVtardir"
			cd $tardir/install
			return
		fi

		echo
		echo "     The device you entered is: " $mydevice
		echo
		echo "     Is this correct?"
		echo
		echo $NL "     Yes or No? (Y/N) $NL1"
		read tmprsp
	done

	while :
	do
		pgbreak
		if [ "$WPUPDATE" = 'y' ]	# an update
		then
			echo
			if [ "$Aflg" = 'A' ]
			then
				tar_mesg 1
			else
echo "     If you are installing from tape, insert the media into the drive"
echo "     and press Enter."
echo
echo "     NOTE: To terminate the Installation Program, type Q and press Enter."
echo
echo "     Once the files have been loaded, type C and press Enter"
echo "     to continue with the installation."
echo
			fi
		else					# an initial install
			tar_mesg 0
		fi

		read response
		if [ "$response" = 'q' -o "$response" = 'Q' ]
		then
			while :
			do
				echo
				echo "     You have chosen to terminate the installation program without"
				echo "     completing the installation of WordPerfect 6.0.  Do you want"
				echo "     to delete the WordPerfect files that have already been loaded"
				echo "     from the media into $tardir?"
				echo $NL "     Yes or No (Y/N) $NL1"
				read resp2
				if [ "$resp2" = 'y' -o "$resp2" = 'Y' ]
				then
					if [ "$WPUPDATE" = 'y' ]	# a reinstall
					then
						cd /
						rm -rf $tardir			# we made directory, delete it.
					else						# no, a first install
						for i in `cat $tardir/install/dir*`
						do						# only delete WP files
							if [ -d "$tardir/$i" -a "$i" != "." ]
							then
								cd /
								rm -rf $tardir/$i
							fi
						done
					fi
					rm -f $tardir/$tprg
					clean_up
				elif [ "$resp2" = 'n' -o "$resp2" = 'N' ]
				then
					clean_up
				else
					echo "Invalid Selection"
					sleep 1
				fi
			done
		fi
		if [ "$response" = 'c' -o "$response" = 'C' ]
		then
			tar_completed
			if [ "$doneyet" = 'n' ]
			then			# missing some files still
				echo
				echo "     The installation program cannot continue until you have loaded the"
				echo "     files from all of the required diskettes.  Insert the next diskette"
				echo "     and press Enter to resume the loading process."
				echo
				doneyet='y'
				sleep 4
				continue
			fi
			break
		fi
		if [ "$Aflg" = 'A' ]		# Full Reinstall/Update
		then
			echo "     Please Wait"
			tar -xf $mydevice
		elif [ "$WPUPDATE" != "y" ]	# Initial Install
		then
			echo "     Please Wait"
			tar -xf $mydevice wpinstall ./wpinstall _FLEX ./_FLEX install ./install _O ./_O _P ./_P _T ./_T _T2 ./_T2 _W ./_W _X ./_X 2> /dev/null
		else						# Partial Install
			STUFF="wpinstall ./wpinstall"
			if [ ! -d install ]
			then
				STUFF="${STUFF} install ./install"
			fi
			if [ "$Pflg" = 'P' ]
			then
				STUFF="${STUFF} _P ./_P $_P_LANGS"
			fi
			if [ "$Tflg" = 'T' ]
			then
				STUFF="${STUFF} _T ./_T _T2 ./_T2"
			fi
			if [ "$Lflg" = 'L' ]
			then
				STUFF="${STUFF} $_L_LANGS"
			fi
			echo "     Please Wait"
			tar -xf $mydevice $STUFF 2> /dev/null
		fi
		sleep 2
		if [ -f /bin/eject -o -f /usr/bin/eject ]
		then
			eject 2> /dev/null
		fi
	done
	cd $tardir/install
}

MoveClient()
{
	if [ ! -d $thisdir/_CLIENT ]
	then
		mkdir $thisdir/_CLIENT
	fi

	cp $thisdir/install.gw $thisdir/_CLIENT
# the next two lines are redundant (err out) on the CD, shut them up.
	cp -r $thisdir/install $thisdir/_CLIENT 2> /dev/null
	chmod 777 $thisdir/_CLIENT/install.gw $thisdir/_CLIENT/install/install.gw 2> /dev/null
	rm -f $thisdir/install/editmgic $thisdir/install/wpmagic $thisdir/install/lang.?? $thisdir/install/perms $thisdir/install/perms.[LMOPST] $thisdir/install/size.[lMO]* $thisdir/install/.Gw41
	rm -f $thisdir/_CLIENT/install/.Ad41

	if [ -f $thisdir/install/dir.O ]	# tape media?
	then								# yes
		Mydirs="$thisdir/install/dir.O $thisdir/install/dirMS"
	else								# no, CD
		Mydirs="$thisdir/_CLIENT/install/dir.list"
	fi

	for i in `cat $Mydirs 2>/dev/null | sort -r` # read client/msg server dirs
	do
		if [ $i = "install" -o $i = "." ]	# skip install and "." directory
		then
			continue
		fi
	
		if [ -d $thisdir/$i ]				# does the directory exist?
		then
			mv $thisdir/$i $thisdir/_CLIENT
		fi
	done
}

decomp_file()
{
	if [ -s $1 ]
	then
		./wpdecompress -s $1 ttmp
		STAT="$?"
		if [ $STAT = 2 ]		# was file compressed?
		then					# no, remove it
			rm -f ttmp
		elif [ $STAT = 1 ]		# decompress failure?
		then
			rm -f ttmp
			clean_up
		else					# yes, move it back
			rm -f $1
			mv -f ttmp $1
			decomp_flg='y'
		fi
	fi
}

check_admin()
{
	if [ "$OffAd" = 'y' ]
	then
		pgbreak
		if [ -f ./wpdomain.db ]
		then
			echo "     A domain database (wpdomain.db) has been created previously."
			echo "     Do you want to run the admin program at this time?"
			echo
		else

			echo "     Do you want to run the admin program to setup and configure"
			echo "     your first domain and post office?  If you don't do this now,"
			echo "     refer to the Installation Guide for help on doing this later."
			echo
		fi
		echo $NL "     Yes or No (Y/N) $NL1"
		read jnk
		while [ "$jnk" != "y" -a "$jnk" != 'Y' -a "$jnk" != "n" -a "$jnk" != 'N' ]
		do
			echo "Invalid Selection"
			echo
			sleep 1
			echo $NL "     Yes or No (Y/N) $NL1"
			read jnk
		done

		if [ "$jnk" = "y" -o "$jnk" = 'Y' ]
		then
			instdir=`echo $INSTALLDIR | sed 's|/[^/]*.$||g'` # dirname
			SVDIR=`pwd`
			cd $instdir
			echo
			echo "     Bringing up admin ..."
			./adunix -p $instdir
			cd $SVDIR
		fi
	fi
}

prelim_stuff()
{
	if [ "$WpSix_0" = 'y' -o "$Office" = 'y' -o "$OffMsg" = 'y' -o "$OffAd" = 'y' ]
	then
		echo "      Corel Installation for:"
		echo
		if [ "$WpSix_0" = 'y' ]
		then
			echo "     WordPerfect 6.0 for UNIX (R) Systems"
		fi
		if [ "$Office" = 'y' ]
		then
			echo "     Novell GroupWise 4.1 for UNIX (R) Systems"
		fi
		if [ "$OffMsg" = 'y' ]
		then
			echo "     Novell GroupWise 4.1 Message Server for UNIX (R) Systems"
		fi
		if [ "$OffAd" = 'y' ]
		then
			echo "     Novell GroupWise 4.1 Administration for UNIX (R) Systems"
		fi
	fi

# decompress all the compressed files in the install directory
	dcflg="$decomp_flg"
	if [ "$dcflg" = 'y' ]
	then
		echo
		echo "     *Please Wait*"
		dcnt=0
	fi
	for i in `ls 2> /dev/null`
	do
		if [ -f .CDROM ]
		then
			break
		fi
		if [ -d "$i" ]
		then
			continue
		fi
		if [ "$dcflg" = 'y' ]
		then
			if [ $dcnt -eq 15 ]	# clear dots
			then
				echo $NL "               $NL1"
			fi
			if [ $dcnt -eq 0 -o $dcnt -ge 15 ]
			then
				echo $NL "     Decompressing Files $NL1"
				dcnt=0
			else
				echo $NL ".$NL1"
			fi
			dcnt=`expr $dcnt + 1`
		fi
		decomp_file $i
	done
	if [ "$dcflg" = 'y' ]
	then
		echo
	fi

# copy files to the app-defaults directory?
	APPDEF=""
	if [ -d /usr/openwin/lib/app-defaults ]
	then
		APPDEF=/usr/openwin/lib/app-defaults
	elif [ -d ${OPENWINHOME}/lib/app-defaults ]
	then
		APPDEF=${OPENWINHOME}/lib/app-defaults
	fi

	APPDEF1=""
	if [ -d /usr/lib/X11/app-defaults ]
	then
		if [ "$APPDEF" ]
		then
			APPDEF1=/usr/lib/X11/app-defaults
		else
			APPDEF=/usr/lib/X11/app-defaults
		fi
	fi

	if [ -f ../_O/Wpoffice -a "$APPDEF" ]
	then
		decomp_file ../_O/Wpoffice
		chmod 444 ../_O/Wpoffice
		cp ../_O/Wpoffice $APPDEF 2> /dev/null
		if [ "$APPDEF1" ]
		then
			cp ../_O/Wpoffice $APPDEF1 2> /dev/null
		fi
	fi

	if [ -f ../_O/Wpnotify -a "$APPDEF" ]
	then
		decomp_file ../_O/Wpnotify
		chmod 444 ../_O/Wpnotify
		cp ../_O/Wpnotify $APPDEF 2> /dev/null
		if [ "$APPDEF1" ]
		then
			cp ../_O/Wpnotify $APPDEF1 2> /dev/null
		fi
	fi

	if [ -f ../_AD/Adunix -a "$APPDEF" ]
	then
		decomp_file ../_AD/Adunix
		chmod 444 ../_AD/Adunix
		cp ../_AD/Adunix $APPDEF 2> /dev/null
		if [ "$APPDEF1" ]
		then
			cp ../_AD/Adunix $APPDEF1 2> /dev/null
		fi
	fi

	if [ -f ../_AD/Adunix -a ! -f $APPDEF/Adunix ]
	then
		echo
		if [ -d "$APPDEF" ]
		then
			echo "     Warning: Unable to copy Adunix to $APPDEF"
		else
			echo "     Warning: Unable to copy Adunix to the app-defaults directory."
		fi
		echo "     Adunix will be installed in the wptools directory."
		echo "     Extended characters may not work if Adunix is not in app-defaults."
	fi

	if [ -f ../_W/Wp60 -a ! -f $APPDEF/Wp60 ]
	then
		WP60_COPYFLG='1'
		if [ "$APPDEF" ]
		then
			decomp_file ../_W/Wp60
			chmod 444 ../_W/Wp60
			cp ../_W/Wp60 $APPDEF 2> /dev/null
			if [ "$APPDEF1" ]
			then
				cp ../_W/Wp60 $APPDEF1 2> /dev/null
			fi
		fi
	fi

	if [ "$WP60_COPYFLG" = '1' -a ! -f $APPDEF/Wp60 ]
	then
		echo
		if [ -d "$APPDEF" ]
		then
			echo "     Warning: Unable to copy Wp60 to $APPDEF"
			if [ -d "$APPDEF1" ]
			then
				echo "     Warning: Unable to copy Wp60 to $APPDEF1"
			fi
		else
			echo "     Warning: Unable to copy Wp60 to the app-defaults directory."
		fi
		echo "     Wp60 will be installed in the wplib directory."
		echo "     This will affect the default colors for WordPerfect 6.0."
		echo "     Refer to Default Colors in your documentation for more information."
		echo $APPDEF > $thisdir/install/AppDefDir 2> /dev/null
	fi
}

desk_top()
{
	if [ "$Lflg" = 'L' -o "$Pflg" = 'P' -o "$Tflg" = 'T' ]
	then
		return		# don't ask during partial installs
	fi

	if [ -f $IDIR/shbin10/dtinstall ]
	then
		while :
		do
			echo
			echo "     Do you want to add the icon for WordPerfect 6.0 to your desktop?"
			echo
			echo $NL "     Yes or No (Y/N) $NL1"
			read RS
			if [ "$RS" = 'y' -o "$RS" = 'Y' ]
			then
				echo
				if [ -f $IDIR/shbin10/dtinstall.sa ]
				then			# is there a system administrator version?
					$IDIR/shbin10/dtinstall.sa	# yes, run it
				else
					$IDIR/shbin10/dtinstall		# no, run regular one
				fi
				return
			fi

			if [ "$RS" = 'n' -o "$RS" = 'N' ]
			then
				return
			else
				echo "Invalid Response"
				sleep 1
			fi
		done
	fi
}

wpinstallgui()
{
	echo
	echo "      Now starting the Corel GUI installation program..."

# run xwpinstall (calls installloop and wpinst1)
	./xwpinstall $thisdir/ $Aflg $Lflg $Pflg $Tflg
	if [ "$?" = 99 ]
	then
		return
	fi
	if [ -f installdir ]
	then
		INSTALLDIR=`cat installdir`
		check_admin
		rm -f installdir
		if [ "$WPUPDATE" = 'y' ]			# a reinstall?
		then								# yes, remove temp tar directory
			if [ -d $INSTALLDIR ]
			then
				mv -f $INSTALLDIR/$tprg $INSTALLDIR/oldjunk
				cp $tardir/$tprg $INSTALLDIR 2> /dev/null # install yourself
				rm -f $INSTALLDIR/oldjunk 2> /dev/null
			fi
			cd /
			rm -rf $tardir
		else								# no, clean up the normal way
			RMDIR=`pwd`
			cd $tardir
			rm -rf $RMDIR
			if [ -d $INSTALLDIR ]
			then
				mv -f $INSTALLDIR/$tprg $INSTALLDIR/oldjunk 2> /dev/null
				cp $tardir/$tprg $INSTALLDIR 2> /dev/null # install yourself
				rm -f $INSTALLDIR/oldjunk $tardir/$tprg 2> /dev/null
			else
				rm -f $tardir/$tprg 2> /dev/null
			fi
		fi
	fi

	IDIR=`echo $INSTALLDIR | sed 's|/[^/]*.$||g'` # dirname
	if [ -f $IDIR/wpbin/xwp -a -f $IDIR/wpbin/wp ]
	then
		WPEXE="./xwp or ./wp"
	elif [ -f $IDIR/wpbin/xwp ]
	then
		WPEXE="./xwp"
	else
		WPEXE="./wp"
	fi
	if [ $WpSix_0 = 'y' ]
	then
		desk_top
		echo
		if [ -f $IDIR/wpbin/wp ]
		then
			echo "Refer to your WordPerfect 5.2 Installation Guide for help on setting"
			echo "the WPTERM52 environment variable."
			echo
		fi
		echo "You may now cd to $IDIR/wpbin and run $WPEXE"
	fi
	clean_up
}

cd_media()
{
	while [ : ]
	do
		echo
		echo "     If your media is a CD, mount it and enter the directory where its"
		echo $NL "     mounted.  Otherwise just press Enter: $NL1"
		read CDDIR
		CDDIR=`echo $CDDIR | sed 's|/*/|/|g' | sed 's|/ *$||g'`
		if [ "$CDDIR" != "" ]
		then
			if [ -d "$CDDIR" -a \( -f "$CDDIR"/install.wp -o -f "$CDDIR"/INSTALL.WP \) ]
			then
				if [ -f "$CDDIR"/install.wp ]
				then
					INST_WP=$CDDIR/install.wp
				else
					INST_WP=$CDDIR/INSTALL.WP
				fi
				if [ "$*" = "-a" ]
				then
					def_idir=`echo $thisdir | sed 's|/[^/]*.$||g'` # dirname
					echo "$def_idir" > /tmp/instdir
					$INST_WP $DEBUG -full
					clean_up 0
				else
					echo
					echo "     Please Wait"
					Linkit="$INST_WP $DEBUG -partial $thisdir $* $LLIST $PLIST"
					$Linkit
					RTVAL=$?
					LNKDIR=`cat /tmp/lnkdir 2> /dev/null`
					if [ "$RTVAL" != 0 ]
					then
						clean_up
					fi
					tardir=`cat $LNKDIR/ifiles/tardir 2> /dev/null`
					rm -f /tmp/tardir /tmp/lnkdir
					if [ "$tardir" = "" ]
					then
						echo $Linkit
						$Linkit	# show the error this time
						echo
						echo "Try running $INST_WP $*"
						clean_up
					else
						cd $tardir/install
						return
					fi
				fi
			else
				echo "Invalid Directory"
				sleep 2
				echo
			fi
		else
			return
		fi
	done
}

which_filesys()
{
	MINBLOCKS=1000
	msize=0
	msize2=0
	cnt=0
	firstflg=0
	DFLINE=`df $DFPARAMS 2> /dev/null`
	szdesc=Kbytes

	set $DFLINE
	w6="$6"
	shift; shift
	w8="$6"
	w11="$9"
 
	if [ "$w6" = "Mounted" ]	# SPARC/(HP/DG - nonroot)
	then
		num_to_skip=6
		FSSize=4
		SizeDesc=5
		FSName=6
		LineSize=6
	elif [ "$w8" = "Mounted" ]	# RS6000
	then
		num_to_skip=8
		FSSize=3
		SizeDesc=4
		FSName=7
		LineSize=7
	elif [ "$w11" = "Mounted" ]	# DEC
	then
		num_to_skip=11
		FSSize=4
		SizeDesc=5
		FSName=6
		LineSize=6
	else						# SCO/(HP/DG - root)
		num_to_skip=-1			# no headings to skip
		FSSize=3
		SizeDesc=4
		FSName=1
		LineSize=6
	fi
 
	for x in $DFLINE			# look for free space among file systems
	do
		if [ $firstflg -le $num_to_skip ]	# skip the headings
		then
			firstflg=`expr $firstflg + 1`
			continue
		fi

		cnt=`expr $cnt + 1`
		if [ "$cnt" = 3 -a $x = "):" ] 	# skip the headings
		then
			cnt=`expr $cnt - 1`		# SCO/HP/DG
			continue
		fi

		if [ $cnt = $FSSize ]		# found a file system size?
		then
			cursize=$x
		fi

		if [ $cnt = "$SizeDesc" -a $x = "blocks" ]	# found a size descriptor?
		then
			szdesc=$x
		fi

		if [ $cnt = $FSName ]		# found a file system name
		then
			curname=$x
		fi

		if [ $cnt = $LineSize ]		# reached the end of the df line
		then
			if [ $curname = "/" ]
			then
				touch /uNlIkLey 2> /dev/null
			else
				touch $curname/uNlIkLey 2> /dev/null
			fi
			if [ "$?" != 0 ]
			then
				if [ $curname = "/" ]
				then
					rm -f /uNlIkLey
				else
					rm -f $curname/uNlIkLey
				fi
				cnt=0
				continue
			fi
			if [ $curname = "/" ]
			then
				rm -f /uNlIkLey
			else
				rm -f $curname/uNlIkLey
			fi
	
# save off the largest file system for possible use later.
			if [ $msize -lt $cursize ]
			then
				msize=$cursize
				dflist1="$curname $cursize"
			fi

# skip file systems less than MINBLOCKS blocks.
			if [ $MINBLOCKS -gt $cursize ]
			then
				cnt=0
				continue
			fi

# save off the file system name and size; put the largest file system first.
			if [ $msize2 -le $cursize ]
			then
				msize2=$cursize
				dflist="$curname $cursize $dflist"	# bigger, add to list front
			else
				dflist="$dflist $curname $cursize"	# smaller, add to list end
			fi
			cnt=0
		fi
	done

# if no file system has MINBLOCKS blocks show the user the largest anyway.
	if [ "$dflist"x = x ]
	then
		dflist="$dflist1"
	fi

	if [ "$dflist" = "" ]	# any partitions the user can write to?
	then					# no, exit before 'set' command messes up screen.
		echo "     ERROR: No write permission on any of the mounted file systems."
		clean_up 1
	fi

	while [ "$validated" != y ]
	do
		fflg=1
		cnt=0
		savecnt=""
		set $dflist
		while [ "$1" ]				# create menu of partitions for user
		do
			cnt=`expr $cnt + 1`
			if [ $fflg = 1 ]
			then
				echo
				echo "     Before you can reinstall WordPerfect 6.0 or do a partial"
				echo "     installation, you must load the files from the media into a"
				echo "     temporary location on your system.  From there, the Installation"
				echo "     Program will install them into the permanent Corel product "
				echo "     directory structure."
				echo
				echo "     Select one of the following filesystems (directories) as a"
				echo "     temporary location to be used during the installation process."
				echo
				echo "     Mounted Filesystem                Size"
				echo "     ------------------                ----"
			fi
			if [ $fflg = 1 ]
			then
				fflg=0
				echo "$cnt $1 $2 $szdesc" | awk '{printf "     %2d) %-21s    %10d %s (Default)\n",$1, $2, $3, $4}'
			else
				echo "$cnt $1 $2 $szdesc" | awk '{printf "     %2d) %-21s    %10d %s\n",$1, $2, $3, $4}'
			fi
			shift;shift
			savecnt="$savecnt $cnt"
		done

		echo 
		echo "     Press Enter to accept the default filesystem (directory) or type"
		echo "     the number corresponding to the filesystem (directory) to be used"
		echo $NL "     and then press Enter: $NL1"
		read answer
		if [ ! "$answer" ]		# the user took the default
		then
			answer=1
		fi

		set $dflist
		for z in $savecnt		# determine selection
		do
			if [ $z = $answer ]
			then
				validated=y
				if [ $1 = / ]
				then
					tardir=/WPTEMP
				else
					tardir=$1/WPTEMP
				fi
				EXT=1
				svtardir=$tardir
				while :	#if WPTEMP already exists, use WPTEMP1, WPTEMP2, etc.
				do
					if [ -d $tardir ]
					then
						tardir=$svtardir$EXT
						EXT=`expr $EXT + 1`
						continue
					fi
					break
				done
				break
			fi
			shift;shift
		done
		if [ "$validated" != y ]
		then
			echo "Invalid Selection"
			sleep 2
			echo
		fi
	done

	echo
	echo "     '$tardir' has been created as the temporary location for the"
	echo "     install.  This directory and its contents will be deleted when the"
	echo "     installation is completed."
	echo
	mkdir $tardir 2> /dev/null	# make a temp directory
	export tardir
}

display_usage()
{
#	echo "Usage: wpinstall -a | -l lang_code [lang_code ...] | -p [lang_code ...]"
	echo "Usage: wpinstall -a"
	echo "       wpinstall -l lang_code [lang_code ...]"
	echo "       wpinstall -p [lang_code]"
	echo "       -a: reinstall a full product"
	echo "       -l lang_code(s): install language module(s)"
	echo "       -p: select/update printers for the default language"
	echo "       -p lang_code: select/update printers for the specified language"
	echo "       -t: select/update terminals"
	clean_up
}

find_ptr_langs()
{
	pcnt=0
	NEWLNG=""
	PLIST=""
	_P_LANGS=""
	PJNK="prsinfo.af prsinfo.ca prsinfo.ce prsinfo.cf prsinfo.de prsinfo.dk prsinfo.es prsinfo.fr prsinfo.it prsinfo.nl prsinfo.no prsinfo.oz prsinfo.sd prsinfo.su prsinfo.sv prsinfo.uk prsinfo.us"
	while [ "$1" != "" ]
	do
		if [ "$1" = -p -o "$1" = -pl -o "$1" = -lp -o "$1" = -pt -o "$1" = -tp -o "$1" = -plt -o "$1" = -ptl -o "$1" = -lpt -o "$1" = -ltp -o "$1" = -tpl -o "$1" = -tlp ]
		then
			while [ "$1" != "" ]
			do
				shift
				if [ "$1" = "" ]
				then
					break 2
				else
					PLIST="$PLIST $1"
					pcnt=`expr $pcnt + 1`
					case $1 in
						af) NEWLNG="_P_AF ./_P_AF"
							PJNK=`echo $PJNK | sed -e 's/prsinfo.af//g'`;;
						ca) NEWLNG="_P_CA ./_P_CA"
							PJNK=`echo $PJNK | sed -e 's/prsinfo.ca//g'`;;
						ce) NEWLNG="_P_CE ./_P_CE"
							PJNK=`echo $PJNK | sed -e 's/prsinfo.ce//g'`;;
						cf) NEWLNG="_P_CF ./_P_CF"
							PJNK=`echo $PJNK | sed -e 's/prsinfo.cf//g'`;;
						de) NEWLNG="_P_DE ./_P_DE"
							PJNK=`echo $PJNK | sed -e 's/prsinfo.de//g'`;;
						dk) NEWLNG="_P_DK ./_P_DK"
							PJNK=`echo $PJNK | sed -e 's/prsinfo.dk//g'`;;
						es) NEWLNG="_P_ES ./_P_ES"
							PJNK=`echo $PJNK | sed -e 's/prsinfo.es//g'`;;
						fr) NEWLNG="_P_FR ./_P_FR"
							PJNK=`echo $PJNK | sed -e 's/prsinfo.fr//g'`;;
						it) NEWLNG="_P_IT ./_P_IT"
							PJNK=`echo $PJNK | sed -e 's/prsinfo.it//g'`;;
						nl) NEWLNG="_P_NL ./_P_NL"
							PJNK=`echo $PJNK | sed -e 's/prsinfo.nl//g'`;;
						no) NEWLNG="_P_NO ./_P_NO"
							PJNK=`echo $PJNK | sed -e 's/prsinfo.no//g'`;;
						oz) NEWLNG="_P_OZ ./_P_OZ"
							PJNK=`echo $PJNK | sed -e 's/prsinfo.oz//g'`;;
						sd) NEWLNG="_P_SD ./_P_SD"
							PJNK=`echo $PJNK | sed -e 's/prsinfo.sd//g'`;;
						su) NEWLNG="_P_SU ./_P_SU"
							PJNK=`echo $PJNK | sed -e 's/prsinfo.su//g'`;;
						sv) NEWLNG="_P_SV ./_P_SV"
							PJNK=`echo $PJNK | sed -e 's/prsinfo.sv//g'`;;
						uk) NEWLNG="_P_UK ./_P_UK"
							PJNK=`echo $PJNK | sed -e 's/prsinfo.uk//g'`;;
						us) NEWLNG="_P_US ./_P_US"
							PJNK=`echo $PJNK | sed -e 's/prsinfo.us//g'`;;
						-p) continue;;
						-l) pcnt=`expr $pcnt - 1`
							break 2;;
						 *) echo "Bad Language Code: $1"
							echo "Valid Language Codes: af ca ce cf de dk es fr it nl no oz sd su sv uk us"
							clean_up;;
					esac
					_P_LANGS="${_P_LANGS} ${NEWLNG}"
				fi
			done
		else
			shift
		fi
	done
	if [ "$pcnt" != 0 -a "$pcnt" != 1 ]
	then
		display_usage
	fi
	export PLIST
}

find_langs()
{
	NEWLNG=""
	_L_LANGS=""
	LLIST=""
	LJNK="lang.af lang.ca lang.ce lang.cf lang.de lang.dk lang.es lang.fr lang.it lang.nl lang.no lang.oz lang.sd lang.su lang.sv lang.uk lang.us"
	while [ "$1" != "" ]
	do
		if [ "$1" = -l -o "$1" = -lp -o "$1" = -pl -o "$1" = -lt -o "$1" = -tl -o "$1" = -lpt -o "$1" = -ltp -o "$1" = -plt -o "$1" = -ptl -o "$1" = -tlp -o "$1" = -tpl ]
		then
			while [ "$1" != "" ]
			do
				shift
				if [ "$1" = "" ]
				then
					break 2
				else
					LLIST="$LLIST $1"
					case $1 in
						af) NEWLNG="_AF ./_AF"
							LJNK=`echo $LJNK | sed -e 's/lang.af//g'`;;
						ca) NEWLNG="_CA ./_CA"
							LJNK=`echo $LJNK | sed -e 's/lang.ca//g'`;;
						ce) NEWLNG="_CE ./_CE"
							LJNK=`echo $LJNK | sed -e 's/lang.ce//g'`;;
						cf) NEWLNG="_CF ./_CF"
							LJNK=`echo $LJNK | sed -e 's/lang.cf//g'`;;
						de) NEWLNG="_DE ./_DE"
							LJNK=`echo $LJNK | sed -e 's/lang.de//g'`;;
						dk) NEWLNG="_DK ./_DK"
							LJNK=`echo $LJNK | sed -e 's/lang.dk//g'`;;
						es) NEWLNG="_ES ./_ES"
							LJNK=`echo $LJNK | sed -e 's/lang.es//g'`;;
						fr) NEWLNG="_FR ./_FR"
							LJNK=`echo $LJNK | sed -e 's/lang.fr//g'`;;
						it) NEWLNG="_IT ./_IT"
							LJNK=`echo $LJNK | sed -e 's/lang.it//g'`;;
						nl) NEWLNG="_NL ./_NL"
							LJNK=`echo $LJNK | sed -e 's/lang.nl//g'`;;
						no) NEWLNG="_NO ./_NO"
							LJNK=`echo $LJNK | sed -e 's/lang.no//g'`;;
						oz) NEWLNG="_OZ ./_OZ"
							LJNK=`echo $LJNK | sed -e 's/lang.oz//g'`;;
						sd) NEWLNG="_SD ./_SD"
							LJNK=`echo $LJNK | sed -e 's/lang.sd//g'`;;
						su) NEWLNG="_SU ./_SU"
							LJNK=`echo $LJNK | sed -e 's/lang.su//g'`;;
						sv) NEWLNG="_SV ./_SV"
							LJNK=`echo $LJNK | sed -e 's/lang.sv//g'`;;
						uk) NEWLNG="_UK ./_UK"
							LJNK=`echo $LJNK | sed -e 's/lang.uk//g'`;;
						us) NEWLNG="_US ./_US"
							LJNK=`echo $LJNK | sed -e 's/lang.us//g'`;;
						-l) continue;;
						-p) break 2;;
						 *) echo "Bad Language Code: $1"
							echo "Valid Language Codes: af ca ce cf de dk es fr it nl no oz sd su sv uk us"
							clean_up;;
					esac
					_L_LANGS="${_L_LANGS} ${NEWLNG}"
				fi
			done
		else
			shift
		fi
	done
	if [ "$_L_LANGS" = "" ]
	then
		display_usage
	fi
	export LLIST
}

##########################
##  START of wpinstall  ##
##########################

trap "clean_up 1" 2

# find the installation directory and go there if not there
thisdir=`echo $0 | sed 's|/[^/]*.$||g'` # dirname
tprg=`echo $0 | awk -F/ '{print $NF}'` # basename
if [ $thisdir != "." -a $thisdir != "./" -a $thisdir != "$0" ]
then
	cd $thisdir
fi
thisdir=`pwd`

if [ -f $thisdir/install/wpinstall ]	# started from "."
then									# yes, restart from install directory
	$thisdir/install/wpinstall $*
	clean_up 0
fi

tardir=`echo $thisdir | sed 's|/[^/]*.$||g'` # save tardir directory
idir=`echo $thisdir | awk -F/ '{print $NF}'` # save install directory
thisdir=$tardir # use parent directory
LNKDIR=""
if [ "$idir" = "install" -a "$1" != "-cdrom" ]
then
	if [ "$*" != "" ]
	then
		echo "ERROR:  Command line options are not allowed on an initial installation."
		echo "After WordPerfect has been installed, command line options can"
		echo "be used for reinstallations or partial installations."
		clean_up
	fi
else
	if [ "$1" = "-cdrom" ]	# from a CD-ROM?
	then					# yes
		CDROMflg='y'
		shift
		thisdir=$1			# get the installation path
		shift
	fi
	params="$*"
	if [ "$*" != '-a' -a "$*" != '-A' ]
	then	# remove lang_codes and misc others
		params=`echo "$*" | sed \
			-e 's/af//g' -e 's/ca//g' -e 's/ce//g' -e 's/cf//g' -e 's/de//g' \
			-e 's/dk//g' -e 's/es//g' -e 's/fr//g' -e 's/it//g' -e 's/nl//g' \
			-e 's/no//g' -e 's/oz//g' -e 's/sd//g' -e 's/su//g' -e 's/sv//g' \
			-e 's/uk//g' -e 's/us//g'`
		params1=`echo "$params" | sed \
			-e 's/ //g' -e 's/-//g' -e 's/a//g' \
			-e 's/l//g' -e 's/p//g' -e 's/t//g'`
		if [ "$params1" != "" ]	# anything left?
		then					# yes, display error
			invalid='y'
		fi
	fi
	if [ "$1" = "" -o "$invalid" = 'y' ]
	then
		display_usage
	else
		if [ "$params" != "`echo "$params" | sed 's/a//g'`" ]
		then
			Aflg='A'		# reinstall a full product
		fi
		if [ "$params" != "`echo "$params" | sed 's/l//g'`" ]
		then
			Lflg='L'		# install a language module
			find_langs $*
		fi
		if [ "$params" != "`echo "$params" | sed 's/p//g'`" ]
		then
			Pflg='P'		# select/update printers
			find_ptr_langs $*
			if [ "$_P_LANGS" = "" ]	# did user specify lang_code(s)?
			then					# no, use the default language
				DefLang="-p us"
				if [ -f ../wplib/.def.lang ]
				then
					DefLang="-p `cat ../wplib/.def.lang`"
				fi
				find_ptr_langs $DefLang
			fi
		fi
		if [ "$params" != "`echo "$params" | sed 's/t//g'`" ]
		then
			Tflg='T'			# select/update terminals
		fi
	fi
	WPUPDATE='y'

	if [ "$CDROMflg" != 'y' ]	# dont mess with thisdir on CD
	then
		olddir=`pwd`
		cd ..
		thisdir=`pwd`			# save off the installation directory
		cd $olddir
	fi
fi
if [ "$Aflg" != 'A' -a "$Lflg" != 'L' -a "$Pflg" != 'P' -a "$Tflg" != 'T' ]
then
	NOflg='N'
fi

moveclient='n'
if [ -f .Ad41 -a -f .Gw41 ]
then
	moveclient='y'
fi

# make sure the user is root
if [ -f ./wgeteuid -a "$moveclient" != 'y' ]
then
	./wgeteuid 2> /dev/null
	if [ $? != 0 ]
	then
		echo "You must be root to run the Installation Program."
		clean_up
	fi
fi

# which echo is being used?
NL="-n"
NL1=
if [ "-nZ" = "`echo -nZ`" ]
then
	NL=
	NL1="\c"
fi
export NL NL1

# set umask
umask 0

if [ -f $tardir/install/.SOLARIS ]	# Solaris?
then
	DFPARAMS="-k"			# yes, set df parameter
fi

if [ -f $tardir/install/.SGIMIPS ]	# MIPS?
then
	DFPARAMS="-k"			# yes, set df parameter
fi

if [ "$CDROMflg" != 'y' ]
then
	if [ "$WPUPDATE" = 'y' ] # a reinstall
	then
		cd_media $params
		if [ "$CDDIR" = "" ]
		then
			pgbreak
			which_filesys
			pgbreak
			perform_tar			# extract files from the media
			rm -f $PJNK $LJNK
		fi
	else					# a full install
		is_tar_needed		# determine if files have been extracted from media
	fi
fi

if [ -f $tardir/install/.UNIXWARE ]	# System V release?
then
	ulimit 20480 2> /dev/null
	NEW_ULIMIT=`ulimit`

	if [ `expr $NEW_ULIMIT \< 20480` != 0 ]
	then
		echo "You must either increase your ulimit to at least 20480 before proceeding"
		echo "or you must become root to run the Installation Program."
		clean_up 1
	fi
fi

if [ "$moveclient" = 'y' ]
then
	MoveClient
fi

WpSix_0='n'
Office='n'
OffMsg='n'
OffAd='n'
if [ -f .Wp60 ]
then
	WpSix_0='y'
fi
if [ -f .Gw41 ]
then
	Office='y'
fi
if [ -f .Ms41 ]
then
	OffMsg='y'
fi
if [ -f .Ad41 ]
then
	OffAd='y'
fi

export thisdir tardir WPUPDATE Aflg Lflg Pflg Tflg NOflg decomp_flg \
	OffAd OffMsg Office WpSix_0

if [ -f xwpinstall ]
then
	decomp_file xwpinstall
fi
if [ -f wpinstall.char ]
then
	decomp_file wpinstall.char
fi

prelim_stuff

if [ -f xwpinstall ]
then
	./xwpinstall -test > TMPERR 2>&1		# can a gui program run?
	if [ "$?" = 0 ]
	then
		rm -f TMPERR
		wpinstallgui						# yes - run gui install
		clean_up
	fi
fi

if [ -f ./wpinstall.char ]
then
	if [ -d /usr/bin/X11 -a "$SKIP_GUI" = "" -a "$NOflg" = "N" ]	#Check to see if error will make sense
	then
		echo
		echo "     Unable to run the GUI install..."
		cat TMPERR | sed 's/Error: /          /g'
		rm -f TMPERR
		echo
		echo $NL "     Start the character-based install? (Y/N) Y$NL1"
		read docharinst
		if [ "$docharinst" = "n" -o "$docharinst" = "N" ]
		then
			clean_up
		else
			SKIP_GUI="YES"
			export SKIP_GUI
			./wpinstall.char $DEBUG					# run character install
		fi
	else					#otherwise, just run character version
		export SKIP_GUI
		echo
		echo "     Starting the character-based install."
		./wpinstall.char $DEBUG
	fi
else
	rm -f TMPERR
	clean_up
fi
if [ "$?" = 99 ]
then
	clean_up
fi
if [ -f installdir ]
then
	INSTALLDIR=`cat installdir`
	check_admin
	rm -f installdir
	if [ "$WPUPDATE" = 'y' ]				# a reinstall?
	then									# yes, remove temporary tar dir
		if [ -d $INSTALLDIR ]
		then
			mv -f $INSTALLDIR/$tprg $INSTALLDIR/oldjunk
			cp $tardir/$tprg $INSTALLDIR 2> /dev/null # install yourself
			rm -f $INSTALLDIR/oldjunk 2> /dev/null
		fi
		cd /
		rm -rf $tardir
	else									# no, clean up the normal way
		RMDIR=`pwd`
		cd $tardir
		rm -rf $RMDIR						# delete the install stuff
		if [ -d $INSTALLDIR ]
		then
			mv -f $INSTALLDIR/$tprg $INSTALLDIR/oldjunk 2> /dev/null
			cp $tardir/$tprg $INSTALLDIR 2> /dev/null	# install yourself
			rm -f $INSTALLDIR/oldjunk $tardir/$tprg 2> /dev/null
		else
			rm -f $tardir/$tprg 2> /dev/null
		fi
	fi
else
	if [ "$WPUPDATE" != 'y' ]				# a reinstall?
	then									# no
		RMDIR=`pwd`
		cd $tardir
		rm -rf $RMDIR						# delete the install stuff
		rm -f $tardir/$tprg
	fi
fi

IDIR=`echo $INSTALLDIR | sed 's|/[^/]*.$||g'` # dirname
if [ -f $IDIR/wpbin/xwp -a -f $IDIR/wpbin/wp ]
then
	WPEXE="./xwp or ./wp"
elif [ -f $IDIR/wpbin/xwp ]
then
	WPEXE="./xwp"
else
	WPEXE="./wp"
fi
if [ $WpSix_0 = 'y' ]
then
	desk_top
	echo
	if [ -f $IDIR/wpbin/wp ]
	then
		echo "Refer to your WordPerfect 5.2 Installation Guide for help on setting"
		echo "the WPTERM52 environment variable."
		echo
	fi
	echo "You may now cd to $IDIR/wpbin and run $WPEXE"
fi
clean_up

