#!/bin/ksh
#
# Script to Install a fix onto Reality 
#
# File:    if_code_10 
# Version: 45.4
#
#
# Syntax 
#       install_fix [opts] <fix file (.tar)>
#
#########################################################################
#
# Display
#
Display ()
{
	[ $overwrite -eq 1 ] && return
	$ECHO "$*"
}
#########################################################################

Usage ()
{
        Display "Usage : install_fix [opts] full path to fix name"
	Display "-a path\t\tpath to directory where multiple fixes exist"
	Display "-y \t\tassume Yes to all prompts"
	Display "-r fix number\tUninstall given fix number"
	Display "-i installer\tSets installers name"
	Display "-n \t\tSkip build phase"
	Display "-u \t\treinstall fix"
	Display "-x\t\tEnable debug tracing"
        exit 1
}                  

#########################################################################

Error ()
{
        Display "\n\007Error: $*."
	TidyUp #get rid of unwanted files
	exit 1
}                     

#########################################################################

#
# TidyUp - remove unwanted files
#

TidyUp ()
{
	cd $Realman #ensure in correct place
        rm -f *.objects
        rm -f *.files 
        rm -f *.rti 
        rm -f *.desc 
        rm -f *.pre
	rm -f *.readme
	rm -f *.platforms
	rm -f *.chksum
	rm -f *.bugnos
}

#########################################################################

#
# Get user details
#

Get_User_Details ()
{
	while [ ! "$Installer" ]
	do
	    Display 'Please enter your initials: \c'
	    read Installer
	done
}

#########################################################################

#
# Update History file
#

Update_History ()
{
	cd $Realman
	if [ "$Operation" = INSTALL ]
	then
  	     Prereq=`echo $Prereq |sed 's/ /;/g'`
	     if [ "$Prereq" ]
	     then
	    	 /usr/local/bin/pdshist -a $Operation -p Reality -v$fixstatus$fixno -tFX \
		-n "$Installer" -d$Fix_Components -c"$Fixno_Desc" -r"$Prereq" 
	     else
		 /usr/local/bin/pdshist -a $Operation -p Reality -v$fixstatus$fixno -tFX \
		 -n "$Installer" -d$Fix_Components -c"$Fixno_Desc" 
	     fi
	else
	  /usr/local/bin/pdshist -a $Operation -p Reality -v$fixno -tFX \
	        -n "$Installer" -cUNINSTALLED
	fi
}

#########################################################################

#
# Verify that fix file (.tar) is present
#

Verify_FixFile ()
{
	suffix=`basename $fix_file | cut -f 5 -d.`

        if [ "$suffix" != "tar" ]
	then
	     Usage
	fi

	if [ ! -r "$fix_file" ]
	then
	     Error Unable to locate fix file 
	fi
	prefix=`basename $fix_file |cut -f1-2 -d. | cut -c2-`
	[ "$prefix" != "$Release.$Revision" ] && Error Invalid fix file for Reality, fix appears to be for Reality $prefix		
}

#########################################################################

#
# Check that daemons are not running and we are running as 'realman'
# Only verify daemons if we know we need to do a build
#

Sanity_Check ()
{
	if [ "$expert" -ne 1 ]
        then  
	    kr=$REALROOT/bin/killreal
	    if [ "$build" -ne 0 -a -f $kr ]
	    then
	         $kr -c && \
	            Error The Reality daemons must first be shutdown
	    fi
	fi
	id | grep realman > /dev/null || 
		Error Must be realman to run this program
}

#########################################################################

#
# Install_Files
# Unpacks .files cpio, creating backup of files changed before 
# installing any new ones
#

