#!/bin/csh -f
# update_script * product update script
#		(C) Copyright 1991-1993 by Xcelerated Systems Inc.
# MODIFICATION HISTORY
#  Tue Nov 30 17:00:00 1993  submitted by henry
#     Use revision 2.0 for license manager key verification.
#  Wed Jul 21 15:05:00 1993  submitted by henry
#     Reword message so there is no reference to 1.2.7.
#     SPR's Fixed: 957
#  Tue Jul 13 09:46:22 1993  submitted by henry
#     Make hard links from lmutil to others.
#     SPR's Fixed: 849
# INSTALLATION CAUTIONS
# DEPENDENCIES
# DOCUMENTATION REQUIREMENTS
#
umask 0
set path = (/usr/ucb $path /bin /usr/etc /etc)
set insdir = `pwd`
need_install_dir:
echo " "
echo "Please enter the name of Liken install directory"
echo -n "     [/usr/Liken] : "
set liken_dir = ($<)
if ( "$liken_dir" == "" ) then
	set liken_dir = "/usr/Liken"
endif
if ( ! -d $liken_dir ) then
	echo " "
	echo "The directory $liken_dir does not exist."
	goto need_install_dir
endif
cd $liken_dir
if ( $status ) then
	goto need_install_dir
endif

if ( ! -e Liken ) then
	if ( ! -e Liken.b4_2.0 ) then
		echo " "
		echo -n "The file Liken does not exist in directory "
		pwd
		goto need_install_dir
	endif
endif

set lic_file = licenses/license.dat
if ( -e Liken_defaults ) then
	set lic_file = `grep licensefile Liken_defaults | sort | head -1 | awk '{print $2}'`
	if ( $lic_file == "" ) set lic_file = licenses/license.dat
endif

need_quiet:
echo " "
echo "This update procedure requires that the license manager and all"
echo "copies of Liken be shut down before proceeding.  In addition, if"
echo "you are using the Liken networking option, the networking software"
echo "should be stopped and/or unloaded."
echo " "
echo -n "Is the Liken system shut down (yes or no)? [unknown] :"
set tmp = ($<)
if ( $tmp == "" ) then
	set tmp = "unknown"
endif
if ( $tmp !~ [yY]* ) then
	if ( $tmp =~ [nN]* ) then
		echo " "
		echo "Please restart when Liken has been stopped."
		goto come_back
	endif
	echo "Please answer yes or no."
	goto need_quiet
endif

need_disk_space:
echo " "
echo "You will need 4 megabytes of free disk space to do this update."
echo "(Note that this can be reclaimed after the update is completed.)"
echo " "
#echo "You will need an additional 5 megabytes of free disk space if you"
#echo "choose to load the online PostScript version of the Liken Manual."
#echo " "
echo -n "Do you have enough free disk space (yes or no)? [y] :"
set tmp = ($<)
if ( $tmp == "" ) then
	set tmp = "y"
endif
if ( $tmp !~ [yY]* ) then
	if ( $tmp =~ [nN]* ) then
		echo " "
		echo "Please restart when you have enough free space."
		goto come_back
	endif
	echo "Please answer yes or no."
	goto need_disk_space
endif

#
#  Try to detect if the FEATURE lines of license.dat file has the
#  proper version number.  Note that someone can have 2.000 and
#  still has the wrong license key typed in!
#    Henry  12-23-93
#
set wrong_vers = 0
set linecount = `'grep' "xsid 1.200" $lic_file | 'wc' -l`
if ( $linecount != 0 ) then
	echo " "
	echo "Please call ANDATACO Customer Service to obtain"
	echo "a new license key for Liken version 2.000 and"
	echo "then modify $lic_file with the new information"
	set wrong_vers = 1
endif

set linecount = `'grep' "LikenNetDaemon" $lic_file | 'wc' -l`
if ( $linecount != 0) then
	set linecount = `'grep' "FEATURE LikenNetDaemon xsid 2.000" $lic_file | 'wc' -l`
	if ( $linecount == 0 ) then
		echo " "
		echo "<FEATURE LikenNetDaemon xsid 2.000> not found."
		echo "Please change the version number in LikenNetDaemon"
		echo "line to 2.000 by editing $lic_file"
		set wrong_vers = 1
	endif
endif

