#!/sbin/sh

#########################################################################
#
# Fix up stuff for Navio and 3270 if appropiate.
# Also fix up HP CDE 
#########################################################################
#
set -a

if [ "x$XTHOME" = "x" ]
then
  XTHOME=/opt/hpxt/enware2/xthome
fi

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

CFGDIR=$XTHOME/config

#---------------------------------------------------------------------
# update directives with Navio info if it got overwritten by install
# (it does on AIX)
#----------------------------------------------------------------------
#
if [ -d /opt/hpxt/enware2/Navio_3.0 ]
then
  egrep -i 'navio.directives' $DIRECTIVES > /dev/null
  if [ $? -ne 0 ]
  then
    echo "INFO:   updating directives file with Navio information"
    echo "#"                                                >> $DIRECTIVES
    echo "# BEGIN NAVIO directives lines"                   >> $DIRECTIVES
    echo 'include $(NsRoot)/Navio_3.0/bin/navio.directives' >> $DIRECTIVES
    echo "# END NAVIO directives lines"                     >> $DIRECTIVES
    echo "#"                                                >> $DIRECTIVES
  fi
fi

#---------------------------------------------------------------------
# update cfg files with Navio info if it got overwritten by install
# (it does on AIX)
#----------------------------------------------------------------------
#
if [ -d /opt/hpxt/enware2/Navio_3.0 ]
then
  for FILE in $CFGDIR/sample.cfg $CFGDIR/default.cfg
  do
     egrep -i navio.cfg $FILE > /dev/null
     if [ $? -ne 0 ]
     then
       echo "#"                                            >> $FILE
       echo "# BEGIN NAVIO config lines"                   >> $FILE
       echo 'include $(NsRoot)/Navio_3.0/config/navio.cfg' >> $FILE
       echo "# END NAVIO config lines"                     >> $FILE
       echo "#"                                            >> $FILE
     fi
  done
fi



#---------------------------------------------------------------------#
# Correct problem where navio links created dynamically were added
# using xtutil_add_file. The problem with this is that on HP-UX 9.0
# this link will not be updated when updating to Netstation 9.0
#---------------------------------------------------------------------#
#
NAVIOHOME=/opt/hpxt/enware2/Navio_3.0
HOST_BIN=$NAVIOHOME/hostbin

if [ -f $HOST_BIN/hpxt.navio ]
then
  echo "INFO:   updating Navio file links"
  mv $HOST_BIN/hpxt.navio $HOST_BIN/hpxt.navio.obsolete
  rm -f $HOST_BIN/hpxt.navio.obsolete
  mv /opt/hpxt/enware2/bin/hpxt.navio /opt/hpxt/enware2/bin/hpxt.navio.obsolete
  rm -f /opt/hpxt/enware2/bin/hpxt.navio.obsolete
  ln /opt/hpxt/enware2/bin/peer $HOST_BIN/hpxt.navio
  ln /opt/hpxt/enware2/bin/peer /opt/hpxt/enware2/bin/hpxt.navio
fi

#
# Update CDE action DB
#

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

if [ -f $ACTIONDB -a -f $HOST_BIN/hpxt.navio ]
then
  STUB=/etc/dt/appconfig/appmanager/C/Netstations
  if [ -d $STUB ]
  then
    cp $STUB/HpnsAdmin $STUB/HpnsBrowser > /dev/null 2>&1
    touch     $STUB/HpnsBrowser
    chmod 555 $STUB/HpnsBrowser
  fi

  egrep HpnsBrowser $ACTIONDB > /dev/null
  if [ $? -ne 0 ]
  then
cat <<EOF >> $ACTIONDB

ACTION HpnsBrowser
{
  DESCRIPTION      Launches HP Navio Browser
  WINDOW_TYPE      NO_STDIO
  ICON             enware
  EXEC_STRING      $HOST_BIN/hpxt.navio
}

EOF
  fi
fi


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

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

if [ -f $ACTIONDB -a -f $HOST_BIN/hpxt.navio ]
then

  STUB=/opt/hpxt/enware2/usr/vue/config/types/tools/Netstations
  if [ -d $STUB ]
  then
    cp $STUB/HpnsAdmin $STUB/HpnsBrowser > /dev/null 2>&1
    touch     $STUB/HpnsBrowser
    chmod 555 $STUB/HpnsBrowser
  fi

  egrep HpnsBrowser $ACTIONDB > /dev/null
  if [ $? -ne 0 ]
  then