Install_Files ()
{
	fixfiledir=$filedir/$fixno
	backuplist=""
	Display "Dealing with UNIX executable files"
	if [ ! -d "$filedir" ]
	then
		  mkdir -p $filedir 2> /dev/null || 
				Error Cannot create $filedir
	fi
	if [ ! -d "$fixfiledir" ] 
	then 
		mkdir -p $fixfiledir 2> /dev/null || 
				Error Cannot create $fixfiledir
	fi
	cp $fixno.files $fixfiledir  
	cp $fixno.desc $fixfiledir/Desc
	cp $fixno.pre $fixfiledir/Pre
	[ -r $fixno.bugnos ] && cp $fixno.bugnos $fixfiledir/bugnos

	filelist=`cpio -itcB < $fixfiledir/$fixno.files 2> /dev/null` || Error Cannot understand $fixfiledir/$fixno.files

	cd $Realman #ensure in right place

	if [  -f "$fixfiledir/Uninstall_cpio" ]
	then
	     rm $fixfiledir/Uninstall_cpio
        fi
	rm -f $fixfiledir/newfiles
	for backupfile in $filelist
	do
   	   if [ -f "$backupfile" ] 
	   then
		backuplist=$backuplist" "$backupfile
	   else
		[ -d "$backupfile" ] || 
		echo $backupfile >> $fixfiledir/newfiles
	   fi
	done
	#
	# now create an uninstall file
	#
	if [ ! -z "$backuplist" ]
	then
	    ls $backuplist | cpio -ocB > $fixfiledir/Uninstall_cpio 2> /dev/null || Error Cannot create uninstall file
	fi
	#
	# remove items so cpio can re-load them (aix change)
	#
	for dlist in $backuplist
	do
	    rm -f $dlist
	done
	#
	# Now we can install fix files
	#
	cpio -dicBum < $fixfiledir/$fixno.files 2>/dev/null || Error Invalid cpio file
	#
	# now we should ensure that they are read only
	#
	#90140 for chmodid in $backuplist
	#90140 do
	    #90140 chmod 555 $chmodid
	#90140 done
}

#########################################################################

#
# DisplayAndWait
# display message which requires a (y/n/q) response and read response
# (exit on quit) 
#

DisplayAndWait ()
{
	if [ $answer_all -ne 0 ] 
	then
	    Display $*
	    return 0
	fi
	
        echo
        while :
        do
                Display "$* (y/n/q) : \c"
                read z || z=q
                case "$z" in
                        q*|Q*) TidyUp
			       exit ;;
                        y*|Y*) return 0 ;;
                        n*|N*) return 1 ;;
                        *)     ;;
                esac
        done
}                               

#########################################################################

#
# Install_Rti
# Install Reality Tape image fix
#

Install_Rti ()
{
	imagefixdir=$imagedir/$fixno
	Display "Dealing with tape image"
        if [ ! -d "$imagedir" ] 
	then
		 mkdir -p $imagedir 2> /dev/null || 
				Error Cannot create $imagedir
	fi
	# Ensure that right priveleges on directory structure
	chmod 755 $rev_dir
	chmod -R 755 $rev_dir/ut
	if [ ! -d "$imagefixdir" ]
	then
        	mkdir -p $imagefixdir 2> /dev/null || 
				Error Cannot create $imagefixdir
	fi
        cp $fixno.rti $imagefixdir/blkfile 
        cp $fixno.desc $imagefixdir/Desc 
	cp $fixno.pre $imagefixdir/Pre
	[ -r $fixno.bugnos ] && cp $fixno.bugnos $imagefixdir/bugnos

	touch $imagefixdir/Version #for now empty file 
	cat $imagedir/Comps 2>/dev/null | grep $fixno > /dev/null || 
				echo $fixno >> $imagedir/Comps 
	rti=1

}                                                         

#########################################################################

#
# Unpack the tar file and set up file type flags
#