set linecount = `'grep' "LikenNetClient" $lic_file | 'wc' -l`
if ( $linecount != 0) then
	set linecount = `'grep' "FEATURE LikenNetClient xsid 2.000" $lic_file | 'wc' -l`
	if ( $linecount == 0 ) then
		echo " "
		echo "<FEATURE LikenNetClient xsid 2.000> not found."
		echo "Please change the version number in LikenNetClient"
		echo "line to 2.000 by editing $lic_file"
		set wrong_vers = 1
	endif
endif

if ( $wrong_vers != 0) then
	echo " "
	echo "Please restart the update procedure"
	echo "when you are ready to try again."
	exit 1
endif

set default_ps = "n"
if ( -e manps ) set default_ps = "y"

set default_pg = "n"
if ( -e manpages ) set default_pg = "y"

'rm' -rf top manps manpages

if ( -e net ) then
	if ( ! -e net.b4_2.0 ) then
		'mv' net net.b4_2.0
		if ( $status ) then
			echo " "
			echo "Could not rename net to net.b4_2.0  --  Please check ownership."
			'ls' -l net*
			goto come_back
		endif
		echo " "
		echo "Your previous net directory has been"
		echo "  renamed to net.b4_2.0"
	endif
endif

if ( -e licenses/license.dat ) then
	if ( ! -e licenses/license.dat.b4_2.0 ) then
		'cp' licenses/license.dat licenses/license.dat.b4_2.0
		if ( $status ) then
			echo " "
			echo "Could not copy licenses/license.dat to licenses/license.dat.b4_2.0"
			echo "  Please check ownership."
			'ls' -l licenses/license.dat*
			goto come_back
		endif
		echo " "
		echo "A copy of licenses/license.dat has been put"
		echo "  in file licenses/license.dat.b4_2.0"
	endif
endif

if ( $lic_file != "licenses/license.dat" ) then
	if ( -e $lic_file ) then
		if ( ! -e $lic_file.b4_2.0 ) then
			'cp' $lic_file $lic_file.b4_2.0
			if ( $status ) then
				echo " "
				echo "Error making a backup copy of your license file:"
				echo "  Could not copy $lic_file to $lic_file.b4_2.0"
				echo "    Please check ownership."
				'ls' -l $lic_file*
				goto come_back
			endif
			echo " "
			echo "A copy of $lic_file has been put"
			echo "  in file $lic_file.b4_2.0"
		endif
	endif
endif

echo " "
echo "Extracting files for update . . ."
'tar' xvf $insdir/XSIdsk1 top licenses net preLiken/gunzip
if ( $status ) then
	echo " "
	echo "Could not extract from $insdir/XSIdsk1"
	goto come_back
endif
'tar' xvf $insdir/XSIdsk2 top licenses net
if ( $status ) then
	echo " "
	echo "Could not extract from $insdir/XSIdsk2"
	goto come_back
