#!/sbin/sh
#########################################################################
# 									
#   File:	 decustomize
#   @(#) decustomize $Revision: 1.4 $ $Date: 93/02/26 09:07:39 $
#   Description: /etc/update decustomization script for HPXT-SUPPL fileset
# 
#########################################################################
#

set -a

PATH="/bin:/usr/bin:/etc:."
FILESET=HPXT-SUPPL

OS=`uname -r | cut -d"." -f 2`
if [ "$OS" = "10" -o "$OS" = "11" ]
then
  OS="hp10"
  INSTALLDIR="`echo ${SW_LOCATION} | sed 's!/$!!'`"
  XTHOME=${INSTALLDIR}/xthome
  . /usr/lbin/sw/control_utils
  if [ "$INSTALLDIR" = "/opt/hpxt/enware" ]
  then
    PANACOMDIR=/opt/hpxt
  else
    PANACOMDIR=$INSTALLDIR
  fi
else
  OS="hp"
  XTHOME="/usr/tftpdir/usr/lib/X11/700X"
fi

# Get environment variables 
#
ENVARDIRS="/opt/hpxt/enware/lbin /usr/bin/X11/700X/admin /tmp /usr/tmp last"
for ENVARDIR in $ENVARDIRS
do
  if [ $ENVARDIR = "last" ]
  then
    echo "WARNING: cannot find suitable env.vars file"
  fi

  if [ -f $ENVARDIR/env.vars ]
  then
    . $ENVARDIR/env.vars
    break
  fi
done



if [ "$OS" = "hp10" ]
then

  if [ -f /usr/bin/dcnodes -o -f /usr/sbin/dcnodes ]
  then
    dcnodes -q
    if [ $? -eq 2 ]
    then
        exit 0
    fi
  fi

fi

if [ "$OS" = "hp" ]
then
  if [ $# -eq 2 ]
  then
    exit 0
  fi
fi

RELEASE=`uname -r | sed -e 's/[^0-9.]//g' -e 's/^\.//' | cut -d. -f1`

#
# remove some files that update is unaware of
#

case $RELEASE in
  10)
    DIR=`echo ${INSTALLDIR}/lbin | sed 's!//!/!g'`
    ;;
  *)
    DIR=/usr/bin/X11/700X/admin
    ;;
esac

rm -rf $XTHOME.hpxt.*
rm -rf $XTHOME/ENWARE*


#--------- Remove eventual version links---------------#
#
rm -f $XTHOME.* > /dev/null 2>&1
rm -f /usr/lib/X11/700X.* > /dev/null 2>&1




FILES="GATEWAY SUBNETMASK XSESSIONCHOICE env.vars"
for FILE in FILES
do
  if [ -f $DIR/$FILE ]
  then
    rm ${DIR}/$FILE
  fi
done


#
# if HP-UX 9.x remove admin script from sam  "other util" menu
#


if [ $RELEASE = "09" -o $RELEASE = "9" ]
then
  SAMMENU=/usr/sam/custom/xtadm.ou
  rm -f $SAMMENU 2>&1
fi

if [ "$OS" = "hp10" ]
then
  egrep "^$PANACOMDIR" /etc/exports > /dev/null 2>&1
  if [ $? -eq 0 ]
  then
    TMPFILE="/tmp/exports.$$"
    sed "/[/]enware/d" /etc/exports > $TMPFILE
    if [ -s $TMPFILE ]
    then
      cp /etc/exports /tmp/exports.bu.$$
      echo "NOTE:    \"$PANACOMDIR\" line removed from /etc/exports"
      echo "         existing \"exports\" saved as /tmp/exports.bu.$$"
      cp $TMPFILE /etc/exports
      rm $TMPFILE
    fi
  fi

  egrep "$PANACOMDIR" /etc/inetd.conf > /dev/null 2>&1
  if [ $? -eq 0 ]
  then
    TMPFILE="/tmp/inetd.conf.$$"
    sed "/^tftp/s!$PANACOMDIR /usr/lib/X11/700X!!g" /etc/inetd.conf > $TMPFILE
    if [ -s $TMPFILE ]
    then
      cp /etc/inetd.conf /tmp/inetd.conf.bu.$$
      echo "NOTE:    Edited tftp entry in /etc/inetd.conf" >&2
      echo "         The $INSTALLDIR directory was removed from entry." >&2
      echo "         existing \"inetd.conf\" saved in /tmp/inetd.conf.bu.$$"
      cp $TMPFILE /etc/inetd.conf
      rm $TMPFILE
    fi
  fi

  SAMMENU=/usr/sam/lib/C/sam.cb
  egrep -i '^label.*ENWARE' $SAMMENU > /dev/null 2>&1
  if [ $? -eq 0 ]
  then
    TMPFILE="/tmp/sam.$$"
    sed '/^label.*ENWARE/,/command.*xtadm.sam/d' $SAMMENU > $TMPFILE
    if [ -s $TMPFILE ]
    then
      mv $SAMMENU $SAMMENU.bu.$$
      echo "NOTE:    Modifying sam menu .. removing entry for ENWARE admin."
      echo "         Existing sam menu file saved as $SAMMENU.bu.$$"
      echo "         To restore old sam menu type:"
      echo "         \"cp $SAMMENU.bu.$$ $SAMMENU\""
      cp $TMPFILE $SAMMENU
    fi
    rm $TMPFILE
  fi

  SAMDIR=$INSTALLDIR/lbin/sam
  if [ -d $SAMDIR ]
  then
    /usr/sam/bin/samreg -u	$SAMDIR
    rm -rf 			$SAMDIR
  fi
fi


#--------------------------------------------------------------------------##
# remove symlink if present
# and remove files that versioning support corrupted
#--------------------------------------------------------------------------##

if [ "$OS" = "hp10" ]
then

  ls /usr/lib/X11/700X/[mM]ulti*version > /dev/null 2>&1 | egrep -i 'multi' > /dev/null
  if [ $? -ne 0 ]
  then
    #
    # Remove "everything" except config and etc directory
    #
    mv $PANACOMDIR/enware/xthome/config /tmp/config.bu
    mv $PANACOMDIR/enware/xthome/etc /tmp/etc.bu
    rm -rf $PANACOMDIR/enware/xthome/*
    mv /tmp/config.bu $PANACOMDIR/enware/xthome/config 
    mv /tmp/etc.bu $PANACOMDIR/enware/xthome/etc 
  fi

  #--------- Remove eventual version trigger file---------------#
  #
  rm -f /usr/lib/X11/700X/[mM]ulti*version > /dev/null 2>&1

  if [ -h /opt/enware ]
  then
    rm /opt/enware
  fi
fi

exit 0
