#!/bin/sh 
# Digital-Signature:  tipix 335EE44B
# /bin/sh -x for debugging
#
#  TIP/ix install script.  1991 through 2019, Inglenet Business Solutions
#
# THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF
#     Inglenet Business Solutions
#         www.inglenet.com  
#
#   $Id: installix,v 4.13 2020/01/20 18:49:23 rjn Exp $
#
#
#  Only "root" should run this. After using "tar" to copy the
# release media into a temporay working directory such as "/tmp/tipix" 
# then 'cd' to that directory and type "sh ./install"
# Or if you are not root, then  "sudo sh ./install"
# Either way the install scripts needs 'root' permission
#
#  On SVR4 systems you may want to copy media into /var/tmp/tipix.
# You must be sure that there is enough disk space. The disk
# space needed varies from 50 MB to 100 MB depending on the machine.
#

# prevent a configure script from thinking that this is a BSD-like install
[ "$1" = "-c" ] && exit -1

os2200Default="n"
takeDefault="n"
removeTemp="n"
if [ "$1" = "-y" ]
then
takeDefault="y"
fi
if [ "$1" = "-Y" ]
then
takeDefault="y"
removeTemp="y"
fi


NAME=`basename $0`
DIR=`pwd`
BASEDIR=$DIR
MACHINE=`uname -n`
OSNAME=`uname -s`
if [ "$OSNAME" = "Darwin" ]
then
OSNAME=MACOS
fi
WHERE=$MACHINE:$DIR
USERID=`id | sed 's@).*$@@;s@^.*(@@'`
quiet=N
query=Y
queryPath=Y
dogenapi=Y
TIPMSGFILE=$BASEDIR/tipfiles/tipmsg.dat

# Set this to Y so as not to confuse D-ISAM
TIPISAMDAT=Y

if  [ "$1" != "" -a "$1" != "-y" -a "$1" != "-Y" ]
then
#
##  This is for hpux because functions called with parameters will
##  set/reset $1
#
	TIPROOT=$1
	queryPath=N
fi

set -- `getopt "yYcC:T:OG" $*`
for OPTCH in $*
do
	case $OPTCH in
	-y)
		takeDefault="y"
		shift
		;;
	-Y)
		takeDefault="y"
		removeTemp="y"
		shift
		;;
	-O)
		os2200Default="y"
		shift
		;;
	-G)
		dogenapi="N"
		shift
		;;
	-C)
		COBDIR=$2
		export COBDIR
		setpath="$COBDIR/bin:$PATH"
		PATH=$setpath
		export PATH
		shift 2
		;;
	-T)
		TIPROOT=$2
		export TIPROOT
		shift 2
		;;
	-c)
		echo TIP/ix install script; Not BSD install 
		exit -1
		shift 
		;;
	--)
		shift
		break
		;;
	esac
done

echo -n | grep -- -n >/dev/null 2>&1
if [ $? -eq 0 ]
then
    echoflag=""
    echochar="\c"
else
    echoflag="-n"
    echochar=""
fi

UNCOMPRESS=uncompress
if [ -f /usr/bin/uncompress ]
then
	UNCOMPRESS=/usr/bin/uncompress
fi
if [ -f /bin/uncompress ]
then
	UNCOMPRESS=/bin/uncompress
fi
if [ "$UNCOMPRESS" = "uncompress" ]
then
	if [ -f /bin/gunzip ]
	then
		UNCOMPRESS="/bin/gunzip -d"
	fi
fi

#
##  Test for the type of copy command that can be used...
#
if [ ! -f VERSION ]
then
	echo The VERSION file was missing!
	echo "2015/05/28 2.5 R0 - 0302" > VERSION
	echo "Thu May 28 16:34:51 EDT 2015" >> VERSION
fi
if [ "$OSNAME" = "SunOS" -o "$OSNAME" = "Linux" -o "$OSNAME" = "HP-UX" -o "$OSNAME" = "MACOS" ]
then
	COPYPCMD="cp -p"
else
cp -p VERSION /tmp/VERSIONx 2>/dev/null
if  [ $? != 0 ]
then
echo Status is $?
	COPYPCMD="copy -o"
else
	COPYPCMD="cp -p"
fi
rm -f /tmp/VERSIONx
fi


pinfo() { [ "$quiet" = "N" ] && echo "$NAME: $*" ; }
perror() { pinfo "*** ERROR *** $*" ; }
pwarn() { pinfo "*** WARNING *** $*" ; }

pquest() { 
	if  [ "$query" = "Y" ]
	then
		[ "$quiet" = "N" ] && echo $echoflag "$NAME: $1 $echochar"
		read ANSWER
	fi
}

pquestY() { 
	if [ "$takeDefault" = "y" ]
	then
		ANSWER="Y"
	else
	if  [ "$query" = "Y" ]
	then
		[ "$quiet" = "N" ] && echo $echoflag "$NAME: $1 $echochar"
		read ANSWER
	fi
	fi
}
pquestN() { 
	if [ "$takeDefault" = "y" ]
	then
		ANSWER="N"
	else
	if  [ "$query" = "Y" ]
	then
		[ "$quiet" = "N" ] && echo $echoflag "$NAME: $1 $echochar"
		read ANSWER
	fi
	fi
}

fail() { 
	if  [ $# -gt 0 ]
	then
		status=$1
		if  [ $# -gt 1 ]
		then 
			shift
			if  [ "$status" != "0" ]
			then
				perror "$*"
				pinfo "Aborting..."
			else
				pinfo "$*"
			fi
		fi
	else
		status=1
	fi
	exit $status
}

contInstall()  {
	pquestY "Do you wish to continue with the installation? (<y>, n) >"
	case $ANSWER in
		""|"y"|"Y"|"yes"|"YES"|"Yes")  break ;;
		*)  fail 0 "Terminated by user" ;;
	esac
}


#trap "fail 1 'failed - interrupted'" 1 2 3 15
umask 0

if  [ "$USERID" != "root" ] 
then
	fail 1 "You must be root to install TIP/ix"
fi

tput clear

#
##  Put up a welcome message
#

pinfo "        TIP/ix Release `cat VERSION | head -1` Installation"
pinfo "        =================================================="
pinfo
pinfo "TIP/ix runs under its own userid and groupid for improved"
pinfo "system security.  If you have not already done so you should"
pinfo "create this TIP/ix administrative userid before continuing."
pinfo "The primary group for this adminstrative userid will be used as"
pinfo "the TIP/ix administrative group."
pinfo
pinfo "  TIP/ix build for `cat VERSION | tail -n 1` "
pinfo
contInstall


#
##  Get and validate TIPROOT.  TIPROOT will be set if passed in as
##  a parameter.
#
if [ "$queryPath" = "Y" ]
then 
	[ "$TIPROOT" = "" ] && TIPROOT=/usr/tipix
	pinfo
	pquest "Enter the path to TIP/ix system (<$TIPROOT>, q to quit) >"
	case $ANSWER in
	"") break ;;
	"q"|"Q"|"quit")  
	   fail 0 "Terminated by user" 
	   ;;
	*) TIPROOT=$ANSWER 
	   ;;
	esac
fi