endif
echo "Uncompressing files for update . . ."
set tmp = 1
foreach i ( */*.gz )
	if ( -e $i:r ) then
		'rm' -f $i:r
		if ( $status ) then
			echo " "
			echo "Could not remove file $i:r"
			goto come_back
		endif
	endif
	if ( $tmp == 3 ) then
		set tmp = 1
		echo "  " $i
	else
		@ tmp = $tmp + 1
		echo -n "  " $i
	endif
	preLiken/gunzip $i
	if ( $status ) then
		echo " "
		echo "Could not uncompress file $i:r"
		goto come_back
	endif
end

#
#	Set up hard links for FLEXlm utilities.
#	lmutil --> lmdown, lmhostid, lmreread, & lmstat.
#
set LICENSEDIR = licenses
if ( -e $LICENSEDIR/lmutil ) then
	if ( -e $LICENSEDIR/lmdown ) then
		rm $LICENSEDIR/lmdown
		ln $LICENSEDIR/lmutil $LICENSEDIR/lmdown
	endif
	if ( -e $LICENSEDIR/lmhostid ) then
		rm $LICENSEDIR/lmhostid
		ln $LICENSEDIR/lmutil $LICENSEDIR/lmhostid
	endif
	if ( -e $LICENSEDIR/lmreread ) then
		rm $LICENSEDIR/lmreread
		ln $LICENSEDIR/lmutil $LICENSEDIR/lmreread
	endif
	if ( -e $LICENSEDIR/lmstat ) then
		rm $LICENSEDIR/lmstat
		ln $LICENSEDIR/lmutil $LICENSEDIR/lmstat
	endif
	rm $LICENSEDIR/lmutil
endif

if ( $tmp != 1 ) echo " "
foreach i (top/*)
	set n = `basename $i`
	if ( -e $n ) then
		if ( ! -e $n.b4_2.0 ) then
			'mv' $n $n.b4_2.0
			if ( $status ) then
				echo " "
				echo "Could not rename $n to $n.b4_2.0  --  Please check ownership."
				'ls' -l $n
				goto come_back
			endif
		endif
	endif
	'mv' top/$n $n
	if ( $status ) then
		echo " "
		echo "Could not rename top/$n to $n  --  Please check ownership."
		'ls' -ld top/$n top .
		goto come_back
	endif
end

echo " "
echo "You may require Liken.b4_2.0 during HFS file conversions, if you"
echo "have out of date HFS volumes.  Please see the release notes."
echo " "
echo "The Liken_keymap file has been updated.  If you have modified"
echo "your original Liken_keymap file, you may want to add those changes"
echo "from the Liken_keymap.b4_2.0 file."

echo " "
echo -n "Do you want the Liken manpages online? [$default_pg] :"
set tmp = ($<)
if ( $tmp == "" ) then
	set tmp = "$default_pg"
endif
if ( $tmp =~ [yY]* ) then
	'tar' xvf $insdir/XSIdsk1 manpages
	if ( $status ) then
		echo " "
		echo "Could not extract from $insdir/XSIdsk1"
		goto come_back
	endif
	'tar' xvf $insdir/XSIdsk2 manpages
	if ( $status ) then
		echo " "
		echo "Could not extract from $insdir/XSIdsk2"
		goto come_back
	endif
	preLiken/gunzip manpages/*.gz
	if ( $status ) then
		echo " "
		echo "Could not uncompress manpages/*.gz"
		goto come_back
	endif
	echo " "
	echo The Liken manpages are in directory manpages:
	'ls' manpages
endif

'rm' -rf preLiken

echo " "
echo "You may request an electronic copy"
echo "of the Liken User's Manual from ANDATACO"
echo "Technical Support at (619) 453-9191."

if ( $status ) then
	echo " "
	echo "Could not write to Liken_defaults  --  Check permissions"
	'ls' -l Liken_defaults
	goto come_back
endif

'rm' -f net/setup net/init-atalk

echo "#\!/bin/sh"                      > net/init-atalk
echo "LM_LICENSE_FILE=$lic_file"      >> net/init-atalk
echo "export LM_LICENSE_FILE"         >> net/init-atalk
echo "$liken_dir/net/appletalkd" '$*' >> net/init-atalk
echo 'exit $?'                        >> net/init-atalk
chmod 555 net/init-atalk

echo '#\!/bin/csh -f'                         > net/setup
echo 'set path = (/usr/ucb $path /bin /usr/etc /etc)' >> net/setup
echo "chown root net/appletalkd"             >> net/setup
echo 'if ($status != 0) exit $status'        >> net/setup
echo "chmod 4755 net/appletalkd"             >> net/setup
echo 'if ($status != 0) exit $status'        >> net/setup

echo ""
echo -n "Do you want to install networking option? [y] "
set resp = ($<)
if ( "$resp" == "" || $resp =~ [yY]* ) then
	set DAEMONLINE = 'FEATURE LikenNetDaemon xsid 2.000 26-jul-0 9999 12345678 " "'
	set CLIENTLINE = 'FEATURE LikenNetClient xsid 2.000 26-jul-0 9999 12345678 " "'
	set LICDAT = licenses/license.dat

	echo "liken.AllHosts.doNetworking:	True" >> Liken_defaults 	
	if ( $status ) then
		echo " "
		echo "Could not write to Liken_defaults  --  Check permissions"
		'ls' -l Liken_defaults
		goto come_back
	endif

	set linecount = `'grep' "LikenNetDaemon" $lic_file | 'wc' -l`
	if ( $linecount == 0 ) then
		echo $DAEMONLINE >> $lic_file
		if ( $status ) then
			echo " "
			echo "Error updating license file with network options:"
			echo "  Could not write to $lic_file  --  Check permissions"
			'ls' -l $lic_file
			goto come_back
		endif
	endif

	set linecount = `'grep' "LikenNetClient" $lic_file | 'wc' -l`
	if ( $linecount == 0 ) then
		echo $CLIENTLINE >> $lic_file
		if ( $status ) then
			echo " "
			echo "Error updating license file with network options:"
			echo "  Could not write to $lic_file  --  Check permissions"
			'ls' -l $lic_file
			goto come_back
		endif
	endif

	if ( $lic_file != $LICDAT ) then
		set linecount = `'grep' "LikenNetDaemon" $LICDAT | 'wc' -l`
		if ( $linecount == 0 ) then
			echo $DAEMONLINE >> $LICDAT
			if ( $status ) then
				echo " "
				echo "Could not write to $LICDAT  --  Check permissions"
				'ls' -l $LICDAT
				goto come_back
			endif
		endif

		set linecount = `'grep' "LikenNetClient" $LICDAT | 'wc' -l`
		if ( $linecount == 0 ) then
			echo $CLIENTLINE >> $LICDAT
			if ( $status ) then
				echo " "
				echo "Could not write to $LICDAT  --  Check permissions"
				'ls' -l $LICDAT
				goto come_back
			endif
		endif
	endif

#
#   install the AppleTalk daemons etc
# 
	echo ""
	echo "The network installation must be completed as 'root'."
	echo ""
	echo "It involves setting up the Liken network daemon"
	echo "to be owned by 'root', and turning on the setuid bit." 
	echo ""
	echo "You will be asked to enter the 'root' password to execute"
	echo "the following two commands:"
	echo ""
	echo "  chown root net/appletalkd"
	echo "  chmod 4755 net/appletalkd"
suagain:
	echo " "
	su root -c "csh net/setup"
	set suret = $status
	echo " "
	switch ($suret)
	case 0:
		echo " "
		echo "Network installation completed"
		echo " "
		breaksw

	case 1:
		echo "Root does not have permission to modify files in the"
		echo "net directory.  This is probably because the net directory"
		echo "is NFS mounted and root on this machine does not have"
		echo "root privileges on the owner machine."
		echo " "
		echo "To complete the network installation, log on to the"
		echo "machine which physically owns the net directory and"
		echo "enter the chown and chmod commands as root."
		echo " "
		breaksw

	case 113:
	case 2:
		echo "The 'root' password you've entered is incorrect."
		echo -n "Do you want to try again? [y] "
		set resp = ($<)
		if ( "$resp" == "" || $resp =~ [yY]* ) then
			goto suagain
		endif
		echo " "
		echo " "
		echo "   THE NETWORK INSTALLATION HAS FAILED "
		echo "   DUE TO AN INVALID ROOT PASSWORD "
		echo " "
		echo " "
		echo -n "Continue installation anyway? [n]"
		set resp = ($<)
		if ( $resp !~ [yY]* ) then
			echo " "
			echo " *******  INSTALLATION ABORTED.  *********"
			exit
		endif
		breaksw

	default:
		echo " "
		echo "An error occured changing the owner and permissions"
		echo "of appletalkd."
		echo " "
		breaksw
	endsw
else
	echo "liken.AllHosts.doNetworking:	False" >> Liken_defaults 	
	if ( $status ) then
		echo " "
		echo "Could not write to Liken_defaults  --  Check permissions"
		'ls' -l Liken_defaults
		goto come_back
	endif
endif

echo " "
'rm' -rf top
'rm' -f $insdir/XSIdsk1
'rm' -f $insdir/XSIdsk2
'rm' -f $insdir/XSIdsk.image
'rm' -f $insdir/install_networking
'rm' -rf $insdir/preLiken
'rm' -f $insdir/install_liken
'rm' -f $insdir/install_script_template
'rm' -f $insdir/hpea
'rm' -f $insdir/update_script
echo "Liken Update Complete"
echo ""
echo "The 'Liken_defaults' file has been modified in $liken_dir"
echo "Note that any user's existing  ~/.Liken_defaults"
echo "files have NOT been changed, and will"
echo "take precedence over the modified one."
echo ""
exit 0

come_back:
echo " "
echo "You may restart the installation procedure with the command"
echo "    csh -f update_script"
echo "when you are ready to try again."
exit 1
