#!/bin/bash
###############################################################################
# Product:  Data Protector
# Version:  A.09.00
# Package:  OB2-CORE
# Function: Postinstall
###############################################################################


OS=`uname -s`

# Exit code
# #########
if [ "${OS}" = "HP-UX" ]; then
   # Failed:1 Partialy Failed:2
   SUCCESS=0
   EXIT_FAILED=1
   EXIT_WARNING=2
else
   # Fatal:1 Warning:2 Halt:3
   SUCCESS=0
   EXIT_FAILED=3
   EXIT_WARNING=2
fi

DEVNULL=/dev/null

SUBPRODUCT=""

# OmniBack II files & directories
# ###############################
OMNIHOME=/opt/omni/
OMNIDBSERVER=`hostname`
OMNIDBINSTALLLOG=/tmp/DPDBInstall.log
OMNIDBUNINSTALLLOG=/tmp/DPDBUnInstall.log
OMNIDBUSERSHELL=`echo $SHELL`
OMNICONFIGBASE=/etc${OMNIHOME}
OMNICONFIG=${OMNICONFIGBASE}server/
OMNICONFIGCLIENT=${OMNICONFIGBASE}client/
OMNICONFIGIS=${OMNICONFIGBASE}IS/
OMNIVAR=/var${OMNIHOME}server/
OMNIVARCLIENT=/var${OMNIHOME}
OMNILOG=${OMNIVAR}/log
OMNILOGCLIENT=${OMNIVARCLIENT}/log
OMNITMP=${OMNIVARCLIENT}/tmp
OMNIENHINCRDB=${OMNIVARCLIENT}/enhincrdb
NEWCONFIG=${OMNIHOME}/newconfig/
OMNIIDBCOMPOSITE=${NEWCONFIG}${OMNICONFIG}idb/
OMNIBIN=${OMNIHOME}bin
OMNILBIN=${OMNIHOME}lbin
OMNILIB=${OMNIHOME}/lib
OMNIINET=${OMNILBIN}/inet
OMNIINFO=client/omni_info
OMNIINFO_IS=IS/omni_info
OMNIFORMAT=client/omni_format
OMNI_IS=${OMNICONFIG}cell/installation_servers
CELLINFO=${OMNICONFIG}/cell/cell_info
CELLSERVER=${OMNICONFIGCLIENT}/cell_server
USERCONF=${OMNICONFIG}/users
DATABASES=${OMNIHOME}databases/vendor/
OMNISITEPERL=${OMNIHOME}/lib/perl
COMPONENTS=/etc/opt/omni/client/components/

OLD_OMNIHOME=/usr/omni/
OLD_OMNICONFIG=${OLD_OMNIHOME}config/
TMP_OMNIHOME=/var/tmp/omni/
TMP_OMNICONFIG=${TMP_OMNIHOME}config/

UPGRADE_SCRIPT=${OMNIHOME}sbin/IDBsetup.sh

# Temporary OmniBack II directory
# ###############################
TOMNI=/tmp/omni_tmp
OMNIDBPARAMFILE=${TOMNI}/omnidbparam
SOCKET_DAT=${TOMNI}/socket.dat
DPDAT=${TOMNI}/dpdat
MGMT_SV=${TOMNI}/mgmt_sv.dat

# The service file, inet config directory
# #######################################
SERVICES=/etc/services
INETDCONF=/etc/inetd.conf
INETDSEC=/var/adm/inetd.sec

SERVICE=omni

TMP=/tmp/inst.tmp


# #############################################################################
# Checks for a MC/SG environment
# #############################################################################

OMNICC_ARG=""
UPGCFG_ARG=""
CHECK_MCSG_ENV=""