# Prevent any destructive install at home
[ "$TIPROOT" = "/usr/u/tipsrc" ] && fail 1 "Cannot install to /usr/u/tipsrc."
[ "$TIPROOT" = "/u/tipsrc" ] && fail 1 "Cannot install to /u/tipsrc."
[ "$TIPROOT" = "$TIPSRC" ] && fail 1 "Cannot install over development $TIPSRC"
[ "$TIPROOT" = "/" ] && fail 1 "Cannot install to /"

# Ensure TIPROOT is absolute path and exists
[ "`expr //$TIPROOT : '//\(/.*\)'`" != "$TIPROOT" ] \
	&& fail 1 "Directory must be absolute"

[ "$TIPROOT" = "$BASEDIR" -o $DIR = "/" ] && fail 1 "Put tar files in a temporary directory."

# Make TIPROOT visible for TIP/ix install commands
export TIPROOT

if  [ ! -d $TIPROOT ]
then
	newInstall=Y
else
	newInstall=N
fi

#
##  Warn the installer about changes to security values.
#
SECOPT=-K
if  [ "$newInstall" = "N" ]
then
	pinfo 
	pinfo "The TIP\$SEC security values have been reviewed and"
	pinfo "adjusted to more appropriate values.  You may choose"
	pinfo "to have these values installed or preserve your"
	pinfo "current settings."
	pinfo 
	pquestN "Do you wish to install the new security values? (<n>, y) >"
	case $ANSWER in
	"y"|"Y"|"yes"|"YES"|"Yes") SECOPT= ;;
	*) break ;;
	esac
fi

#
##  Warn the installer about changes to security values.
#
if [ "$os2200Default" = "y" ]
then
LOGOFFIS=CLEAR
else
LOGOFFIS=FIN
pinfo 
pinfo "The LOGOFF transaction was like FIN for TIP/30, but"
pinfo "LOGOFF is like CLEAR for former OS2200"
pinfo 
pquestN "Are you a former OS2200 customer? (<n>, y) >"
case $ANSWER in
"y"|"Y"|"yes"|"YES"|"Yes") LOGOFFIS=CLEAR ;;
*) break ;;
esac
fi


#
##  Warn the installer about install removing the journal and qbl files.
#
if  [ -f $TIPROOT/tipfiles/tipix.jrn ]
then
    pinfo 
    pinfo " *** WARNING ***"
    pinfo 
    pinfo " The TIP/ix installation will remove any journal files and"
    pinfo " qbl files.  No data will be available for roll forwards"
    pinfo " or roll backwards once the install has completed."
    pinfo " Any required recovery should be performed before updating"
    pinfo " the TIP/ix system."
    pinfo 
	contInstall
fi

#
##  Set to install all components
#
copyTIP=Y
copyDOC=Y
copyDBI=Y
copyHSP=Y
copyDEV=Y
copyTQL=Y

###########################################################################
#  Preparation that must always been done regardless of what is to be     #
#  copied.                                                                #
###########################################################################

#
##  Just confirm before continuing
#
if  [ -f $TIPROOT/tipboot.sys ]
then
	installType=Updating
else
	installType=Installing
fi
pinfo 
pinfo "$installType TIP/ix system $TIPROOT from $BASEDIR"
pinfo
contInstall

#
##  Create TIP/ix directory structure.  If this is an update some 
##  directories might already exist.
#
if  [ ! -d $TIPROOT ]
then
	pinfo "Creating $TIPROOT directory"
	mkdir $TIPROOT
	[ ! $? ] && fail 1 "Unable to create $TIPROOT directory"
	chmod 0755 $TIPROOT
else
	if [ -f $TIPROOT/bin/tipctl ]
	then
		$TIPROOT/bin/tipctl shutdown		# make sure TIP/ix is not running
	fi
	newInstall=N
fi

cd $TIPROOT
for dir in bin conf help log scripts src tipfe tipfiles patch \
		tipfiles/dynamic tipfiles/sfg tipfiles/mcs tmpwrk tql lib
do
	if  [ ! -d $dir ]
	then
		mkdir $dir
		[ ! $? ] && fail 1 "Unable to create directory $TIPROOT/$dir"
	fi
	chmod 775 $dir
done
for dir in tipsoa cpy
do
	if  [ ! -d $dir ]
	then
		mkdir $dir
		[ ! $? ] && fail 1 "Unable to create directory $TIPROOT/$dir"
	fi
	chmod 777 $dir
done

cd $BASEDIR
if  [ -f $BASEDIR/bin/tipinstall.Z ]
then
	$UNCOMPRESS -f $BASEDIR/bin/tipinstall
fi
cp $BASEDIR/bin/tipinstall $TIPROOT/bin
chown root $TIPROOT/bin/tipinstall
chmod 4771  $TIPROOT/bin/tipinstall

if [ -f $TIPROOT/tipboot.sys ]
then
	pinfo "Updating system; run  tipinstall -i   later if needed"
	chmod a+r $TIPROOT/tipboot.sys
	$TIPROOT/bin/tipinstall
else
	if [ "$takeDefault" = "y" ]
	then
		$TIPROOT/bin/tipinstall -i -y
		[ $? -ne 0 ] && fail 1 "Unable to create boot file tipboot.sys"
	else
		$TIPROOT/bin/tipinstall -i 
		[ $? -ne 0 ] && fail 1 "Unable to create boot file tipboot.sys"
	fi
fi
x=`$TIPROOT/bin/tipinstall -t`
set $x
export TIPUID; TIPUID=$1
export TIPGID; TIPGID=$2

#
##  Set owner of directories created before TIPUID and TIPGID
##  was determined.
#
chown $TIPUID $TIPROOT
chgrp $TIPGID $TIPROOT
chmod u+rwx $TIPROOT
chmod g+rwx $TIPROOT
chmod o+rx $TIPROOT

cd $TIPROOT
for dir in bin conf help log lib scripts src tipfe tipfiles  \
		tipfiles/dynamic tipfiles/sfg tipfiles/mcs tmpwrk tql
do
	chown $TIPUID $dir
	chgrp $TIPGID $dir
	chmod u+rwx $dir
	chmod g+rwx $dir
	chmod o+rx $dir
done
cd $TIPROOT
for dir in cpy tipsoa 
do
	chown $TIPUID $dir
	chgrp $TIPGID $dir
	chmod a+rwx $dir
done

if  [ -f $TIPROOT/tipmmap ]
then
	chown $TIPUID $TIPROOT/tipmmap
	chgrp $TIPGID $TIPROOT/tipmmap
	chmod 0660 $TIPROOT/tipmmap
fi



###########################################################################
#  All required preparation has been completed and validated.  Start the  #
#  copy of the release contents.                                          #
###########################################################################

###################################################
##  Product: TIP/ix                              ##
###################################################

if  [ "$copyTIP" = "Y" ]
then

	pinfo
	pinfo "Installing base TIP/ix"

#
##  Uncompress the installation package.
#
	pinfo "Uncompressing TIP/ix modules for installation."
	cd $BASEDIR
	for dir in bin conf help scripts tipfiles tipfe
	do
		pinfo "	processing $dir"
		find $BASEDIR/$dir -type f -name "*.Z" -exec $UNCOMPRESS -f {} \; 2>/dev/null
	done

