#!/bin/sh
###############################################################################
# Product:  OMNIBACK-II
# 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

# OmniBack II files & directories
# ###############################
OMNIHOME=/opt/omni/
OMNICONFIGBASE=/etc${OMNIHOME}
OMNICONFIG=${OMNICONFIGBASE}server/
OMNICONFIGCLIENT=${OMNICONFIGBASE}client/
OMNIVAR=/var${OMNIHOME}server/
OMNIVARCLIENT=/var${OMNIHOME}
OMNILOG=${OMNIVAR}/log
OMNILOGCLIENT=${OMNIVARCLIENT}/log
OMNITMP=${OMNIVARCLIENT}/tmp
NEWCONFIG=${OMNIHOME}/newconfig/
OMNILBIN=${OMNIHOME}lbin
OMNIINET=${OMNILBIN}/inet
OMNIWINDUREG=${OMNIVARCLIENT}/windu
OMNIINFO=client/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

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

UPGRADE_SCRIPT=${OMNIHOME}sbin/DBupgrade.sh

# Temporary OmniBack II directory
# ###############################
TOMNI=/tmp/omni_tmp
SOCKET_DAT=${TOMNI}/socket.dat
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 "$@"
}




# #############################################################################
# Perl configuration
# #############################################################################
configer_perl()
{
    if [ -d ${OMNISITEPERL} ]; then
        MY_C_PATH=`pwd`
        cd ${OMNISITEPERL}
        if [ -f ./site_perl.tar ]; then
            tar -xvf ./site_perl.tar 1>/dev/null 2>/dev/null
        fi
        cd ${MY_C_PATH}
    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
}



# #############################################################################
# Removes OmniBack II entries from /etc/services and /etc/inetd.log
# #############################################################################
clean()
{
  if [ -f /etc/xinetd.conf ]; then
    XINETDFILE=`cat /etc/xinetd.conf | grep includedir | awk '{ print $2 }'`
    if [ "${XINETDFILE}" != "" ]; then
      XINETDFILE=${XINETDFILE}/omni
    else
      XINETDFILE="/etc/xinetd.conf"
    fi
  fi
  for file in ${SERVICES} ${INETDCONF}; do
    if [ -f ${file} ]; then
      awk '{if(($1 != "omni_" && $1 != SERV) && $2 != "DATA-PROTECTOR") {print}} ' SERV=${SERVICE} ${file} > ${TMP}
      cp ${TMP} ${file}
      rm ${TMP}
    fi
  done
  if [ ${XINETDFILE} ]; then
    if [ "${XINETDFILE}" != "/etc/xinetd.conf" ]; then
      rm -f ${XINETDFILE}
    else
      sed /^"service omni"$/,/^$/d ${XINETDFILE} > /${TOMNI}/new.xinetd.conf
      mv /${TOMNI}/new.xinetd.conf ${XINETDFILE}
    fi
  fi
}



