#!/bin/posix/sh
  #
  # xtutil_initenv
  #
  #  Determine system-specific parameters and send them to stdout
  #  as environment variable definitions.
  #

set -u
set -a

#
# This routine returns path where "product" is installed on 10.0
# 
# e:g  'get_install_path ENWARE' would return "/opt/enware" 
#       assuming enware is installed at /opt/enware
#     
#       
get_install_path ()
{
    case $# in
    1)  _prod_=$1
        ;;
    *)  echo "FAILURE"
        return 1
        ;;
    esac

    set -- $(/usr/sbin/swlist -l product -a location $_prod_ 2>/dev/null)
    while [[ $1 != $_prod_ && $# -gt 1 ]]
    do
        shift
    done

    if [[ $1 = $_prod_ ]]
    then
        _path_=$2
    fi
    echo ${_path_:-""}
}

# 
# This script starts from here
#

[ "${INITENV_DONE:-}" = "true" ] && exit 0

OS=`xtutil_get-os`

case $OS in

hp)


        PATH=/bin:/usr/bin:$LBINDIR:$SCRIPTDIR:$SCRIPTDIR/default

        NFS_STARTUP_CMD="/etc/netnfsrc"
        NFS_CMD_START_OPT=""
        NFS_CMD_STOP_OPT=""
        NFS_CONFIG_FILE="/etc/netnfsrc"

	TFTPUSER=tftp
	EXPORTS=/etc/exports
	PASSWD=/etc/passwd
	INETDCONF=/etc/inetd.conf
        NETNFSRC=/etc/netnfsrc
	INITDEFAULT=initdefault
	INITTAB=/etc/inittab
	TELINIT=/etc/telinit
	VUERC_ENTRY=/etc/vuerc
	VUERC=/etc/vuerc
	VUEINIT="\"vue :34:respawn:/etc/vuerc # VUE validation and invocation\""
	TFTPDIR=`nisUserEntry $TFTPUSER | awk -F: ' {print $6}' `

	MOUNTTABLE=/etc/checklist
	DFCMD="bdf"
	EXPORTFS=/usr/etc/exportfs

	XDMDIR=/usr/lib/X11/xdm
	XDMBIN=/usr/bin/X11/xdm
#	BOOTPTAB=/etc/bootptab		For now, inherited from env.vars
	NSLOOKUP=/usr/bin/nslookup
     
        INETD="/etc/inetd"
        INETD_START_OPT="-c"
	
	HOSTNAME=`hostname`
	TFTPGROUP=guest
	TFTPGROUPID=10
	TFTPINETDLINE="\"tftp     dgram   udp    wait    root    /etc/tftpd    tftpd\n\""
	TFTPPASSWD="*"
	TFTPGECOS="\"Trivial FTP user\""
	TFTPSHELL=/bin/false
	TFTPHOME=/usr/tftpdir
	BOOTPDINETDLINE="\"bootps dgram udp wait root /etc/bootpd bootpd\n\""

       [ $TFTPDIR = "/" ] && TFTPDIR=""

       BINDIR="$TFTPDIR/usr/lib/X11/700X/bin"
       RGBFILE="$TFTPDIR/usr/lib/X11/700X/rgb.txt"
       FONTDIR="$TFTPDIR/usr/lib/X11/700X/fonts"
       CONFIGDIR="$TFTPDIR/usr/lib/X11/700X/config"
       ETCDIR="$TFTPDIR/usr/lib/X11/700X/etc"

       NFSDIRS="\"$TFTPDIR $BINDIR $FONTDIR $CONFIGDIR $ETCDIR\""

       SYSLOG="/usr/adm/syslog"

	;;


 hp10) 

        NFS_STARTUP_CMD="/sbin/init.d/nfs.server"
        NFS_CMD_START_OPT="start"
        NFS_CMD_STOP_OPT="stop"
        NFS_CONFIG_FILE="/etc/rc.config.d/nfsconf"
        ALL_CONFIG_FILES="/etc/rc.config" 
     
        INITDEFAULT="initdefault"
        INITTAB="/etc/inittab"
        TELINIT="/sbin/init"
        VUERC="/usr/vue/bin/vuerc"
        VUERC_ENTRY="/usr/vue/bin/vuerc"
        VUEINIT="\"vue :4:respawn:/usr/vue/bin/vuerc # VUE validation and invocation\""

        MOUNTTABLE="/etc/fstab"
        DFCMD="bdf"
        EXPORTFS="/usr/sbin/exportfs"
        EXPORTS="/etc/exports"

        BOOTPTAB="/etc/bootptab"
        NSLOOKUP="/usr/bin/nslookup"
        HOSTNAME=`hostname`
      
        INETDCONF=/etc/inetd.conf        
        INETD="/usr/sbin/inetd"
        INETD_START_OPT="-c"
        BOOTPDINETDLINE="\"bootps dgram udp wait root /usr/lbin/bootpd bootpd\n\""


        #
        # Find the location of ENWARE product
        #

        #  ENWARE_ROOT=`get_install_path ENWARE`
        if [ -z $ENWARE_ROOT ]
        then 
          echo "Unable to get location of ENWARE product"
          exit 1
        fi
        
        #  On HPUX 10.0,
        #  tftpd operates in either of two modes or their combination.  The
        #  first mode requires a defined home directory for the pseudo-user
        #  tftp, and looks for files relative to that path.  The second
        #  mode requires one or more paths be specified on the command
        #  line, and allows access only to files whose paths match or begin
        #  with one of the command line specifications.  The first mode is
        #  backward-compatible with previous releases of HP-UX and supports
        #  somewhat tighter security.  The second mode is compatible with
        #  other vendors' implementations of tftpd and allows greater
        #  flexibility in accessing files.
        #
        #  Therefore we won't be creating tftp user on 10.0
        #

        TFTPINETDLINE="\"tftp         dgram  udp wait   root /usr/lbin/tftpd    tftpd $ENWARE_ROOT /usr/lib/X11/700X\n\""
        

        SYSLOG=/var/adm/syslog/syslog.log
        PATH=/sbin:/usr/sbin:/usr/lbin:/bin:/usr/bin:$LBINDIR:$SCRIPTDIR:$SCRIPTDIR/default

        ;;        
        
