#!/bin/bash

LogFile=/tmp/HmcInstall.log

#-------------------------------------------------------------------------------
# Common exit point
#-------------------------------------------------------------------------------
function ExitCleanup {
    # keep the log file, but ensure a different user can overwrite it next time
    cd /
    chmod 666 $LogFile

    if [ $1 -ne 0 ]; then
        exit $1
    else
        exit 0
    fi
}

#-------------------------------------------------------------------------------
# Cleanup script for BobCat
#-------------------------------------------------------------------------------
function BobCatCleanup {
    rm -rf /tmp/_bcat_
    if [ $1 -ne 0 ]; then
        rm -rf /opt/bobcat
    fi
    exit $1
}

#-------------------------------------------------------------------------------
# This function does the RPM installation task.
#-------------------------------------------------------------------------------
function InstallRpm {
    if [ -f /opt/hsc/data/config/NO_UPDATE_RPMS ]; then
        x="$2"
        # Strip version then leading directory name
        f=`echo ${x%%-[0-9]*}`
        r=`echo ${f##*/}`
        for i in `cat /opt/hsc/data/config/NO_UPDATE_RPMS`; do
            if [ "$r" == "$i" ]; then
                return
            fi
        done
    fi

    CMD=`echo $1`; shift;
    RPM=`echo $1`; shift;
    OPT=`echo $*`
    OPT="$OPT --force --nodeps"

    # Log the test install output. The format for the "normal" RPM install
    # processing inside this script is 'rpm -i <file spec> --force --nodeps'
    if [ -f $RPM ]; then
        echo "=====================================================" >> $LogFile
        echo "***** Executing rpm -vv $CMD $RPM $OPT *****         " >> $LogFile
        echo "=====================================================" >> $LogFile
        rpm -vv $CMD $RPM $OPT >> $LogFile 2>&1
        if [ $? -ne 0 ]; then
            echo "Error installing rpm fileset named $2" >> $LogFile
            if [ "$Update" == "true" ]; then
                echo "Error installing rpm fileset named $2"
                ExitCleanup 9
            fi
        fi
    fi
}

#-------------------------------------------------------------------------------
# This function does the RPM removal task.
#-------------------------------------------------------------------------------
function EraseRpm {
    # If rpm is part of no update list then do not do anything with it
    if [ -f /opt/hsc/data/config/NO_UPDATE_RPMS ]; then
        x="$2"
        for i in `cat /opt/hsc/data/config/NO_UPDATE_RPMS`; do
            if [ "$x" == "$i" ]; then
                return
            fi
        done
    fi
    echo "=====================================================" >> $LogFile
    echo "***** Executing rpm -evv $* *****                    " >> $LogFile
    echo "=====================================================" >> $LogFile
    rpm -evv $* --nodeps --allmatches >> $LogFile 2>&1
    if [ $? -ne 0 ]; then
        echo "Error removing rpm fileset named $2" >> $LogFile
    fi
}

#-------------------------------------------------------------------------------
# This function Updates if already installed, else it installs
#-------------------------------------------------------------------------------
function RsctInstall {
    rpm -q $1 1>&2 2>/dev/null
    if [ $? -eq 0 ]; then
        InstallRpm -Uvh $2
    else
        InstallRpm -ivh $2
    fi
}

#-------------------------------------------------------------------------------
# This function installs patches that are not in rpms
#-------------------------------------------------------------------------------
function InstallPatch {
    FILE=`echo $1`; shift;
    MESG=`echo $*`
    if [ -f $FILE ]; then
        echo "--- Installing ${MESG}...." 
        cd /
        tar -xf $FILE
        if [ $? -ne 0 ]; then
            ExitCleanup 3
        fi
    fi
}