Unpack ()
{
    $debug && set -x
	cksum_msg="It is not possible to install this fix\n"
	end_msg="\tAlthough in no way did this affect the installation of the fix\n\tonto this system you should be aware that during the installation \n\tproblems were found with the following file(s):"
        checksum_error=0 

	cd $Realman #ensure in realman's home directory
	Verify_FixFile #Check we can access file
	Operation=INSTALL
        fixlist=""

	tar -xf $fix_file > /dev/null || Error Invalid tar file
#
# lets verify that fix is for this platform
#
        Platform=`$REALROOT/bin/sup/whom | cut -f1 -d' '` > /dev/null
        if grep "$Platform" $fixno".platforms" > /dev/null
	then
	    :
        else
	    if [ $select -eq 1 ]
	    then
		Display "Fix $fixno not required on this platform"
	    else
		Display "Error $fixno - fix cannot be installed on this platform"
	    fi
            return
        fi

        #
        # build list of file to install
        #
        Tempfixlist=`tar -tf $fix_file`
	# checksum test
	chksumlist=""
        chksum_file=`tar -tf $fix_file | grep chksum`
        if [ -n "$chksum_file" ]
        then
            chksumlist=`cat $chksum_file`
        fi
        for chksum_item in $chksumlist
        do
            fixid=`echo $chksum_item | cut -f1 -d ':'`
            orig_checksum=`echo $chksum_item | cut -f2 -d ':'`
            Prefix=`echo $fixid | cut -f1 -d.`
            checksum=`sum -r $fixid` || exit
            file_checksum=`echo $checksum | cut -f1 -d ' '`
            if [ $file_checksum != $orig_checksum ]
            then
                # problem but it might not prevent us from continuing
                if [ "$Prefix" = "$Platform" ] || [ "$Prefix" = "$Release" ]
                then
                    # fix is dependant on this file & it might be duff 
                    cksum_msg="\t$fixid checksum is incorrect\n\twas $file_checksum and should be $orig_checksum"
                    Error $cksum_msg
                else
                    case $Prefix
                    in
                        aix) system="IBM AIX";;
                        hp) system="HP Unix";;
                        lrx) system="Red Hat 7.2,ES(2.1),AS(2.1)";;
                        l9x) system="Red Hat 9,ES(3.0),AS(3.0)";;
                        ss) system="Solaris";;
                    esac
                    checksum_error=1
                    end_msg="$end_msg\n\n\tNOTE: This file is only used on $system systems"
                    end_msg="$end_msg\n\t$fixid checksum was $file_checksum and should be $orig_checksum"
                fi
            fi
        done

        for fixid in $Tempfixlist
        do
           Firstchar=`echo $fixid | cut -c1`
	   Dummy=`echo $Release | cut -c1`
           if [ "$Firstchar" != "$Dummy" ]
           then
                #
                #we must have a platform specific file
                #
                Prefix=`echo $fixid | cut -f1 -d.`
                if [ "$Prefix" = "$Platform" ] 
		then
                    if [ -z "$fixlist" ]
                    then
                        fixlist=`echo $fixid | cut -f2- -d.`
                    else
                        fixlist=$fixlist' '`echo $fixid |cut -f2- -d.`
                    fi
                    #
                    # rename fix removing prefix
                    #
                    mv $fixid `echo $fixid |cut -f2- -d.`
                else
		    continue
		fi
           else
                if [ -z "$fixlist" ]
                then
                    fixlist=$fixid
                else
                    fixlist=$fixlist' '$fixid
                fi
           fi
        done                                    

	Fixno_Desc=`cat $fixno.desc`
        [ -r $fixno.readme ] && Fixno_Readme=`cat $fixno.readme`   
	Prereq=`cat $fixno.pre |sed 's/;/ /g'`
	fixnosave=$fixno

	for fixno in $Prereq
	do	
	   Verify_Fix
	   if [ "$oper" != I ] 
	   then
		Display "Unable to install fix $fixnosave it has a pre-requisite of fix $fixno"
		build=0
	   	return
	   fi
	done    

	fixno=$fixnosave

        Display "Installing fix $fixno - $Fixno_Desc"
	Display "_________________________________________________________________"
        [ -r $fixno.readme ] && tr "\375" "," < $fixno.readme
        DisplayAndWait "\n\nContinue" || return

        for file in $fixlist
	do
	    filext=`echo $file |cut -f 5 -d.`
	    case $filext in
		 "objects") Display "Dealing with object files"
			    build=1
			    Sanity_Check #daemons cannot be alive, build req.
			    cpio -dicBum < $file 2> /dev/null || Error Invalid cpio file
			    fixnum=`echo $fixno|cut -d. -f4`
			    cp $fixno.desc $fixdir/fix_$fixnum/Desc
			    cp $fixno.pre $fixdir/fix_$fixnum/Pre
			    Remove_Exc    # remove from exclusions if present
			    Fix_Components=$Fix_Components";.objects"
			    ;;

	         "files")   Install_Files 
			    Fix_Components=$Fix_Components";.files"
			    ;;

		 "rti")	    if [ $ignore_image -eq 1 ]
                            then
                                  break
                            fi
			    Install_Rti
			    Fix_Components=$Fix_Components";.rti"
			    ;;
	    esac
	done
	Fix_Components=`echo $Fix_Components|cut -c2-` #get rid of first ';'
	Update_History
}
#########################################################################

#
# Uninstall_image
#

Uninstall_Image ()
{
	Display 'Uninstalling tape images..'
	cd $Realman
	imagefixdir=$imagedir/$fixno
	rm -rf $imagefixdir 2> /dev/null
	#
	#now we need to dereference fix number in Comps file
	#
	Comps=`cat $imagedir/Comps | sed s/$fixno//`
	echo $Comps > $imagedir/Comps
	rti=1
}

#########################################################################

#
# Uninstall_Files
#