*)
	echo "Unknown OS type: \"$OS\""
	exit 1
	;;
esac




#
#		Assume we are not NIS master server
#		for service, hosts or passwd maps
#

HOSTNAME=`uname -n`

AMSMASTER=false
AMHMASTER=false
AMPMASTER=false
NISS=false
NISH=false
NISP=false

if [ -x /usr/bin/ypwhich ]
then
    NISHMASTER=`ypwhich -m hosts 2>&1`
    echo $NISHMASTER | fgrep 'ypwhich:' > /dev/null
    if [ $? -ne 0 ]
    then
	NISH=true
	if [ $NISHMASTER = $HOSTNAME ]
	then
	    AMHMASTER=true
	fi
    else
	unset NISHMASTER
    fi

    NISSMASTER=`ypwhich -m services 2>&1`
    echo $NISSMASTER | fgrep 'ypwhich:' > /dev/null
    if [ $? -ne 0 ]
    then
	NISS=true
	if [ $NISSMASTER = $HOSTNAME ]
	then
	    AMSMASTER=true
	fi
    else
	unset NISSMASTER
    fi

    NISPMASTER=`ypwhich -m passwd 2>&1`
    echo $NISPMASTER | fgrep 'ypwhich:' > /dev/null
    if [ $? -ne 0 ]
    then
	NISP=true
	if [ $NISPMASTER = $HOSTNAME ]
	then
	    AMPMASTER=true
	fi
    else
	unset NISPMASTER
    fi
fi



NLECHO=xtutil_nlecho_french


if [ -d /usr/tmp ]
then
   TMP="/usr/tmp"
elif
   [ -d /tmp ]
   then
      TMP="/tmp" ]
else
	echo "No /tmp or /usr/tmp working directories, - cannot continue."
	exit 1
fi

terminalDirectory=${CFGDIR:-"/usr/lib/X11/700X"}

#
# get domain name and nameserver IP address
#
if [ -f /etc/resolv.conf -a -f $NSLOOKUP ]
then
  DOMN=`egrep '^domain[ 	]' /etc/resolv.conf | head -1 | awk '{print $2}'`
  DOMA=`egrep '^nameserver[ 	]' /etc/resolv.conf | head -1 | awk '{print $2}'`
fi

if [ ! -z "${DOMA:-}" ]
then
	/bin/echo $DOMA | egrep '[0-9]' > /dev/null 2>&1
	if [ $? -ne 0 ]
	then
		unset DOMA
		DOMN=""
	fi
else
	unset DOMA
	DOMN=""
fi


DOMN=`/bin/echo $DOMN | sed -e 's/[.]*$//'`

if [ ! -z "${DOMN:-}" ]
then
	/bin/echo $DOMN | egrep '[a-z|A-Z]' > /dev/null 2>&1
	if [ $? -ne 0 ]
	then
		DOMN=""
		unset DOMA
	fi

	DOMN=".$DOMN"
else
	DOMN=""
	unset DOMA
fi

#
#
# Does bootp daemon seem to understand the ba tag
# 1) so we may broadcast queries using bootpquery
# 2) and put ba tags in bootptab
#
#
strings $BOOTPD | egrep 'ba -- broadcast address' > /dev/null
if [ $? -eq 0 ]
then
  #
  # yes, it seem to know about it, make a note for later
  #
  UNDERSTANDSBA="true"
else
  unset UNDERSTANDSBA
fi


INITENV_DONE=true
env|egrep -v "^PS1="|egrep -v "^PS2="

exit 0
















