#!/bin/sh
#
# Copyright 1993 Sun Microsystems, Inc. All Rights Reserved
#       @(#)preremove	1.6 94/09/05
#
#  Preremove script for: SUNWvtexe
#
#	Removes or Saves the VT license


# Exit codes for installation scripts 
e_ok=0      
e_fatal=1      # stop installation on this exit
e_warning=2    # Installation will go on. 
e_int=3        # Interrupted. Stop installation
e_reboot=10    # User must reboot after installation of all selected packages
e_rebootnow=20 # User must reboot right after installation of current package
               # To be added to one of the single-digit exit code above

# Trap interrupt
trap `exit $e_int` 15


###########################################
# The following lines should be modified for use by individual products
###########################################
# Identifies the basename of the license file and license
# location file, before the ,loc or,lic are attached to it
# e.g., if license_file=featfile
# the license file will then be called featfile,lic

license_file=osivt8.0

####################################################
# Subsequent lines should not be modified by individual products
#####################################################
licdir="/etc/opt/licenses"
licfile=${license_file}.lic
locfile=${license_file}.loc

# Find the location of the license files
if [ ! -f ${licdir}/${locfile} ]
then
	echo Cannot remove licenses - no license location file ${licdir}/${locfile}
	exit 0
fi
temppath=`cat ${licdir}/${locfile}`

if [ -f ${temppath}/${licfile}* ]; then
	notdone=0
	while [ $notdone -eq 0 ]
	do
		ans=`ckyorn -e "please answer y or n: "  -h  \
		  "please answer y or n:" \
		-p "License files exist for this product. Do you want them saved[y|n]?"`
		if [ $ans = "y" -o $ans = "yes" -o $ans = "Y"  \
	    	-o $ans = "YES" -o $ans = "Yes" ]; then

		#
		# Copy licenses from product directory to standard license
		# directory
			for infile in `ls ${temppath}/$licfile*`
			do
				i=0
				nd=0
				while [ $nd -eq 0 ]
				do
					outputfile=$licdir/$licfile,$i
					if [ ! -f $outputfile ]
					then
						nd=1
					else
						i=`expr $i + 1`
					fi
				done
				basefile=`basename ${infile}`
				cp ${temppath}/${basefile} $outputfile
				if [ $? -ne 0 ]
				then
					echo Exiting
					exit 1
				fi
				rm ${temppath}/${basefile}
			done
			echo "Licenses copied to $licdir"
			notdone=1
		elif [ $ans = "n" -o $ans = "no" -o $ans = "N"  \
	    	-o $ans = "NO" -o $ans = "No" ]; then
			rm ${temppath}/${licfile}*
			echo "License files removed from ${temppath}"
			notdone=1
		else
			notdone=0
		fi
	done
fi
# Remove the loc file, since it no longer applies
rm ${licdir}/${locfile} > /dev/null 2>&1

exit 0



# Happy end
exit $e_ok




