#!/bin/sh

umask 022

set -a

###################################################
# pull in environment variables common to
# postinstall/postremove/request/and.. scripts
###################################################

ADMINDIR=/opt/hpxt/enware2/lbin
. $ADMINDIR/env.vars


if [ "$OS" = "sco" ]
then
  SMANDIR=$SYMLINK/usr/share/man/man1
  DMANDIR=/usr/man/cat.LOCAL
  MANPAGES="hpxt.xterm.LOCAL hpxt.hpterm.LOCAL hpxt.twm.LOCAL \
  hpxt.mwm.LOCAL vuerx.LOCAL vuerxrc.LOCAL hpxt.xflash.LOCAL \
  hpxt.flashcpimg.LOCAL dkmserver.LOCAL hpxt.xlock.LOCAL \
  hpxt.xclock.LOCAL hpxt.format.LOCAL"
else
  SMANDIR=/opt/hpxt/enware2/share/man
  DMANDIR=/usr/share/man
  MANPAGES="man1/hpxt.xterm.1 man1/hpxt.hpterm.1 man1/hpxt.twm.1 \
  man1/hpxt.mwm.1 man1/vuerx.1 man4/vuerxrc.4 man1/hpxt.ffm.1 \
  man1/dkmserver.1 man1/hpxt.xlock.1 man1/hpxt.SharedX.1 \
  man1/hpxt.whiteboard.1 man1/hpxt.xclock.1"
fi

# echo $MANPAGES
if [ "$COPYMAN" = "yes" ]
then
  #echo ""
  #echo $NL1 "Copy local client man pages into $DMANDIR ? $NL2"
  #REPLY=`line`
  REPLY="yes"
else
  REPLY="no"
fi

case $REPLY in
  y*|Y*)
    # MAN PAGES
    #################################################
    COPYMAN="yes"

    for i in $MANPAGES
    do
      if [ ! -f $SMANDIR/$i ]
      then
	echo cannot find $SMANDIR/$i
	continue
      fi
      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

#---------------------------------------------#
# Make some links for 10.0 style locale names
#
#---------------------------------------------#

LINK_SCRIPT="${ADMINDIR}/xtutil_nls_links"

if [ -x "$LINK_SCRIPT" ]
then
  $LINK_SCRIPT ADD
fi



#--------------------------------------------------------
# update directives local client info
#--------------------------------------------------------
#
PARTS="cclients"
for PART in $PARTS
do
  THISDIRECTIVE=$NEWDIR/bin/directives.$PART
  cat $NEWDIR/bin/directives | egrep -i directive | egrep -i "$PART" > /dev/null
  if [ $? -ne 0 ]
  then
    if [ -f $THISDIRECTIVE ]
    then
      cat $THISDIRECTIVE >> $NEWDIR/bin/directives
    else
      echo "WARNING: could not find $THISDIRECTIVE"
    fi
  fi
  rm  -f $THISDIRECTIVE
done



#
#-----------------------------------------------------------------------#
# If CDE seems to be installed then add local clients to CDE actions
#-----------------------------------------------------------------------#

CDEHOME=/usr/dt
AC_INSTALLSCRIPT="${ADMINDIR}/xtutil_add_lc_cde"
ACTIONDB="$ADMINDIR/hpns.dt"

if [ -d "$CDEHOME" -a -x "$AC_INSTALLSCRIPT" ]
then
  $AC_INSTALLSCRIPT $ACTIONDB
fi


#-------------------------------------------------------
# If ENWARE is installed:
# Merge app-defaults files for ENWARE and Netstation SW
#--------------------------------------------------
#
$ADMINDIR/xtutil_merge_app-defaults create

#--------------------------------------------------
# If Navio and/or 3270 is installed
# fix stuff that might have been overwritten
# when UPGRADING from 8.0 to 9.0
#--------------------------------------------------
#
$ADMINDIR/xtutil_fix_3270_navio_stuff

exit 0