check_mcsg()
{
    if [ ! -z "$CHECK_MCSG_ENV" ]; then return; fi
    CHECK_MCSG_ENV=0
    if [ "${OS}" != "HP-UX" ]; then return; fi
    if [ ! -x /usr/sbin/cmviewcl ]; then return; fi
    if [ ! -f $OMNICONFIG/sg/sg.conf -o \
         ! -f $OMNICONFIG/cell/cell_info ]; then return; fi
    if [ \( -h /etc/$OMNIHOME/server -a -h /var/$OMNIHOME/server \) -o \
         \( -h /etc/opt/omni -a -h /var/opt/omni \) ]
    then
        CSHOST=`cat $OMNICONFIGCLIENT/cell_server 2>/dev/null`
        if [ -z "$CSHOST" ]; then return; fi
        grep "[-]host [ \"]*$CSHOST\"* .*-virtual" $OMNICONFIG/cell/cell_info >/dev/null 2>/dev/null
        if [ $? != 0 ]; then return; fi
        grep "^[^#]*CS_SERVICE_HOSTNAME=\"*$CSHOST\"*" $OMNICONFIG/sg/sg.conf >/dev/null 2>/dev/null
        if [ $? != 0 ]; then return; fi
        SHARED_DISK_ROOT=`grep "^[^#]*SHARED_DISK_ROOT=" $OMNICONFIG/sg/sg.conf 2>/dev/null | cut -d= -f2 | tr -d "\"'"`
        if [ -z "$SHARED_DISK_ROOT" ]; then return; fi
        if [ ! -d "$SHARED_DISK_ROOT" ]; then return; fi
        OMNICC_ARG="-server "`hostname | tr "[A-Z]" "[a-z]"`
        UPGCFG_ARG="$OMNICC_ARG"
        CHECK_MCSG_ENV=1
    fi
}

call_omnicc()
{
    check_mcsg
    ${OMNIHOME}/bin/omnicc $OMNICC_ARG "$@"
}

remove_duplicated_push_packets()
{
    # remove old push packets
    DIR_LST=`find ${DATABASES}/ -name '*.*.*' 2>$DEVNULL`
    if [ "${DIR_LST}" ]; then
     for DIR in ${DIR_LST}; do
       if [ `basename "${DIR}"` != "A.09.00" -a -d `dirname "${DIR}"`/A.09.00 ]; then
         rm -rf ${DIR}
       fi
     done
    fi
}




# #############################################################################
# Creates socket file on the newconfig directory
# #############################################################################
create_socket_file()
{
  if [ -f ${SOCKET_DAT} ]; then
    cp ${SOCKET_DAT} ${NEWCONFIG}/${OMNICONFIGCLIENT}/customize/socket
    chown root:sys ${NEWCONFIG}/${OMNICONFIGCLIENT}/customize/socket
    chmod 644 ${NEWCONFIG}/${OMNICONFIGCLIENT}/customize/socket
  fi
}



# #############################################################################
# Creates config and log directories
# #############################################################################
create_dir()
{
  for DIR in ${OMNIVAR} ${OMNICONFIG} ${OMNICONFIGCLIENT} ${OMNICONFIG}/cell ${OMNICONFIGCLIENT}/customize ${OMNICONFIG}/nls; do
    if [ ! -d ${DIR} ]; then
      mkdir -p ${DIR}
      chown root:sys ${DIR}
      chmod 755 ${DIR}
    fi
  done

  for DIR in ${OMNIVARCLIENT} ${OMNILOG} ${OMNILOGCLIENT}; do
    if [ ! -d ${DIR} ]; then
      mkdir -p ${DIR}
      chown root:sys ${DIR}
      chmod 777 ${DIR}
    fi
  done

  for DIR in ${OMNIENHINCRDB} ${OMNITMP}; do
    if [ ! -d ${DIR} ]; then
      mkdir -p ${DIR}
      chown root:sys ${DIR}
    fi
      chmod 1777 ${DIR}
  done

  touch ${OMNILOGCLIENT}/debug.log
  chown root:sys ${OMNILOGCLIENT}/debug.log
  chmod 666 ${OMNILOGCLIENT}/debug.log
}