#
##  Copy/merge TIP/ix system files
#
	pinfo "Merging TIP/ix system files over to $TIPROOT"
	cd $TIPROOT
	chmod 777 $TIPROOT/tipfiles
	# SOME TIPFILES NEED OLD+NEW MERGED
	cp $BASEDIR/tipfiles/tipixmsg.* $TIPROOT/tipfiles  2>/dev/null
	chmod 664 $TIPROOT/tipfiles/tipixmsg.*
	cp $BASEDIR/tipfiles/tipiximage $TIPROOT/tipfiles 2>/dev/null
	chmod 444 $TIPROOT/tipfiles/tipiximage

	rm -f $TIPROOT/tipfiles/tipix.qbl $TIPROOT/tipfiles/tipix.jrn

	pinfo "	processing tipmcs"
	$TIPROOT/bin/tipinstall -H -m $BASEDIR/tipfiles/tipmcs >/dev/null
		[ $? -ne 0 ] && fail 1 "Unable to create tipmcs"

	pinfo "	processing tipsys"
	$TIPROOT/bin/tipinstall -H -g $BASEDIR/tipfiles/tipsys >/dev/null
		[ $? -ne 0 ] && fail 1 "Unable to create tipsys"

	pinfo "	processing tipsec"
	$TIPROOT/bin/tipinstall -H $SECOPT -s $BASEDIR/tipfiles/tipsec >/dev/null
		[ $? -ne 0 ] && fail 1 "Unable to create tipsec"
	$TIPROOT/bin/tipinstall -w LOGOFF -x $LOGOFFIS

	pinfo "	processing tipmsg"
	$TIPROOT/bin/tipinstall -H -c $BASEDIR/tipfiles/tipmsg >/dev/null
		[ $? -ne 0 ] && fail 1 "Unable to create tipmsg"

	pinfo "Constructing basic security information"
	$TIPROOT/bin/tipinstall -X >/dev/null
	[ $? -ne 0 ] && fail 1 "Unable to create security information"
	$TIPROOT/bin/tipinstall -p >/dev/null
	[ $? -ne 0 ] && fail 1 "Unable to set privilege field"

#
##  Transfer contents of $BASEDIR to $TIPROOT
#
	cd $BASEDIR
	for dir in bin help scripts 
	do
		pinfo "Copying $dir"
		find $dir -type f -exec $COPYPCMD {} $TIPROOT/$dir \;
		[ ! $? ] && fail $? "Unable to copy contents of $dir"
		find $TIPROOT/$dir -type f -exec chown $TIPUID {} \;
		find $TIPROOT/$dir -type f -exec chgrp $TIPGID {} \;
	done
#
##  The following should be setuid root
#
	for file in tipctl tipinstall tipmon tipmonldap tipdtp isreorg csmon csctl 
	do
		if  [ -f $file ]
		then
			chown root $file
			chgrp $TIPGID $file
			chmod 4775 $file
		fi
	done

	if [ -d tipfe ]
	then
		pinfo "Copying TIP/fe binaries"
		cd $BASEDIR/tipfe
		find . -exec $COPYPCMD -r {} $TIPROOT/tipfe \;
		[ ! $? ] && fail $? "Unable to copy contents of tipfe"
		find $TIPROOT/tipfe -exec chown $TIPUID {} \;
		find $TIPROOT/tipfe -exec chgrp $TIPGID {} \;
#
##  Make sure tipfe terminfo is defined
#
		pinfo "Installing TIP/fe terminfo entry"
		if  [ -f $BASEDIR/include/tipfe.ti.Z ]
		then
			$UNCOMPRESS -f $BASEDIR/include/tipfe.ti
		fi
		[ -x /usr/bin/tic_colr ] && tic_colr $BASEDIR/include/tipfe.ti
		tic $BASEDIR/include/tipfe.ti
	fi
	if  [ -f $BASEDIR/include/tipfe.ti.Z ]
	then
		$UNCOMPRESS -f $BASEDIR/include/tipfe.ti
	fi
	[ -x /usr/bin/tic_colr ] && /usr/bin/tic_colr $BASEDIR/include/tipfe.ti
	[ -x /bin/tic ] && /bin/tic $BASEDIR/include/tipfe.ti
	[ -x /usr/bin/tic ] && /usr/bin/tic $BASEDIR/include/tipfe.ti
	if [ "x$COBDIR" = "x" ]
	then
		pinfo "COBDIR is not defined for Micro Focus Cobol"
	else
		[ -x $COBDIR/bin/mftic ] && pinfo " Runing  mftic tipfe.ti"
		[ -x $COBDIR/bin/mftic ] && $COBDIR/bin/mftic $BASEDIR/include/tipfe.ti
	fi

#
##  Complete permissions changes for executables
#
	pinfo "Setting executable permissions"
	cd $TIPROOT/bin
#
##  The following are runnable only by root
#
	for file in fixperms
	do
		if  [ -f $file ]
		then
			chown root $file
			chgrp $TIPGID $file
			chmod 744 $file
		fi
	done
	
#
##  The following should be setuid root
#
	for file in tipctl tipinstall tipmon tipmonldap tipdtp isreorg isrembp isrembp4 
	do
		if  [ -f $file ]
		then
			chown root $file
			chgrp $TIPGID $file
			chmod 4775 $file
		fi
	done

#
##  The following are links to tipctl
#
	for file in apb boottip eoj msg stopsystem stoptip
	do
		rm -f $file
		ln -s tipctl $file
	done

#
##  The following is a link to whoson
#
	for file in die purge setlog
	do
		rm -f $file
		ln -s whoson $file
	done

#
##  The following are links to fopen
#
	for file in fclose lopen lclose lreset freset tranup trandown portup portdown
	do
		rm -f $file
		ln -s fopen $file
	done

#
##  The following are links to  status
#
    for file in dsf
    do
        rm -f $file
        ln -s status $file
    done

#
##  The following should be setuid TIPUID setgid TIPGID
#
	for file in cnvseq jrnswap mbpfcs mbp4fcs dpscnv msgar readjrn rollfwd tfd tipfcs tipmcsio tipdump tipvbfcs
	do
		if  [ -f $file ]
		then
			chown $TIPUID $file
			chgrp $TIPGID $file
			chmod 6775 $file
		fi
	done

#
##  The following should not be setuid
#
	for file in seqreorg
	do
		if  [ -f $file ]
		then
			chown $TIPUID $file
			chgrp $TIPGID $file
			chmod 0775 $file
		fi
	done

#
##  The following should be setuid TIPUID
#
	for file in readjrn tippack tippcstm tipque tipupack tipstartup
	do
		if  [ -f $file ]
		then
			chown $TIPUID $file
			chgrp $TIPGID $file
			chmod 4775 $file
		fi
	done


#
##  The following should be setgid TIPGID
#
	for file in aft fcsdbug fopen isonline pingtip precob status \
				whoson dcheck tipflg \
				tipback tipixtcp tipixcpi tipixtty tiprsub tipixcs tipixint1 \
				tipbatsv tipixsoa tipixua tipixaion tipixcita 
	do
		if  [ -f $file ]
		then
			chown $TIPUID $file
			chgrp $TIPGID $file
			chmod 2775 $file
		fi
	done