Uninstall_Files ()
{

	Display 'Uninstalling Files..'
	cd $Realman
	fixfiledir=$filedir/$fixno	
	cpio -dicBum < $fixfiledir/Uninstall_cpio 2> /dev/null || Cannot understand Uninstall cpio
	deletefiles=`cat $fixfiledir/newfiles 2> /dev/null`
	for delfiles in $deletefiles
	do
	    rm -f $delfiles 2> /dev/null
	done
	rm -rf $fixfiledir 2> /dev/null
}

#########################################################################  

#
# Uninstall_Object
#

Uninstall_Object ()

{

	Display 'Uninstalling Objects..'
	exc_fixes= 
	exc_ovlys= 
	exc_rpqs= 
	fix_num=`echo $fixno | cut -f4 -d.`

	if [ -r $exc_file ]
	then
	   exc_fixes=`grep EXC_FIXES $exc_file | cut -f2 -d:` 
	   exc_ovlys=`grep EXC_OVLYS $exc_file | cut -f2 -d:`
	   exc_rpqs=`grep EXC_RPQS $exc_file | cut -f2 -d:` 
	   rm -f $exc_file
	fi
#
# now add fix to exc_fixes if not already there
#
	temp=`echo $exc_fixes | grep fix_$fix_num` 
   	[ "$temp" ] || exc_fixes="$exc_fixes fix_$fix_num"

	touch $exc_file
	chmod 644 $exc_file

	[ "$exc_ovlys" ]    && echo "EXC_OVLYS:${exc_ovlys}"    >> $exc_file
	[ "$exc_fixes" ]    && echo "EXC_FIXES:$exc_fixes"    >> $exc_file
	[ "$exc_rpqs" ]     && echo "EXC_RPQS:${exc_rpqs}"      >> $exc_file 

#
# now remove fix from inclusion file if it is present
#

	inc_fixes=
	inc_ovlys=
	inc_rpqs=

	if [ -r $inc_file ]
	then
   	   inc_fixes=`grep INC_FIXES $inc_file | cut -f2 -d:`
           inc_ovlys=`grep INC_OVLYS $inc_file | cut -f2 -d:`
           inc_rpqs=`grep INC_RPQS $inc_file | cut -f2 -d:`
           rm -f $inc_file                                       
	fi

	if [ "$inc_fixes" ]
	then
	   inc_fixes=`echo $inc_fixes |sed "s/fix_$fix_num//"`
	fi
	touch $inc_file
	chmod 644 $inc_file

	[ "$inc_ovlys" ]    && echo "INC_OVLYS:${inc_ovlys}"    >> $inc_file
	[ "$inc_fixes" ]    && echo "INC_FIXES:${inc_fixes}"    >> $inc_file
	[ "$inc_rpqs" ]     && echo "INC_RPQS:${inc_rpqs}"      >> $inc_file

	build=1
}
########################################################################

#
# Remove_Exc
#                     

Remove_Exc ()
{
  	exc_fixes=
  	exc_ovlys=
  	exc_rpqs=
  	fix_num=`echo $fixno |cut -f4 -d.`
  	if [ -r $exc_file ]
  	then
           exc_fixes=`grep EXC_FIXES $exc_file | cut -f2 -d:`
           exc_ovlys=`grep EXC_OVLYS $exc_file | cut -f2 -d:`
           exc_rpqs=`grep EXC_RPQS $exc_file | cut -f2 -d:`
           rm -f $exc_file
  	fi

  	if [ "$exc_fixes" ]
  	then
           exc_fixes=`echo $exc_fixes |sed "s/fix_$fix_num//"`
    	 fi
  	touch $exc_file
  	chmod 644 $exc_file

  	[ "$exc_ovlys" ]    && echo "EXC_OVLYS:${exc_ovlys}"    >> $exc_file
  	[ "$exc_fixes" ]    && echo "EXC_FIXES:${exc_fixes}"    >> $exc_file
  	[ "$exc_rpqs" ]     && echo "EXC_RPQS:${exc_rpqs}"      >> $exc_file
} 

########################################################################

#
# Uninstall
#

