#!/bin/sh

#########################################################################
# 									
#   File:	 customize
#   @(#) customize $Revision: 1.4 $ $Date: 93/02/17 14:52:10 $
#   Description: /etc/update customization script for HPXT2-JRE fileset
# 
#########################################################################
#

umask 022
set -a
PATH="/bin:/usr/bin:/etc:/usr/sbin:/sbin:/usr/ucb:/usr/ccs/bin:."
FILESET=HPXT2-JRE
THIS_FILESET=$FILESET
PRODUCT=hpns_java

#
# Get environment variables as setup earlier in prerequisite fileset    
#

OS=`uname`

if [ "$OS" != "AIX" -a "$OS" != "HI-UX" ]
then
  ENVARDIRS="/opt/hpxt/enware2/lbin /opt/hpxt/enware2/bin /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
fi

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


RMSCRIPT=/opt/hpxt/enware2/lbin/xtutil_rm-file
ADDSCRIPT=/opt/hpxt/enware2/lbin/xtutil_add-file

XTHOME=/opt/hpxt/enware2/xthome
CFGDIR=$XTHOME/config
JREHOME=/opt/hpxt/enware2/Java_1.1.2
USERJAVAHOME=/opt/hpxt/enware2/user_java
HOST_BIN=$JREHOME/hostbin


#--------------------------------------------------#
#   Add peer links for JVM, appletviewer, debugger
#--------------------------------------------------#
#

HOST_BIN=$JREHOME/hostbin

PEERS="hpxt.java_peer hpxt.appletviewer_peer"
for PEER in $PEERS
do
  rm -f                                 $HOST_BIN/$PEER
  ln /opt/hpxt/enware2/bin/peer         $HOST_BIN/$PEER
  if [ $OS = "hp10" -o "$OS" = "hp" ]
  then
    $ADDSCRIPT                          $HOST_BIN/$PEER
  fi
done


#--------------------------------#
#   Update directives file
#--------------------------------#
#

if [ "x$NEWDIR" = "x" ]
then
  DIRECTIVES=${XTHOME}/bin/directives
else
  DIRECTIVES=${NEWDIR}/bin/directives
fi

egrep -i 'java.directives' ${DIRECTIVES} > /dev/null
if [ $? -ne 0 ]
then
  cp ${DIRECTIVES} ${DIRECTIVES}.orig.$$
  cat ${JREHOME}/bin/directives.java                 >>     ${DIRECTIVES} 
  if [ $OS = "hp10" -o "$OS" = "hp" ]
  then
    $ADDSCRIPT ${DIRECTIVES}.orig.$$
    $ADDSCRIPT ${DIRECTIVES} 
  fi
fi

if [ $OS = "hp10" -o "$OS" = "hp" ]
then
  $RMSCRIPT ${JREHOME}/bin/directives.java 
fi

if [ "$OS" != "AIX" ]
then
  rm -f ${JREHOME}/bin/directives.java 
fi


#---------------------------------------------------------------------#
# Create default config file with java information
# Also create a sample.cfg 
#---------------------------------------------------------------------#
#
if [ ! -f $CFGDIR/default.cfg ]
then
  cp $CFGDIR/sample.cfg $CFGDIR/default.cfg

  if [ $OS = "hp10" -o "$OS" = "hp" ]
  then
    $ADDSCRIPT		$CFGDIR/default.cfg
  fi
fi

for FILE in $CFGDIR/default.cfg $CFGDIR/sample.cfg
do
  egrep java.cfg $FILE > /dev/null
  if [ $? -ne 0 ]
  then
    cp $FILE $FILE.orig.$$

    if [ $OS = "hp10" -o "$OS" = "hp" ]
    then
      $ADDSCRIPT		$FILE.orig.$$
    fi

    cat ${JREHOME}/config/java.appendix.cfg              >> $FILE

    if [ $OS = "hp10" -o "$OS" = "hp" ]
    then
      $ADDSCRIPT		$FILE
    fi

  fi
done

if [ $OS = "hp10" -o "$OS" = "hp" ]
then
    $RMSCRIPT		${JREHOME}/config/java.appendix.cfg
fi

if [ "$OS" != "AIX" ]
then
  rm -f			${JREHOME}/config/java.appendix.cfg
fi



#---------------------------------------------------------------------#
# Create user_java stuff - FOR BETA TEST ONLY
(cd ${JREHOME}; find user_java -depth |cpio -pdm /opt/hpxt/enware2/ )

#---------------------------------------------------------------------#
# Optionally create directories for user-defined Java stuff 
#
for USERJAVADIR in . hostbin bin lib
do
    if [ ! -d ${USERJAVAHOME}/${USERJAVADIR} ]
    then
	mkdir -p ${USERJAVAHOME}/${USERJAVADIR} > /dev/null 2>&1
	chown root ${USERJAVAHOME}/${USERJAVADIR}
	chgrp bin ${USERJAVAHOME}/${USERJAVADIR}
    fi