#
##  Fix permissions on TIP/ix system files
#
	pinfo "Fixing permissions on TIP/ix system files"
	$TIPROOT/bin/fixperms -1sd
	cd $TIPROOT
	for dir in bin log tipfiles tipfiles/dynamic tipfiles/sfg tipfiles/mcs tmpwrk
	do
		if  [ -d $dir ]
		then
			chmod 777 $dir
		fi
	done
	cd $TIPROOT/tipfiles
	for file in tipmcs tipmsg tipsec tipsys
	do
		chown $TIPUID $file.*
		chgrp $TIPGID $file.*
		chmod 664 $file.*
		if  [ -f $TIPROOT/bin/isreorg ]
		then
		$TIPROOT/bin/isreorg -r -q $file
		fi
	done
	for file in tipmnu tiptrm
	do
		if  [ -f $file.dat ]
		then
			if  [ -f $TIPROOT/bin/isreorg ]
			then
			$TIPROOT/bin/isreorg -r -q $file
			fi
		fi
	done
#
##  End executable-permissions section
#

#
##  Create conf file if doesn't exist or move it if
##  it already exists under $TIPROOT
#
	if [ ! -f $TIPROOT/conf/tipix.conf ]
	then
		if  [ -f $TIPROOT/tipix.conf ]
		then
			pinfo "Moving $TIPROOT/tipix.conf to $TIPROOT/conf directory"
			mv -f $TIPROOT/tipix.conf $TIPROOT/conf/tipix.conf
		else
			pinfo "Creating default tipix.conf file"
#
##  Add TIPROOT/bin to PATH for tipix.conf, if not present already
#
			if [ `expr "$PATH" : ".*$TIPROOT/bin.*"` -eq 0 ]
			then
				setpath="$TIPROOT/bin:$PATH"
			else
				setpath="$PATH"
			fi
			cat > $TIPROOT/conf/tipix.conf << EOF
# Default tipix.conf file
# Created automatically by $NAME `date`
# (c) Copyright 1991-2019  Inglenet Business Solutions  All Rights Reserved
#
# THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF
#         Inglenet Business Solutions
#    www.inglenet.com   
#
# The copyright notice above does not evidence any actual or
# intended publication of such source code.
#
# This tipix.conf file was generated from $USER's environment
# during a TIP/ix installation.  It should contain environment
# variable settings to be used by all TIP/ix daemons.  Previously
# the environments of the daemons were taken from the user who
# booted TIP/ix.
#
# Valid tipix.conf commands are: SETENV, INCLUDE, CLEARENV, and EXIT.
# Consult your release notes for details about the tipix.conf file.
#
EOF
			PATH="$setpath" env | sed -n -e "/^PATH/P" \
			                             -e "/^LANG/P" \
										 -e "/^LC_/P"	\
										 -e "/^COBDIR/P" \
										 -e "/^LD_LIBRARY_PATH/P" \
										 -e "/^TZ/P"               \
										>> $TIPROOT/conf/tipix.conf
			chmod 664 $TIPROOT/conf/tipix.conf
			chown $TIPUID $TIPROOT/conf/tipix.conf
			chgrp $TIPGID $TIPROOT/conf/tipix.conf
		fi
	fi

# Move in VERSION for later update procedure
cp $BASEDIR/VERSION $TIPROOT/conf/VERSION
cp $BASEDIR/README $TIPROOT/conf/README

#
##  Clean up any obsolete files
#
	pinfo "Removing obsolete items"

	cd /usr/bin 
	rm -f tipix tipctl tipfcs tipinstall genmain tipmon 2>/dev/null

	cd $TIPROOT/bin
	for file in key qkey peerfcs rmtfcs sendque tippsp dbiunload
	do
		if  [ -f $file ]
		then
			rm -f $file
		fi
	done
fi

###################################################
##  Product: TIP/ix Documentation                ##
###################################################

if  [ "$copyDOC" = "Y" ]
then
#
##  Create required directories
#
	if  [ ! -d $TIPROOT/docs ]
	then
		mkdir $TIPROOT/docs
		chown $TIPUID $TIPROOT/docs
		chgrp $TIPGID $TIPROOT/docs
		chmod 775 $TIPROOT/docs
	fi

	if  [ -d $BASEDIR/docs ]
	then
		pinfo
#
##  Uncompress the installation package.
#
		pinfo "Uncompressing TIP/ix documentation for installation."
		cd $BASEDIR/docs
		find . -type f -name "*.Z" -exec $UNCOMPRESS -f {} \; 2>/dev/null
#
##  Copy TIP/ix documentation
#
		pinfo "Installing TIP/ix documentation files"
		for file in *
		do
			cp $file $TIPROOT/docs
			chown $TIPUID $TIPROOT/docs/$file
			chgrp $TIPGID $TIPROOT/docs/$file
			chmod 555 $TIPROOT/docs/$file
		done
	fi
fi

###################################################
##  Product: TIP/ix Development                  ##
###################################################

if  [ "$copyDEV" = "Y" ]
then
	pinfo
	pinfo "Installing TIP/ix development environment"

#
##  Create any required directories
#
	cd $TIPROOT
	for dir in include lib patch src src/tip
	do
		if  [ ! -d $dir ]
		then
			mkdir $dir
			[ ! $? ] && fail 1 "Unable to create directory $TIPROOT/$dir"
		fi
		chmod 777 $dir
		chown $TIPUID $dir
		chgrp $TIPGID $dir
	done