# #############################################################################
# Creates config and log directories
# #############################################################################
create_dir()
{
  for DIR in ${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 ${OMNIVAR} ${OMNIVARCLIENT} ${OMNITMP} ${OMNILOG} ${OMNILOGCLIENT} ${OMNIWINDUREG}; do
    if [ ! -d ${DIR} ]; then
      mkdir -p ${DIR}
      chown root:sys ${DIR}
      chmod 777 ${DIR}
    fi
  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
      fi
    done
  else
    echo "ERROR:   Directoy ${NEWCONFIG} does not exist" >&2
    exit ${EXIT_FAILED}
  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
}



# #############################################################################
# Checks if socket number is already occupied with some other application
# #############################################################################
check_socket_number()
{
  # determine socket number, 5555 is default value
  # the search order is: socket, services, global
  if [ -f ${NEWCONFIG}/${OMNICONFIGCLIENT}/customize/socket ]; then
    SOCKET_NUMBER=`awk '{print}' ${NEWCONFIG}/${OMNICONFIGCLIENT}/customize/socket`
    if [ "$SOCKET_NUMBER" = "" ]; then
      SOCKET_NUMBER=5555
    fi
  else
    SOCKET_NUMBER=`awk '{if($1 == SERV) {print $2}}' SERV=${SERVICE} ${SERVICES} | cut -d'/' -f1`
    if [ -z "$SOCKET_NUMBER" ]; then
      if [ -f ${OMNICONFIG}/options/global ]; then
        SOCKET_NUMBER=`cat ${OMNICONFIG}/options/global | awk '{if ( $1 ~ /^[pP][oO][rR][tT]/){split($0,a,"=");print a[2]} else{;}}'`
        if [ "$SOCKET_NUMBER" = "" ]; then
          SOCKET_NUMBER=5555
        fi
      else
        SOCKET_NUMBER=5555
      fi
    fi
  fi
  # grep for ${SOCKET_NUMBER} in /etc/services
  OC=`egrep "^[^#]*\ ${SOCKET_NUMBER}\/" "${SERVICES}" | awk '{print $1}' | uniq`
  if [ "${OC}" -a "${OC}" != "${SERVICE}" ]; then
    echo "ERROR:   Data Protector socket number ${SOCKET_NUMBER} is already occupied" >&2
    exit ${EXIT_FAILED}
  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
}



# #############################################################################
# Adds new OmniBack II entries to the /etc/services /etc/inetd.conf
# #############################################################################
update_services()
{
  echo "${SERVICE}  ${SOCKET_NUMBER}/tcp     # DATA-PROTECTOR " >> ${SERVICES}
  if [ -f /etc/xinetd.conf ]; then
    XINETDFILE=`cat /etc/xinetd.conf | grep includedir | awk '{ print $2 }'`
    if [ "${XINETDFILE}" != "" ]; then
      XINETDFILE=${XINETDFILE}/omni
    else
      XINETDFILE="/etc/xinetd.conf"
    fi
  fi
    if [ "${XINETDFILE}" != "" ]; then
      echo "service omni
  {
          socket_type             = stream
          protocol                = tcp
          wait                    = no
          user                    = root
          server                  = /opt/omni/lbin/inet
          server_args             = inet -log /var/opt/omni/log/inet.log
          disable                 = no
  }
  " >> ${XINETDFILE}
       /etc/rc.d/init.d/xinetd restart >/dev/null 2>/dev/null
       /etc/init.d/xinetd restart >/dev/null 2>/dev/null
    else
  echo "${SERVICE} stream tcp nowait root ${OMNIINET} inet -log ${OMNILOGCLIENT}/inet.log" >> ${INETDCONF}
  INETDPID=`ps -e | egrep '[/ ]inetd'| awk '{print $1}'`
  if [ "${INETDPID}" ]; then
     kill -HUP ${INETDPID} 2>/dev/null
     kill -HUP ${INETDPID} 2>/dev/null
  fi
       /etc/init.d/inetd restart >/dev/null 2>/dev/null
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" != "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 obsoleted filesets
   if [ "${OS}" = "HP-UX" ]; then
     for i in `swlist -l patch OMNIBACK-II.\*,r\<A.06.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.06.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.06.00 2>/dev/null | grep DATA-PROTECTOR >$DEVNULL
     if [ $? = 0 ]
     then
       swmodify -u DATA-PROTECTOR.\*,r\<A.06.00 DATA-PROTECTOR,r\<A.06.00 2>$DEVNULL
     fi
     swlist -l bundle B6960MA,r\<A.06.00 2>/dev/null | grep B6960MA >$DEVNULL
     if [ $? = 0 ]
     then
       swmodify -u B6960MA,r\<A.06.00 2>$DEVNULL
     fi
     swlist -l bundle B6960MJ,r\<A.06.00 2>/dev/null | grep B6960MJ >$DEVNULL
     if [ $? = 0 ]
     then
       swmodify -u B6960MJ,r\<A.06.00 2>$DEVNULL
     fi
     swlist -l bundle B6960BA,r\<A.06.00 2>/dev/null | grep B6960BA >$DEVNULL
     if [ $? = 0 ]
     then
       swmodify -u B6960BA,r\<A.06.00 2>$DEVNULL
     fi
   fi

   # remove obsoleted 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 obsoleted 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 obsoleted 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 obsoleted 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 old push packets
   DIR_LST=`find ${DATABASES}/ -name '*.*.*' 2>$DEVNULL`
   if [ "${DIR_LST}" ]; then
     for DIR in ${DIR_LST}; do
       if [ `basename "${DIR}"` != "A.06.00" ]; then
         rm -rf ${DIR}
       fi
     done
   fi
   # remove require.dat files
   DIR_LST=`find ${DATABASES}/ -name 'require.dat' 2>$DEVNULL`
   if [ "${DIR_LST}" ]; then
     for DIR in ${DIR_LST}; do
       if [ `echo "${DIR}" | grep -v "A.06.00"` ]; then
         rm -rf ${DIR}
       fi
     done
   fi
}



# ############################################################################
# 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
    do
      if [ -f "${OMNICONFIG}install/omni_info" ]
      then
        OUTPUT=`call_omnicc -remove_component_str $PAC $OMNIFORMAT install/omni_info  2>&1`
        if [ $? -ne 0 -a $? -ne 3 ]
        then
          echo "WARNING: $OUTPUT"
          echo "WARNING: Update of the install/omni_info file failed for $PAC!"
        fi
      fi

      if [ -f "${OMNICONFIGCLIENT}omni_info" ]
      then
        OUTPUT=`call_omnicc -remove_component_str $PAC $OMNIFORMAT client/omni_info  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
}


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

configer_perl

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

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

move_dirs

rm_component_str

check_omni_info_format

check_socket_number

create_dir

copy_newconfig
copy_newconfig_files

copy_cs_file

clean

update_services

# # 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
#preuninstall scriptlet (through /bin/sh):
