#!/bin/sh

umask 022

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

ADMINDIR=$TOPDIR/usr/bin/X11/700X/admin
. $ADMINDIR/env.vars


if [ "$OS" = "sco" ]
then
  SMANDIR=$TOPDIR/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=$TOPDIR/usr/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.xflash.1 \
  man1/hpxt.flashcpimg.1 man1/dkmserver.1 man1/hpxt.xlock.1 \
  man1/hpxt.xclock.1 man1/hpxt.format.1 man1/hpxt.olwm.1 \
  man1/hpxt.shelltool.1 \
  man1/hpxt.cmdtool.1 man1/hpxt.clock.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_add_nls_links"

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


#--------------------------------------------------------
# update modules.ld with local client info
#--------------------------------------------------------
#
PARTS="clients xlock xclock xtouch"
for PART in $PARTS
do
  cat $NEWDIR/bin/modules.$PART >> $NEWDIR/bin/modules.ld
  rm -f $NEWDIR/bin/modules.$PART
done



#make links from hpxt.blah to xt.blah for aptrex users

if [ "X$APTREX_INSTALLDIR" != "X" ]
then 
    if [ -d $APTREX_INSTALLDIR/bin.aptrex ]
    then
        CLIENT_DIR=/usr/bin/X11/700X
        (cd $APTREX_INSTALLDIR/bin.aptrex ;
         for i in `ls xt.*`
         do 
          if [ -x $CLIENT_DIR/"hp$i" ] 
          then
             ln -s $CLIENT_DIR/"hp$i" $CLIENT_DIR/$i 
          else 
             cp $i $CLIENT_DIR
          fi
         done
       )
    fi
 

   if [ -d $APTREX_INSTALLDIR/man.aptrex ]
   then
       for i in `ls $APTREX_INSTALLDIR/man.aptrex/man1`
       do
         if [ -f $TOPDIR/usr/share/man/man1/hp$i ]
         then
            ln  $TOPDIR/usr/share/man/man1/hp$i $TOPDIR/usr/share/man/man1/$i > /dev/null 2>&1
         else
            cp $APTREX_INSTALLDIR/man.aptrex/man1/$i $TOPDIR/usr/share/man/man1 >/dev/null 2>&1
         fi
       done 
       for i in `ls  $APTREX_INSTALLDIR/man.aptrex/man1m`
       do
         if [ -f $TOPDIR/usr/share/man/man1/hp$i ]
         then
            ln  $TOPDIR/usr/share/man/man1/hp$i $TOPDIR/usr/share/man/man1/$i > /dev/null 2>&1
         else
            cp $APTREX_INSTALLDIR/man.aptrex/man1m/$i $TOPDIR/usr/share/man/man1 > /dev/null 2>&1
         fi
      done 
   fi 
 fi


#
#-----------------------------------------------------------------------#
# 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/hpxt.dt"

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

 exit 0