#
##  Uncompress the installation package.
#
	pinfo "Uncompressing TIP/ix development modules for installation."
	cd $BASEDIR
	for dir in include lib src/tip 
	do
		pinfo "	processing $dir"
		find $dir -type f -name "*.Z"  -exec $UNCOMPRESS -f {} \;		2>/dev/null
	done

	pinfo "Copying COBOL copy books and C headers"
	cd $BASEDIR/include
	for file in *
	do
		cp $file $TIPROOT/include
		chown $TIPUID $TIPROOT/include/$file
		chgrp $TIPGID $TIPROOT/include/$file
	done

	if  [ -f $BASEDIR/lib/libcob.5.dylib ]
	then
		pinfo "Copying MAC OS libcob.5.dylib to /usr/local/lib"
		mkdir -p /usr/local/include
		mkdir -p /usr/local/bin
		mkdir -p /usr/local/lib
		cd /usr/local/lib
		cp -p $BASEDIR/lib/libcob* /usr/local/lib
		cp -p $BASEDIR/lib/libcob* $TIPROOT/lib
		cp -p $BASEDIR/lib/libgmp* /usr/local/lib
		cp -p $BASEDIR/lib/libgmp* $TIPROOT/lib
		ln -s libcob.4.dylib libcob.dylib
	elif  [ -f $BASEDIR/lib/libcob.4.dylib ]
	then
		pinfo "Copying MAC OS libcob.4.dylib to /usr/local/lib"
		mkdir -p /usr/local/include
		mkdir -p /usr/local/bin
		mkdir -p /usr/local/lib
		cd /usr/local/lib
		cp -p $BASEDIR/lib/libcob* /usr/local/lib
		cp -p $BASEDIR/lib/libcob* $TIPROOT/lib
		cp -p $BASEDIR/lib/libgmp* /usr/local/lib
		cp -p $BASEDIR/lib/libgmp* $TIPROOT/lib
		ln -s libcob.4.dylib libcob.dylib
	elif  [ -f $BASEDIR/lib/libcob.2.dylib ]
	then
		pinfo "Copying MAC OS libcob.2.dylib to /usr/local/lib"
		mkdir -p /usr/local/include
		mkdir -p /usr/local/bin
		mkdir -p /usr/local/lib
		cd /usr/local/lib
		cp -p $BASEDIR/lib/libcob* /usr/local/lib
		cp -p $BASEDIR/lib/libcob* $TIPROOT/lib
		cp -p $BASEDIR/lib/libgmp* /usr/local/lib
		cp -p $BASEDIR/lib/libgmp* $TIPROOT/lib
	fi

	if  [ -f $BASEDIR/lib/libcob.so.5.0.0 ]
	then
		cd /usr/local/lib
		rm -f libcob.so.5 libcob.so.5.0.0 libcob.so
		pinfo "Copying GnuCOBOL libcob.so.5.0.0 to /usr/local/lib"
		cp $BASEDIR/lib/libcob.so.5.0.0 /usr/local/lib
		cd /usr/local/lib
		ln -s libcob.so.5.0.0 libcob.so.5 
		ln -s libcob.so.5.0.0 libcob.so
		chmod a+rx /usr/local/lib/libcob.so*
		pinfo "Remember to add '/usr/local/lib' to each user LD_LIBRARY_PATH"
		sleep 1
		if [ -f $BASEDIR/lib/libcob.a ]
		then
			cp $BASEDIR/lib/libcob.a $TIPROOT/lib
		fi
		pinfo "Copying GnuCOBOL libcob.so.5.0.0 to $TIPROOT/lib"
		cd $TIPROOT/lib 
		rm -f libcob.so.5 libcob.so.5.0.0 libcob.so
		cp $BASEDIR/lib/libcob.so.5.0.0 $TIPROOT/lib
		ln -s libcob.so.5.0.0 libcob.so.5 
		ln -s libcob.so.5.0.0 libcob.so
		chmod a+rx $TIPROOT/lib/libcob.so*
		if [ ! -d $TIPROOT/liboc ]
		then
			mkdir $TIPROOT/liboc
		fi
		chmod a+rwx $TIPROOT/liboc
		cp $BASEDIR/lib/libcob.so.5.0.0 /usr/local/liboc
		if [ -f $BASEDIR/lib/libcob.a ]
		then
			cp $BASEDIR/lib/libcob.a $TIPROOT/liboc
		fi
		pinfo "Copying GnuCOBOL libcob.so.5.0.0 to $TIPROOT/liboc"
		cd $TIPROOT/liboc 
		rm -f libcob.so.5 libcob.so.5.0.0 libcob.so
		cp $BASEDIR/lib/libcob.so.5.0.0 $TIPROOT/liboc
		ln -s libcob.so.5.0.0 libcob.so.2 
		ln -s libcob.so.5.0.0 libcob.so.5 
		ln -s libcob.so.5.0.0 libcob.so
		chmod a+rx $TIPROOT/liboc/libcob.so*
		rm -f $BASEDIR/lib/libcob.so 
	elif  [ -f $BASEDIR/lib/libcob.so.4.0.0 ]
	then
		cd /usr/local/lib
		rm -f libcob.so.2 libcob.so.2.0.0 libcob.so
		rm -f libcob.so.4 libcob.so.4.0.0
		pinfo "Copying GnuCOBOL libcob.so.4.0.0 to /usr/local/lib"
		cp $BASEDIR/lib/libcob.so.4.0.0 /usr/local/lib
		cd /usr/local/lib
		ln -s libcob.so.4.0.0 libcob.so.2 
		ln -s libcob.so.4.0.0 libcob.so.4 
		ln -s libcob.so.4.0.0 libcob.so
		chmod a+rx /usr/local/lib/libcob.so*
		pinfo "Remember to add '/usr/local/lib' to each user LD_LIBRARY_PATH"
		sleep 1
		if [ -f $BASEDIR/lib/libcob.a ]
		then
			cp $BASEDIR/lib/libcob.a $TIPROOT/lib
		fi
		pinfo "Copying GnuCOBOL libcob.so.4.0.0 to $TIPROOT/lib"
		cd $TIPROOT/lib 
		rm -f libcob.so.2 libcob.so.2.0.0 libcob.so
		rm -f libcob.so.4 libcob.so.4.0.0
		cp $BASEDIR/lib/libcob.so.4.0.0 $TIPROOT/lib
		ln -s libcob.so.4.0.0 libcob.so.2 
		ln -s libcob.so.4.0.0 libcob.so.4 
		ln -s libcob.so.4.0.0 libcob.so
		chmod a+rx $TIPROOT/lib/libcob.so*
		if [ ! -d $TIPROOT/liboc ]
		then
			mkdir $TIPROOT/liboc
		fi
		chmod a+rwx $TIPROOT/liboc
		cp $BASEDIR/lib/libcob.so.4.0.0 /usr/local/liboc
		if [ -f $BASEDIR/lib/libcob.a ]
		then
			cp $BASEDIR/lib/libcob.a $TIPROOT/liboc
		fi
		pinfo "Copying GnuCOBOL libcob.so.4.0.0 to $TIPROOT/liboc"
		cd $TIPROOT/liboc 
		rm -f libcob.so.2 libcob.so.2.0.0 libcob.so
		rm -f libcob.so.4 libcob.so.4.0.0
		cp $BASEDIR/lib/libcob.so.4.0.0 $TIPROOT/liboc
		ln -s libcob.so.4.0.0 libcob.so.2 
		ln -s libcob.so.4.0.0 libcob.so.4 
		ln -s libcob.so.4.0.0 libcob.so
		chmod a+rx $TIPROOT/liboc/libcob.so*
		rm -f $BASEDIR/lib/libcob.so 
	elif  [ -f $BASEDIR/lib/libcob.so ]
	then
		if  [ ! -f /usr/local/lib/libcob.so ]
		then
			pinfo "Copying libcob.so to /usr/local/lib"
			cd /usr/local/lib
			rm -f libcob.so.2 libcob.so.2.0.0
			cp $BASEDIR/lib/libcob.so /usr/local/lib
			ln -s libcob.so libcob.so.2 
			ln -s libcob.so libcob.so.2.0.0
			chmod a+rx /usr/local/lib/libcob.so*
			pinfo "Remember to add '/usr/local/lib' to each user LD_LIBRARY_PATH"
			sleep 2
		fi
		if [ -f $BASEDIR/lib/libcob.a ]
		then
			cp $BASEDIR/lib/libcob.a $TIPROOT/lib
		fi
		pinfo "Copying GnuCOBOL libcob.so to $TIPROOT/lib"
		cp $BASEDIR/lib/libcob.so $TIPROOT/lib
		cd $TIPROOT/lib 
		rm -f libcob.so.2 libcob.so.2.0.0
		ln -s libcob.so libcob.so.2 
		ln -s libcob.so libcob.so.2.0.0
		chmod a+rx $TIPROOT/lib/libcob.so*
		if [ ! -d $TIPROOT/liboc ]
		then
			mkdir $TIPROOT/liboc
		fi
		chmod a+rwx $TIPROOT/liboc
		cp $BASEDIR/lib/libcob.so.4.0.0 /usr/local/liboc
		if [ -f $BASEDIR/lib/libcob.a ]
		then
			cp $BASEDIR/lib/libcob.a $TIPROOT/liboc
		fi
		pinfo "Copying GnuCOBOL libcob.so to $TIPROOT/liboc"
		cd $TIPROOT/liboc 
		rm -f libcob.so.2 libcob.so.2.0.0 libcob.so
		rm -f libcob.so.4 libcob.so.4.0.0
		cp $BASEDIR/lib/libcob.so $TIPROOT/liboc
		ln -s libcob.so libcob.so.2 
		ln -s libcob.so libcob.so.2.0.0
		chmod a+rx $TIPROOT/liboc/libcob.so*
		rm -f $BASEDIR/lib/libcob.so 
	fi
	if  [ -f $BASEDIR/lib/libldap.a ]
	then
		if  [ ! -f /usr/lib/libldap.a ]
		then
			pinfo "Copying libldap.a to /usr/lib"
			cp $BASEDIR/lib/libldap.a /usr/lib
		fi
		rm -f $BASEDIR/lib/libldap.a 
	fi
	if  [ -f $BASEDIR/lib/libldapiconv.a ]
	then
		if  [ ! -f /usr/lib/libldapiconv.a ]
		then
			pinfo "Copying libldapiconv.a to /usr/lib"
			cp $BASEDIR/lib/libldapiconv.a /usr/lib
		fi
		rm -f $BASEDIR/lib/libldapiconv.a 
	fi
	if [ -f $BASEDIR/lib/libldap.so.2 ]
	then
		if [ ! -f /usr/lib/libldap.so.2 ]
		then
			pinfo "Copying libldap.so to /usr/lib"
			cp $BASEDIR/lib/libldap.so.2 /usr/lib/libldap.so.2
		fi
	fi
	if [ -f $BASEDIR/lib/libibmldap64n.a ]
	then
		if [ ! -f /usr/lib/libibmldap64.a ]
		then
			pinfo "Copying AIX libmldap64.a to /usr/ldap/lib"
			if [ ! -d /usr/ldap ]
			then
				mkdir /usr/ldap
			fi
			if [ ! -d /usr/ldap/lib ]
			then
				mkdir /usr/ldap/lib
			fi
			cp $BASEDIR/lib/libibmldap64n.a /usr/ldap/lib
			ln -s /usr/ldap/lib/libibmldap64n.a /usr/lib/libibmldap64.a
		fi
	fi
	if [ -f $BASEDIR/lib/libldapiconv64n.a ]
	then
		if [ ! -f /usr/lib/libldapiconv64.a ]
		then
			pinfo "Copying AIX libldapiconv64.a to /usr/ldap/lib"
			if [ ! -f /usr/ldap/lib/libldapiconv64n.a ]
			then
				if [ ! -d /usr/ldap/lib ]
				then
					mkdir /usr/ldap/lib
				fi
				cp $BASEDIR/lib/libldapiconv64n.a /usr/ldap/lib
			fi
			ln -s /usr/ldap/lib/libldapiconv64n.a /usr/lib/libldapiconv64.a
		fi
	fi
	if [ -f $BASEDIR/lib/liblber.so.2 ]
	then
		if [ ! -f /usr/lib/liblber.so.2 ]
		then
			pinfo "Copying liblber.so to /usr/lib"
			cp $BASEDIR/lib/liblber.so.2 /usr/lib/liblber.so.2
		fi
	fi
	if [ -f $BASEDIR/lib/libssl.so.4 ]
	then
		if [ ! -f /usr/lib/libssl.so.4 ]
		then
			if [ ! -f /lib/libssl.so.4 ]
			then
				pinfo "Copying libssl.so to /usr/lib"
				cp $BASEDIR/lib/libssl.so.4 /usr/lib/libssl.so.4
			fi
		fi
	fi
	if [ -d $BASEDIR/lib/kerberos ]
	then
		cd $BASEDIR/lib/kerberos
		libs=`ls`
		for lib in $libs
		do
			if [ ! -f /usr/lib/$lib ]
			then
				if [ ! -f /usr/kerberos/lib/$lib ]
				then
					if [ ! -f /lib/$lib ]
					then
						cp -dp $lib /usr/lib
						chown root /usr/lib/$lib
						chgrp root /usr/lib/$lib
					fi
				fi
			fi
		done
		rm -rf $BASEDIR/lib/kerberos
	fi

	pinfo "Copying libraries"
	cd $BASEDIR/lib
	for file in *
	do
		rm -f $TIPROOT/lib/$file
		cp $file $TIPROOT/lib
		chmod 444 $TIPROOT/lib/$file
		chown $TIPUID $TIPROOT/lib/$file
		chgrp $TIPGID $TIPROOT/lib/$file
	done

	cd $TIPROOT/lib
	for file in *.so*
	do
		if [ -f $file ]
		then
			chmod a+rx $file
		fi
	done
	cd $TIPROOT/lib
	chmod ug+rw lib*.a


	pinfo "Copying sample source code"
	cd $BASEDIR/src/tip
	for file in *
	do
		cp $file $TIPROOT/src/tip
		chmod 444 $TIPROOT/src/tip/$file
		chown $TIPUID $TIPROOT/src/tip/$file
		chgrp $TIPGID $TIPROOT/src/tip/$file
	done