# ############################################################################
# Copies the newconfig direcory
# ############################################################################
copy_newconfig()
{
  if [ -d "${NEWCONFIG}/" ]; then

    cd ${NEWCONFIG}/
    for dir in `find . -type d`; do
        cd /
        if [ ! -d $dir ]; then
            mkdir -p $dir
            chown root:sys $dir
            # if directory is log or tmp change permission to 777
            if [ "`basename $dir`" = "log" -o "`basename $dir`" = "tmp" ]; then
                chmod 777 $dir
            elif [ "`basename $dir`" = "enhincrdb" ]; then
                chmod 777 $dir
            else
                chmod 755 $dir
            fi
        fi
    done

    cd ${NEWCONFIG}/
    for file in `find . -type f`; do
      cd /
      if [ ! -r $file ]; then
        cp -p ${NEWCONFIG}/$file $file
        # if file has log extension change premission to 666
        if [ "`echo $file | grep '\.log$'`" != "" ]; then
          chmod 666 $file
        fi
      else
        FN=`basename $file`
        case $FN in
          omni_format )
            cp -p ${NEWCONFIG}/$file $file ;;
          writerstab_format | writerstab_info )
            cp ${NEWCONFIG}/$file $file ;;
          providerstab_format )
            cp ${NEWCONFIG}/$file $file ;;
          vdsproviderstab_info | vssproviderstab_info )
            cp ${NEWCONFIG}/$file $file ;;
          vdsproviderstab_format | vssproviderstab_format )
            cp ${NEWCONFIG}/$file $file
            chown root $file
            chmod 644 $file ;;
        esac
      fi
    done
  else
    echo "ERROR:   Directoy ${NEWCONFIG} does not exist" >&2
    exit ${EXIT_FAILED}
  fi

  if [ -d "${NEWCONFIG}/${COMPONENTS}/" ]; then

    cd ${NEWCONFIG}/${COMPONENTS}/
    for file in `ls *.xml *.properties 2>$DEVNULL |grep -v webservice |grep -v Logger`; do
        cd /
        cp -p ${NEWCONFIG}/${COMPONENTS}/$file ${COMPONENTS}/$file
    done
  fi

  if [ -d "${NEWCONFIG}/${COMPONENTS}/registry/" ]; then

    cd ${NEWCONFIG}/${COMPONENTS}/registry/
    for file in `ls` ; do
        cd /
        cp -p ${NEWCONFIG}/${COMPONENTS}/registry/$file ${COMPONENTS}/registry/$file
    done
  fi
}



# #############################################################################
# Checks if omni_info has old format
# #############################################################################
check_omni_info_format()
{
  if [ -f "${OMNICONFIGBASE}/${OMNIINFO}" ]; then
    head -n 1 "${OMNICONFIGBASE}/${OMNIINFO}" | grep "^-key " > /dev/null 2>&1

    if [ $? -ne 0 ]; then
      rm -f "${OMNICONFIGBASE}/${OMNIINFO}"
    fi
  fi
}



# #############################################################################
# Copies specific files in newconfig directory
# #############################################################################
copy_newconfig_files()
{
  # # copy omni_format file to the OmniBack II config directory
  # ###########################################################################
  if [ -f ${NEWCONFIG}/${OMNICONFIGBASE}/${OMNIFORMAT} ]; then
    cp ${NEWCONFIG}/${OMNICONFIGBASE}/${OMNIFORMAT} ${OMNICONFIGBASE}/${OMNIFORMAT}
    chown root:sys ${OMNICONFIGBASE}/${OMNIFORMAT}
    chmod 644 ${OMNICONFIGBASE}/${OMNIFORMAT}
  fi
}



# #############################################################################
# Copies cell_server file to the OmniBack II config directory
# #############################################################################
copy_cs_file()
{
  if [ -f ${NEWCONFIG}/${CELLSERVER} ]; then
    cp ${NEWCONFIG}/${CELLSERVER} ${CELLSERVER}
    chown root:sys ${CELLSERVER}
    chmod 644 ${CELLSERVER}
  fi
}