done

#---------------------------------------------------------------------#
# Optionally create directives file for user-defined Java stuff
if [ ! -s ${USERJAVAHOME}/bin/user_java.directives ]
then
    cp ${JREHOME}/user_java/bin/user_java.directives ${USERJAVAHOME}/bin/user_java.directives
    if [ $OS = "hp10" -o "$OS" = "hp" ]
    then
       $ADDSCRIPT ${USERJAVAHOME}/bin/user_java.directives
    fi
fi


if [ $OS = "hp10" -o "$OS" = "hp" ]
then
    $RMSCRIPT		${JREHOME}/user_java/bin/user_java.directives
    $RMSCRIPT		${JREHOME}/user_java/bin
    $RMSCRIPT		${JREHOME}/user_java
fi


if [ "$OS" != "AIX" ]
then
  rm -rf			${JREHOME}/user_java
fi


# -------------------------------#
# Update CDE action DB
# -------------------------------#
#

ACTIONDB=/etc/dt/appconfig/types/C/hpns.dt

if [ -f $ACTIONDB -a -d /usr/dt/bin ]
then

  STUB=/etc/dt/appconfig/appmanager/C/Netstations
  if [ ! -d $STUB ]
  then
    mkdir -p $STUB
  fi

  cp $STUB/HpnsAdmin $STUB/HpnsJava > /dev/null 2>&1
  touch     $STUB/HpnsJava
  chmod 555 $STUB/HpnsJava
  rm -f $STUB/HpnsJavaAppViewer
  if [ $OS = "hp10" -o "$OS" = "hp" ]
  then
    $ADDSCRIPT $STUB/HpnsJava
  fi

fi

# --------------------------------#
# Update VUE action DB
# --------------------------------#

ACTIONDB=/opt/hpxt/enware2/usr/vue/types/hpns.vf

if [ -f $ACTIONDB -a -d /usr/vue/bin ]
then

  STUB=/opt/hpxt/enware2/usr/vue/config/types/tools/Netstations
  if [ -d $STUB ]
  then
    if [ ! -f $STUB/HpnsJava ]
    then
      cp $STUB/HpnsAdmin $STUB/HpnsJava > /dev/null 2>&1
      touch     $STUB/HpnsJava
      chmod 555 $STUB/HpnsJava
      rm -f $STUB/HpnsJavaAppViewer
      if [ $OS = "hp10" -o "$OS" = "hp" ]
      then
        $ADDSCRIPT $STUB/HpnsJava
      fi
    fi
  fi
fi

# --------------------------------#
# Install man pages on suns
# --------------------------------#

if [ "$OS" = "SunOS" -o "$OS" = "sun4" -o "$OS" = "sun5" ]
then
  SMANDIR=/opt/hpxt/enware2/share/man
  DMANDIR=/usr/share/man
  MANPAGES="man1/hpxt.java.1 man1/hpxt.appletviewer.1"

  if [ "$COPYMAN" = "yes" ]
  then
    REPLY="yes"
  else
    REPLY="no"
  fi

  case $REPLY in
    y*|Y*)
      for i in $MANPAGES
      do
        cp $SMANDIR/$i $DMANDIR/$i > /dev/null
        if [ $? -ne 0 ]
        then
          echo ""
          echo "Copy of man page failed."
          echo "$DMANDIR is probably nfs mounted or mounted read-only."
          echo "you can do this copy manually after installation"
          echo ".. continuing"
          echo ""
          break
        fi
        chmod 444  $DMANDIR/${i}
        chown root $DMANDIR/${i}
        chgrp bin  $DMANDIR/${i}
      done
      ;;
  esac
fi



if [ "$OS" = "AIX" ]
then
    #
    # there is a problem on AIX where the installation tool does not
    # like $ and ~ in file names (demo directory has got some of those)
    # so create these files here instead.
    
    mkdir -p ${JREHOME}/demo
    chown bin ${JREHOME}/demo
    chgrp bin ${JREHOME}/demo
    chmod 755 ${JREHOME}/demo


    cd ${JREHOME}/demo
    tar xf ../demo.tar
    rm ../demo.tar
    touch ../demo.tar
    find . -type d | xargs -i chmod 755 {}
    find . -type f | xargs -i chmod 444 {}
    find . -type f | xargs -i chgrp bin {}
    find . -type d | xargs -i chgrp bin {}
    find . -type f | xargs -i chown bin {}
    find . -type d | xargs -i chown bin {}
fi


exit 0