#
##  Sense the compiler being used and link makefile to the
##  correct make.$COBOL file
#
	if  [ ! -f $TIPROOT/src/tip/makefile ]
	then
		if  [ -f /usr/local/bin/cobc ]
		then
			cobol=cob
		else
			cobol=mf
		fi
		if  [ -f $COBDIR/bin/cob ]
		then
			cobol=cob
		fi

		cd $TIPROOT/src/tip
		rm -f makefile
		ln -s make.$cobol makefile
	fi
fi


###################################################
##  Product: TIP/dbi                             ##
###################################################

if  [ "$copyDBI" = "Y" ]
then
	pinfo
	pinfo "Installing TIP/dbi"

#
##  Uncompress the package
#
	pinfo "Uncompressing TIP/dbi modules"
	find $BASEDIR/dbi -type f -name "*.Z" -exec $UNCOMPRESS -f {} \;
#
##  Copy executables to $TIPROOT/bin
#
	pinfo "Copying executables"
	cd $BASEDIR/dbi/bin
	for file in *
	do
		cp $file $TIPROOT/bin
		chown $TIPUID $TIPROOT/bin/$file
		chgrp $TIPGID $TIPROOT/bin/$file
	done

#
##  Copy DBI headers
#
	pinfo "Copying include files"
	cd $BASEDIR/dbi/include
	for file in *
	do
		cp $file $TIPROOT/include
		chown $TIPUID $TIPROOT/include/$file
		chgrp $TIPGID $TIPROOT/include/$file
	done

#
##  Copy DBI libraries
#
	pinfo "Copying libraries"
	cd $BASEDIR/dbi/lib
	for file in *
	do
		cp $file $TIPROOT/lib
		chown $TIPUID $TIPROOT/lib/$file
		chgrp $TIPGID $TIPROOT/lib/$file
	done

#
##  Copy DBI examples
#
	if  [ -f $BASEDIR/dbi/examples/oradiff.pc ]
	then
		pinfo "Copying TIP/dbi examples"
		if  [ ! -d $TIPROOT/src/dbi ]
		then
			mkdir $TIPROOT/src/dbi
		fi
		chmod 777 $TIPROOT/src/dbi
		chown $TIPUID $TIPROOT/src/dbi
		chgrp $TIPGID $TIPROOT/src/dbi
		cd $BASEDIR/dbi/examples
		for file in *
		do
			cp $file $TIPROOT/src/dbi
			chown $TIPUID $TIPROOT/src/dbi/$file
			chgrp $TIPGID $TIPROOT/src/dbi/$file
		done
	fi
