#! /bin/bash
###########################################################################
#  Copyright (c) 2003, Hewlett Packard Technologies Group, L. P.           #
############################################################################
#   PROGRAM: install.sh                                                    #
#   PURPOSE: Shell script for initiating the HP Linux Deployment Utility.  #
############################################################################
# $Id: install.sh,v 1.15.2.45 2006/03/30 18:35:07 GarnerMi Exp $
############################################################################

#DEBUG DEBUG DEBUG
# set -x

#################
##    LOCALE   ##
#################

#LANG=ENG

#################
##   GLOBALS   ##
#################
# Change the pass number on this variable for each pass.
TARBALL=hppldu-1.0.9-1.tar.gz
RLS=7.50
export LDUVERSION=`echo $RLS|tr -d '.'`

BUILD=${TARBALL#*-}
BUILD=${BUILD%\.*\.*}
LIBTARBALL="hppldu-librpms-${BUILD}.tar.gz"

# Variables
RMLIST=/tmp/rmlist.$$
RLS=${RLS%\.*\.*}
LCKDIR=/var/lock/hppldu
LCKFILE=${LCKDIR}/hppldu.lock
LOGFILE=/var/log/hppldu.log
TMPDIR="/tmp/hppldu"
HPDir="/var/hp"
AUTO=""
SPACE_REQD=70000
pid=99999
RC=`expr 0`
componentInstall=false

[ -z "$HOME" ] && HOME=/root

# Linux distro codes.
RHEL21_32=0
RHEL3_32=1
RHEL3_64=2
RHEL4_32=3
RHEL4_64=4
UL10_32=5
UL10_64=6
UL10_SP3_32=7
UL10_SP3_64=8
SLES8_32=9
SLES8_64=10
SLES9_32=11
SLES9_64=12

# Required GDK Library.
GDK_LIB="/usr/lib/libgdk_pixbuf.so.2"
GDK_RPM="gdk-pixbuf-0.18.0-8.1.i386.rpm"

# Required GTK Library.
GTK_LIB="libgtk-1.2.so.0"

# Required RPMs
GLUT="glut-3.7-12.i386.rpm"
GLIB="glib-1.2.10-15.i386.rpm"
CURSES="ncurses-5.4-13.i386.rpm"
COMPAT_32_CPP="compat-libstdc++-7.3-2.96.122.i386.rpm"
COMPAT_64_CPP="compat-libstdc++-7.3-2.96.128.i386.rpm"
COMPAT_32_CPP_RHEL4_1="compat-libstdc++-296-2.96-132.7.2.i386.rpm"
COMPAT_32_CPP_RHEL4_2="compat-libstdc++-33-3.2.3-47.3.i386.rpm"
COMPAT_64_CPP_RHEL4="compat-libstdc++-33-3.2.3-47.3.x86_64.rpm"
COMPAT_DB_RH3_32="compat-db-4.0.14-5.i386.rpm"
COMPAT_DB_RH3_64="compat-db-4.0.14-5.x86_64.rpm"
COMPAT_DB_RH4_32="compat-db-4.1.25-9.i386.rpm"
COMPAT_DB_RH4_64="compat-db-4.1.25-9.x86_64.rpm"
COMPAT_DB_UL10_32="compat-2003.1.10-0.i586.rpm"
COMPAT_DB_SLES8_32="compat-2002.8.15-29.i586.rpm"
COMPAT_DB_SLES9_32="compat-2004.7.1-1.2.i586.rpm"
COMPAT_DB_SLES9_64="db40-4.0.14-148.3.x86_64.rpm"
COMPAT_CRYPT_SLES9_32="compat-sles8-1.3-93.3.i586.rpm"
COMPAT_CRYPT_SLES9_64="compat-sles8-1.3-93.3.x86_64.rpm"

NETSNMP_LIB_RH4_32="net-snmp-libs-5.1.2-11.i386.rpm"
NETSNMP_LIB_RH4_64="net-snmp-libs-5.1.2-11.x86_64.rpm"
NETSNMP_RH4_32="net-snmp-5.1.2-11.i386.rpm"
NETSNMP_RH4_64="net-snmp-5.1.2-11.x86_64.rpm"
NETSNMP_RH3_32="net-snmp-5.0.9-2.30E.6.i386.rpm"
NETSNMP_RH3_64="net-snmp-5.0.9-2.30E.6.x86_64.rpm"
NETSNMP_SLES9_32="net-snmp-5.1-80.1.i586.rpm"
NETSNMP_SLES9_64="net-snmp-5.1-80.3.x86_64.rpm"
NETSNMP_UTILS_RH3_32="net-snmp-utils-5.0.9-2.30E.6.i386.rpm"
NETSNMP_UTILS_RH3_64="net-snmp-utils-5.0.9-2.30E.6.x86_64.rpm"
UCDSNMP_UL10_32="ucdsnmp-4.2.5-132.i586.rpm"
UCDSNMP_UL10_64="ucdsnmp-4.2.5-145.x86_64.rpm"

X11_LIBS_RHEL4="xorg-x11-libs-6.8.1-23.EL.i386"
X11_LIBS_RHEL4_RPM="xorg-x11-libs-6.8.1-23.EL.i386.rpm"
LM_SENSORS_32="lm_sensors-2.8.7-2.i386.rpm"
LM_SENSORS_64="lm_sensors-2.8.7-2.x86_64.rpm"
COMPAT_GCC="compat-gcc-32-3.2.3-47.3.i386.rpm"
COMPAT_GCC_CPP="compat-gcc-32-c++-3.2.3-47.3.i386.rpm"
LIBGCC="libgcc-3.4.3-9.EL4.i386.rpm"
LIBSTDC_32="libstdc++-3.4.3-9.EL4.i386.rpm"


# Process table command to use.
PSE="ps -e"
# Flag for indicating the user has interrupted our execution.
RFLAG=0
# Color definitions.
GREEN="[1;32m"
BLUE="[1;34m"
RED="[1;31m"
HILITE="[1;39m"
NORMAL="[0;39m"
# Default copy and remove commands to use.
CPCMD="/bin/cp -f"
MVCMD="/bin/mv -f"
RMCMD="/bin/rm -f"
MKDIR="/bin/mkdir -p"
TARCMD="/bin/tar xzf"
KILCMD="/bin/kill -9"
# Some temporary scratch files to use.
TEMP1=/tmp/templsp1.$$
TEMP2=/tmp/templsp2.$$
# Option Preset from commandline.
CMDLINE=false
IsItRHEL3=false
IsItRHEL3U5=false
IsItRHEL3_64=false
IsItRHEL4=false
IsItRHEL4_64=false
ItIsRHEL4=false
# Boolean flags for setting states.
BLDRPMDIR=false
STOPPED=false
NOHPASM=false
UNTAR=false
INTR=false
RO=false
HelpOnly=false
DELAY=false
ADDED_X11_RHEL4=false

# Filenames for snmpd.conf files per distribution
RHConfFile="/etc/snmp/snmpd.conf"
#SLES7ConfFile="/usr/share/snmp/snmpd.conf"
UL10ConfFile="/usr/share/snmp/snmpd.conf"
SLES9ConfFile="/etc/snmpd.conf"
tmpConfFile="/var/hp/snmpd.conf.orig"
ThresholdEntryFiles="/var/spool/compaq/hpasm/registry/threshold/"
TempThresholdEntries="/tmp/threshold/"
rpmMacroFile=".rpmmacros"

# Base kernel versions for each supported Linux Distro.
RHAS21="2.4.9-e.24"
RHEL21="2.4.9-e.24"
RHEL3="2.4.21-4"
RH73="2.4.18-3"
RH80="2.4.18-14"
RH90="2.4.20-2.21"
SLES7SMP="2.4.7-19"
SLES7="2.4.7-20"
SLES9="2.6.5-7.5"
SLES964="2.6.5-7.5"
UL10SMP="2.4.19-113"
UL10="2.4.19-120"

# Distro Packages required
RHRPM="rpm rpm-build rpm-devel"
SURPM="rpm"

#################
##  FUNCTIONS  ##
#################

# create ram for transport intra-process communications files
function createRamDisk()
{
   mknod -m 600 /dev/ram.$$ b 1 1 > /dev/null 2>&1
   chown root:disk /dev/ram.$$ > /dev/null 2>&1
   mkfs /dev/ram.$$ > /dev/null 2>&1
   mkdir -p /tmp/hppldu_ram > /dev/null 2>&1
   chown root /tmp/hppldu_ram > /dev/null 2>&1
   chgrp root /tmp/hppldu_ram > /dev/null 2>&1
   chmod 700 /tmp/hppldu_ram > /dev/null 2>&1
   mount /dev/ram.$$ /tmp/hppldu_ram > /dev/null 2>&1
}

# remove ramdisk
function removeRamDisk()
{
   umount /tmp/hppldu_ram > /dev/null 2>&1
   rm -f /dev/ram.$$ > /dev/null 2>&1
   rm -rf /tmp/hppldu_ram > /dev/null 2>&1
}

#Determine which OS this is, and setup the required directories accordingly.
function SetupForOS()
{
    RELFILE=""
    RKRNL=`uname -r`
    if [ -f /etc/redhat-release ]
    then
        RemoteAccess="NFS"
        RELFILE="/etc/redhat-release"
        CheckKerneldoth
        GetDistrVer
        if [ ! -d /usr/src/redhat ]
        then
            BldDirs "/usr/src/redhat"
            BLDRPMDIR=true
        fi
        export RPMDIR=/usr/src/redhat
        if [ "$IsItRHEL4" = "true" -o "$IsItRHEL4_64" = "true" ]
        then
          KERNELSRC="/lib/modules/`uname -r`/build"
          export KERNELSRC
        else
          KERNELSRC=`uname -r | sed -e 's/enterprise//' -e 's/debug//' -e 's/[sS][mM][pP]//' -e 's/workstation//' -e 's/bigmem//' -e 's/summit//' -e 's/hugemem//' -e 's/largesmp//'`
        export KERNELSRC=/usr/src/linux-${KERNELSRC}
        fi
        Version=`grep "[89]\.[0-9]" </etc/redhat-release`
        if [ ${#Version} -gt 0 ]
        then
            PSE="ps -em"
        fi
        if [ "$IsItRHEL3_64" = "true" ]
        then
            GTKLanded "RH64"
        else
            GTKLanded "RH"
        fi
        export SNMPDCFGFILE=${RHConfFile}
        if [ -f ${RHConfFile} ]
        then
            ${CPCMD} ${RHConfFile} ${tmpConfFile} >/dev/null 2>&1
        fi
        CheckRPMPkgs "$RHRPM"
    elif [ -f /etc/UnitedLinux-release ]
    then
        CompareKernels
        RemoteAccess="NFS"
        RELFILE="/etc/UnitedLinux-release"
        if [ ! -d /usr/src/packages ]
        then
            BldDirs "/usr/src/packages"
            BLDRPMDIR=true
        fi
        export RPMDIR=/usr/src/packages
        tKrnl=`uname -r`
        sp3bld=$tKrnl
        tKrnl=${tKrnl#*\.} # Strip the major
        tKrnl=${tKrnl#*\.} # strip the minor
        tKrnl=${tKrnl%%-*} # strip the pass & trailing info
        if [ $tKrnl -ge 21 ]
        then
            export KERNELSRC=/usr/src/linux-`uname -r | sed -e 's/[-A-Za-z]*$//'`
        else
            RKRNL=`rpm -qf /boot/vmlinuz`
            export KERNELSRC=/usr/src/linux-`uname -r | sed -e 's/-[-0-9A-Za-z]*$//' -e 's/$/\.SuSE/'`
        fi
        # Are we running one of the SP3 kernels?
        sp3bld=${sp3bld#*-}
        sp3bld=`echo $sp3bld | sed 's/[-A-Za-z.]*$//'`
        if [ -n $sp3bld -a $sp3bld -ge 85  ]
        then
            export SP3=YES
            export KRNLCFG="/boot/config-`uname -r`"
        else
            export SP3=NO
            export KRNLCFG="/boot/vmlinuz*.config"
        fi
        GetDistrVer
        if [ "$ARCHITECTURE" = "x86_64" ]
        then
            IsItAMD64
            GTKLanded "UL64"
        else
            GTKLanded "UL"
        fi
        export SNMPDCFGFILE=${UL10ConfFile}
        if [ -f ${UL10ConfFile} ]
        then
            ${CPCMD} ${UL10ConfFile} ${tmpConfFile}
        fi
        CheckRPMPkgs "$SURPM"
    elif [ -f /etc/SuSE-release ]
    then
        RemoteAccess="NFS"
        OS="SU"
        RELFILE="/etc/S?SE-release"
        if [ `grep -ic "suse linux enterprise server 9" ${RELFILE}`  -gt 0 ]
        then
            if [ "`uname -m`" = "x86_64" ]
            then
                IsItSLES9_64=true
                GTKLanded "SU64"
            else
                IsItSLES9=true
                GTKLanded "SU9"
            fi
            RKRNL=`uname -r`
            export KERNELSRC=/usr/src/linux-`uname -r | sed -e 's/-[a-zA-Z]*$//'`
        else
            GTKLanded "SU"
            RKRNL=`rpm -qf /boot/vmlinuz`
            export KERNELSRC=/usr/src/linux-`uname -r | sed -e 's/-[-0-9A-Za-z]*$//' -e 's/$/\.SuSE/'`
        fi
        if [ ! -d /usr/src/packages ]
        then
            BldDirs "/usr/src/packages"
            BLDRPMDIR=true
        fi
        export RPMDIR=/usr/src/packages
        GetDistrVer
        export SNMPDCFGFILE=${SLES9ConfFile}
        if [ -f ${SLES9ConfFile} ]
        then
            ${CPCMD} ${SLES9ConfFile} ${tmpConfFile}
        fi	
        CheckRPMPkgs "$SURPM"
    fi
    if [ ${#RELFILE} -eq 0 ]
    then
        putmsg "\n\n${RED}ERROR:\nA key file, \"/etc/<OS Name>-release\" appears to be missing.\nThe HP ProLiant Linux Deployment Utility cannot continue without it.\n\nPlease correct this condition before running this application.${NORMAL}\n\n" 0
        exit 2
    fi
    # Lets see if we have kernel source available.
    avail="`ls $KERNELSRC 2>/dev/null`"
    if [  \( ! -d $KERNELSRC -o -z "$avail" \) -a "$HelpOnly" = "false" -a "$SILENT" = "false" ]
    then
        ans=""
        putmsg "\nThe HP ProLiant Linux Deployment Utility requires source code\nfor the ${BLUE}${RKRNL}${NORMAL} kernel be available for building and installing\ncertain drivers included in this bundle.\nThe directory, ${BLUE}$KERNELSRC${NORMAL}, is either missing, or is empty.\n\nKernel source code may also be made available via ${RemoteAccess} from a\nremote system.\n\nDo you wish to continue? [Y] \c" 30
        CheckAns "y"
        if [ "$ans" != "y" ]
        then
            HelpOnly=true  # Using this flag to prevent restarting daemons.
            cleanup "\nPlease install the RPM package for the ${BLUE}`echo $RKRNL|sed 's/[-a-zA-Z]*$//'`${NORMAL} kernel source code,\nand restart the HP ProLiant Linux Deployment Utility.\n"
            exit 23
        fi
    fi

    # Now lets protect the rpmmacro file if present.
    if [ -f ${HOME}/${rpmMacroFile} ]
    then
        ${CPCMD} ${HOME}/${rpmMacroFile} ${HPDir}/${rpmMacroFile} >/dev/null
    fi

    # Preserve the thresholds that a user may have set for the agents
    if [ "$HelpOnly" = "false" ]
    then
    	[ "$SILENT" = "false" ] && echo -e "Saving user-defined agent thresholds...\c"
    	mkdir -p $TempThresholdEntries 1>/dev/null 2>&1
    	${CPCMD} ${ThresholdEntryFiles}/entry.* ${TempThresholdEntries} 1>/dev/null 2>&1
    	[ "$SILENT" = "false" ] && echo -e "${GREEN}Done${NORMAL}\n"
    fi
    return
}

# This function compares the running kernel on UL10 with the 
# kernel image linked to /boot/vmlinuz.  They need to be the
# same for a proper LDU installation.
function CompareKernels()
{
    local runKrnl
    local instKrnl
    local option
    local line
    local file=/boot/grub/menu.lst
    local KrnlCnt=0
    local Found=false

    runKrnl=`uname -r|sed -e 's/[-a-zA-Z]*$//'`
    instKrnl=`rpm -qf /boot/vmlinuz|sed 's/k_[a-zA-Z]*-//'`
    for i in $instKrnl
    do
        KrnlCnt=`expr $KrnlCnt + 1`   
        if [ "$runKrnl" = "$i" ]
        then
            Found=true
        fi
    done
    if [ "$Found" = "false" ]
    then
        line=`grep -n "/boot/vmlinuz " $file|awk -F ':' '{print $1}'`
        line=`expr $line - 1`
        option=`awk -v ln=$line '{if(NR == ln) print $2}' $file`
        if [ -z "$option" ]
        then
            option="boot menu option that relates to the $instKrnl kernel."
        else
            option="\"$option\" boot menu option, which relates to the $instKrnl kernel."
        fi
        putmsg "\n\n---N O T I C E ----\nThe current running kernel, $runKrnl, is not the installed /boot/vmlinuz\nimage which is $instKrnl.  Installation under this condition could result\nin improperly installed components.  Accordingly, the HP ProLiant Linux\nDeployment Utility cannot continue.\n\nTo correct this condition, reboot the system and select the\n$option\n\n" 0
        exit 0
    else    
        return
    fi
}

# This function is to ensure that we have a clean /boot/kernel.h
# for compiling certain of the component drivers.
function CheckKerneldoth()
{
    file=/sbin/mkkerneldoth # initscript for creating the /boot/kernel.h file during bootup.
    tfile=/tmp/mkkernel.h   # temporary scratch file.

    # Scan the initscript to determine which types of kernels this system will support.
    # then ID the types that are initialized.  The purpose of this function is to ensure
    # that all types supported are initialized to a 0 value.  Then the script will set
    # the value of the running kernel type to 1.

    if [ -s $file ]
    then
        k_types=`cat $file|egrep "^KERNEL_TYPE"|awk -F\) '{print $1}'|awk -F\( '{print $2}'|sed 's/\\\//g'|tr "|" " "`
        k_types="$k_types up"
        K_TYPES=`egrep "^  [A-Z]*='0'" $file`
        k_cnt=`echo $k_types|wc -w`
    else
        return
    fi
    touch $tfile
    str=""
    for j in $K_TYPES
    do
        pos=`expr index $j '='`
        (( pos-- ))
        str="$str `echo ${j:0:$pos}|tr [:upper:] [:lower:]`"
    done
    lineno=0
    for i in $k_types
    do
        matched=0
        if [ ${#i} -ne 0 ]
        then
            matched=`echo $str|grep -c $i`
        fi
        if [ $matched -eq 0 ]
        then
            newstr=`echo $i|tr [:lower:] [:upper:]`
	        echo "# The following line was added by the HP ProLiant Linux Deployment Utility" >> $tfile
	        echo "# to fix a bug in the original script that was preventing certain NIC drivers" >> $tfile
	        echo "# from compiling." >>$tfile
	        echo >>$tfile
	        echo "  $newstr='0'" >> $tfile
	        echo >>$tfile
        else
            (( match_cnt++ ))
        fi
    done
    if [ $k_cnt -ne $match_cnt ]
    then
        cat $file >> $tfile
        chmod 755 $tfile
        $MVCMD $tfile $file
        $MVCMD /boot/kernel.h /boot/kernel.h.orig
        $file
    fi
    return
}


function CheckRPMPkgs()
{
    rpm_cnt=0
    pkgs=""
    for i in $1
    do
    	rpm -q $i >/dev/null 2>&1
    	if [ $? -ne 0 ]
    	then
    		let "rpm_cn += 1"
		pkgs="$pkgs, $i"
    	fi
    done
    if [ $rpm_cnt -eq 1 ]
    then
        word1="A required package"
        word2="is"
    else
        word1="Required packages"
        word2="are"
    fi
    if [ ${#pkgs} -gt 2 ]
    then
         putmsg "\n${word1}${BLUE}${pkgs}${NORMAL}, ${word2} not installed on this system.\nThis may result in one or more of the components in this bundle to fail\nto install.\n\nDo you wish to continue? [Y]\c" 10

        CheckAns "y"
        if [ "$ans" != "y" ]
        then
            exit 3
        fi
    fi
    return
}
	

# Function for formatting user responses.
function CheckAns()
{
    if [ ${#ans} -eq 0 ]
    then
        ans="$1"
    fi
    ans=`echo ${ans:0:1}|tr [:upper:] [:lower:]`
    return
}

# Function for establishing the RPM Build dirtree if not present.
function BldDirs()
{
    RootDir=$1
    rc=999
    while [ $rc -ne 0 ]
    do
        rc=0
        $MKDIR ${RootDir}/BUILD >/dev/null 2>&1
        rc=`expr $rc + $?`
        $MKDIR ${RootDir}/RPMS/athlon >/dev/null 2>&1
        rc=`expr $rc + $?`
        $MKDIR ${RootDir}/RPMS/i386 >/dev/null 2>&1
        rc=`expr $rc + $?`
        $MKDIR ${RootDir}/RPMS/i486 >/dev/null 2>&1
        rc=`expr $rc + $?`
        $MKDIR ${RootDir}/RPMS/i586 >/dev/null 2>&1
        rc=`expr $rc + $?`
        $MKDIR ${RootDir}/RPMS/i686 >/dev/null 2>&1
        rc=`expr $rc + $?`
        $MKDIR ${RootDir}/RPMS/noarch >/dev/null 2>&1
        rc=`expr $rc + $?`
        $MKDIR ${RootDir}/SOURCES >/dev/null 2>&1
        rc=`expr $rc + $?`
        $MKDIR ${RootDir}/SPECS >/dev/null 2>&1
        rc=`expr $rc + $?`
        $MKDIR ${RootDir}/SRPMS >/dev/null 2>&1
        rc=`expr $rc + $?`
        if [ $rc -ne 0 ]
        then
            putmsg "\nA directory tree at ${RPMDIR} does not appear to be present\non this system.\nIf this dirtree is not present, some of the components will not install properly.\nDo you wish to continue? (Default = No)  \c" 30
            CheckAns "N"
            if [ "$ans" = "y" ]
            then
                return
            else
                cleanup "\nThe user aborted installation of the HP ProLiant Linux Deployment Utility.\n\n"
                exit 23
            fi
        fi
        return
    done
}


# Function for locating required GTK libraries.
function GTKLanded()
{
    [ "$IsItRHEL4_64" = "true" ] && return
    case "$1" in
       "SU9")  GTK_DIR=/opt/gnome/lib/
               ;;
      "SU64")  GTK_DIR=/opt/gnome/lib64/
               ;;
      "RH64")  GTK_DIR=/usr/lib64/
               ;;
           *)  GTK_DIR=/usr/lib/
               ;;
    esac
    GTK_LIB_PATH="${GTK_DIR}${GTK_LIB}"
    if [ ! -e ${GTK_LIB_PATH} ]
    then
        putmsg "\nA necessary graphics library, (${BLUE}${GTK_LIB_PATH}${NORMAL}) required by the\nHP ProLiant Linux Deployment Utility GUI is not installed on this server.\n\nAccordingly, the Graphical User Interface cannot be used.\n\nThe process will continue in Text mode.\c" 0
        sleep 3
        GUI="false"
    fi
    return
}

# Function for verifying the presence of required RPM packages.
function CheckInstalledRPMs()
{
    [ "$HelpOnly" = "true" ] && return;
    local String
    local itsarch
    local pkgarch
    local pkgname
    local found=true
    local TB=true
    typeset -a itsarch
    rpmStr="\n"
    Intro="The RPM package"
    pkg="package is that"
    rpms="this package"
    conj="and is"
    unit="package"
    flag=0


    case $OSDISTR in
        $RHEL3_32) String="$COMPAT_32_CPP $GLUT $COMPAT_DB_RH3_32 $NETSNMP_RH3_32 $NETSNMP_UTILS_RH3_32"
                   osname="Red Hat 3"
                   ;;
        $RHEL3_64) String="$COMPAT_64_CPP $GLUT $COMPAT_DB_RH3_64 $NETSNMP_RH3_64 $NETSNMP_UTILS_RH3_64"
                   osname="Red Hat 3"
                   ;;
        $RHEL4_32) String="$GLIB $COMPAT_DB_RH4_32 $CURSES $LIBGCC $COMPAT_GCC $COMPAT_32_CPP_RHEL4_1 $COMPAT_32_CPP_RHEL4_2 $COMPAT_GCC_CPP $LM_SENSORS_32 $NETSNMP_LIB_RH4_32 $NETSNMP_RH4_32" 
                   osname="Red Hat 4"
                   ;;
        $RHEL4_64) String="$GLIB $COMPAT_DB_RH4_64 $CURSES $LIBGCC $COMPAT_GCC $COMPAT_32_CPP_RHEL4_1 $COMPAT_64_CPP_RHEL4 $COMPAT_GCC_CPP $LIBSTDC_32 $LM_SENSORS_64 $NETSNMP_LIB_RH4_64 $NETSNMP_RH4_64"
                   osname="Red Hat 4"
                   ;;
         $UL10_32) String="$COMPAT_DB_UL10_32 $UCDSNMP_UL10_32"
                   osname="UnitedLinux 1.0"
                   ;;
         $UL10_64) String="$UCDSNMP_UL10_64"
                   osname="UnitedLinux 1.0"
                   ;;
        $SLES8_32) String="$COMPAT_DB_SLES8_32 $UCDSNMP_UL10_32"
                   osname="SUSE Linux Enterprise Server 8"
                   ;;
        $SLES9_32) String="$COMPAT_DB_SLES9_32 $COMPAT_CRYPT_SLES9_32 $NETSNMP_SLES9_32"
                   osname="SUSE Linux Enterprise Server 9"
                   ;;
        $SLES9_64) String="$COMPAT_DB_SLES9_64 $COMPAT_CRYPT_SLES9_64 $NETSNMP_SLES9_64"
                   osname="SUSE Linux Enterprise Server 9"
                   ;;
                *) ;;
    esac

    for i in $String
    do
        found=true
        if [ `echo $i|grep -c "i386"` -gt 0 ]
        then
            pkgarch=i386
        elif [ `echo $i|grep -c "i486"` -gt 0 ]
        then
            pkgarch=i486
        elif [ `echo $i|grep -c "i586"` -gt 0 ]
        then
            pkgarch=i586
        elif [ `echo $i|grep -c "i686"` -gt 0 ]
        then
            pkgarch=i686
        else
            pkgarch=x86_64
        fi
        if [ `echo $i|grep -ic compat-200` -gt 0 ]
        then
            pkgname=${i%%-[0-9]*}
        elif [ `echo $i|grep -ic compat-libstdc++-33` -gt 0 ]
        then
            pkgname="compat-libstdc++-33"
        elif [ `echo $i|grep -ic compat-libstdc++-296` -gt 0 ]
        then
            pkgname="compat-libstdc++-296"
        elif [ `echo $i|grep -ic compat-gcc-32` -gt 0 ]
        then
            pkgname="compat-gcc-32"
        elif [ `echo $i|grep -ic compat-gcc-32-c++` -gt 0 ]
        then
            pkgname="compat-gcc-32-c++"
        else
            pkgname=${i%%-[0-9]*-[0-9]*}
        fi
        itsarch=`rpm -q --queryformat '%{ARCH}  ' ${pkgname}`
        for j in $itsarch
        do
            if [ -n "$j" -a "$j" != "$pkgarch" ]
            then
                found=false
            else
                found=true
                break
            fi
        done
        if [ \( "${i:0:10}" = "lm_sensors" \) -o \( "${i:0:8}" = "net-snmp" \) -o  \( "${i:0:7}" = "ucdsnmp" \) ]
        then
            # extract the given rpm
            extractRPM $i

            # query package versions and convert to integer
            newver=`rpm -qp --queryformat '%{VERSION}-%{RELEASE}' ${i} 2>/dev/null`

            # query installed rpm versions and convert to integer
            curver=`rpm -q --queryformat '%{VERSION}-%{RELEASE}' ${i%%-[0-9]*} 2>/dev/null`
            ret_val=$?
            [ $ret_val != "0" ]  && curver=0

            # by default, the rpm is NOT installed
            installRPM=`expr 0`

            # if the package version is greater than the installed
            # version then do the RPM install. 
            ./vercmp $curver $newver > /dev/null 2>&1
            isVersionNewer=$?
            [ $isVersionNewer -eq 1 ] && installRPM=`expr 1`

            # if installRPM is equal to one, then installation 
            # proceeds, else skip installation
            if [ $installRPM -eq 1 ] 
            then
               rpm -Uv --nodeps --force $i >/dev/null 2>&1
            fi
            found=true
            popd > /dev/null 2>&1
        fi
        if [ "$found" = "false" ]
        then
            rpmStr="${rpmStr}\t${i}\n"
            flag=`expr $flag + 1`
        fi
        if [ $flag -gt 1 ]
        then
            Intro="The RPM packages"
            pkg="packages are those"
            rpms="these packages"
            conj="and are"
            unit="packages"
        fi
    done
    if [ ${#rpmStr} -gt 2 ]
    then
        if [ ! -e $LIBTARBALL ]
        then
            msg="\n$Intro, ${BLUE}${rpmStr}${NORMAL}, required for the successful installation\nof one or more of the following:\n\n\tHP System Management Homepage for Linux.\n\tHP Storage Agents for Linux.\n\tHP Array Configuration Utility for Linux.\n\tHP Insight Diagnostics Online Edition for Linux.\n\tHP Version Control Agent for Linux.\n\tHP Tested and Approved Linux 802.1q VLAN Driver.\n\nis not present on this system.\n\nYou may install the required packages from your ${osname} distribution CDs.\nIf installation proceeds without installing ${rpms},\none or more of the above listed components will not install.\nDo you wish to stop now to obtain and install $rpms.? [N] \c"
            TB=false
        else
            msg="\n$Intro, ${BLUE}${rpmStr}${NORMAL}, required for the successful installation\nof one, or more, of the following:\n\n\tHP System Management Homepage for Linux.\n\tHP Storage Agents for Linux.\n\tHP Array Configuration Utility for Linux.\n\tHP Insight Diagnostics Online Edition for Linux.\n\tHP Version Control Agent for Linux.\n\tHP Tested and Approved Linux 802.1q VLAN Driver.\n\nis not present on this system.\nThe ${BLUE}${rpmStr}${NORMAL} $pkg from the\n${osname} distribution CD ${conj} included with this bundle.\nIf you proceed without installing ${rpms}, one or more of the above listed components will not install.\nDo you wish to install ${rpms} now? [Y] \c"
            TB=true
        fi
        if [ "$DELAY" = "false" ]
        then
          putmsg "$msg" 30
        fi
        if [ "$TB" = "true" ]
        then
            CheckAns "Y"
            if [ "$ans" != "y" ]
            then
                return
            fi
            declare -a failed
            fail=0
            ptr=1
            if [ "$RO" = "true" ]
            then
                cd $TMPDIR
            else
                cd "$ORIGDIR"
            fi
    
            for i in `echo -e $rpmStr|tr "\n\t" " "`
            do
                if [ ! -f $i ]
                then
                    extractRPM $i
                fi
                [ "$SILENT" = "false" ] && echo -e "Installing $i.....\c"
                rpm -Uhv --force $i >/dev/null 2>&1
                if [ $? -ne 0 ]
                then
                    fail=1
                    failed[$ptr]=$i
                    [ "$SILENT" = "false" ] && echo -e "${RED}Failed!${NORMAL}"
                    (( ptr++ ))
                else
                    sleep 1
                    [ "$SILENT" = "false" ] && echo -e "${GREEN}Done${NORMAL}"
                fi
            done
            sync;sync
#        if [ -f /var/hp/hpverdb.xml ]
#        then
#            [ "$SILENT" = "false" ] && echo -e  "Updating the RPM database....\c"
#            rpm --rebuilddb >/dev/null 2>&1
#            [ "$SILENT" = "false" ] && echo -e "${GREEN}Done${NORMAL}"
#        fi
            if [ $fail -ne 0 ]
            then
                (( ptr-- ))
                str="\n\t"
                while [ $ptr -gt 0 ]
                do
                    str="${str}\n\t${failed[$ptr]}"
                    (( ptr-- ))
                done
                putmsg "\n\n${RED}ERROR: The $str\n\npackage/s failed to install.${NORMAL}\nPlease determine the cause and re-install.\n\nPress <ENTER> to continue.\c" 99
            fi
        else
            CheckAns "Y"
            if [ "$ans" = "y" ]
            then
                putmsg "\nPlease install the ${BLUE}${rpmStr}${NORMAL} $unit,\nthen rerun the HP ProLiant Linux Deployment Utility.\n\nExiting.\n\n" 30
                exit 5
            fi
        fi       
    fi
    return
}

# Function for extracting selected RPMs from tarball.
function extractRPM()
{
    if [ ${#1} -eq 0 -o ! -f $LIBTARBALL ]
    then
        return
    else
        ${TARCMD} $LIBTARBALL "${1}"
    fi
    return
}



# Function for verifying the presence of required gdk library on RHEL3.
function CheckGDKLib()
{
    if [ "$TERM" = "linux" -a ${#AUTO} -eq 0 ]
    then
        GUI=false
    fi
    if [ "$GUI" = "false" ]
    then
       return
    else
       GUI=true
    fi
    PROMPT=false
    LIB=$GDK_LIB
    RPM=$GDK_RPM
    if [ ! -s "$LIB" ]
    then
        ans=""
        putmsg "\nA necessary graphics library, (${BLUE}${LIB}${NORMAL},\nprovided by the ${BLUE}${RPM}${NORMAL}) required by the\nHP ProLiant Linux Deployment Utility GUI is not installed on this server.\nDo you want the LDU to install the RPM providing this library\nand continue the installation [default=Y]? \c" 30
        CheckAns "Y"
        if [ "$ans" = "y" ]
        then
            extractRPM $RPM
            if [ -s "$RPM" ]
            then
                /bin/rpm -iv $RPM >/dev/null 2>&1
                [ $? -eq 0 ] && return
                putmsg "\nERROR: The installation of ${BLUE}$RPM${NORMAL} was not successful.\nDo you wish to continue the Linux ProLiant Support Pack installation\nwithout the GUI [default=Y]? \c" 30
                CheckAns "Y"
                if [ "$ans" = "y" ]
                then
                    GUI=false
                else
                    cleanup "\nThe user aborted installation of the HP ProLiant Linux Deployment Utility.\n\n"
                    exit 23
                fi
            else
                putmsg "\nThe RPM, ${BLUE}$GDK_RPM${NORMAL}, is missing or corrupt\nand cannot be installed at this time." 99
                PROMPT=true
            fi
        else
            PROMPT=true
        fi
    fi
    if [ "$PROMPT" = "true" ]
    then
        putmsg "\nDo you wish to continue the Linux ProLiant Support Pack\ninstallation without the GUI [default=Y]? \c" 30
        CheckAns "Y"
        if [ "$ans" = "y" ]
        then
            GUI=false
        else
            cleanup "\nThe user aborted installation of the HP ProLiant Linux Deployment Utility.\n\n"
            exit 23
        fi
    fi
    return
}


# Function for determining if ELM has passwords configured.
function IsELMCfg()
{
    export CMAFDTNECHO=yes
    export LSPELMCONFIGURED=NO
    if [ -x /opt/compaq/foundation/etc/hpwebsetup ]
    then
        /opt/compaq/foundation/etc/hpwebsetup -q: >/dev/null 2>&1
        if [ $? = 4 ]; then
            export LSPELMCONFIGURED=YES
        fi
    fi
    return
}

function GetParentProcess()
{
    PID=$$
    PP=$PPID
    pgname=$1
    PNAM=""
    idx=0
    [ -f /tmp/pids ] && ${RMCMD} /tmp/pids
    while [ $PP -ne 1 -a $idx -lt 3 ]
    do
        echo -e i"`ps -ef|grep $PP|grep -v grep|grep -v "ps -ef"`" >/tmp/pids
        while read f0 f1 f2 f3 f4 f5 f6 f7
        do
            if [ $f1 -eq $PP ]
            then
                PNAM=$f7
                PP=$f2
            fi
            if [ `echo $PNAM|grep -c $pgname` -gt 0 ]
            then
                PARENT_VCA=true
                PP=1
                break
            else
                PARENT_VCA=false
            fi
            idx=`expr $idx + 1`
        done < /tmp/pids
    done
    ${RMCMD} /tmp/pids
    return
}
    

function IsVCACfg()
{
    export HPLSPINSTALL=TRUE
    if [ -d /opt/hp/vcagent ]
    then
        LD_LIBRARY_PATH=/opt/hp/vcagent/lib
        /opt/hp/vcagent/bin/vcasetup >/dev/null 2>&1
        if [ $? -eq 0 ]
	    then
            export LSPVCACONFIGURED=YES
            unset LD_LIBRARY_PATH
            return
        fi
        unset LD_LIBRARY_PATH
    fi
    export LSPVCACONFIGURED=NO
    return
}

# Function for determining which Bundle File we need to use.
function GetBundle()
{
    if [ "$Identified" = "false" ]
    then
        cleanup "\n\nThe Linux O/S on this system cannot be identified\nby the HP ProLiant Linux Deployment Utility.\nPlease check $RELFILE for correctness.\nCannot continue.  Exiting.\n"
        exit 3
    fi
    pushd "$ORIGDIR" > /dev/null 2>&1
    for i in [bB][pP]*.xml
    do
        if [ ${#i} -ne 0 -a ${#os} -ne 0 -a ${#version} -ne 0 ]
        then
            grep -i "operating_system_xlate" $i >/tmp/bfile
            while read line
            do
              if [ `echo $line |grep -ic "$os $version"` -gt 0 ]
              then
                BUNDLE="$i"
                /usr/bin/dos2unix -k -q $BUNDLE 2>/dev/null
                break
              fi
            done < /tmp/bfile
            ${RMCMD} /tmp/bfile >/dev/null 2>&1
        fi
    done
    if [ "$BUNDLE" = "" ]
    then
      echo "No supported bundle XML file found to use for this installation"
      exit 3
    fi

    [ "$DELAY" = "false" -a "$HelpOnly" = "false" ] && CompareVersion $BUNDLE
    if [ -z "$BUNDLE" -a "$HelpOnly" = "false" ]
    then
        HelpOnly=true
        cleanup "\nThe ${RLS} release of the HP Linux Deployment Utility\ndoes not include support for ${os} ${version}.\n\nPlease visit the www.hp.com/linux website for available support.\n"
        exit 3
    elif [ -n "$BUNDLE" ]
    then
    	grep -n "<package install=\"yes\">" "$BUNDLE" | awk -F\> '{print $2}'| awk -F\< '{print $1}' > $TEMP1
    fi
	if [ "$RO" = "true" ]
	then
		MEDIA_TYPE="Read-Only"
	elif [ $NOLINK -ne 0 ]
	then
		MEDIA_TYPE="USB Key"
	fi
    if [ -d ${TMPDIR} ] 
    then
        putmsg "\n\nBecause of $MEDIA_TYPE media, the HP ProLiant Linux Deployment Utility\nis copying the files to a temporary work location.\n\nThis may take several seconds..." 55
        rm -f ${RMLIST}
        touch ${RMLIST}
        while read LOOP1 LOOP2
        do 
            NEWLOOP=${LOOP1%.rpm}
            if [ -f "${ORIGDIR}"/${LOOP1} ]
            then
                ${CPCMD} "${ORIGDIR}"/${LOOP1} ${TMPDIR} >/dev/null  2>&1
                pushd ${TMPDIR} > /dev/null 2>&1
                tar zvxf ${LOOP1} >> ${RMLIST}
                popd > /dev/null 2>&1
            elif [ -f "${ORIGDIR}"/${NEWLOOP}.tar.gz ]
            then
               ${CPCMD} "${ORIGDIR}"/${NEWLOOP}.tar.gz ${TMPDIR} >/dev/null 2>&1
               UNTAR=true
            fi
        done < $TEMP1
        ${RMCMD} $TEMP1
        ${CPCMD} "$ORIGDIR"/install???.sh ${TMPDIR} >/dev/null  2>&1
        ${CPCMD} "$ORIGDIR"/hppldu-*.tar.gz ${TMPDIR} >/dev/null  2>&1
        [ $pid -ne 99999 ] && $KILCMD $pid >/dev/null 2>&1
        pid=99999
    else
        for i in `ls *.tar.gz`
        do
            if [ `echo $i|grep -c hppldu-` -eq 0 ]
            then
                UNTAR=true
            fi
        done
    fi
    popd > /dev/null 2>&1

    return
}

function CompareVersion()
{
    local BPfile="$1"
    local BPVersion
    local BaseVersion
    local CurrVer
    local msg

    BaseVersion=`basename $0`
    BaseVersion=`echo $BaseVersion|tr -d '[a-z.]'`
    [ "$BaseVersion" = "" ] && BaseVersion=0
    BPVersion=`egrep -s "install[0-9][0-9][0-9]\.sh" "$BPfile"|uniq|tr -d '[a-z<>/.]'|tr -d ' ' 2>/dev/null`
    if [ $? != 0 -o -z "$BPVersion" ]
    then
    	echo -e "\nThe bundle XML file, $BPfile, appears to be corrupted or, it is not\ncompatible with this version of the HP Linux ProLiant Deployment Utiltiy.\nIf you do not have another copy of $BPfile, please visit www.hp.com/linux\nwebsite for support.\n"
	exit 3
    fi
    CurrVer=`awk -v ver=$BPVersion 'BEGIN {printf("%4.2f", ver/100.0)}'`
    if [ -z "$BPVersion" -o $BPVersion -gt $BaseVersion ]
    then
        msg="\n\nThe command, ${0}, used to initiate this installation,\nis not compatible with version ${CurrVer} of the HP Linux ProLiant Deployment Utiltiy.\nIf you do not have a copy of install${BPVersion}.sh, please visit www.hp.com/linux\nwebsite for support.\n"
        putmsg "$msg" 0
        exit 3
    fi
    return
}
function GetOpts()
{
    if [ "$TERM" = "linux" ]
    then
        if [ ${#AUTO} -gt 0 ]
        then
            GUI=true
        else
            GUI=false
        fi
    else
        GUI=true
    fi
    SILENT=false
	for i in $1
	do
        opt=`echo $i|tr [:upper:] [:lower:]`
		if [ "$opt" = "-s" -o "$opt" = "--silent" -o "$opt" = "-silent" ] #-o "$opt" = "-c" ]
		then
			GUI=false
            CMDLINE=true
            SILENT=true
            export HPSMHSILENT=true
        elif [ "$opt" = "-c" ]
        then
            DELAY=true
            componentInstall=true
            GetParentProcess "vca"
            if [ "${PARENT_VCA}" = "true" ]
            then
                SILENT=true
            fi
	elif [ "$opt" = "--nui" -o "$opt" = "-nui" ]
        then
            CMDLINE=true
        elif [ "$opt" = "-h" \
            -o "$opt" = "-help" \
            -o "$opt" = "--help" \
            -o "$opt" = "-?" \
            -o "$opt" = "--view" \
            -o "$opt" = "-view" \
            -o "$opt" = "--querystatuscode" \
            -o "$opt" = "-querystatuscode" \
            -o "$opt" = "-q" ]
        then
            HelpOnly=true
        elif [ "$opt" = "--inputfile" -o "$opt" = "-inputfile" ]
        then
            export HPVCARECONFIGURE="YES"
        fi
	done
    return
}


# Function for IDing the OS, Version and Base Kernel version.
function GetDistrVer()
{
    BASEKRNL=""
    Identified=false
    krnl=`uname -r`
    ktype=`echo $krnl|grep -i smp`
    for File in /etc/redhat-release /etc/UnitedLinux-release /etc/S?SE-release
    do
        if [ -f ${File} ]
        then
            if [ `grep -c "Red Hat" $File` -gt 0 ]
            then
                if [ `grep -c "Red Hat Enterprise" $File` -gt 0 ]
                then
                # we found a RedHat Enterprise Linux
                    version=`cat $File | awk '{print $6}'`
                    if [ "$version" = "release" ]
                    then
                        # Must be RHEL21
                        version=`cat $File | awk '{print $7}'`
                        if [ "$version" = "3" ]
		                then
                            BASEKRNL=$RHEL3
                            if [ "$ARCHITECTURE" = "x86_64" ]
                            then
                                OSDISTR=$RHEL3_64
                                IsItRHEL3_64=true
                            else
                                OSDISTR=$RHEL3_32
                                IsItRHEL3=true
                            fi
                            if [ $IsItRHEL3 = "true" ]
                            then
                               krnlver=`uname -r | sed -e 's/\.[-A-Za-z]*$//'`
                               ./vercmp $krnlver "2.4.20-32" > /dev/null 2>&1
                               isVersionNewer=$?
                               # if it's greater than or equal - then true
                               [ $isVersionNewer -ge 0 ] && IsItRHEL3U5=true
                               # else false!
                               [ $isVersionNewer -eq 255 ] && IsItRHEL3U5=false
                            fi
                            export KERNELSRC=/usr/src/linux-`uname -r|tr -d "[a-z]"`
                        elif [ "$version" = "4" ]
                        then
                            version=4
                            if [ "$ARCHITECTURE" = "x86_64" ]
                            then
                                OSDISTR=$RHEL4_64
                                IsItRHEL4_64=true
                                if [ `rpm -q $X11_LIBS_RHEL4 | wc -l` -eq 0 ]
                                then
                                   ADDED_X11_RHEL4=true
                                fi
                            else
                                OSDISTR=$RHEL4_32
                                IsItRHEL4=true
                            fi
                            export KERNELSRC=/lib/modules/`uname -r`/build
                        else
                            OSDISTR=$RHEL21_32
                            BASEKRNL=$RHEL21
                        fi
                    fi
                    os="Red Hat Enterprise Linux"
                    [ ${#version} -gt 0 -a ${#os} -gt 0 ] && Identified=true
                elif [ `grep -c Advanced $File` -gt 0 -o `grep -c AS $File` -gt 0 ]
                then
                    # we found a RedHat Advanced Server Linux
                    version=`cat $File | awk '{print $7}'`
                    if [ "$version" = "2.1AS" ]
                    then
                        os="Red Hat Enterprise Linux"
                        version=`echo $version|sed 's/AS//'`
                        BASEKRNL=$RHAS21
                        OSDISTR=RHEL21_32
                    else
                        os="Red Hat Advanced Server"
                        BASEKRNL=$RHAS21
                        OSDISTR=RHEL21_32
                    fi
                    [ ${#version} -gt 0 -a ${#os} -gt 0 ] && Identified=true
                elif [ `grep -c "Red Hat Linux" $File` -gt 0 ]
                then
                    # we found a RedHat Linux Professional system.
                    version=`cat $File | awk '{print $5}'`
                    os="Red Hat Linux"
                    case "$version" in
                        "7.3") BASEKRNL=$RH73 ;;
                        "8.0") BASEKRNL=$RH80
                               CheckRPM ;;
                            *) ;;
                    esac
                    [ ${#version} -gt 0 -a ${#os} -gt 0 ] && Identified=true
                fi
            elif [ `grep -c "UnitedLinux" $File` -gt 0 ]
            then
                version=`cat $File | awk '{if(NR == 1) {print $2}}'`
                os="UnitedLinux"
#                IsItAMD64
                if [ "$ARCHITECTURE" = "x86_64" ]
                then
                    OSDISTR=$UL10_64
                else
                    OSDISTR=$UL10_32
                fi
                if [ -n "$ktype" ]
                then
                    BASEKRNL=$UL10SMP
                else
                    BASEKRNL=$UL10
                fi
                [ ${#version} -gt 0 -a ${#os} -gt 0 ] && Identified=true
            elif [ `grep -ic "suse sles-7" $File` -gt 0 ]
            then
                if [ -n "$ktype" ]
                then
                    BASEKRNL=$SLES7SMP
                else
                    BASEKRNL=$SLES7
                fi
                version=`cat $File | awk '{if(NR == 2) {print substr($3,0,1)}}'`
                os="SUSE LINUX Enterprise Server"
                [ ${#version} -gt 0 -a ${#os} -gt 0 ] && Identified=true
            elif [ `grep -ic "suse sles-8" $File` -gt 0 ]
            then
                if [ "$ARCHITECTURE" = "x86_64" ]
                then
                    OSDISTR=$SLES8_64
                else
                    OSDISTR=$SLES8_32
                fi
                version=`cat $File | awk '{if(NR == 2) {print substr($3,0,1)}}'`
                os="SUSE LINUX Enterprise Server"
                [ ${#version} -gt 0 -a ${#os} -gt 0 ] && Identified=true
	        elif [ `grep -ic "SUSE LINUX Enterprise Server 9" $File` -gt 0 ]
            then
                if [ "$ARCHITECTURE" = "x86_64" ]
                then
                    OSDISTR=$SLES9_64
                    BASEKRNL=SLES964
                else
                    OSDISTR=$SLES9_32
                    BASEKRNL=SLES9
                fi
                version=`cat $File | awk '{if(NR == 2) {print substr($3,0,1)}}'`
                os="SUSE LINUX Enterprise Server"
                [ ${#version} -gt 0 -a ${#os} -gt 0 ] && Identified=true
            fi
        fi
    done
    # Now we have identified the Base Kernel, lets move it to the environment.
    export BASEKRNL
    return
}

function MoveGtkRC()
{
    for i in `ls ~/.gtkrc* 2>/dev/null`
    do
        ${MVCMD} $i ${i}.LSP >/dev/null 2>&1
    done
    return
}


function IsItAMD64()
{
    if [ "$PROC_TYPE" = "AMD" ]
    then
        return
    else
        cleanup "\n$os, v$version, on $PROC_TYPE is not supported on this release of HP ProLiant Support Packs.\nPlease download a version of the HP ProLiant Support Packs for Linux >= 7.11 from www.hp.com to obtain support for the processor family used in this server.\n\n"
        
        exit 1
    fi
    return
}

#Function for displaying messages to user.
function putmsg()
{
    [ "$SILENT" = "true" ] && return
    [ $2 -eq 99 ] && timer=999 || timer=$2
    # Make sure we have the display program available.
    if [ ! -s $HPDir/displayit.sh ]
    then
cat >$HPDir/displayit.sh <<-END
echo -e \$1
read ans
echo \$ans >/tmp/tmpans
END
    chmod 700 $HPDir/displayit.sh
    fi
    # Display the message either on a popup or console.
    old_resume=${auto_resume}
    unset auto_resume
    answered=0
    if [ ${#AUTO} -gt 0 ]
    then
        xterm -bg white -fg black -T "NOTICE!!!" -hold -e $HPDir/displayit.sh "$1" >/dev/null 2>&1 &
        pid=$!
        [ $2 -eq 55 ] && return
    else
        echo -e "$1"
        [ $2 -eq 55 ] && return
        if [ ${#1} -gt 0 ]
        then
            read -t $timer ans
        fi
        return
    fi
    if [ ${#1} -gt 0 ]
    then
        while [ $timer -gt 0 ]
        do
            if [ -s /tmp/tmpans ]
            then
                answered=1
                read ans </tmp/tmpans
                $RMCMD /tmp/tmpans >/dev/null 2>&1
                break
            fi
            sleep 1
            (( timer++ ))
        done
    fi
    ${RMCMD} /tmp/tmpans >/dev/null 2>&1
    [ $pid -ne 99999 ] && $KILCMD $pid >/dev/null 2>&1
    pid=99999
    [ ${#answered} -eq 0 ] && ans="Y"
    set auto_resume=$old_resume
    return
}


# Function for validating the RPM package on RH80 systems.
function CheckRPM()
{
    if [ "$GUI" = "false" -o "$SILENT" = "true" -o "$HelpOnly" = "true" ]
    then
        return
    fi
    RPMQ=`$PSE  | grep rpm`
    if [ ${#RPMQ} -gt 0 ]
    then
        ans=""
        putmsg "\nThe RPM database on this system appears to be open, or locked.\nAccordingly, the HP ProLiant Linux Deployment Utility cannot continue.\nPlease refer to Bugzilla Issue #73097 for instructions on how to resolve\nthis condition.\n\nPlease resolve the issue and re-start the HP ProLiant Linux Deployment Utility.\n\nExiting...\n" 99
         exit 23
   fi
   return
}


# Function for cleaning up the work area.
function cleanup()
{
    # Ensure all buffers are flushed.
    sync;sync
    # Remove the lock.
    if [ -d $LCKDIR -a ${RFLAG} -eq 1 ]
    then
       rm -rf $LCKDIR >/dev/null 2>&1
    fi
    # Restore the user terminal
    tput cnorm
    # Determine if we need to restart the agents.
    if [ -f /var/spool/compaq/cma.install ]
    then
    	$RMCMD /var/spool/compaq/cma.install >/dev/null 2>&1
    fi
#    if [ -f /opt/compaq/cma.conf ]
#    then
#        if [ `grep -c exclude /opt/compaq/cma.conf` -gt 0 ]
#        then
#            cat /opt/compaq/cma.conf|grep -v exclude >/tmp/cma.conf
#            $MVCMD /tmp/cma.conf /opt/compaq/cma.conf
#        fi
#    fi
    if [ -s /opt/compaq/hpasm/etc/hpasm -o "$STOPPED" = "true" -o "$NOHPASM" = "true" ]
    then
        RESTARTEM=true
    fi
    
    # Restore the thresholds that a user may have set for the agents
    if [ "$HelpOnly" = "false" -a $RC -ne 16 ]
    then
    	[ "$SILENT" = "false" ] && echo -e "Restoring user defined agent thresholds...\c"
    	mkdir -p ${ThresholdEntrieFiles} 1>/dev/null 2>&1
    	${CPCMD} ${TempThresholdEntries}/entry.* ${ThresholdEntryFiles} 1>/dev/null 2>&1
    	rm -rf ${TempThresholdEntries} 1>/dev/null 2>&1
    	[ "$SILENT" = "false" ] && echo -e "${GREEN}Done${NORMAL}\n"
    fi

    if [ "$HelpOnly" = "false" -a $RC -ne 16 ]
    then
        if [ "$RESTARTEM" = "true" -a "$DELAY" = "false" -a "$SILENT" = "false" ]
        then
           echo -e "\nRestarting SNMP Daemon...\c"
           /etc/init.d/snmpd restart >/dev/null 2>&1
           echo -e "${GREEN}Done${NORMAL}\n"
           echo -e "\nRestarting HP System Management Homepage...\c"
           /etc/init.d/hpvca restart >/dev/null 2>&1
           /etc/init.d/hpsmhd restart >/dev/null 2>&1
           echo -e "${GREEN}Done${NORMAL}\n"
        fi
        if [ "$RESTARTEM" = "true" -a \( "$INTR" = "false" -a -f /tmp/didit.tmp \) ]
        then
           [ "$SILENT" = "false" ] && echo -e "\nRestarting HP System Management Drivers and Agents...\c"
           /etc/init.d/hpasm restart >/dev/null 2>&1
           /etc/init.d/cmanic restart >/dev/null 2>&1
           [ "$SILENT" = "false" ] && echo -e "${GREEN}Done${NORMAL}\n"
        elif [ "$RESTARTEM" = "true" -a \( "$INTR" = "true"  -o ! -f /tmp/didit.tmp \) ]
        then
           [ "$SILENT" = "false" ] && echo -e "\nRestarting HP System Management Drivers and Agents...\c"
           /etc/init.d/hpasm restart >/dev/null 2>&1
           /etc/init.d/cmanic restart >/dev/null 2>&1
           [ "$SILENT" = "false" ] && echo -e "${GREEN}Done${NORMAL}\n"
        fi
      fi
    if [ -s /opt/compaq/hpasm/etc/hpasm -o "$STOPPED" = "true" -o "$NOHPASM" = "true" ]
    then
        RESTARTDIAGS=true
    fi
    if [ "$HelpOnly" = "false" -a $RC -ne 16 ]
    then
      if [ "$IsItRHEL3" = "true" ]
      then
        if [ "$RESTARTDIAGS" = "true" -a \( "$INTR" = "false" -a -f /tmp/didit.tmp \) ]
        then
           [ "$SILENT" = "false" ] && echo -e "\nRestarting HP Insight Diagnostics Online Edition for Linux...\c"
           /etc/init.d/hpdiags start >/dev/null 2>&1
           [ "$SILENT" = "false" ] && echo -e "${GREEN}Done${NORMAL}\n"
        elif [ "$RESTARTDIAGS" = "true" -a \( "$INTR" = "true"  -o ! -f /tmp/didit.tmp \) ]
        then
           [ "$SILENT" = "false" ] && echo -e "\nRestarting HP Insight Diagnostics Online Edition for Linux...\c"
           /etc/init.d/hpdiags restart >/dev/null 2>&1
           [ "$SILENT" = "false" ] && echo -e "${GREEN}Done${NORMAL}\n"
        fi
      fi
    fi
    # See if we need to cleanup any Remote Access mounts/directories.
    if [ ${#KERNELSRC} -ne 0 ]
    then
        MTD=`mount | grep $KERNELSRC 2>/dev/null`
        if [ -n "$MTD" ]
        then
            umount $KERNELSRC 1>/dev/null 2>&1
        fi
        if [ -d $KERNELSRC ]
        then
            /bin/rmdir $KERNELSRC 1>/dev/null 2>&1
        fi
    fi
    # Lets restore the .rpmmacros file if we copied it.
    if [ -f ${HPDir}/${rpmMacroFile} ]
    then
        ${MVCMD} ${HPDir}/${rpmMacroFile} ${HOME}/${rpmMacroFile}
    fi
    # Restore the GtkRC files if needed.
    if [ "${IsItRHEL3_64}" = "true" -o "${IsItRHEL4_64}" = "true" ]
    then
        for i in `ls ~/.gtkrc* 2>/dev/null`
        do
    	    ${MVCMD} ${i} ${i%%\.LSP*} >/dev/null 2>&1
        done
    fi
    
    # Remove the xorg-x11-libs RPM that we needed for GUI install...
    if [ "$IsItRHEL4_64" = "true" -a "$ADDED_X11_RHEL4" = "true" ]
    then
       rpm -e --nodeps $X11_LIBS_RHEL4 >/dev/null 2>&1
    fi
    # Did we have to build the RPM directory tree?
    if [ "$BLDRPMDIR" = "true" ]
    then
       /bin/rm -rf ${RPMDIR} >/dev/null 2>&1
    fi
    # Did we have to copy the files to a /tmp directory?
    # If so, we need to clean it up, or just cleanup here.
    unset HPLSPINSTALL KERNELSRC RPMDIR BASEKRNL LSPELMCONFIGURED SNMPDCFGFILE
    unset LSPVCACONFIGURED HPVCARECONFIGURE
    
    ${RMCMD} ${TEMP1}
    ${RMCMD} ${TEMP2}
    removeRamDisk  # remove the ramdisk
    if [ -d $TMPDIR -a $RFLAG -eq 1 ]
    then
       cd "$ORIGDIR"
       /bin/rm -rf ${TMPDIR} >/dev/null 2>&1
    elif [ $RFLAG -eq 1 ]
    then
        ${RMCMD} vercmp >/dev/null 2>&1
        ${RMCMD} *snmp* >/dev/null 2>&1
        ${RMCMD} hppldu >/dev/null 2>&1
        ${RMCMD} hpplduparserss >/dev/null 2>&1
        ${RMCMD} crypton >/dev/null 2>&1
        ${RMCMD} hpplduioss >/dev/null 2>&1
        ${RMCMD} hppldudepchkss >/dev/null 2>&1
        ${RMCMD} hpplduinstallerss >/dev/null 2>&1
        ${RMCMD} hpplduverchkdbss >/dev/null 2>&1
        ${RMCMD} hppldu.conf >/dev/null 2>&1
        ${RMCMD} hppldu.prm >/dev/null 2>&1
        ${RMCMD} ncmcon.cfg >/dev/null 2>&1
        ${RMCMD} bcmpatch.sed >/dev/null 2>&1
        ${RMCMD} libcpqlsp* >/dev/null 2>&1
        ${RMCMD} install\?\?\?.sh >/dev/null 2>&1
        ${RMCMD} ${HPDir}/displayit.sh >/dev/null 2>&1
        ${RMCMD} ${GDK_RPM} >/dev/null 2>&1
        ${RMCMD} ${GLUT} >/dev/null 2>&1
        ${RMCMD} ${GLIB} >/dev/null 2>&1
        ${RMCMD} ${CURSES} >/dev/null 2>&1
        ${RMCMD} compat* >/dev/null 2>&1
        ${RMCMD} db40* >/dev/null 2>&1
        ${RMCMD} lm_sensors-2.8.7-2* >/dev/null 2>&1
        ${RMCMD} libgcc-3.4* >/dev/null 2>&1
        ${RMCMD} ${LIBSTDC_32} >/dev/null 2>&1
        ${RMCMD} xorg-x11-libs* >/dev/null 2>&1
        ${RMCMD} /usr/lib/libcpqlsptransport.* >/dev/null 2>&1
        ${RMCMD} /tmp/didit.tmp >/dev/null 2>&1
        if [ "$IsItRHEL3_64" = "true" -o "$IsItRHEL4_64" = "true" ]
        then
            [ "$GTK_COPIED" = "true" -o "$COPIEDGTKLIB" = "yes" ] && ${RMCMD} /usr/lib/libgtk-1.2.so* > /dev/null 2>&1
            [ "$GDK_COPIED" = "true" -o "$COPIEDGDKLIB" = "yes" ] && ${RMCMD} /usr/lib/libgdk-1.2.so* > /dev/null 2>&1
        fi
    fi
    # Move to the original working directory and get ready to exit.
    cd "$ORIGDIR"

    # remove detrius from the working directory
    if [ -s ${RMLIST} ]
    then
       while read RMFILE DETRIUS
       do
          [ ${RMFILE} = "./" -o ${RMFILE} = "."  -o ${RMFILE} = ".." ] && 
             continue
          if [ -n "${RMFILE}" ] && [ -e "${RMFILE}" ]
          then
             ${RMCMD} "${RMFILE}"
          fi
       done < ${RMLIST}
    fi

    ${RMCMD} ${RMLIST}

    # Echo message, if any, to user.
    if [ -n "$1" ]
    then
        putmsg "$1" 0
    fi
    # Clear the traps.
    trap '' 2 3 15
    
    # Then return.
    return
}


# Function for killing all hppldu processes.
function killer()
{
    # Identify all our appl processes.
    PIDs=`${PSE}|grep hppldu|awk '{print $1}'|sort -r`
    # Now kill them one at a time. (use SIGKILL to make sure)
    for k in $PIDs
    do
        $KILCMD $k >/dev/null 2>&1
    done
    return
}

# Function for catching a user interrupt, then
# terminate our HPPLDU.
function interrupt()
{
    # Set a flag to indicate interrupt has occurred.
    INTR=true
    # Call killer to terminate all hppldu processes.
    killer
    # Set the remove flag.
    RFLAG=1
    # Call the cleanup crew.
    cleanup "$1"
    # Make an entry in logfile.
    [ -f /var/log/hppldu.log ] && echo -e "$1" >> /var/log/hppldu.log
    # and, get out!
    exit 21
}

function SetProcTypeAndArchitecture()
{
    ARCHITECTURE=`uname -m`
    export ARCHITECTURE

    VALUE=`cat /proc/cpuinfo | grep -i genuineintel | sed 's/[ ]//g'`
    if [ -n "$VALUE" ]
    then
      PROC_TYPE="INTEL"
    else
      VALUE=`cat /proc/cpuinfo | grep -i authenticamd | sed 's/[ ]//g'`
      if [ "$VALUE" != "" ]
      then
        PROC_TYPE="AMD"
      else
        PROC_TYPE="INTEL"
      fi
    fi
    # If it is RHEL3 lets verify the Kernel Arch.
    if [ "$IsItRHEL3" = "true" ]
    then
        for i in K6= K7= K8=
        do
            if [ -f /boot/config-${RKRNL} ]
            then
                VALUE=`grep -c "^CONFIG_M${i}" /boot/config-${RKRNL}`
                if [ $VALUE -gt 0 ]
                then
                    PROC_TYPE="AMD"
                fi
            fi
        done
    fi
    export PROC_TYPE
    return
}

function checkForComponentInstall()
{
argv=$@
declare -i n=0

touch $RMLIST
for param in $argv
do
   if [ $param = "-c" ]
   then
     componentInstall="true"
   fi
   n=`echo $param|grep -n .rpm.tar.gz|awk -F ':' '{print $1}'`
   if [ "$componentInstall" = "true" -a -s $param -a $n -gt 0 ]
   then
      COMPNAME=$param
      RPMNAME=`basename $param .tar.gz`
      XMLNAME=`basename $param .rpm.tar.gz`.xml
      tar xzvf $COMPNAME $RPMNAME >> $RMLIST
      tar xzvf $COMPNAME $XMLNAME >> $RMLIST
   fi
   shift
done
}

###################################
##                               ##
##          M A I N              ##
##                               ##
###################################
# Lets verify that 'superuser' is running this app.
if [ `id -u` -eq 0 ]
then
    AUTO=${SS_CD_MOUNTPOINT}
    # Set some traps.
    trap 'interrupt "\nTerminated!\n"' 2
    trap 'cleanup ""' 1 3 15
    
    # Remove an empty lock directory
    if [ -d ${LCKDIR} -a ! -s ${LCKFILE} ]
    then
      rmdir $LCKDIR
    fi

    # Now setup a lock, so that we only allow one instance of
    # the HPPLDU to run at a time.
    if [ ! -d ${LCKDIR} ]
    then
        $MKDIR $LCKDIR >/dev/null 2>&1
        echo $$ >$LCKFILE
    else
        ISITCURR=0
        CHKLCK=`cat $LCKFILE 2>/dev/null`
        [ -n "$CHKLCK" ] && ISITCURR=`$PSE | grep "^ *$CHKLCK"`
        if [ ${#ISITCURR} -gt 0 ]
        then
            RFLAG=0
            cleanup "\nOnly one instance of the HP ProLiant Linux Deployment Utility\nmay run at a time.\n"
            exit 22  
        else
            echo $$ >$LCKFILE
        fi
    fi

    # Setup our HP directory if needed.
    if [ ! -d $HPDir ]
    then
        $MKDIR $HPDir
        [ $? -ne 0 ] && cleanup "Unable to create $HPDir..this directory is required for\nstoring certain files used with the HP ProLiant Linux Deployment Utility."
    fi

    # Determine the path to our executables, and move there.
    ORIGDIR=`dirname "$0"`
    if [ "${ORIGDIR}" = "." ]
    then
       ORIGDIR="${PWD}"
    elif [ `echo ${ORIGDIR} | egrep -c "^\.\/"` -ne 0 ]
    then
       workingDir=`echo ${ORIGDIR} | awk -F '.' '{print $2}'`
       ORIGDIR="${PWD}""${workingDir}"
    fi

    cd "$ORIGDIR"

    # Lets make the command line options local.
    GetOpts "$*"

    # Which Distr. of Linux are we on.
    SetProcTypeAndArchitecture
    SetupForOS

    checkForComponentInstall $@
	#  Are we on a RO filesystem, or one that prohibits soft links?
	/bin/ln -s ./install???.sh ./dummy &>/dev/null
	NOLINK=$?
	/bin/rm -f ./dummy &>/dev/null
    touch "${ORIGDIR}"/install???.sh >/dev/null 2>&1
    if [ $? -ne 0 -o $NOLINK -ne 0 ]
    then
        RO=true  # This is a READ-ONLY directory, or non-linkable FS.
        if [ ${#AUTO} -gt 0 ]
        then
            CDDEV=$MNTDEV
        else
            CDDEV=`df -k "$ORIGDIR"|awk '{if( NR > 1) print $1}'`
        fi
        export CDDEV
        if [ "$IsItRHEL4" = "true" -o "$IsItRHEL4_64" = "true" ]
        then
          SPACE_AVAIL=`df /tmp |  awk '{if(NR > 1) print $3}'`
        else
          SPACE_AVAIL=`df /tmp |  awk '{if(NR > 1) print $4}'`
        fi
        if [ $SPACE_AVAIL -ge $SPACE_REQD ]
        then
            $MKDIR "$TMPDIR" >/dev/null 2>&1    # Create a temporary work space.
            if [ $? -ne 0 ]
            then
                cleanup "\n\nUnable to create a temporary working directory in '/tmp'.\nPlease verify, or set '/tmp' for proper permissions, and re-run\nthe HP ProLiant Linux Deployment Utility."
            exit 1
            fi
            if [ "$componentInstall" = "false" ]
            then
              GetBundle "$TMPDIR"
              ${CPCMD} ${BUNDLE} "${TMPDIR}" >/dev/null 2>&1
              cd "${TMPDIR}"
            fi 
            # Well we finally got thru all the preliminaries, so now
            # we can get down to business.
            # Setup the execution environment. 
            tar zxf ${TARBALL} >/dev/null
        else
            cleanup "\n\nThere is inadequate disk space available in '/tmp' to execute\nthe HP ProLiant Linux Deployment Utility.\n Exiting...\n"
            exit 1
        fi
    else
        if [ "$componentInstall" = "false" ]
        then
          GetBundle "$ORIGDIR"
        fi
    
          # Well we finally got thru all the preliminaries, so now
          # we can get down to business.
          # Setup the execution environment. 
          tar zxf ${TARBALL} >/dev/null
    fi
    rm -f ${RMLIST}
    touch ${RMLIST}
    if [ "$UNTAR" = "true" ]
    then
        for i in `ls *.tar.gz`
        do
            if [ `echo $i|grep -c hppldu-` -eq 0 ]
            then
               /bin/tar zvxf ${i} >> ${RMLIST}
            fi
        done
    fi
    # See if we are on RH EL3, if so verify libgdk_pixbuf.so.2 and required RPMs are present.
    if [ "$IsItRHEL3" = "true" ]
    then
        CheckGDKLib
        #  The next two lines were added to fix the RHEL3 rpm database corruption issue.
        export LD_ASSUME_KERNEL=2.4.1  
        export RPM_FORCE_NPTL=1
    elif [ "$IsItRHEL3_64" = "true" -o "$IsItRHEL4_64" = "true" ]
    then
         MoveGtkRC
        #  The next two lines were added to fix the RHEL3 rpm database corruption issue.
        if [ "$IsItRHEL3_64" = "true" ]
        then
          export LD_ASSUME_KERNEL=2.4.21  
        fi
        export RPM_FORCE_NPTL=1
    fi

    CheckInstalledRPMs

    # Is HPASM installed, and are the agents running, if so, stop them.
    if [ "$HelpOnly" = "false" ]
    then
        # Is the hpasm running?
        ASM=`ps -e | grep hpasmd`
        if [ ${#ASM} -ne 0 ]
        then
           [ "$SILENT" = "false" ] && echo -e "\nStopping HP System Management Drivers and Agents...\c"
           /etc/init.d/cmanic stop >/dev/null 2>&1
           /etc/init.d/hpasm stop >/dev/null 2>&1
           [ "$SILENT" = "false" ] && echo -e "${GREEN}Done${NORMAL}\n"
           if [ "$DELAY" = "false" -a "$SILENT" = "false" ]
           then
               echo -e "\nStopping HP System Management Homepage...\c"
               /etc/init.d/hpvca stop >/dev/null 2>&1
               /etc/init.d/hpsmhd stop >/dev/null 2>&1
               echo -e "${GREEN}Done${NORMAL}\n"
               echo -e "\nStopping SNMP Daemon...\c"
               /etc/init.d/snmpd stop >/dev/null 2>&1
               echo -e "${GREEN}Done${NORMAL}\n"
           fi
           STOPPED=true
        else
           ASM=`/bin/rpm -q hpasm 2>&1|grep "not installed"`
           if [ ${#ASM} -ne 0 ]
           then
               NOHPASM=true
           fi
        fi
    fi

    if [ -f /var/spool/compaq/cma.install ]
    then
    	$RMCMD /var/spool/compaq/cma.install >/dev/null 2>&1
    fi
    if [ ! -d /var/spool/compaq ]
    then
        $MKDIR /var/spool/compaq >/dev/null 2>&1
    fi

    # Added hpasmd per request from S. Sherbert 10/11/04.
    # Added cmastor per request from S. Sherbert 10/13/04.
    echo "hpasmd cmastor cmafdtn cmasvr" > /var/spool/compaq/cma.install 

    # Is ELM configured with passwords?
    IsELMCfg

    # Is VCA configured?
    IsVCACfg

    # Add the x11-libs needed by the UI if necessary...
    if [ "$IsItRHEL4_64" = "true" -a "$ADDED_X11_RHEL4" = "true" -a "${GUI}" = "true" ]
    then
       extractRPM $X11_LIBS_RHEL4_RPM
       rpm -iv --nodeps $X11_LIBS_RHEL4_RPM >/dev/null 2>&1
    fi

    ln -sf libcpqlsptransport.so.0.0 libcpqlsptransport.so.0 >/dev/null 2>&1
    ln -sf libcpqlsptransport.so.0 libcpqlsptransport.so >/dev/null 2>&1
    ${CPCMD} libcpqlsptransport.so.0.0 /usr/lib/ >/dev/null 2>&1
    ${CPCMD} libcpqlsptransport.so.0 /usr/lib/ >/dev/null 2>&1
    /sbin/ldconfig >/dev/null 2>&1
    HPLSPINSTALL=TRUE
    export HPLSPINSTALL

    # Then kick off the Application.
    RFLAG=1
    
    if [ "$IsItRHEL4" = "true" -o "$IsItRHEL4_64" = "true" ]
    then
      export ItIsRHEL4=true
    else
      export ItIsRHEL4=false
    fi
    
    if [ "$GUI" = "false" -a "$CMDLINE" = "false" ]
    then
        createRamDisk
        ./hppldu $@ "--nui"
        RC=`expr $?`
        # Capture the return code from the HPPLDU.
        removeRamDisk
    else
      if [ "$IsItRHEL3_64" = "true" -o "$IsItRHEL4_64" = "true" ]
      then
          if [ ! -e /usr/lib/libgtk-1.2.so.0.9.1 ]
          then
                extractRPM libgtk-1.2.so.0.9.1
                ${CPCMD} libgtk-1.2.so.0.9.1 /usr/lib/libgtk-1.2.so.0
                GTK_COPIED=true
          fi
          if [ ! -e /usr/lib/libgdk-1.2.so.0.9.1 ]
          then
                extractRPM libgdk-1.2.so.0.9.1
                ${CPCMD} libgdk-1.2.so.0.9.1 /usr/lib/libgdk-1.2.so.0
                GDK_COPIED=true
          fi
      fi
      /sbin/ldconfig >/dev/null 2>&1
      createRamDisk
      ./hppldu "$@" 
      # Capture the return code from the HPPLDU.
      RC=`expr $?`
      removeRamDisk
    fi

    # Delay for a few seconds if we are running a VCA install.
    if [ "$DELAY" = "true" ]
    then
        sleep 15
    fi
 
    # We are finished, so call the cleanup crew.
    cleanup ""
else
    RFLAG=1
    cleanup "\n'root' access is required to run the HP Deployment Utility for Linux.\n"
    RC=`expr 1`
fi

# If we were called from a CD using autorun and a reboot is scheduled,
# we need to eject the CD.
if [ \( -n "$AUTO"  -a -n "$CDDEV" \) -a $RC -eq 16 ]
then
	[ -x /usr/bin/eject ] && EJECT=/usr/bin/eject
	[ -x /bin/eject ] && EJECT=/bin/eject
	cat >/tmp/eject.sh <<-[]

	cd /root
	autorunpid=`ps -eaf | grep autorun | awk '{print $2}'`
	kill -HUP $autorunpid
	sleep 2
	kill -HUP $PPID
	sleep 2
	$EJECT -r $CDDEV
	sleep 5
	/bin/rm -f /tmp/eject.sh
	exit
	[]
    cd /tmp
    chmod 700 /tmp/eject.sh
    nohup /tmp/eject.sh >/dev/null 2>&1 &
    disown %nohup
    $EJECT -r $CDDEV > /dev/null 2>&1
    sleep 3
    $EJECT -r $CDDEV > /dev/null 2>&1
fi
cd "$HOME"
exit $RC