# #############################################################################
# move old directories to the client/server directories
# #############################################################################
move_dirs()
{
  OMNI_VAR=/var/opt/omni
  OMNI_ETC=/etc/opt/omni

  for i in cell/cell_server \
           cell/omni_format \
           cell/omni_info \
           cell/allow_hosts \
           cell/deny_hosts \
           customize
  do
     if [ -f $OMNI_ETC/$i ];
     then
        mkdir -p $OMNI_ETC/client
        mv $OMNI_ETC/$i $OMNI_ETC/client/ 2>/dev/null
     fi
  done

  if [ -d $OMNI_ETC ]
  then
     cd $OMNI_ETC
     for i in *
     do
        if [ "$i" != "*" \
            -a "$i" != "client" -a "$i" != "IS" \
            -a "$i" != "server" -a "$i" != "server.save" \
            -a "$i" != "informix" -a "$i" != "sybase" ]
        then
           mv "$OMNI_ETC/$i" "$OMNI_ETC/server" 2>/dev/null
        fi
     done
  fi

  if [ -d $OMNI_VAR/sessions ];
  then
     mkdir -p $OMNI_VAR/server
     mv $OMNI_VAR/sessions $OMNI_VAR/server/ 2>/dev/null
  fi
  if [ -d $OMNI_VAR/db40 ];
  then
     mkdir -p $OMNI_VAR/server
     mv $OMNI_VAR/db40 $OMNI_VAR/server/ 2>/dev/null
     #If the move fails because of $OMNI_VAR/db40 being
     #in a different file system then copy the same.
     if [ $? -ne 0 ];
     then
        cp -pR $OMNI_VAR/db40 $OMNI_VAR/server/ 
        rm -rf $OMNI_VAR/db40/*
        umount $OMNI_VAR/db40
        rm -rf $OMNI_VAR/db40
     fi
  fi

  if [ -d $OMNI_VAR/log ];
  then
     cd $OMNI_VAR/log
     mkdir -p $OMNI_VAR/server/log
     for i in HealthCheck.log Check_*.txt Ob2Event* OB2_upgrade.log \
         lic.log omnisv.log media.log  sm.log security.log \
         crsevents.log purge.log readascii.log cleaning.log \
         upgrade.log trace.log cluster.log
     do
        if [ -f $i ]
        then
           mv $i $OMNI_VAR/server/log/ 2>/dev/null
        fi
     done
  fi
}



# #############################################################################
# Removes old directories
# #############################################################################
rm_old_dir ()
{
   # remove obsolete filesets
   if [ "${OS}" = "HP-UX" ]; then
     for i in `swlist -l patch OMNIBACK-II.\*,r\<A.09.00 2>/dev/null | grep -v \# | awk 'FS="." {print $1}' | sort -u`
     do
       swmodify -x patch_commit=true $i 2>$DEVNULL
       swmodify -u $i.\* $i 2>$DEVNULL
     done
     for i in `swlist -l patch DATA-PROTECTOR.\*,r\<A.09.00 2>/dev/null | grep -v \# | awk 'FS="." {print $1}' | sort -u`
     do
       swmodify -x patch_commit=true $i 2>$DEVNULL
       swmodify -u $i.\* $i 2>$DEVNULL
     done
     swlist -l product DATA-PROTECTOR,r\<A.09.00 2>/dev/null | grep DATA-PROTECTOR >$DEVNULL
     if [ $? = 0 ]
     then
       swmodify -u DATA-PROTECTOR.\*,r\<A.09.00 DATA-PROTECTOR,r\<A.09.00 2>$DEVNULL
     fi
     swlist -l bundle B6960MA,r\<A.09.00 2>/dev/null | grep B6960MA >$DEVNULL
     if [ $? = 0 ]
     then
       swmodify -u B6960MA,r\<A.09.00 2>$DEVNULL
     fi
     swlist -l bundle B6960MJ,r\<A.09.00 2>/dev/null | grep B6960MJ >$DEVNULL
     if [ $? = 0 ]
     then
       swmodify -u B6960MJ,r\<A.09.00 2>$DEVNULL
     fi
     swlist -l bundle B6960BA,r\<A.09.00 2>/dev/null | grep B6960BA >$DEVNULL
     if [ $? = 0 ]
     then
       swmodify -u B6960BA,r\<A.09.00 2>$DEVNULL
     fi
   fi

### remove obsolete files from DP7.00
   for i in databases/vendor/ma/ibm/rs6000/aix-53 \
   databases/vendor/vepa/gpl/i386 \
   databases/vendor/ma/sco/ \
   databases/vendor/cc/sco/i386/unixware \
   databases/vendor/cc/sco/i386/sco_sv \
   databases/vendor/cc/sgi \
   databases/vendor/omnicf/sco/i386/unixware \
   databases/vendor/omnicf/sco/i386/sco_sv \
   databases/vendor/omnicf/sgi \
   databases/vendor/da/sco/i386/unixware \
   databases/vendor/da/sco/i386/sco_sv \
   databases/vendor/da/sgi \
   databases/vendor/smisa/hp/s800/hp-ux-11 \
   databases/vendor/pegasus/hp/s800/hp-ux-11 \
   databases/utils/sgi \
   databases/utils/sco/i386/unixware \
   databases/utils/sco/i386/sco_sv \
   newconfig/etc/opt/omni/server/dltemplates/lists/datalist/NT_NNM_template \
   newconfig/etc/opt/omni/server/dltemplates/lists/datalist/Unix_NNM_template \
   databases/vendor/ov \
   .CII_OV \
   .patch_ov \
   newconfig/etc/opt/omni/client/customize/.VersionOV \
   databases/vendor/vls_am \
   .CII_VLS_AM \
   .patch_vls_am \
   newconfig/etc/opt/omni/client/customize/.VersionVLS_AM \
   databases/vendor/javagui \
   .CII_JAVAGUI \
   .patch_javagui \
   newconfig/etc/opt/omni/client/customize/.VersionJAVAGUI 
   do
     rm -rf ${OMNIHOME}/$i
   done

   for i in client/customize/.Version* \
   server/dltemplates/lists/datalist/NT_NNM_template \
   server/dltemplates/lists/datalist/Unix_NNM_template 
   do
     rm -rf /etc/${OMNIHOME}/$i
   done

### remove obsolete files from DP6.00
   for i in gui \
   bin/xomninshelp \
   bin/xregedit \
   .CII_MOMGUI \
   .patch_momgui \
   newconfig/etc/opt/omni/client/customize/.VersionMOMGUI \
   databases/utils/dec/alpha/osf1-4 \
   databases/utils/sgi/mips/irix \
   databases/vendor/lotus/hp \
   databases/vendor/momgui
   do
     rm -rf ${OMNIHOME}/$i
   done
   if [ -f /opt/omni/bin/xomni ] && [ ! -h /opt/omni/bin/xomni ]
   then 
     rm -rf /opt/omni/bin/xomni
   fi 
   if [ -f /opt/omni/bin/xomnimom ] && [ ! -h /opt/omni/bin/xomnimom ]
   then 
     rm -rf /opt/omni/bin/xomnimom
   fi 
   
### remove obsolete files from DP5.50
   for i in /gui/lib.hpux_pa/libX11.3
   do
     rm -rf ${OMNIHOME}/$i
   done

### remove newconfig direcotries from DP5.10
   DIR_LST="cell customize HealthCheckConfig Holidays Notifications Version vault_locations \
   CDROM amo amoschedules barlists barschedules datalists devices dlgroups dltemplates dr \
   dsi install integ mom nls options resources rid rptgroups rptschedules schedules sg snmp users xcopy"
   for i in $DIR_LST
   do
     rm -rf ${NEWCONFIG}etc/opt/omni/$i
   done
   rm -rf ${NEWCONFIG}var/opt/omni/db40 ${NEWCONFIG}var/opt/omni/sessions

### remove obsolete files from DP5.10
   for i in /bin/omnihealthcheck \
   /lib/man/man1m/omniabort.1m \
   /lib/man/man1m/omniamo.1m \
   /lib/man/man1m/omnib.1m \
   /lib/man/man1m/omnicc.1m \
   /lib/man/man1m/omnicellinfo.1m \
   /lib/man/man1m/omniclus.1m \
   /lib/man/man1m/omnicreatedl.1m \
   /lib/man/man1m/omnidb.1m \
   /lib/man/man1m/omnidbeva.1m \
   /lib/man/man1m/omnidbsa.1m \
   /lib/man/man1m/omnidbva.1m \
   /lib/man/man1m/omnidbxp.1m \
   /lib/man/man1m/omnidownload.1m \
   /lib/man/man1m/omnimcopy.1m \
   /lib/man/man1m/omniminit.1m \
   /lib/man/man1m/omnimlist.1m \
   /lib/man/man1m/omnimm.1m \
   /lib/man/man1m/omnimnt.1m \
   /lib/man/man1m/omnimver.1m \
   /lib/man/man1m/omnir.1m \
   /lib/man/man1m/omnirpt.1m \
   /lib/man/man1m/omnistat.1m \
   /lib/man/man1m/omniupload.1m \
   /lib/man/man1m/syb_tool.1m \
   /lib/man/man5/omniintro.5 \
   /gui/bin/idbupgwiz \
   /databases/vendor/acs \
   /databases/vendor/das \
   /databases/utils/hp/sia64/hp-ux-1122 \
   /databases/vendor/omnicf/hp/sia64/hp-ux-1122 \
   /databases/vendor/integ/hp/sia64/hp-ux-1122 \
   /databases/vendor/cc/hp/sia64/hp-ux-1122 \
   /databases/vendor/da/hp/sia64/hp-ux-1122 \
   /databases/vendor/ma/hp/sia64/hp-ux-1122 \
   /databases/vendor/oracle8/hp/sia64/hp-ux-1122 \
   /newconfig/etc/opt/omni/nls/locale.map \
   /bin/omnidbsa \
   /bin/omniamo \
   /lbin/testbsm \
   /doc/C/IntegrationNT.pdf \
   /doc/C/IntegrationUX.pdf \
   /doc/C/Snapshot.pdf \
   /doc/C/StorageworksXP.pdf \
   /doc/C/Emc.pdf \
   /.CII_DAS \
   /.CII_ACS \
   /.CII_FASTRAX \
   /.CII_FXMA \
   /.CII_ORACLE \
   /newconfig/etc/opt/omni/client/customize/.VersionDAS \
   /newconfig/etc/opt/omni/client/customize/.VersionACS \
   /newconfig/etc/opt/omni/client/customize/.VersionFASTRAX \
   /newconfig/etc/opt/omni/client/customize/.VersionFXMA \
   /newconfig/etc/opt/omni/client/customize/.VersionORACLE
   do
     rm -rf ${OMNIHOME}/$i
   done
   rm -f /usr/omni/bin/omniamo
   rm -f /usr/omni/bin/omnihealthcheck
   rm -f /usr/omni/.CII_DAS
   rm -f /usr/omni/.CII_ACS
   rm -f /usr/omni/.CII_FASTRAX
   rm -f /usr/omni/.CII_FXMA
   rm -f /usr/omni/.CII_ORACLE
   rm -f /usr/omni/.VersionDAS
   rm -f /usr/omni/.VersionACS
   rm -f /usr/omni/.VersionFASTRAX
   rm -f /usr/omni/.VersionFXMA
   rm -f /usr/omni/.VersionORACLE
   rm -f /usr/omni/DAS.fileset
   rm -f /usr/omni/ACS.fileset
   rm -f /usr/omni/FASTRAX.fileset
   rm -f /usr/omni/FXMA.fileset
   rm -f /usr/omni/ORACLE.fileset

### remove obsolete files from DP5.00
  for i in /bin/utilns/licensechecker \
   /bin/utilns/omnilicensecheck \
   /doc/C/support_matrices/EMC_Fastrax_SptMtx.pdf \
   /doc/C/support_matrices/HPSvrless_SuptMtrx.pdf \
   /databases/vendor/fastrax \
   /databases/vendor/fxma
   do
     rm -rf ${OMNIHOME}/$i
   done


### remove obsolete files from DP4.10
   for i in /lbin/getextf \
   /lbin/ob2dcecmd \
   /lbin/.fdS800-10.ksh \
   /lib/man/man4/omnibarlist.4 \
   /lib/man/man4/omnidatalist.4 \
   /lib/lib_edbc.sl \
   /lib/lib_ekeyb.sl \
   /lib/lib_exif.sl \
   /lib/lib_gw.sl \
   /lib/lib_sched.sl \
   /lib/lib_uapi.sl \
   /databases/utils/hp/s800/hp-ux-1020 \
   /databases/utils/ibm/rs6000/aix-42/utils.tar \
   /databases/utils/ncr/i386/mp-ras/utils.tar \
   /databases/utils/sequent/i386/dynix/utils.tar \
   /sbin/utilns/omnicp \
   /sbin/utilns/dal \
   /sbin/nb_oracle \
   /sbin/ns_oracle.sh \
   /sbin/omnisv11 \
   /sbin/omniupg \
   /doc/C/support_matrices/DEVICE.pdf \
   /doc/C/support_matrices/EMC_FX.pdf \
   /doc/C/support_matrices/EMC_split_mirror_int.pdf \
   /doc/C/support_matrices/HPVA_SupportMatrix_OB41.pdf \
   /doc/C/support_matrices/HPXP_SupportMatrix_OB41.pdf \
   /doc/C/support_matrices/OBDR.pdf \
   /doc/C/support_matrices/Platform_Integrtn_SptMtx_OB41.pdf \
   /doc/C/support_matrices/fc_san_solution.pdf \
   /doc/C/support_matrices/third-party_SAN.pdf \
   /doc/C/OBDB_capacity_planning.xls \
   /doc/C/OB_OVO_Admin.pdf \
   /doc/C/SureStore.pdf \
   /doc/C/VirtualArray.pdf \
   /gui/help/Trouble.txt \
   /gui/lib.hp700mt \
   /java/bin/images.gif \
   /java/bin/webreporting.html
   do
     rm -rf ${OMNIHOME}/$i
   done
}



# ############################################################################
# Remove component strings
# ############################################################################
rm_component_str()
{
  if [ ! -f "${OMNIHOME}/bin/omnicc" ]; then
    echo "ERROR:   Cannot find ${OMNIHOME}/bin/omnicc" >&2
    exit ${EXIT_FAILED}
  else
    for PAC in acs das deu_ls fastrax fxma oracle evaa omnist javagui vls_am ov
    do
      if [ -f "${OMNICONFIGIS}/omni_info" ]
      then
        OUTPUT=`call_omnicc -remove_component_str $PAC $OMNIFORMAT $OMNIINFO_IS  2>&1`
        if [ $? -ne 0 -a $? -ne 3 ]
        then
          echo "WARNING: $OUTPUT"
          echo "WARNING: Update of the $OMNIINFO_IS file failed for $PAC!"
        fi
      fi

      if [ -f "${OMNICONFIGCLIENT}omni_info" ]
      then
        OUTPUT=`call_omnicc -remove_component_str $PAC $OMNIFORMAT $OMNIINFO  2>&1`
        if [ $? -ne 0 -a $? -ne 3 ]
        then
          echo "WARNING: $OUTPUT"
          echo "WARNING: Update of the client/omni_info file failed for $PAC!"
        fi
      fi
    done
  fi
}



# #############################################################################
# Updates the information about the installed OmniBack II agents
# in the omni_info file
# #############################################################################
update_omni_info()
{
  PAC=$1
  VERS=$2
  if [ "$3" ]
  then
    OMNIINFO=$3
    
    # Remove duplicated push packets 
    remove_duplicated_push_packets
  fi
  
  if [ ! -f "${OMNICONFIGBASE}/${OMNIFORMAT}" ]; then
    echo "ERROR:   Cannot find ${OMNICONFIGBASE}/${OMNIFORMAT}" >&2
    exit ${EXIT_FAILED}
  else
    OUTPUT=`call_omnicc -put_component_str $PAC $OMNIFORMAT $OMNIINFO $VERS 2>&1`
    if [ $? -ne 0 ]
    then
        echo "WARNING: $OUTPUT"
        echo "WARNING: Update of the omni_info file failed for $PAC!"
    fi
  fi
}



# #############################################################################
# Checks version file and updates omni_info file
# #############################################################################
check_and_update_omni_info()
{
  VERFILE=$1
  PAC=$2
  
  if [ -f ${NEWCONFIG}/${OMNICONFIGCLIENT}/customize/${VERFILE} ]; then
    VERS=`awk '{print $1}' ${NEWCONFIG}/${OMNICONFIGCLIENT}/customize/${VERFILE}`
    V64BIT=`awk '{print $2}' ${NEWCONFIG}/${OMNICONFIGCLIENT}/customize/${VERFILE}`
    if [ ${VERS} ]; then
      update_omni_info ${PAC} ${VERS}
    fi
    if [ ${V64BIT} ]; then
      update_omni_info "64BIT" ""
    fi
  fi
}



# ############################################################################
# Updates the cell_info file
# ############################################################################
update_cell_info ()
{
  HOSTNAME=`hostname | tr "[A-Z]" "[a-z]"`

  if [ -f ${DPDAT} ]; then
    NOENCRYPTION=`cat ${DPDAT} |grep NOENCRYPTION | awk -F"=" '{ print $2 }'`
  fi

  if [ "${NOENCRYPTION}" = "1" ]; then
    call_omnicc -update_host ${HOSTNAME} -encr_disable 1>$DEVNULL 2>$DEVNULL
  else
    call_omnicc -update_host ${HOSTNAME} 1>$DEVNULL 2>$DEVNULL
  fi
}


# ###########
# Script body
# ###########

# Postinstal Part
# ###############
create_socket_file

# Configuration Part
# ##################
rm_old_dir

move_dirs

rm_component_str

check_omni_info_format

create_dir

copy_newconfig

copy_newconfig_files

check_and_update_omni_info .VersionCORE core

update_cell_info

copy_cs_file

${OMNIHOME}/sbin/dpsvcsetup.sh -update

# # Copy old config (stored in /var/tmp) to the new directory
# ###########################################################
if [ -d ${TMP_OMNICONFIG} ]
then
    n=`ls ${TMP_OMNICONFIG} | wc -l`
    if [ $n -gt 0 ]
    then
        # This is for DP 5.1 and 5.0 versions.
        if [ -f ${TMP_OMNICONFIG}/cell/allow_hosts ]
        then
                cp -p ${TMP_OMNICONFIG}/cell/allow_hosts ${OMNICONFIGCLIENT}
                if [ $? -ne 0 ]
                then
                     echo "Warning:  ${OLD_OMNICONFIG}/cell/allow_hosts could not be copied to ${OMNICONFIGCLIENT}"
                fi
        fi

        # This is for DP 5.5 version.
        if [ -f ${TMP_OMNICONFIG}/client/allow_hosts ]
        then
                cp -p ${TMP_OMNICONFIG}/client/allow_hosts ${OMNICONFIGCLIENT}
                if [ $? -ne 0 ]
                then
                     echo "Warning:  ${OLD_OMNICONFIG}/client/allow_hosts could not be copied to ${OMNICONFIGCLIENT}"
                fi
        fi

        # This is for DP 5.1 and 5.0 versions.
        if [ -f ${TMP_OMNICONFIG}/cell/deny_hosts ]
        then
                cp -p ${TMP_OMNICONFIG}/cell/deny_hosts ${OMNICONFIGCLIENT}
                if [ $? -ne 0 ]
                then
                     echo "Warning:  ${TMP_OMNICONFIG}/cell/deny_hosts could not be copied to ${OMNICONFIGCLIENT}"
                fi
        fi

        # This is for DP 5.5 version.
        if [ -f ${TMP_OMNICONFIG}/client/deny_hosts ]
        then
                cp -p ${TMP_OMNICONFIG}/client/deny_hosts ${OMNICONFIGCLIENT}
                if [ $? -ne 0 ]
                then
                     echo "Warning:  ${TMP_OMNICONFIG}/client/deny_hosts could not be copied to ${OMNICONFIGCLIENT}"
                fi
        fi

        if [ -f ${TMP_OMNICONFIG}/.omnirc ]
        then
                cp -p ${TMP_OMNICONFIG}/.omnirc $OMNIHOME
                if [ $? -ne 0 ]
                then
                     echo "Warning:  ${TMP_OMNICONFIG}/.omnirc could not be copied to ${OMNIHOME}"
                fi
        fi
        rm -rf ${TMP_OMNICONFIG} > /dev/null 2>&1

    fi
    #Move the contents that are still present.
    mv -f ${OLD_OMNIHOME} ${OMNITMP}/usr_omni > /dev/null 2>&1
    if [ $? -ne 0 ]
    then
           echo "Warning: ${OLD_OMNIHOME} could not be moved to ${OMNITMP}/usr_omni"
    fi
fi

exit 0