fi


###################################################
##  Product: TQL/ix                              ##
###################################################

if  [ "$copyTQL" = "Y" ]
then
	pinfo
	pinfo "Installing TQL/ix"
#
##  Create TQL/ix directory structure if necessary
#
	pinfo "Creating directory structure"
	cd $TIPROOT
	if  [ ! -d tql ]
	then
		mkdir tql
		[ ! $? ] && fail 1 "Unable to create directory $TIPROOT/tql"
	fi
	chmod 777 tql
	chown $TIPUID tql
	chgrp $TIPGID tql

	cd tql
	for dir in schema selects tqlfiles tqlprogs tqlfiles/template tqlprogs/template
	do
		if  [ ! -d $dir ]
		then
			mkdir $dir
			[ ! $? ] && fail 1 "Unable to create directory $TIPROOT/tql/$dir"
		fi
		chmod 777 $dir
	done

#
##  Copy from temporary dir to $TIPROOT/src/tql
#
	if  [ ! -d $TIPROOT/src/tql ]
	then
		mkdir $TIPROOT/src/tql
		[ ! $? ] && fail 1 "Unable to create directory $TIPROOT/src/tql"
	fi
	chmod 777 $TIPROOT/src/tql
	chown $TIPUID $TIPROOT/src/tql
	chgrp $TIPGID $TIPROOT/src/tql

	pinfo "Uncompressing TQL/ix modules"
	cd $BASEDIR/tql
	find . -type f -name "*.Z" -exec $UNCOMPRESS -f {} \; 2>/dev/null

	pinfo "Copying executables"
	cd $BASEDIR/tql/bin
	for file in *
	do
		cp $file $TIPROOT/bin
		chmod 555 $TIPROOT/bin/$file
		chown $TIPUID $TIPROOT/bin/$file
		chgrp $TIPGID $TIPROOT/bin/$file
	done

	pinfo "Copying examples"
	cd $BASEDIR/tql/examples
	for file in *
	do
		cp $file $TIPROOT/src/tql
		chown $TIPUID $TIPROOT/src/tql/$file
		chgrp $TIPGID $TIPROOT/src/tql/$file
	done

#
##  Copy TQL template modules to correct directories.  Also link
##  cvttql to tqlccp.  Copy the templates only if they don't exist.
##  Link "transactional" compiler entry
#
	cd $TIPROOT/bin
	rm -f cvttql
	ln -s tqlccp cvttql

	cd $BASEDIR
	if  [ ! -f $TIPROOT/tql/tqlprogs/template/DEFAULT.tpd ]
	then
		pinfo "Copying program template"
		cp  $TIPROOT/src/tql/DEFAULT.tpd $TIPROOT/tql/tqlprogs/template 2>/dev/null
		[ ! $? ] && fail 1 "Unable to install TQL default program template"
	fi
	if  [ ! -f $TIPROOT/tql/tqlfiles/template/DEFAULT.trd ]
	then
		pinfo "Copying record template"
		cp  $TIPROOT/src/tql/DEFAULT.trd $TIPROOT/tql/tqlfiles/template 2>/dev/null
		[ ! $? ] && fail 1 "Unable to install TQL default record template"
	fi

#
##  Reset any bogus permissions that may have crept in.
#
	pinfo "Setting TQL permissions"
	find $TIPROOT/tql -type d -exec chmod 0777 {} \;
	find $TIPROOT/tql -type d -exec chown $TIPUID {} \;
	find $TIPROOT/tql -type d -exec chgrp $TIPGID {} \;
	find $TIPROOT/tql -type f -exec chmod 0666 {} \;
	find $TIPROOT/tql -type f -exec chown $TIPUID {} \;
	find $TIPROOT/tql -type f -exec chgrp $TIPGID {} \;
#
##  Clean up any obsolete files
#
	pinfo "Removing obsolete items"
	cd $TIPROOT/bin
	for file in tqlccf tqlccr tqlerr tqlint tqllst tqltccp
	do
		if  [ -f $file ]
		then
			rm -f $file
		fi
	done
	cd $TIPROOT/tql
	rm -f TQL\$ERR
fi


###################################################
##  Product: HSP/xx                              ##
###################################################

if  [ "$copyHSP" = "Y" ]
then
	pinfo
	pinfo "Installing HSP/xx"

#
##  Uncompress HSP modules.
#
	pinfo "Uncompressing HSP modules"
	cd $BASEDIR/arm
	find . -type f -name "*.Z" -exec $UNCOMPRESS -f {} \; 2>/dev/null
#
##  Copy binaries into $TIPROOT/bin
#
	pinfo "Clearing old executables"
	cd $TIPROOT/bin
	for file in arm* cnvcob cnvjcl cnvmnu fcsload libs mbp3sort \
				mbpload mbp4load os3sort rpgcob smxfer
	do
		rm -f $file
	done

	pinfo "Copying executables"
	cd $BASEDIR/arm/bin
	for file in *
	do
		cp $file $TIPROOT/bin
		chown $TIPUID $TIPROOT/bin/$file
		chgrp $TIPGID $TIPROOT/bin/$file
	done

	pinfo "Copying configuration files"
	cd $BASEDIR/arm/conf
	for file in *
	do
		cp $file $TIPROOT/conf
		chown $TIPUID $TIPROOT/conf/$file
		chgrp $TIPGID $TIPROOT/conf/$file
	done
#
##  Copy any sample command files and scripts
#
	if  [ ! -d $TIPROOT/src/arm ]
	then
		mkdir $TIPROOT/src/arm
		[ ! $? ] && fail 1 "Unable to create directory $TIPROOT/src/arm"
	fi
	chown $TIPUID $TIPROOT/src/arm
	chgrp $TIPGID $TIPROOT/src/arm

	pinfo "Copying examples"
	cd $BASEDIR/arm/examples
	for file in *
	do
		cp $file $TIPROOT/src/arm
		[ ! $? ] && fail 1 "Unable to copy HSP examples"
		chown $TIPUID $TIPROOT/src/arm/$file
		chgrp $TIPGID $TIPROOT/src/arm/$file
	done

	pinfo "Copying include files"
	cd $BASEDIR/arm/include
	for file in *
	do
		cp $file $TIPROOT/include
		[ ! $? ] && fail 1 "Unable to copy HSP include files"
		chown $TIPUID $TIPROOT/include/$file
		chgrp $TIPGID $TIPROOT/include/$file
	done

	pinfo "Copying scripts"
# save old armjcl.rc and armecl.rc if any
	if [ -f $TIPROOT/scripts/armjcl.rc ]; then
		mv -f $TIPROOT/scripts/armjcl.rc $TIPROOT/scripts/armjcl.rc.old
	fi
	if [ -f $TIPROOT/scripts/armecl.rc ]; then
		mv -f $TIPROOT/scripts/armecl.rc $TIPROOT/scripts/armecl.rc.old
	fi
	if [ -f $TIPROOT/scripts/tipperms ]; then
		chmod a+x $TIPROOT/scripts/tipperms
	fi
	if [ -f $TIPROOT/scripts/tipfixbin ]; then
		chmod a+x $TIPROOT/scripts/tipfixbin
	fi
	cd $BASEDIR/arm/scripts
	for file in *
	do
		cp $file $TIPROOT/scripts
		[ ! $? ] && fail 1 "Unable to copy HSP scripts"
		chown $TIPUID $TIPROOT/scripts/$file
		chgrp $TIPGID $TIPROOT/scripts/$file
		chmod 555 $TIPROOT/scripts/$file
	done
	if [ -f $TIPROOT/scripts/recomptql ]; then
		chmod a+x $TIPROOT/scripts/recomptql
	fi