#-------------------------------------------------------------------------------
# This function renames the modules for hmc
#-------------------------------------------------------------------------------
function SetModules {
    cd /boot
    KERNEL=`ls bzImage-*default | cut -c9-`
    cd /
    KERN_DIR="/lib/modules/$KERNEL/kernel"
    mv $KERN_DIR/drivers/net/bcm/bcm5700.ko $KERN_DIR/drivers/net/bcm/bcm5700_8_1_11.ko 
    touch $KERN_DIR/drivers/net/bcm/bcm5700_8_1_11.ko 

    mv $KERN_DIR/extra_drivers/open/bcm5700_8_2_7/bcm5700_8_2_7.ko $KERN_DIR/extra_drivers/open/bcm5700_8_2_7/bcm5700.ko
    touch $KERN_DIR/extra_drivers/open/bcm5700_8_2_7/bcm5700.ko

    mv $KERN_DIR/extra_drivers/open/e1000_7_3_15/e1000_7_3_15.ko $KERN_DIR/extra_drivers/open/e1000_7_3_15/e1000.ko
    touch $KERN_DIR/extra_drivers/open/e1000_7_3_15/e1000.ko
    mv $KERN_DIR/drivers/net/e1000/e1000.ko $KERN_DIR/drivers/net/e1000/e1000_6_0_52.ko
    touch $KERN_DIR/drivers/net/e1000/e1000_6_0_52.ko

    mv $KERN_DIR/extra_drivers/open/bnx2_1_3/bnx2_1_3.ko $KERN_DIR/extra_drivers/open/bnx2_1_3/bnx2.ko
    touch $KERN_DIR/extra_drivers/open/bnx2_1_3/bnx2.ko

    /sbin/depmod -a -v $KERNEL
}

#-------------------------------------------------------------------------------
# This function Updates the Base Operating System
#-------------------------------------------------------------------------------
function UpdateOS {
    if [ -d $image/baseOS ]; then
        CURR_DIR=$PWD
        cd $image/baseOS
        echo "--- Updating base ...."
        dhcpd_conf=0
        if [ -f /etc/dhcpd.conf ]; then
            dhcpd_conf=1
        fi

        OldUpdates=`rpm -qa|grep hmc-update-GA`     # Locate the older updates
        for i in $OldUpdates                        # and remove them all
        do                                          # before we add the 
            rpm -e $i --nodeps 2>&1                 # latest updates
        done
        # MCP Update. return code of 0 indicates successful update
        # return code of 66 indicates update has already been applied
        TYPE=`file $image/baseOS/*update* | cut -f2 -d ":"|cut -f2 -d" "`
        if [ "$TYPE" == "RPM" ]; then
            InstallRpm -ivh hmc-update-GA-*.i386.rpm
            if [ $? -eq 0 ]; then
                cd /tmp/mcp-update
                ./post_install.*.sh
                case $? in
                    0 | 66 ) ;;
                         * ) EraseRpm hmc-update-GA
                             ExitCleanup 4 ;;
                esac
            fi
        else
            for UPD in `cat index`
            do
                echo "***** Updating $UPD *****" >> $LogFile
                $UPD --nox11 >> $LogFile 2>&1
                case $? in
                    0 | 66 ) ;;
                         * ) ExitCleanup 4 ;;
                esac
            done
	    ln -sf /boot/bzImage-* /boot/bzImage
        fi

        rm -f /opt/IBMJava/src.jar 2>/dev/null

        sed -e 's/ENABLE_SUSECONFIG=no/ENABLE_CONFIG=yes/' \
            /etc/sysconfig/suseconfig > /tmp/suseconfig
        mv /etc/sysconfig/suseconfig /etc/sysconfig/suseconfig.orig
        cp /tmp/suseconfig /etc/sysconfig

        # We need to preserve /etc/hosts before runing SuSEconfig as it updates
        # localhost to point to 127.0.0.2 which access problems to users.

        mv /etc/hosts /etc/hosts.orig
        cp /etc/hosts.orig /etc/hosts
        /sbin/SuSEconfig >> $LogFile 2>&1
        mv /etc/sysconfig/suseconfig.orig /etc/sysconfig/suseconfig
        mv /etc/hosts.orig /etc/hosts

#        cp /etc/opera6rc.fixed /tmp/saved_opera6rc.fixed
#        InstallRpm -Uvh $image/baseOS/opera*rpm
#        cp /tmp/saved_opera6rc.fixed /etc/opera6rc.fixed

        # If there was no dhcpd.conf file before installation, then remove 
        # the file created by installing dhcp-server

        if [ "$dhcpd_conf" == "0" ]; then
            if [ -f /etc/dhcpd.conf ]; then
                rm -f /etc/dhcpd.conf
            fi
        fi

        DISKINFO="/usr/sbin/hwinfo --disk 2>/dev/null"
        hdl=`$DISKINFO | grep "Device File" | cut -d'/' -f3 | sed -e 's/ //g'`
        for hd in $hdl
        do  
            if [ "$hd" = "" ]; then
                hd="hda"
            fi
            break
        done
        
        echo "========================================" >> $LogFile
        echo "******** Updating Module Names  ********" >> $LogFile
        echo "========================================" >> $LogFile
        SetModules >> $LogFile 2>&1
        echo "========================================" >> $LogFile
        echo "********* Updating Boot Record *********" >> $LogFile
        echo "========================================" >> $LogFile
        /usr/sbin/grub-install /dev/$hd>> $LogFile 2>&1
        
        rm /opt/IBMJava
        ln -sf /opt/ibm/java2-i386-50 /opt/IBMJava
        cd $CURR_DIR
    fi
}