cat <<EOF >> $ACTIONDB

ACTION HpnsBrowser
        L-ICON          enware.l
        S-ICON          enware.s
        TYPE            COMMAND
        EXEC-STRING      $HOST_BIN/hpxt.navio
        WINDOW-TYPE     NO-STDIO
        DESCRIPTION     The HpnsBrowser action will start a local browser \
executing on your HP Netstation.
END

EOF
  fi
fi





#---------------------------------------------------------------------
# update 3270 peer if present
#----------------------------------------------------------------------
#
TN3270DIR=/opt/hpxt/enware2/xthome/tn3270
PEERDIR=/opt/hpxt/enware2/bin
if [ -d $TN3270DIR ]
then
  echo "INFO:   updating 3270 file links"
  mv $PEERDIR/hpxt.3270_peer $PEERDIR/hpxt.3270_peer.obsolete
  rm -f $PEERDIR/hpxt.3270_peer.obsolete
  mv $TN3270DIR/bin/hpxt.3270_peer $TN3270DIR/bin/hpxt.3270_peer.obsolete
  rm -f $TN3270DIR/bin/hpxt.3270_peer.obsolete
  cp $PEERDIR/peer $PEERDIR/hpxt.3270_peer
  ln $PEERDIR/hpxt.3270_peer $TN3270DIR/bin/hpxt.3270_peer
fi


#---------------------------------------------------------------------
# update directives with 3270 info if it got overwritten by install
# (it does on AIX)
#----------------------------------------------------------------------
#
if [ -d $TN3270DIR ]
then
  egrep -i 'directives.*3270' $DIRECTIVES > /dev/null
  if [ $? -ne 0 ]
  then
    echo "INFO:   updating directives file with 3270 information"
    echo "#"                                                      >> $DIRECTIVES
    echo "# directives entries for 3270"                          >> $DIRECTIVES
    echo "noconfig Driver xt3270Ext=drvr/3270Ext"                 >> $DIRECTIVES
    echo 'App xtn3270ui=xtn3270ui "3270 Emulator User Interface"' >> $DIRECTIVES
    echo 'App xtnp3270=xtnp3270   "3270 Emulator TCP/IP Engine"'  >> $DIRECTIVES
    echo "#"                                                      >> $DIRECTIVES
  fi
fi



#---------------------------------------------------------------------
# update CDE peer if present
#----------------------------------------------------------------------
#
PEERDIR=/opt/hpxt/enware2/bin
DTWM=$PEERDIR/hpxt.dtwm
DTTERM=$PEERDIR/hpxt.dtterm

if [ -f $DTWM ]
then
  echo "INFO:   updating CDE file links"
  mv $DTWM   $DTWM.obsolete
  mv $DTTERM $DTTERM.obsolete
  rm -f      $DTWM.obsolete
  rm -f      $DTTERM.obsolete
  ln $PEERDIR/peer $DTWM
  ln $PEERDIR/peer $DTTERM
fi


#---------------------------------------------------------------------
# update directives with CDE info if it got overwritten by install
# (it does on AIX)
#----------------------------------------------------------------------
#
if [ -f $DTWM ]
then
  egrep -i 'cde.*directives' $DIRECTIVES > /dev/null
  if [ $? -ne 0 ]
  then
    echo "INFO:   updating directives file with CDE information"
    echo "#"                                                      >> $DIRECTIVES
    echo "# START CDE DIRECTIVES"                          >> $DIRECTIVES
    echo "App dtterm=\"dtterm -title Netstation_dtterm\" \"dtterm rlogin session\""                 >> $DIRECTIVES
    echo "App tdtterm=\"dtterm -dev /dev/telnet -title Netstation_dt_telnet_term\" \"dtterm telnet session\""                 >> $DIRECTIVES
    echo "# END CDE DIRECTIVES"                                   >> $DIRECTIVES
    echo "#"                                                      >> $DIRECTIVES
  fi
fi


exit 0