#
##  Copy in the ECL Shell processor
#
	cd $TIPROOT/bin
	if  [ -f /bin/eclexec ]
	then
		mv /bin/eclexec /bin/eclexec.old
	fi
	if  [ -f eclexec ]
	then
		cp eclexec /bin/eclexec
		chown root /bin/eclexec
		chgrp $TIPGID /bin/eclexec
		chmod 4775 /bin/eclexec
		chown root eclexec
		chgrp $TIPGID eclexec
		chmod 4775 eclexec
	fi

#
##  The following should be setuid TIPUID setgid TIPGID
#
	cd $TIPROOT/bin
	for file in armdata armdmbp armdmbp4 
	do
		if  [ -f $file ]
		then
			chown $TIPUID $file
			chgrp $TIPGID $file
			chmod 6775 $file
		fi
	done

#
##  The following should be setuid TIPUID
#
	for file in armjcl armecl armgen dbipwd
	do
		if  [ -f $file ]
		then
			chown $TIPUID $file
			chgrp $TIPGID $file
			chmod 4775 $file
		fi
	done
	
#
##  Set up any required links to binaries
#
	[ -f eclexec ] && rm -f st && ln -s eclexec st
	[ -f eclexec ] && rm -f @start && ln -s eclexec @start
	[ -f eclexec ] && rm -f @START && ln -s eclexec @START
	[ -f eclexec ] && rm -f @xqt && ln -s eclexec @xqt
	[ -f eclexec ] && rm -f @XQT && ln -s eclexec @XQT
	[ -f eclexec ] && rm -f @jobs && ln -s eclexec @jobs
	[ -f eclexec ] && rm -f @JOBS && ln -s eclexec @JOBS
	[ -f eclexec ] && rm -f @stop && ln -s eclexec @stop
	[ -f eclexec ] && rm -f @STOP && ln -s eclexec @STOP
	[ -f armcat  ] && rm -f smxfer && ln -s armcat  smxfer
	[ -f armdata ] && rm -f fcsload && ln -s armdata fcsload
	[ -f armdmbp ] && rm -f mbpload && ln -s armdmbp mbpload
	[ -f armjcl  ] && rm -f cnvjcl && ln -s armjcl  cnvjcl
	[ -f armlibs ] && rm -f libs   && ln -s armlibs libs
	[ -f armmnu  ] && rm -f cnvmnu && ln -s armmnu  cnvmnu
	[ -f armrpg  ] && rm -f rpgcob && ln -s armrpg rpgcob
	[ -f armsmbp ] && rm -f mbp3sort && ln -s armsmbp mbp3sort
	[ -f armsort ] && rm -f os3sort  && ln -s armsort os3sort
#
##  Set up for TSP SOAP/XML example
#
	if [ -f $TIPROOT/scripts/XMLTSP.xml ]
	then
		cp $TIPROOT/scripts/XMLTSP.xml $TIPROOT/tipsoa/XMLTSP.xml
		cp $TIPROOT/scripts/tsp.reply $TIPROOT/tipsoa
		cp $TIPROOT/scripts/tsp.reply.xml $TIPROOT/tipsoa
		cp $TIPROOT/scripts/tsp.reply.json $TIPROOT/tipsoa
		cd $TIPROOT/include
		$TIPROOT/bin/tipcblxml -m 'TF$TSP0_' XM-TSP1X 
		$TIPROOT/bin/tipcblxml -m 'TF$TSP1_' XM-TSP1X 
		$TIPROOT/bin/tipcblxml -m 'TF$TSP2_' XM-TSP2X 
		$TIPROOT/bin/tipcblxml -m 'TF$TSP3_' XM-TSP3X 
	fi
#
##  Clean up any obsolete files
#
	cd $TIPROOT/bin
	for file in tsu* xrefprocs
	do
		if  [ -f $file ]
		then
			rm -f $file
		fi
	done
fi

###########################################################################
#  Time to start winding down.  Clean up after ourself and print out any  #
#  relevant information.                                                  #
###########################################################################

#
##  Check if temporary files should be removed
#
if [ "$removeTemp" = "y" ]
then
	pinfo "Removing temporary TIP/ix installation files"
	cd $BASEDIR
	rm -rf $BASEDIR/*
else
pinfo
pinfo  "TIP/ix installation temporary files are in $BASEDIR"
pquest "Do you want the TIP/ix installation temporary files removed? (<n>, y) >"
case $ANSWER in
	""|"n"|"N"|"no"|"NO"|"No")
		pinfo "TIP/ix installation files remain in $BASEDIR"
		;;
	*)  
		pinfo "Removing temporary TIP/ix installation files"
		cd $BASEDIR
		rm -rf $BASEDIR/*
		;;
esac
fi

pinfo
pinfo "Remember to add  TIPROOT=$TIPROOT  to your and each user environment"
pinfo "Remember to add  '$TIPROOT/bin'    to each user PATH"
pinfo "Remember to add  '$TIPROOT/lib'    to each user LD_LIBRARY_PATH"
if [ "$COBDIR" = "" ]
then
	if [ -f $TIPROOT/bin/rts32 ]
	then
		pinfo "Remember to add        COBDIR=$TIPROOT/bin to your environment"
	fi
else
	if [ -f $TIPROOT/bin/rts32 ]
	then
		rm -f $TIPROOT/bin/rts32
	fi
fi
pinfo
if  [ -f $TIPROOT/src/tip/menu.cbl ]
then
pinfo
if [ "$OSNAME" = "Linux" -o "$OSNAME" = "SunOS" -o "$OSNAME" = "MACOS" ]
then
pinfo "   Running maketipcobol is not required on $OSNAME"
pinfo
if [ "$OSNAME" = "Linux" ]
then
pinfo "  Have a look at $TIPROOT/scripts  linuxpkginstall32.sh "
pinfo " and linuxpkginstall64.sh for a list of some "
pinfo " optional Linux packages that may be needed "
pinfo "  You should run those scripts as 'root' if required "
fi
else
pinfo "To compile the TIP/ix COBOL utility programs with your MF Cobol Compiler"
pinfo "Remember to run  maketipcobol "
fi
pinfo
fi
if [ "$dogenapi" = "N" ]
then
	pinfo "To compile API entry routines for your version of MF COBOL later run:"
	pinfo "    $TIPROOT/bin/genapi "
else
if [ "x$COBDIR" = "x" ]
then
	pinfo "COBDIR is not defined for Micro Focus Cobol"
	pinfo "To compile API entry routines for your version of MF COBOL run:"
	pinfo "    $TIPROOT/bin/genapi "
else
	pinfo "Running  genapi "
	pinfo "To compile API entry routines for your version of Micro Focus COBOL"
	$TIPROOT/bin/genapi
fi
fi
if [ "$os2200Default" = "y" ]
then
pinfo " *** Remember to recompile the libonlsub.so *** "
pinfo " *** cd $TIPSITE/sub; make ***"
fi
pinfo "Installation is complete"