Uninstall ()
{
   	fixlist=$fixno
   	Dependants=`/usr/local/bin/pdshist -m -p reality -v $fixno -tFX 2> /dev/null | sed 's/;/ /g'`

   	if [ "$Dependants" ] 
   	then 
   	   Display "WARNING Uninstalling this fix, will also uninstall fixes"
   	   for fixno in $Dependants
   	   do
	      Verify_Fix
	      if [ "$InstallFlag" -eq 1 ]
	      then
   	          Display $fixno - $comment
	          fixlist=$fixlist' '$fixno 
	      fi
   	   done
   	fi
   	DisplayAndWait Are you sure you wish to continue this operation ||
	return

  	for fixno in $fixlist
   	do 
   	   Operation=UNINSTALL
	   Verify_Fix
	   Display Uninstalling $fixno
   	   for Ufiles in $components
   	   do
	       case $Ufiles in 
		   ".objects") Uninstall_Object;;
		   ".files") Uninstall_Files;;
		   ".rti") Uninstall_Image;;
               esac
   	   done
	   Update_History
         done

}

#########################################################################  

#
# Verify_Fix  - Check fix has not already been loaded
#

Verify_Fix ()
{
	components=
	oper=
	req=
	comment=
	pref=
	Result=`/usr/local/bin/pdshist -j -ssdorc reality $fixno`

	components=`echo $Result |cut -d\| -f2 |sed 's/;/ /g'`
	oper=`echo $Result |cut -d\| -f3`
	req=`echo $Result |cut -d\| -f4 |sed 's/;/ /g'`
	comment=`echo $Result |cut -d\| -f5`
	pref=`echo $Result |cut -c4`
        if [ "$pref" = "T" -a $uninstall -ne 1 ]
        then
                InstallFlag=0 # return not installed, even if it is as it is being
                return        # 'T' status fixes are allowed to be overwritten
        fi           

	if [ $overwrite -eq 1 -a $uninstall -ne 1 ] 
	then
		InstallFlag=0 # return not installed, even if it is as it is being  
		return	      # installed from a service pack
	fi
	if [ $reinstall -eq 1 -a $uninstall -ne 1 ]
	then 
		InstallFlag=0 # return not installed as we are in a reinstall
		return
	fi

	if [ ! "$components" ]
	then
		InstallFlag=0
		return
	fi
	if [ "$oper" = U ]
	then
		InstallFlag=2
	else 
		InstallFlag=1
	fi
	
}

########################################################################

#
# main starts here
#
progname=$0
answer_all=0
uninstall=0
select=0
overwrite=0
reinstall=0
expert=0
checksum_error=0
nobuild=0
ignore_image=0
Installer=
Realman=${REALMAN:-/usr/realman}

ECHO="echo"

# dot in the build.conf file and work out important directories & file names
# build.conf constructs the base_dir, make_dir, rel_dir, rev_dir dir. paths

build_conf=$REALROOT/files/build.conf
[ -r "$build_conf" ] || Error "Cannot read the $build_conf file\nCheck REALROOT"
. $build_conf 

[ "$Machine" = "lrx" -o "$Machine" = "l9x" ] && ECHO="echo -e"
#set -x
debug=false
opts=
nest=nest

[ $# -lt 1 ] && Usage
while getopts adenruyxzi: opt
do
        case $opt in
                a) select=1
                   ;;
		d) ignore_image=1
		   opts="$opts -d"
		   ;;
                r) uninstall=1
                   ;;
                x) debug=true
		   set -x
		   opts="$opts -x"
                   ;;  
		u) reinstall=1
		   opts="$opts -u"
		   ;;
		y) answer_all=1
		   opts="$opts -y"
		   ;;
		e) expert=1
		   opts="$opts -e"
		   ;;
		n) nobuild=1
		   opts="$opts -n"
		   ;;
		z) nest=
		   opts="$opts -z"
		   ;;
		i) Installer=$OPTARG
		   ;;
		*) Usage;;
        esac
done                          
#[ $# -eq 2 ] && shift
shift $(($OPTIND - 1))

trap : 1 2 15 # don't allow this to be interrupted!
 
build=0 #assume no build to start with
rti=0 #assume no tape image to be installed
fixes=$*
overwrite=${IF_OVERWRITE:=0}	# If called from install_sp


filedir=${rev_dir}/ut/files
imagedir=${rev_dir}/ut/dbase
fixdir=${rev_dir}/ut/fix
exc_file=$make_dir/exclusions
inc_file=$make_dir/inclusions
here=`pwd`