#-------------------------------------------------------------------------------
# Start the product install...
#-------------------------------------------------------------------------------
cd /
image=$1

if [ "$image" == "" ]; then
    echo "Please specify directory containing installable packages"
    echo "usage: installImages  <directory>"
    ExitCleanup 1
fi

# Check if directory exists
if [ ! -d $image ]; then
    echo "The directory $patchdir doesn't exist"
    echo "Please specify directory containing the installable packages."
    ExitCleanup 2
fi

if [ -f /opt/hsc/data/config/NO_UPDATE_FILES ]; then
    rm -f /tmp/saved_files.tar
    cat /opt/hsc/data/config/NO_UPDATE_FILES | \
        xargs tar -cvf /tmp/saved_files.tar
fi

PATH=$PATH:/opt/IBMJava/jre/bin:
LD_LIBRARY_PATH=/opt/hsc/lib:/opt/hsc/lib/hcmjni:/lib:/usr/lib:$LD_LIBRARY_PATH
export PATH LD_LIBRARY_PATH

if [ ! -d /opt/IBMJava ]; then
    ln -sf /opt/ibm/java2-i386-50 /opt/IBMJava
fi

# Remove the zip file to save space
rm -f /usr/local/hsc_install.images/*.zip

# Save old log files
if [ -f $LogFile ]; then
    mv -f ${LogFile}.3 ${LogFile}.4 2>/dev/null
    mv -f ${LogFile}.2 ${LogFile}.3 2>/dev/null
    mv -f ${LogFile}.1 ${LogFile}.2 2>/dev/null
    mv -f ${LogFile}   ${LogFile}.1 2>/dev/null
fi

cp -f /opt/hsc/data/version /tmp/.version.orig

# requirement for installing Update images
if [ -f $image/.require ]; then
    /opt/hsc/bin/hsc version > /tmp/.version
    INSTALL="true"
    VERSION=`cat $image/.require | cut -d '|' -f 1`
    RELEASE=`cat $image/.require | cut -d '|' -f 2`

    grep -q "$VERSION" /tmp/.version
    if [ $? -ne 0 ]; then
        INSTALL="false"
    else
        if [ "$RELEASE" != "" ]; then
            grep -q "$RELEASE" /tmp/.version
            if [ $? -ne 0 ]; then
                INSTALL="false"
            fi
        fi
    fi

    if [ "$INSTALL" == "false" ]; then
        echo "Installation of this update image requires HMC $VERSION $RELEASE"
        echo "Current HMC is not $VERSION $RELEASE"
        echo "Unable to install this update image."
        ExitCleanup 3
    fi
fi

# check and install ptf-req rpm
if [ -f $image/IBMhmc.MH0*rpm ]; then
    cd $image
    PTF=`ls IBMhmc.MH0*rpm | cut -d '.' -f 2 | cut -d '_' -f 1`
    PTF_d=`rpm -qpl IBMhmc.MH0*rpm | grep MH0`
    if [ -f /opt/hsc/data/ptf/${PTF}_obs ]; then
        echo "--- Install error: This fix is now obsolete.  "
        ExitCleanup 3
    else
        echo "--- Installing ptf-req ...."
        rpm --force -Uvh IBMhmc.${PTF}*rpm >> $LogFile 2>&1
        if [ $? -ne 0 ]; then
            echo "--- Install error: failed dependencies"
            ExitCleanup 3
        else
            PTFdesc=`rpm -qpic IBMhmc.MH0*rpm | grep "$PTF:"`

            # remove ptf-req if it's 1st part(s) of an Update "_z1", "_d1", or "_d2"
            PTFREQ=`rpm -qpR IBMhmc.${PTF}*.rpm | grep ${PTF} | cut -d '=' -f 1`
            PTFupd=`echo ${PTFREQ} | cut -d '_' -f 2`
            if [[ "$PTFupd" == "z1" || "$PTFupd" == "d1" || "$PTFupd" == "d2" ]]; then
                rpm -e --nodeps ${PTFREQ}
            fi
        fi
    fi
fi


echo "=========================================================" >> $LogFile
disk=`cat $image/.signature | cut -d' ' -f 4`
if [[ "$disk" == "0" || -f $image/.image.updates ]]; then
    Update="true"
    echo "*********   Performing Update operation `date`  *********" >> $LogFile
else
    Update="false"
    echo "*********   Performing Install operation `date` *********" >> $LogFile
fi
#if [ "$Update" == "true" ]; then
#    cd /
#    rm -f /tmp/WsmSaved.tar
#    /bin/tar cf /tmp/WsmSaved.tar /var/websm/security /usr/websm/codebase/SM* \
#       /var/websm/config/user_settings/websm.cfg 2>/dev/null
#fi
echo "=========================================================" >> $LogFile

# Save security information This will get processed in next reboot
sp=`grep ^SocketProvider /opt/hsc/data/cim.properties`
if [[ $sp == *PKCS12SocketProvider ]]; then
    echo $sp > /var/hsc/tmp/cimomcfg.properties.reboot
fi

# Install RMC and CSM if rmc directory exists
if [ -d $image/rmc ]; then
    cd $image/rmc
    echo "--- Installing RSCT ...."
    RsctInstall src src-*rpm
    if [ "$Update" == "false" ]; then
        # Ensure src is started
        cd /
        /sbin/srcmstr -r &
	srcmstr_pid=$!
    fi
    cd $image/rmc
    RsctInstall rsct.core.utils rsct.core.utils-*rpm 
    RsctInstall rsct.core       rsct.core-*rpm 
    RsctInstall rsct.service    rsct.service-*rpm 
    RsctInstall rsct.basic      rsct.basic-*rpm 
    echo "--- Installing CSM ...."
    RsctInstall csm.core        csm.core-*rpm 
    RsctInstall csm.deploy      csm.deploy*rpm
    RsctInstall csm_hmc.server  csm_hmc.server-*rpm 
    RsctInstall csm_hmc.hdwr_svr  csm_hmc.hdwr_svr-*rpm 
    RsctInstall csm_hmc.client  csm_hmc.client-*rpm 
    RsctInstall csm.server.hsc  csm.server.hsc-*rpm 
    echo "--- Installing LPARCMD ...."
    RsctInstall hsc.lparcmd     hsc.lparcmd*.rpm 
    if [ "$Update" == "false" ]; then
       if [ "$srcmstr_pid" != "" ]; then
	  kill -9 $srcmstr_pid
       fi
    fi
fi

rpm -qa | grep -q sysmgt.websm.framework
if [ $? -eq 0 ]; then
   EraseRpm sysmgt.websm.framework
fi
# Install websm if websm directory exists
#if [ -d $image/websm ]; then
#    cd $image/websm
#    echo "--- Installing WebSM ....."
#    InstallRpm -ivh sysmgt.websm.framework*.rpm
#fi


# Install the base HMC rpms if baseHMC directory exists
if [ -d $image/baseHMC ]; then
    cd $image/baseHMC
    
    if [ -f $image/baseHMC/apache-tomcat-5.5.20-embed.tar.gz ]; then
       cd /opt
       tar -xzf $image/baseHMC/apache-tomcat-5.5.20-embed.tar.gz
       cd $image/baseHMC
    fi

    echo "--- Installing Common Console Framework...."
    /usr/sbin/groupadd -g 508 ccfw 2>/dev/null

    for i in `rpm -qa | grep ccfw`
    do
        CCFW=`echo $i|cut -f1 -d "-"`
        EraseRpm $CCFW
    done

    if [ "$Update" == "false" ]; then
        rm -rf /opt/ccfw
    fi
    InstallRpm -ivh ccfw*.rpm
    /usr/sbin/useradd -c "Common Console Framework" -M -g ccfw -d /opt/ccfw ccfw
    echo "--- Installing HMC ..."
#    if [ "$Update" == "true" ]; then
#	grep -q "/bin/hmcbash" /etc/shells
#	if [ $? -ne 0 ]; then
#	   migration_needed=1
#	fi
#    fi
#    InstallRpm -Uvh IBMhsc.corepe*.rpm
#    InstallRpm -Uvh IBMhsc.auiml_en_US*.rpm
#    EraseRpm IBMhsc.cimprovider
    InstallRpm -Uvh IBMhsc.cimprovider*.rpm
    InstallRpm -Uvh IBMhsc.coreserver*.rpm

#    echo "--- Installing HMC Help Software..."
#    InstallRpm -Uvh IBMhmc-help*.rpm 
#    echo "--- Installing Netboot ..."
#    InstallRpm -Uvh IBMhsc.netboot*rpm
#    InstallRpm -Uvh nimol*rpm
#    InstallRpm -Uvh osinstall*rpm

#    echo "--- Installing NLS..."
#    for i in IBMhsc.bundles_*.rpm
#    do
#        RPM_NAME=`echo $i|cut -f1 -d "-"`
#        EraseRpm $RPM_NAME
#        InstallRpm -Uvh $i
#    done

    echo "Creating asmproxy and sysplanviewer directory under /opt/ccfw/tomcat/webapps" >> $LogFile
    mkdir -p /opt/ccfw/tomcat/webapps/asmproxy
    mkdir -p /opt/ccfw/tomcat/webapps/sysplanviewer

    echo "Copying extension webapps config to /opt/ccfw/tomcat/extensions" >> $LogFile
    cp -f /opt/hsc/data/asmproxyExtension.xml   /opt/ccfw/tomcat/extensions
    cp -f /opt/hsc/data/sysplanviewerExtension.xml   /opt/ccfw/tomcat/extensions

    echo "Extracting asmproxy.war to /opt/ccfw/tomcat/webapps/asmproxy" >> $LogFile
    cd /opt/ccfw/tomcat/webapps/asmproxy
    /opt/IBMJava/bin/jar  -xvf /opt/hsc/data/asmproxy.war >> $LogFile 2>&1

#    echo "Importing ASM server signed public key to JVM keystore"
#    /opt/IBMJava/bin/keytool -import -v -noprompt -trustcacerts -alias asm -file /opt/hsc/data/asm.cer -keystore /opt/IBMJava2-142/jre/lib/security/cacerts -storepass changeit -storetype jks

    #System Plan Viewer: uninstall it if it exists, install via jar xvf
    if [ "$Update" == "true" ]; then
        echo "--- Removing old System Plan Viewer ...." >> $LogFile
        rm -rf /opt/ccfw/tomcat/webapps/sysplanviewer/*
    fi
    echo -n "--- Installing System Plan Viewer ......." >> $LogFile
    unzip /usr/websm/codebase/pluginjars/sysplanviewer.war -d /opt/ccfw/tomcat/webapps/sysplanviewer/ 2>&1 >/dev/null >> $LogFile 2>&1
#    echo " done"
    #System Plan Viewer: done
fi

# Install InfoCenter if info directory exists
if [ -d $image/info ]; then
    cd $image/info
    echo "--- Installing service documentation ...."
    if [ "$Update" == "true" ]; then
        EraseRpm IBMhmc.InfoCenter
        EraseRpm IBMhmc.InfoCenterBase
        EraseRpm IBMhmc.InfoCenter.en_US
    fi
    for RPM in `cat index`
    do
        InstallRpm -Uvh ${RPM}*.rpm
    done
fi

# Install SNM logging
if [ -d $image/snm ]; then
    cd $image/snm
    if [ -f IBMhsc.HPSNM_log*rpm ]; then
         echo "--- Installing HPSNM ...."
         InstallRpm -Uvh IBMhsc.HPSNM_log*rpm
    fi
fi

# Install Infiniband
if [ -d $image/infiniband ]; then
    cd $image/infiniband
    echo "--- Installing Infiniband ...."
    old_rpms=`rpm -qa | grep IBMhsc.IBNM`
    if [ "$old_rpms" != "" ]; then
        EraseRpm $old_rpms
    fi
    EraseRpm IBMhsc.NM_Common
    InstallRpm -Uvh IBMhsc.NM_Common-*rpm
fi

# Install Inventory Scout if service directory exists
if [ -d $image/service ]; then
    cd $image/service
    if [ -f IBMinvscout*rpm ]; then
        echo "--- Installing InventoryScout ...."
        InstallRpm -Uvh IBMinvscout*rpm
    fi
    if [ -f IBMhsc.service_img*rpm ]; then
       InstallRpm -Uvh IBMhsc.service_img*.rpm
    fi
    if [ -f IBMhsc.service_content*rpm ]; then
       InstallRpm -Uvh IBMhsc.service_content*.rpm
    fi
fi

# Install Pegasus
if [ -d $image/pegasus ]; then
    cd $image/pegasus
    if [ -f IBMhmc.pegasus*rpm ]; then
        echo "--- Installing Pegasus ...."
        InstallRpm -Uvh IBMhmc.pegasus*rpm
    fi
    if [ -f oob-hw-provider-0*rpm ]; then
        InstallRpm -Uvh oob-hw-provider-0*rpm
    fi
    if [ -f IBMhsc.hmc_vsm-*rpm ]; then
        InstallRpm -Uvh IBMhsc.hmc_vsm-*rpm
    fi
fi

InstallPatch $image/hsc.tar   "Miscellaneous Updates"
InstallPatch $image/X.tar     "X Server Config"
#InstallPatch $image/websm.tar "WebSM Updates"

# correction to infocenter
chmod 655 /info/en_US
chmod 655 /info/en_US/eclipse
chmod 655 /info/en_US/eclipse/plugins

# correct nwif files in /tmp
rm -f /tmp/nwif* 2>/dev/null

# /tmp/hmc permission
mkdir -p /tmp/hmc
chown -R ccfw.ccfw /tmp/hmc
 
/usr/sbin/usermod -G ccfw,root,hmc ccfw 2>/dev/null

# remove /opt/ccfw world write
chmod 775 /opt/ccfw

# resolve ssh id files installed from CSM rpms
rm -f /home/hscroot/.ssh/id*

#
if [ -f /opt/hsc/data/config/NO_UPDATE_FILES ]; then
    if [ -f /tmp/saved_files.tar ]; then
        cd /
        tar -xvf /tmp/saved_files.tar
        rm -f /tmp/saved_files.tar
    fi
fi
 
if [ "$Update" == "true" ]; then
    UpdateOS
    if [ -d $image/patch ]; then
        cd $image/patch
        rm -f /tmp/UpdateKernel
        for i in `ls`; do
            $i >> $LogFile 2>&1
            case $? in
                 0 ) touch /tmp/UpdateKernel ;;
                66 ) ;;
                *  ) ExitCleanup 4 ;;
            esac
        done
        if [ -f /tmp/UpdateKernel ]; then
            mount /mnt/dos
            mv /mnt/dos/linux/vmlinuz /mnt/dos/linux/vmlinuz.old
            cp /boot/vmlinuz /mnt/dos/linux/
            umount /mnt/dos
            rm -f /tmp/UpdateKernel
        fi
    fi
fi

# 
if [ -f $image/postinstall ]; then
    $image/postinstall
fi

if [ -f $image/.VERSION ]; then
    if [ -f $image/.dev ]; then
        cat $image/.VERSION >> /opt/hsc/data/version
    fi
    cat $image/.VERSION > /root/.version
    cat $image/.VERSION > /home/hscroot/.version
    chmod 644 /home/hscroot/.version
    chown hscroot.hmc /home/hscroot/.version
fi

if [ "$Update" == "true" ]; then
    if [ ! -f /done.boothmc ]; then
        touch /done.boothmc
    fi
fi

if [ "$PTF" != "" ]; then
   # if this PTF installed before, remove its desc
   grep -q "$PTF" /tmp/.version.orig
   if [ $? -eq 0 ]; then
   # If there is a coreserver present then the /opt/hsc/data/version
   # file should not be overwritten
   # otherwise it is ok to do the next line
      if [ /opt/hsc/data/version -nt /tmp/.version.orig ]; then
      # remove PTF info from /opt/hs/data/version
         grep -q "$PTF" /opt/hsc/data/version
         if [ $? -eq 0 ]; then
            grep -v "$PTF" /opt/hsc/data/version  > /tmp/_version_old_
            cp -p /tmp/_version_old_ /opt/hsc/data/version
         fi
      else
        grep -v "$PTF" /tmp/.version.orig > /opt/hsc/data/version
      fi
   fi
fi

#if [ "$PTFdesc" != "" ]; then
#   echo "$PTFdesc" >> /opt/hsc/data/version
#fi

# indicate if this ptf requires another ptf
if [ "$PTF_d" != "" ]; then
    REQUIRE=`cat ${PTF_d} | grep REQUIRE | cut -d ':' -f 2`
    if [ "$REQUIRE" != "NONE" ]; then
        echo "*** The following package is a requisite of this installation:"
        echo "*** ${REQUIRE}"
        echo "*** Please apply the above requisite to complete this installation."
    fi
fi

echo "==========================================================" >> $LogFile
echo "********* Install/Update complete at `date` *********"      >> $LogFile
echo "==========================================================" >> $LogFile
ExitCleanup 0