# Make sure absolute path to all fixes.
new_fixes=""
for fix_file in $fixes
do
    case $fix_file in
    /*) ;;
    *)  fix_file=$here/$fix_file;;
    esac
    new_fixes="$new_fixes $fix_file";
done
fixes="$new_fixes"

if [ $overwrite -eq 1 ]
then
	Installer="ServicePack"
else
	Display "Reality Fix Installation"
	Get_User_Details
fi

Sanity_Check #Check running as realman
if [ $uninstall -eq 1 ]
then
	fixno=`basename $fixes | cut -f 1-4 -d.`
        pref=`basename $fixes | cut -c1`
        if [ "$pref" = "T" -o "$pref" = "V" ]
        then
            fixno=`echo $fixno | cut -c2-`
        fi                                    

	# Normalise fix number
	frel=`echo $fixno | cut -f 1 -d.`
	frev=`echo $fixno | cut -f 2 -d.`
	fsp=`echo $fixno | cut -f 3 -d.`
	fno=`echo $fixno | cut -f 4 -d. | sed -e 's/^0*//'`
	fixno=`printf "%d.%d.%d.%04d" $frel $frev $fsp $fno`

        Verify_Fix
	case $InstallFlag in 
		"0") Display "Fix has not been installed"
		     exit;;
		"1") DisplayAndWait "You are about to Uninstall fix $fixno - $comment\n Continue " || exit
		     Uninstall;;
		"2") Display "Fix has already been uninstalled"
		     exit;;
	esac

else
	if [ "$select" -ne 0 ]
	then

	    # code below actually performs a sort on the fix files based only upon
	    # the numeric part of the fix number, this enables fixes to be installed
	    # in the correct order
	    oldir=`pwd`
	    fixdirname=$fixes
	    tmpfile=/tmp/fixes.$$
	    cd $fixdirname

	    # Service pack now comes with a copy of the latest if_code_...
	    # If present then use that to do the install.
	    isfile=if_code
	    if [ "$nest" -a -r $isfile ]
	    then
		opts="$opts -i $Installer"
		echo Using supplied $isfile with $opts -z -a .
		ksh ./$isfile $opts -z -a .
	        exit
	    fi

	    fixes=`ls ?$Release.$Revision.*.tar > $tmpfile`
	    
	    list=`cat $tmpfile |sort -k 1.2 -t.`
	    rm $tmpfile
	    cd $oldir
	    fixes=
	    for file in $list
	    do
		fixes=$fixes' '$fixdirname/$file
	    done                           

	fi
	#
	# we check to see if build is required
	#
	#tmpdir=/tmp/fix.$$
	#mkdir $tmpdir
	#cd $tmpdir
	cd $Realman
	for fix_file in $fixes
        do                    
	    if [ "`tar -tvf $fix_file | grep .objects 2>/dev/null`" ]
	    then 
	         fixno=`basename $fix_file | cut -f 1-4 -d. |cut -c2-`
		 Verify_Fix
            	 if [ $InstallFlag -ne 1 -o $reinstall -eq 1 ] 
            	 then                     
		     tar -xf $fix_file > /dev/null || Error Invalid tar file
                     #
                     # lets verify that fix is for this platform
                     #
                      Platform=`$REALROOT/bin/sup/whom | cut -f1 -d' '` > /dev/null
                      if grep "$Platform" $fixno".platforms" > /dev/null
                      then
                          build=1; break
                      fi
		 fi
	    fi
	done

	if [ $build -eq 1 ]
	then
	    Sanity_Check
	fi

	build=0
	for fix_file in $fixes 
	do
	    fixstatus=`basename $fix_file |cut -c1`
	    fixno=`basename $fix_file | cut -f 1-4 -d. |cut -c2-`
	    Verify_FixFile
	    Verify_Fix
	    if [ $InstallFlag -eq 1 ] 
	    then
  		 Display Fix $fixno has already been installed, ignoring; continue 
	    fi

	    Unpack   #unpack the fix file and set the relevant flags for file types
	
       	    Fix_Components=""
	done
fi

if [ $rti -eq 1 ]
then
        if [ "$Operation" = INSTALL ]
        then 
            Display You must logon to each database to complete $Operation using DBUPDATE
	else
	    Display You must logon to each database to complete $Operation using SYS-UPDATE
	fi
	sleep 2
fi

TidyUp #get rid of unwanted files

if [ "$build" -eq 1 -a "$nobuild" -eq 0 ]
then
   	[ $overwrite -eq 1 ] && exit
       	cd $rev_dir/make
	if [ "$expert" -eq 1 ] 
	then
	    ./build -e
	else
            ./build -f
	fi
fi

if [ $checksum_error = 1 ]
then
        Display "\n\007Information: \n$end_msg\n\n"
fi
 
