#!/bin/sh
#
###############################################################################
#
# Annex Installation Script
#
# Usage: install-annex [-f] [-b] [-d]
# 			-b = brief mode (default = verbose mode)
# 			-d = debug on
# 			-f = allow fixed config (default = false)
#
# Based upon rn's "Configure", by Larry Wall
#
# This is $Revision: 1.166.100.2 $
#
###############################################################################
#
# Edited to reflect the R6.2 branch of the tree.
#
###############################################################################
#
# Edited 9/15 for                   Pyramid changes (from pyramid)
#                                   Also corrections of historical problems
#
###############################################################################
#
# Edited 9/4/92 to make changes for NCR Tower (copy socket.h to src/inc/sys)
#                                   Sequent PTX Man pages
#                                   Unisys
#                                   SGI (?)
#
###############################################################################
#
# Edited to add additional binary install options.... 7/16/92
#
###############################################################################
#
# Edited to reflect B7.0.5 testing.... 7/9/92
#       NCR - 3445
#       DELL - 325
#       SUN  - (pogo)
#
# Edited to reflect B7.0 changes.... 5/22/92
#
# Edited for Ultrix -- 07OCT92 by jdc -- notes to script hackers:
#	- the sh "read" command doesn't like more than one space between
#	  tokens, unlike other Unixes.
#	- the sh "eval" command is apt to execute things unexpectedly.
#	  Use eval $iname=`echo $that` instead of eval $iname=$that.
#
###############################################################################

###############################################################################
#
# sanity checks
#
# Setup path so that it is functional
#
PATH='.:/bin:/usr/bin:/usr/ucb:/usr/etc:/etc:/usr/local/bin:/usr/local:/usr/lbin:/usr/BSDbin:/usr/5bin:/usr/ccs/bin:/usr/sbin'
#
# export path, if fails then isn't being run under a shell.
# force the issue and issue a shell.
#
export PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh $0; kill $$)

cwd=`pwd`

#
###############################################################################
#
# reasonable defaults
#
############
allowfixedconfig=false
didfixedconfig=false

#
# default values for arguments:
#  default verbose mode
#  default no-debug messages
#  default nomake is false 
#          (i.e. there is a C compiler on system)
#
brief=false
debug=false
nomake=false
suicidal=false

#
# Look for these UNIX programs; they are required
#
loclist="ar awk cat cc chown chmod cp date echo expr grep mkdir mv ranlib rm sed"

#
# Look for these UNIX programs; they are optional
#
trylist="inetd pack strip"

#
# We look for these functions
#
funclist="bcopy(0,0,0) bzero(0,0) dup2(0,0)
	  gethostbyname(0) gethostbyaddr(0,0,0) gethostname(0,0)
          getservbyname(0,0) htonl(0) htons(0) ntohl(0) ntohs(0)
          inet_addr(0) inet_ntoa(0) sigmask(0) strncasecmp(0,0,0)
	  strcasecmp(0,0)"


#
# Socket type API functions, not needed for TLI.
#
sfunclist="recvfrom(0,0,0,0,0,0) recvmsg(0,0,0) sendmsg(0,0,0)
	sendto(0,0,0,0,0,0)"

#
# set flag so that if ntoh files are needed a Warning will
# be printed.
#
warning_ntoh=true

#
#  initialize constants
#
n='' c='' startsh=''
usebinary=false

#
# generic manual page handling
#
mantype='' manlayout='' mansrc='' manext=''
dfltinst=n
# This is for handling man versus cat directory names.
MAN="man"
packed=false

#
# build/compile parameters
#
ANXSRC="libannex netadm na erpcd"
CH_PASSWD="ch_passwd"
SUPSRC="ien-116 timserver"
# SOCSRC not for XENIX.... we will now allow for UMAX V.
SOCSRC="aprint"
ALLSRC="$ANXSRC $SUPSRC $SOCSRC"
SRCDIRS=""
nortelnet=false

INSTALL_INITD=""
OTHERINSTALL="install-bfs"

DEF="#define"

# -Ipath include directory list.
INCLUDES=''

# -lname library search list.
LIBFLAG=''

# -Dname symbols and compiler flags needed for this platform.
HWFLAG=''

# Default installation directory, if any.
DEFDIR=''

# Any files listed here will be included by src/inc/config.h.
INCFILES="sys/types.h"

instdir=''
system=''
os_type='' netware_type='' hw_type=''
os_default=''
nettype="network"
hp_os=''
LIBANX_C="erpc_subr.c srpc.c api_if.c"
LIBANX_O="erpc_subr.o srpc.o api_if.o"
tryLIBFLAG=
ERPCD="/usr/spool/erpcd"
USER_BFS="$ERPCD/bfs"

tempfiles=".loc .filexp .myread .ckfunc .ckincl .ckfunc.o .ckincl.o .needsome .ckincs.h .mkpath .contains .ckalign1 .ckalign2"

#
# default release information
# may be changed if a "release" file exists.
#
box=annex Box=Annex type= TYPE= release=R relword= vers=R7.1

#################################################################
#
# check arguments passed at command line.
#
# Debug            : used in debug of script or new install
# Brief            : output less to the user...quicker...quieter
# allowfixedconfig : is an OEM flag. if true then check for oem
#                    files to do special install "stuff"
#
# n.b. allowfixedconfig condition has been changed (11/13) so 
#      that if the flag is used on the "% install-annex" command 
#      line then the flag will be set.
#################################################################
for arg
do
    case "$arg" in
    -e)
# Just leave this undocumented.  We can use it when necessary.
	(
	echo "Automatic install-annex bug reporting mechanism."
	echo " "
	tar -cf - errors | compress -c | uuencode errors.tar.Z
	) | /usr/bin/mail annex-support@xylogics.com
	exit 0
	;;
    -b)
	brief=true
	;;
    -f)
	allowfixedconfig=true
	;;
    -d)
	debug=true
	;;
    -k)
# Allows user to force installation in an inappropriate directory.
	suicidal=true
	;;
    *)
	echo "Unknown flag $arg"
	exit 1
	;;
    esac
done

if $debug
then
    echo "Brief=" $brief
    echo "Debug=" $debug
    echo "Allow fixed config=" $allowfixedconfig
fi

# This has to be done before any files are modified!
case "$cwd" in
/u*/*)
    ;;
/u*|/)
    if $suicidal
    then
	if $debug
	then
	    echo "Installing in $pwd against my better judgment."
	fi
    else
	cat << ETEXT
You are currently in ${cwd}.  Installing here might be quite dangerous,
and may destroy $cwd/bin.  Using /usr/annex as the installation
directory is recommended.

If you want to install here anyway, specify the -k switch on the command
line.
ETEXT
	exit 1
    fi
    ;;
esac

# Remove and recreate "errors" directory for debugging and testing
# install problems.
rm -rf errors > /dev/null 2>&1
mkdir errors > /dev/null 2>&1

# Redirect this shell's stderr output to a file so that any commands
# executed without redirection will save their messages here.
# Nifty, eh?
exec 2> errors/shell

#
###############################################################################
#
# Include the subroutines now....
########################################################################3
#
# read in release information (if file exists)
#
if [ -f release ]
then
    . ./release
fi

#
# read in possible OEM configuration
# if allowfixedconfig == true and oem file exists
#   then set majormode = configure
#        execute the oem script
#
if $allowfixedconfig && [ -f oem ]
then
    majormode=configure
    . ./oem
fi

#
# Tell user to use a shell command to run install script.  OEM may
# change "box" parameter, so this has to be done after the OEM stuff.
#
if [ ! -t 0 ]
then
    echo "Say './install-$box' or 'sh install-$box', not 'sh < install-$box'"
    exit 1
fi

#
# If running an OEM install, set verbose mode.
#
# if allowfixedconfig == true, don't change brief
# if allowfixedconfig == false, then set brief = false
#
if $allowfixedconfig
then
    brief=false
fi

package=$Box
if [ "$TYPE" ]
then
    package=$package'-'$TYPE
fi
if [ "$vers" ]
then
    package=$package' '$vers
fi

# 
# if this is an X25 install then clear the CH_PASSWD parameter
# i.e. don't compile ch_passwd.
#
case $type in
[xX]*25)
    CH_PASSWD=""
    ;;
esac
#
#########################################################################
#
# Introductory instructions
#
# if didfixedconfig == true and oem file exists
#   then do oem script with intromsg set
#
if $didfixedconfig && [ -f oem ]
then
    majormode=intromsg
    . ./oem
# 
# if brief mode == true and majormode doesn't == introdone
#   then ...
#
    if $brief && [ "$majormode" != introdone ]
    then
	echo " "
	echo "Installing the $package host utilities on your"
	echo "$desc."
	echo " "

	if [ "$toinstall" = "y" ]
	then
	    insmsg=" installed" inssep=" and" bldsep=","
	fi
	if [ "$tobuild" = "y" ]
	then
	    bldmsg=" compiled" bldsep=${bldsep-" and"}
	fi 

	echo "Everything will be automatically" \
	    "configured$bldsep$bldmsg$inssep$insmsg"
	[ "$place" ] && insinmsg="with the utilities installed in"
	place="${DEFDIR-${instdir-someplace}}"
	echo "for your system$insinmsg$place."
	echo " "
	echo "If you don't wish to use the default configuration,"
	echo "then rerun `basename $0` with the \"-f\" option."
	echo " "
    fi
fi

#
# Long introductory instructions
#
# if brief == true then don't display following text
#
$brief || cat << EOH

         $package Host Utilities Installation Script

************************************************************************
*** It is recommended that you run this install-annex script as root.***
************************************************************************

This installation shell script will examine your system and possibly
ask you questions to generate the needed configuration to allow you
to compile the $Box host utilites.

You can abort the script at any time and restart it without any 
ill effects.  Once install-$box completes the configuration section,
you will only need to use

         "make all"    and    "make install"

from the "src" directory to later re-build or re-install the utilities.

At any question prompt you can escape to a shell by typing "!".
When you exit that shell you will bounce back to the question prompt.
Many of the questions will have default answers in square brackets;
typing carriage return will give you the default.

EOH

#
###############################################################################
#
# some greps do not return status, grrr.
echo "grimblepritz" > .grimble
c=true
if grep blurfldyick .grimble >/dev/null 2>errors/grep-test
then
    :
else
    if grep grimblepritz .grimble >/dev/null 2>>errors/grep-test
    then
	c=false
    fi
fi
rm -f .grimble
echo "" > errors/grep-run
if $c
then
    cat > .contains << EOSS
grep \$* > .greptmp 2>>errors/grep-run && \
	cat .greptmp >/dev/null 2>>errors/grep-run && \
	test -s .greptmp 1>>errors/grep-run 2>&1 && exit 0
exit 1
EOSS
else
    cat > .contains << EOSS
grep \$* >/dev/null 2>>errors/grep-run && exit 0
exit 1
EOSS
fi
chmod 755 .contains

# first determine how to suppress newline on echo command
(echo "hi there\c" ; echo " ") >.echotmp
if ./.contains c .echotmp
then
    n='-n'
    c=''
else
    n=''
    c='\c'
fi
rm -f .echotmp

#
###############################################################################
#

if $brief || [ -t 1 ]
then
    echo $n "Type carriage return to continue.  Your cursor should be here-->$c"
    read ans
fi

#
###############################################################################
#
# Now set up to do reads with possible shell escape
#
echo " " > errors/userinput
cat > .myread << EOSC
cont=true
echo "\$rp" >> errors/userinput
while \$cont
do
    echo $n "\$rp $c"
    read ans
    case "\$ans" in
    !)
	sh
	echo " "
	;;
    !*)
	sh -c "\$ans"
	echo " "
	;;
    *)
	cont=false
    esac
    echo ">> '\$ans'" >> errors/userinput
done
rp='Your answer:'
EOSC

#
###############################################################################
#

echo " "
echo "Beginning configuration."

echo " "
echo "Locating common programs..."

#
###############################################################################
#
pth="/bin /usr/bin /usr/ucb /usr/local /usr/local/bin /usr/lbin /usr/etc /etc /usr/lib /usr/ccs/bin /usr/cs/bin"
echo " " > errors/locator
cat > .loc << EOSC
$startsh
thing=\$1
shift
dflt=\$1
shift
echo "Locating \$thing in \$*" >>errors/locator
for dir
do
    case "\$thing" in
    ".")
	if test -d \$dir 2>>errors/locator
	then
	    echo \$dir
	    exit 0
	fi
	;;
    *)
	if test -f \$dir/\$thing 2>>errors/locator
	then
	    echo \$dir/\$thing
	    exit 0
	fi
	;;
    esac
done
echo \$dflt
exit 1
EOSC
chmod 755 .loc

#
#####################################################################
#
# If brief is set then don't print info, else print status of search
#
#####################################################################
for file in $loclist
do
    xxx=`./.loc $file $file $pth`
    case "$xxx" in
    /*)
	$brief || echo $file is in $xxx.
	;;
    ranlib)
	$brief || echo "I don't find ranlib; assuming it does not need to be run on a library"
	xxx="echo done with library"
	;;
    cc)
	echo "I will not be able to compile the tools without a C compiler"
	nomake=true
	;;
    *)
	$brief || echo "I don't know where $file is.  I hope it's in my PATH."
	;;
    esac
    eval $file=\"$xxx\"
    $brief && echo $n ".$c"
done

#
#######################################################################
#
$brief || echo " "
$brief || echo "Don't worry if any of the following aren't found..."
ans=offhand
for file in $trylist
do
    xxx=`./.loc $file $file $pth`
    eval $file=\"$xxx\"
    case "$xxx" in
    /*)
	$brief || echo $file is in $xxx.
	;;
    *)
	$brief || echo "I don't see $file out there, $ans."
	ans=either
	;;
    esac
    $brief && echo $n ".$c"
done

#
###############################################################################
# What?
if [ "$inetd" != "inetd" ]
then
	HWFLAG="$HWFLAG -DINETD"
fi

$brief && echo " "

#
###############################################################################
#

# set up shell script to do ~ expansion
cat > .filexp << EOSS
$startsh
# expand filename
case "\$1" in
~/*|~)
    echo \$1 | $sed "s|~|\${HOME-\$LOGDIR}|"
    ;;
~*)
    if test -f /bin/csh
    then
	/bin/csh -f -c "glob \$1"
	echo ""
    else
	name=\`$expr x\$1 : '..\([^/]*\)'\`
	dir=\`$sed </etc/passwd -n -e "/^\${name}:/{s/^[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:\([^:]*\).*"'\$'"/\1/" -e p -e q -e '}'\`
	if test ! -d "\$dir"
	then
	    me=\`basename \$0\`
	    echo "\$me: can't locate home directory for: \$name" >&2
	    exit 1
	fi
	case "\$1" in
	*/*)
	    echo \$dir/\`$expr x\$1 : '..[^/]*/\(.*\)'\`
	    ;;
	*)
	    echo \$dir
	    ;;
	esac
    fi
    ;;
*)
    echo \$1
    ;;
esac
EOSS
chmod 755 .filexp

#
###############################################################################
#

# clean up for repeated execution
$rm -f .needsome .ckincs.h
(
	$rm -f src/newrtelnet/machdep.c
	$rm -f src/newrtelnet/debugging.c
	cd src/inc
	$rm -f config.h netdb.h signal.h strings.h sgtty.h unistd.h
	$rm -f port/install_dir.h
	$rm -rf netinet sys arpa
	$mkdir netinet sys arpa
) >errors/cleanup 2>&1

$debug && echo "Creating .mkpath"

cat > .mkpath << MKPATH
DIR=\$1
DIRL=
while [ ! -z "\$DIR" ]
do
	DIRL="\$DIR \$DIRL"
	DIR=\`$expr /\$DIR : '/\(.*\)/.*'\`
done
for i in \$DIRL
do
	if [ ! -d \$i ]
	then
		$mkdir \$i
		if [ ! -d \$i ]
		then
			exit 1
		fi
	fi
done
exit 0
MKPATH
chmod 755 .mkpath

OPERS="oper.16.enet oper.42.enet oper.52.enet oper.55.enet"

###############################################################################
#
# ask what type of system, answers can be either number or a name.
#
# This will loop around until an acceptable system has been chosen.

if [ -z "$hw_type" ]
then
    echo " "
    echo " "
    echo "Select the most appropriate machine type"
    echo " "
    echo " 1. Sun                              10. Hewlett Packard"
    echo " 2. Encore 90 Family or Multimax     11. Decstation (ULTRIX)"
    echo " 3. UNISYS                           12. MIPS"
    echo " 4. UNISYS S Series CTIX             13. Silicon Graphics"
    echo " 5. NCR                              14. SCO Unix"
    echo " 6. Pyramid                          15. AT&T Star Server FT"
    echo " 7. Sequent PTX                      16. Interactive Unix"
    echo " 8. Sequent Dynix                    17. ICL DRS/6000"
    echo " 9. IBM RS/6000 (AIX)                18. DG AViiON (DG/UX)"
    echo " "
    echo " 0. Generic (no special code needed, or machine not listed)"
    echo " "
    rp="Enter machine type #:"
    . .myread
else
    ans=$hw_type
    hw_type=
fi
#
# Loop when answer is not on printed list.
#
while true
do
    case $ans in
#
#  Current SUN Architectures
#
#       Application       Kernel             Current Sun
#       architecture   architecture         System Models
#           sun3           sun3        3/50, 3/60, 3/75, 3/110,
#                                       3/140, 3/160, 3/180,
#                                           3/260, 3/280
#           sun3          sun3x       3/80, 3/460, 3/470, 3/480
#           sun4           sun4          4/110, 4/260, 4/280,
#                                         SPARCsystem 330,
#                                          SPARCserver 390
#           sun4          sun4c            SPARCstation 1
#          sun386         sun386         386i/150, 386i/250
#

    1|SUN)
	hw_type="SUN"
	case `uname -r` in
	[1234]*)
	    echo " "
	    echo "Building for SunOS."
	    os_type="BSD"
	    netware_type="BSD"
	    INCFILES="$INCFILES sys/stat.h"
	    ;;
	5.[01])
	    echo " "
	    echo "Building for Solaris 2.0 or 2.1."
	    os_type="SVR4"
	    netware_type="TLI"
	    LIBFLAG="-lnls -ltcpip"
	    tryLIBFLAG="$LIBFLAG"
	    INCFILES="$INCFILES sys/socket.h"
	    ;;
	*)
	    echo " "
	    echo "Building for Solaris 2.2 or newer."
	    os_type="SVR4"
	    netware_type="TLI"
	    LIBFLAG="-lnsl"
	    tryLIBFLAG="$LIBFLAG"
	    CKBSDINC=true
	    INCFILES="$INCFILES sys/socket.h"
	    ;;
	esac
	while true
	do
	    if [ -z "$system" ]
	    then
		echo " "
		echo " "
		echo "How do you want $box tools installed?"
		echo " "
		echo " a. Build and install from source files"
		echo " b. Install previously compiled binaries (REQUIRES SPARC PROCESSOR)"
		echo " "
		rp="Enter build/install choice: "
		. .myread
	    else
		ans=a
	    fi
	    case $ans in
		a|A)
		    usebinary=false
		    ;;
		b|B)
#
# Confirm that this actually is a SUN 4 processor.
#
		    ARCH=`arch`
		    if [ "$ARCH" = "sun4" ]
		    then
		       usebinary=true
		    else
		       echo "This is not a sun4, not using binaries."
		       usebinary=false
		    fi
		    ;;
		*)
		    echo " "
		    echo "**** Enter a or b only, please!"
		    echo " "
		    continue
		    ;;
		esac
	    break
	done
	$debug && echo "Link correct newrtelnet files."
	if [ -d src/newrtelnet ]
	then
	    ln -s debugging.vf src/newrtelnet/debugging.c
	    if [ $os_type = "SVR4" ]
	    then
		ln -s machdep.sol src/newrtelnet/machdep.c
	    else
		ln -s machdep.sun src/newrtelnet/machdep.c
	    fi
	fi
	;;

    2|ENCORE)
	hw_type="ENCORE"
	netware_type="BSD"
	ans=`(uname -r) 2>/dev/null || echo bsd`
	if [ "$ans" = "bsd" ]
	then
	    os_default="1"
	else
	    os_default="2"
	fi
	;;

    3|UNISYS)
	hw_type="UNISYS"
	while true; do
	    if [ -z "$system" ]; then
		echo " "
		echo " "
		echo "Select the most appropriate hardware type"
		echo " "
		echo " 1. UNISYS 6000 Series 30/50"
		echo " 2. UNISYS 6000 Series 70/80 (R3.2.0)"
		echo " "
		rp="Enter hardware type #:"
		. .myread
	    else
		# if there is a default system variable set
		# then use it rather than asking the user.
		# then clear the variable.
		ans=$system
		system=
	    fi
	    case $ans in
	    *TOWER|*5000/35|*5000/55)
		hw_type="NCR_TOWER"
		os_type="SYS_V"
		SRCDIRS="$ANXSRC $SUPSRC $SOCSRC"
		netware_type="EXOS" 
		mantype=none
		LIBFLAG="-lsocket"
		INCLUDES="-I/usr/include/NET-5000"
		;;
	    *ARIX|*5000/80|*5000/85|*5000/90|*5000/95)
		hw_type="ARIX"
		os_type="SYS_V"
		SRCDIRS="$ANXSRC $SUPSRC $SOCSRC"
		netware_type="EXOS" nettype="EXOS"
		mantype=V manlayout=packed manext=''
		mansrc=/usr/catman/a_man/man1
		LIBFLAG="-lsocket"
		INCLUDES="-I/usr/include/NET-5000"
		;;
	    1|*CONVERGENT|*6000/30|*6000/50)
		hw_type="CONVERGENT"
		os_type="SYS_V"
		netware_type="BSD"
		mantype=V manlayout=packed manext=''
		mansrc=/usr/catman/a_man/man1
		LIBFLAG="-lsocket"
		;;
	    2|*SEQUENT|*6000/70|*6000/80)
		hw_type="U6070"
		os_type="SYS_V"
		netware_type="TLI"
#		Need -lseq for newrtelnet.
		LIBFLAG="-linet /usr/lib/seq_libnsl.a -lseq"
		tryLIBFLAG="$LIBFLAG"
		select="have"
		index="need"
		rindex="need"
		bcopy="bcopy(a,b,c) memcpy(b,a,c)"
		bzero="bzero(a,b) memset(a,0,b)"
		mantype=v7 manlayout=dist manext=''
		mansrc=/usr/man/man8
		$debug && echo "Link correct newrtelnet files."
		if [ -d src/newrtelnet ]
		then
		    ln -s machdep.uni src/newrtelnet/machdep.c
		    ln -s debugging.vf src/newrtelnet/debugging.c
		fi
		;;
	    *TAHOE|*7000/40)
		hw_type="TAHOE"
		# -a prevents structures from being longword padded
		HWFLAG="$HWFLAG -a"
		SRCDIRS="$ANXSRC $SUPSRC $SOCSRC"
		os_type="SYS_V"
		netware_type="BSD"
		mantype=V manlayout=packed manext=''
		mansrc=/usr/catman/a_man/man1
		LIBFLAG="-lnet -linet"
		;;
	    *)
		echo " "
		echo "**** Enter a number, please!"
		echo " "
		continue
		;;
	    esac
	    break
	done
	didfixedconfig=true
	echo " "
	;;

    4|CTIX)
	hw_type="CONVERGENT"
	os_type="SYS_V"
	netware_type="BSD"
	LIBFLAG="-lsocket"
	tryLIBFLAG="-lsocket"
	$debug && echo "Link correct newrtelnet files."
	if [ -d src/newrtelnet ]
	then
	    ln -s machdep.ctix src/newrtelnet/machdep.c
	    ln -s debugging.vf src/newrtelnet/debugging.c
	fi
	;;

    MX*)
# 
# This assumes that user is running on the MX300 system and that the universe
# command will return the shell equivalent. att is the expected value.
#
	universe=`universe`
	if [ "$universe" != "att" ]; then
	   echo "**** You MUST be in the att universe to run this script."
	   echo "**** Please enter the att universe and try again."
	   exit 2
	fi
	hw_type="MX300"
	os_type="SYS_V"
	netware_type="BSD"
	LIBANX_C="$LIBANX_C sendrecv.c"
	LIBANX_O="$LIBANX_O sendrecv.o"
	if [ -f /usr/lib/libsocket.a ]; then 
	   LIBFLAG="-lsocket"
	   tryLIBFLAG="-lsocket"
	else
	   if [ -f $cwd/MX300/libsocket.a ]; then
	       LIBFLAG="$cwd/MX300/libsocket.a"
	       tryLIBFLAG="$cwd/MX300/libsocket.a"
	   else
	       echo "**** You MUST install socket libraries before running install-${box}."
	       exit 2
	   fi
	fi
	if [ -f src/rtelnet/rtelnet.smns ]
	then
	    $mv src/rtelnet/rtelnet.c src/rtelnet/rtelnet.old
	    $mv src/rtelnet/rtelnet.smns src/rtelnet/rtelnet.c
	fi
	;;

    5|NCR)
	hw_type="NCR"
# These are redefined in /usr/include/strings.h with a #define to
# strchr and strrchr for ANSI.
	index='have'
	rindex='have'
	sigmask='need'
	LIBFLAG="$LIBFLAG -lsocket -lnsl "
        INCFILES="$INCFILES sys/socket.h"
	tryLIBFLAG="$LIBFLAG"
	while true; do
	    if [ -z "$system" ]; then
		echo " "
		echo " "
		echo "Select the most appropriate NCR system: "
		echo " "
		echo " 1. NCR Tower"
		echo " 2. NCR System 3000"
		echo " "
		rp="Enter NCR system:"
		. .myread
	    else
		ans=$system
		system=
	    fi
	    case $ans in
	    1)
		netware_type="WINS"
		HWFLAG="$HWFLAG -DWINS"
		LIBFLAG="$LIBFLAG -lnsl_s"
		tryLIBFLAG="$LIBFLAG"
		sendmsg='need'
		rcvmsg='need'
		os_type="SYS_V"
		#########################################
		# Changes for NCR Tower ioctl.h missing #
		#########################################
		if [ ! -f /usr/include/sys/ioctl.h ]; then
		    echo "/* dummy file to keep ccp happy */" \
		    > src/inc/sys/ioctl.h
		fi
		#################################################
		# Change due to redeclaration of iovec in uio.h #
		# (NCR Tower bug)                               #
		# If socket.h exists then copy to src/inc/sys   #
		#################################################
		if [ -f /usr/netinclude/sys/socket.h ]; then
		    $cp /usr/netinclude/sys/socket.h src/inc/sys
		fi
		;;
	    2)
		os_type="SVR4"
		SRCDIRS="$ALLSRC"
		LIBFLAG="-L/usr/ucblib $LIBFLAG"
		INCFILES="$INCFILES sys/stat.h"
		###################################
		# Figure what type of man page    #
		# organization exists on NCR 3000 #
		###################################
		if [ -d /usr/catman/index ]; then
		    mansrc="/usr/catman/index"
		else
		    if [ -d /usr/share/man ]; then
			mansrc="/usr/share/man/man8"
			if [ ! -d /usr/share/man/man1 ]; then
			    mkdir /usr/share/man/man1
			fi
			if [ ! -d /usr/share/man/man5 ]; then
			    mkdir /usr/share/man/man5
			fi
			if [ ! -d /usr/share/man/man8 ]; then
			    mkdir /usr/share/man/man8
			fi
		    else
			if [ -d /usr/man ]; then
			    mansrc="/usr/man/man8"
			else
			    # Give-up, on man page directory
			    mantype=none
			fi
		    fi
		fi
		;;
	    *) 
		echo " "
		echo "**** Enter a number, please!"
		echo " "
		continue
		;;
	    esac
	    break
	done
	$debug && echo "Link correct newrtelnet files."
	if [ -d src/newrtelnet ]
	then
	    ln -s machdep.ncr src/newrtelnet/machdep.c
	    ln -s debugging.vf src/newrtelnet/debugging.c
	fi
	;;

    6|PYRAMID)
#########################
#
#	hw_type="PYRAMID"
#	# -q prevents structures from being longword padded
#	HWFLAG="$HWFLAG -q"
#
#########################
	hw_type="PYRAMID"
	instdir=$cwd
	while true
	do
	    if [ -z "$system" ]
	    then
		echo " "
		echo " "
		echo "Select the most appropriate hardware type"
		echo " "
		echo " 1. PYRAMID OS/x"
		echo " 2. PYRAMID DC/OSx"
		echo " "
		rp="Enter hardware type #:"
		. .myread
	    else
		ans=$system
		system=
	    fi
	    case $ans in
	    1)
		os_type="BSD"
		netware_type="BSD"
# -q prevents structs from being padded
		HWFLAG="$HWFLAG -q"
#		mantype=none
#		LIBFLAG="-lsocket "
		;;
	    2)
		os_type="SYS_V"
		netware_type="TLI"
#		mantype=V manlayout=packed manext=''
#		mansrc=/usr/catman/a_man/man1
#		OTHERINSTALL="$OTHERINSTALL install-man"
		LIBFLAG="-lsocket -lnsl -lns "
		INCFILES="$INCFILES sys/socket.h"
		$debug && echo "Link correct newrtelnet files."
		if [ -d src/newrtelnet ]
		then
		    ln -s machdep.pyr src/newrtelnet/machdep.c
		    ln -s debugging.vf src/newrtelnet/debugging.c
		fi
		;;
	    *) 
		echo " "
		echo "**** Enter a number, please!"
		echo " "
		continue
		;;
	    esac
	    break
	done
	;;

    CONCURRENT)
	hw_type="CONCURRENT"
	cc="att cc"
	mantype=v7 manlayout=dist manext=''
	mansrc=/usr/man/man8
#	OTHERINSTALL="$OTHERINSTALL install-man"
	while true
	do
	    if [ -z "$system" ]
	    then
		echo " "
		echo " "
		echo "Select the most appropriate RTU release" 
		echo " "
		echo " 1. RTU 4.1"
		echo " 2. RTU 5.0, 5.1 (use sockets)"
		echo " 3. RTU 6.0, 6.1, or later (use TLI)"
		echo " "
		rp="Enter RTU type number:"
		. .myread
	    else
		ans=$system
		system=
	    fi
	    case $ans in
	    1|*4*)
		os_type="SYS_V"
		netware_type="BSD"
		# they have broken recvmsg/sendmsg
		recvmsg='need'
		sendmsg='need'
		;;
	    2|*5*)
		os_type="SYS_V"
		netware_type="BSD"
		LIBFLAG=""
		# they have broken recvmsg/sendmsg
		recvmsg='need'
		sendmsg='need'
		;;
	    3|*[67]*)
		os_type="SYS_V"
		netware_type="TLI"
		HWFLAG="$HWFLAG -DTLI -DTLIPOLL"
		sockdefs='need'
		funclist="$funclist sockdefs(0)"
		LIBFLAG="-lnsl"
		;;
	    esac
	    break
	done
	didfixedconfig=true
	;;

    7|SEQUENT_PTX)
	hw_type="SEQUENT_PTX"
	os_type="SYS_V"
	netware_type="TLI"
# Need "-linet -lnsl" to compile with standard network functions.
# Need "-lseq" to use pty functions with rtelnet.
	LIBFLAG="-linet -lnsl -lseq"
	tryLIBFLAG="-linet -lnsl -lseq"
	index="need"
	rindex="need"
	select="have"
	sigmask="need"
	bcopy="bcopy(a,b,c) memcpy(b,a,c)"
	bzero="bzero(a,b) memset(a,0,b)"
	###########################################
	# Define the man page install information #
	###########################################
	if $debug ; then
	  echo " Define the man page install information"
	fi
	mantype=v7 manlayout=dist manext='' packed=true
	if [ -d /usr/catman/index ]; then
	    mansrc=/usr/catman/index
	else
	    mansrc=/usr/catman
	fi
	if $debug ; then
	  echo "Within PTX selection:"
	  echo "mantype = $mantype, manlayout = $manlayout"
	  echo "mansrc = $mansrc, manext = $manext"
	fi
#        OTHERINSTALL="$OTHERINSTALL install-man"
	$debug && echo "Link correct newrtelnet files."
	if [ -d src/newrtelnet ]
	then
	    ln -s machdep.seqptx src/newrtelnet/machdep.c
	    ln -s debugging.vf src/newrtelnet/debugging.c
	fi
	;;

    8|SEQUENT_DYNIX)
####################################################################
# 
# This assumes that user is running on the Dynnix system and that 
# the universe command will return the shell equivelant. BSD is 
# the expected value.
#
####################################################################
	universe=`universe`
	if [ "$universe" != "ucb" ]; then
	   echo "** You MUST be in the ucb universe to run this script."
	   echo "** Please enter the ucb universe and try again."
	   exit 2
	fi
	hw_type="SEQUENT"
	os_type="BSD"
	netware_type="BSD"
	$debug && echo "Link correct newrtelnet files."
	if [ -d src/newrtelnet ]
	then
	    ln -s machdep.seqdyn src/newrtelnet/machdep.c
	    ln -s debugging.vf src/newrtelnet/debugging.c
	fi
	;;

    9|AIX)
	hw_type="AIX"
	os_type="SYS_V"
	netware_type="BSD"
	usebinary=false
	$debug && echo "Link correct newrtelnet files."
	if [ -d src/newrtelnet ]
	then
	    ln -s machdep.aix src/newrtelnet/machdep.c
	    ln -s debugging.vf src/newrtelnet/debugging.c
	fi
	;;

    ALPHA)
	hw_type="ALPHA"
	os_type="SYS_V"
	HWFLAG="$HWFLAG -DUSE_64"
	netware_type="BSD"
	usebinary=false
	INCFILES="$INCFILES sys/stat.h"
	nortelnet=true
	;;

    10|HP)
	hw_type="HP"
	os_type="SYS_V"
	HWFLAG="$HWFLAG -DBSDSIG"
	netware_type="BSD"
	mantype=v7 manlayout=dist manext=''
	mansrc=/usr/man/man1
	while true
	do
	    if [ -z "$system" ]
	    then
		echo " "
		echo " "
		echo "Select the most appropriate HP-UX revision: "
		echo " "
		echo " 1. HP-UX 7.0"
		echo " 2. HP-UX 8.0 or greater"
		echo " "
		rp="Enter HP-UX selection:"
		. .myread
	    else
		ans=$system
		system=
	    fi
	    case $ans in
	      1)
		hp_os="seven"
		HWFLAG="$HWFLAG -DHPUX7"
		bcopy="need"
		bzero="need"
		strcasecmp="need"
		strncasecmp="need"
		index="need"
		rindex="need"
		;;
	      2)
		hp_os="eight"
		;;
	      *) 
		echo " "
		echo "**** Enter a number, please!"
		echo " "
		continue
		;;
	    esac
	    break
	done
	$debug && echo "Link correct newrtelnet files."
	if [ -d src/newrtelnet ]
	then
	    ln -s machdep.hpux src/newrtelnet/machdep.c
	    ln -s debugging.vf src/newrtelnet/debugging.c
	fi
	;;

    11|ULTRIX)
	hw_type="ULTRIX"
	os_type="BSD"
	netware_type="BSD"
	$debug && echo "Link correct newrtelnet files."
	if [ -d src/newrtelnet ]
	then
	    ln -s machdep.ultrix src/newrtelnet/machdep.c
	    ln -s debugging.vf src/newrtelnet/debugging.c
	fi
	;;

    MOTOROLA)
	hw_type="MOTO_88K"
	os_type="SYS_V"
	netware_type="BSD"
	LIBFLAG="-lbsd"
	tryLIBFLAG="-lbsd"
	;;

    12|MIPS)
	hw_type="MIPS"
	os_type="SYS_V"
	netware_type="BSD"
	if [ -d /usr/man ]
	then
	    mantype=V manlayout=dist manext=''
	    mansrc=/usr/man/a_man
# If there's a straight text directory for the man pages, and either
# the man source directories are missing or if the source directories
# are just a symbolic link to the straight text, then use catman.
	    if [ -d /usr/man/catman ]
	    then
		if [ "`file /usr/man/a_man | cut -f2`" != "directory" ]
		then
			mansrc=/usr/man/catman/a_man
		fi
	    fi
	fi
	didfixedconfig=true
	LIBFLAG="-lbsd"
	tryLIBFLAG="-lbsd"
	INCLUDES="$INCLUDES -I/usr/include/bsd"
	$debug && echo "Link correct newrtelnet files."
	if [ -d src/newrtelnet ]
	then
	    ln -s machdep.mips src/newrtelnet/machdep.c
	    ln -s debugging.vf src/newrtelnet/debugging.c
	fi
	;;

    PRIME)
	hw_type="PRIME"
	while true; do
	    if [ -z "$system" ]; then
		echo " "
		echo " "
		echo "Select the most appropriate OS: "
		echo " "
		echo " 1. UNIX V.3.x system"
		echo " 2. UNIX V.4 system"
		echo " 3. RISC/OS system"
		echo " "
		rp="Enter appropriate system number:"
		. .myread
	    else
		ans=$system
		system=
	    fi
	    case $ans in
	    1)
		os_type="SYS_V"
		SRCDIRS="$ALLSRC"
		netware_type="TLI"
		HWFLAG="$HWFLAG -DTLI -DTLIPOLL"
		sockdefs='need'
		funclist="$funclist sockdefs(0)"
		LIBFLAG="-lstcp -lnls -lnsl_s"
		tryLIBFLAG="-lstcp -lnls -lnsl_s"
		$cp /usr/include/time.h src/inc/sys/time.h
		$cat /usr/include/sys/bsd_time.h >> src/inc/sys/time.h
		;;
	    2)
		os_type="SVR4"
		SRCDIRS="$ALLSRC"
		netware_type="BSD"
		;;
	    3)
		hw_type="MIPS"
		os_type="SYS_V"
		netware_type="BSD"
		LIBFLAG="-lbsd"
		tryLIBFLAG="-lbsd"
		;;
	    *) 
		echo " "
		echo "**** Enter a number, please!"
		echo " "
		continue
		;;
	    esac
	    break
	done
	;;

    13|SGI) 
	hw_type="SGI"
	os_type="SYS_V"
	netware_type="BSD"
	mantype="V" manlayout="dist" manext=''
	mansrc="/usr/catman/a_man"
	didfixedconfig=true
	LIBFLAG="-lbsd"
	tryLIBFLAG="-lbsd"
	$debug && echo "Link correct newrtelnet files."
	if [ -d src/newrtelnet ]
	then
	    ln -s machdep.sgiv src/newrtelnet/machdep.c
	    ln -s debugging.vf src/newrtelnet/debugging.c
	fi
	;;

    BULL)
	hw_type="BULL"
	os_type="SYS_V"
	netware_type="BSD"
	LIBFLAG="-linet -lnsl"
	tryLIBFLAG="-linet -lnsl"
	mantype="V" manlayout="dist" manext=''
	mansrc="/usr/catman/a_man"
	while true
	do
	    if [ -z "$system" ]
	    then
		echo " "
		echo " "
		echo "Select the appropriate system: "
		echo " "
		echo " 1. DPX/2 Model 200" 
		echo " 2. DPX/2 Model 300"
		echo " "
		rp="Enter appropriate system number:"
		. .myread
	    else
		ans=$system
		system=
	    fi
	    case $ans in
	      1)
		hw_type="DPX200"
		recvmsg='need'
		sendmsg='need'
		;;
	      2)
		hw_type="DPX300"
		;;
	      *)
		echo " "
		echo "**** Enter a number, please!"
		echo " "
		continue
		;;
	    esac
	    break
	done
	;;

    14|SCO)
	hw_type="SCO"
	os_type="SYS_V"
	netware_type="BSD"
	ranlib="/bin/ar t"
	while true; do
	    if [ -z "$system" ]; then
		echo " "
		echo " "
		echo "How do you want this software installed?"
		echo " "
		echo " a. Build and install from source files"
		echo " b. Install previously compiled binaries"
		echo " "
		rp="Enter build/install choice:"
		. .myread
	    else
		ans=a
	    fi
	    case $ans in
		a|A)
		    sendmsg='need'
		    recvmsg='need'
		    HWFLAG="$HWFLAG -DLAI_TCP -Di386 -pack"
		    LIBFLAG="-lsocket -lnsl_s -lnls -lpt"
		    tryLIBFLAG="-lsocket -lnls -lnsl_s -lpt"
		    usebinary=false
		    ;;
		b|B)
		    usebinary=true
		    ;;
		*)
		    echo " "
		    echo "**** Enter a or b only, please!"
		    echo " "
		    continue
		    ;;
		esac
	     break
	done
	if $debug ; then
	    echo "Use binaries= $usebinary"
	fi
# Note:  SCO doesn't have symbolic links.
	$debug && echo "If src/newrtelnet exists, then link correct versions"
	if [ -f src/newrtelnet/machdep.sco ]
	then
	    ln src/newrtelnet/machdep.sco src/newrtelnet/machdep.c
	    ln src/newrtelnet/debugging.vf src/newrtelnet/debugging.c
	fi
	;; 

    15|SSFT)
	hw_type="SSFT"
	os_type="SYS_V"
	netware_type="BSD"
	LIBFLAG="-lbsd -lnsl"
	tryLIBFLAG="-lnsl -lbsd"
 	INCLUDES="$INCLUDES -I/usr/include/bsd"
 	if [ -f /usr/include/sgtty.h ] ; then
 	    $cp /usr/include/sgtty.h src/inc
 	else
 	    echo "WARNING: Cannot find /usr/include/sgtty.h"
 	fi
	;;

    DELL)
	hw_type="DELL"
	os_type="SVR4"	
	LIBFLAG="-lsocket -lnsl -lucb"
	tryLIBFLAG="-lsocket -lnsl -lucb"
	$debug && echo "Link correct newrtelnet files."
	if [ -d src/newrtelnet ]
	then
	    ln -s machdep.dell src/newrtelnet/machdep.c
	    ln -s debugging.vf src/newrtelnet/debugging.c
	fi
	;;

    16|IUNIX)
	hw_type="IUNIX"
	os_type="SYS_V"
	netware_type="TLI"
	tryLIBFLAG="-lgen -linet -lnls -lnsl_s -lpt"
	LIBFLAG="-lgen -linet -lnls -lnsl_s -lpt"
        INCFILES="$INCFILES sys/socket.h"
	while true; do
	    if [ -z "$system" ]; then
		echo " "
		echo " "
		echo "Which type of install do you wish?"
		echo " "
		echo " a. Build and Install from source files"
		echo " b. Install previously compiled binaries"
		echo " "
		rp="Enter build/install choice:"
		. .myread
	    else
		ans=a
	    fi
	    case $ans in
		a|A)
		    usebinary=false
		    ;;
		b|B)
		    usebinary=true
		    ;;
		*)
		    echo " "
		    echo "**** Enter a or b only, please!"
		    echo " "
		    continue
		    ;;
		esac
	    break
	done
# Note:  IUNIX doesn't have symbolic links.
	$debug && echo "If src/newrtelnet exists, then link correct versions"
	if [ -f src/newrtelnet/machdep.iunix ]
	then
	    ln src/newrtelnet/machdep.iunix src/newrtelnet/machdep.c
	    ln src/newrtelnet/debugging.vf src/newrtelnet/debugging.c
	fi
	;;

    17|ICL)
	hw_type="ICL"
	os_type="SYS_V"
	netware_type="BSD"
	LIBFLAG="-lsocket -lnsl"
	tryLIBFLAG="$LIBFLAG"
# Avoid problems caused by BSD versions of the tools.
	ar="/bin/ar"
	cc="/bin/cc"
	ranlib="echo done with library"
	$debug && echo "Link correct newrtelnet files."
	if [ -d src/newrtelnet ]
	then
	    ln -s machdep.icl src/newrtelnet/machdep.c
	    ln -s debugging.vf src/newrtelnet/debugging.c
	fi
	;;

    18|DG)
	hw_type="DGUX"
	os_type="SYS_V"
	netware_type="TLI"
	mantype=V
	sockdefs='need'
	funclist="$funclist sockdefs(0)"
	LIBFLAG="-lnsl"
	tryLIBFLAG="$LIBFLAG"
	$debug && echo "Link correct newrtelnet files."
	if [ -d src/newrtelnet ]
	then
	    ln -s machdep.dgux src/newrtelnet/machdep.c
	    ln -s debugging.vf src/newrtelnet/debugging.c
	fi
	;;

    0|GENERIC)
	hw_type="GENERIC"
	;;

    TAHOE)
	hw_type="TAHOE"
	HWFLAG="$HWFLAG -a"
	# -a prevents structures from being longword padded
	;;

    CONVERGENT)
	hw_type="CONVERGENT"
	os_type="SYS_V"
	netware_type="BSD"
	;;

    N[eE]XT)
	hw_type="NEXT"
	os_type="BSD"
	netware_type="BSD"
	SRCDIRS="$ALLSRC"
	INCLUDES="-bsd $INCLUDES"
	;;

    PC)
	hw_type="PC"
	HWFLAG="$HWFLAG -Ml"        # "small" model
	;;

    *) 
	echo " "
	echo "**** Enter a number, please!"
	echo " "
	rp="Enter Machine Type #:"
	. .myread
	continue
	;;
    esac
    break
done

############
#
# Call both osinstall and nwinstall to confirm that the
# correct parameters/flags are set for the values
#
############
$debug && echo "Running os-install"

################################################################
#
# osinstall
#
# purpose   :   called to configure OS type for undetermined system types.
#
# Edited 3/23/92 for Concurrent changes
#
################################################################

if [ -z "$os_type" ]
then
    echo " "
    echo " "
    echo "Select the most appropriate OS"
    echo " "
    echo " 1. 4.[23]BSD Unix (& UMAX BSD)"
    echo " 2. System V Unix (& UMAX V)"
    echo " 3. XENIX System V"
    echo " 4. MACH"
    echo " 5. SVR4 "
    echo " "
    if [ -z "$os_default" ]
    then
	rp="Enter OS number:"
    else
	rp="Enter OS number [$os_default]:"
    fi
    . .myread
    [ -z "$ans" ] && ans="$os_default"
else
    ans=$os_type
fi

$debug && echo "OS Response: $ans"

while true
do
    case $ans in
    1|BSD)
	os_type="BSD"
	[ -z "$netware_type" ] && netware_type="BSD"
	[ -z "$mantype" ] && mantype=v7
	case $hw_type in
	ENCORE)
	    $debug && echo "Link correct newrtelnet files."
	    if [ -d src/newrtelnet ]
	    then
		ln -s machdep.umax src/newrtelnet/machdep.c
		ln -s debugging.vf src/newrtelnet/debugging.c
	    fi
	    SRCDIRS="$ANXSRC $SUPSRC $SOCSRC"
	    ;;
	SUN)
	    SRCDIRS="$ANXSRC $SUPSRC $NEWRSRC $SOCSRC"
	    ;;
	*)
	    SRCDIRS="$ALLSRC"
	    ;;
	esac
	;;
    2|SYS_V)
	os_type="SYS_V"
	[ -z "$mantype" ] && mantype=V
	HWFLAG="$HWFLAG -DSYS_V"
	SRCDIRS="$ANXSRC $SUPSRC $SOCSRC"
	CKBSDINC=true
	case $hw_type in
	ENCORE)
	    # We will now allow aprint for UMAXV
	    SRCDIRS="$ANXSRC $SUPSRC $SOCSRC"
	    if [ -d /dev/inet ]
	    then
		HWFLAG="$HWFLAG -DUMAX_V -DENCORE -q ext=pcc"
	    else
		HWFLAG="$HWFLAG -DUMAX_V"
		$cat /usr/include/sys/h/socket.h \
		> src/inc/sys/socket.h
		$cat /usr/include/sys/netinet/in.h \
		> src/inc/netinet/in.h
		$cat /usr/include/signal.h > src/inc/signal.h
		INCLUDES="$INCLUDES -I/usr/include/sys/aux"
		LIBFLAG="-laux"
	    fi
	    $debug && echo "Link correct newrtelnet files."
	    if [ -d src/newrtelnet ]
	    then
		ln -s machdep.umaxv src/newrtelnet/machdep.c
		ln -s debugging.vf src/newrtelnet/debugging.c
	    fi
	    ;;
	CONVERGENT)
	    if [ -f /usr/include/sys/in.h ]; then
		$cat /usr/include/sys/in.h \
		    > src/inc/netinet/in.h
	    fi
	    ;;
	HP)
	    if [ "$hp_os" = "seven" ]; then
		sendmsg='need'
		recvmsg='need'
	    fi
	    if [ ! -f /usr/include/arpa/telnet.h ] ; then
		if [ ! -f /usr/include/netinet/telnet.h ] ; then
		    $cp src/inc/port/xtelnet.h src/inc/arpa/telnet.h
		else
		    $cp /usr/include/netinet/telnet.h src/inc/arpa/telnet.h
		fi
#		INCLUDES="$INCLUDES -I../inc/arpa"
	    fi
	    ;;
	MOTO_88K)
	    recvmsg='need'
	    sendmsg='need'
	    ;;
	MIPS)
	    if [ -f /usr/include/sgtty.h ] ; then
		$cp /usr/include/sgtty.h src/inc
	    else
		echo "WARNING: Can not find /usr/include/sgtty.h"
	    fi
	    ;;
	esac
	;;
    3|XENIX)
	os_type="XENIX"
	if [ "$hw_type" = "ENCORE" ]; then
	  echo "WARNING!!  Encore system running XENIX not supported."
	fi
	index='need'    # don't trust xenix
	rindex='need'
	$cat /usr/include/string.h > src/inc/strings.h
	$cat src/inc/port/xuio.h > src/inc/sys/uio.h
	echo " " > src/inc/sys/wait.h
	SRCDIRS="$ANXSRC $SUPSRC"
	HWFLAG="$HWFLAG -F 3000 -DSYS_V -DSYS_V_2 -DXENIX"
	;;
    4|MACH)
	os_type="MACH"
	netware_type="BSD"
	SRCDIRS="$ALLSRC"
	HWFLAG="$HWFLAG -DMACH"
	INCLUDES="-I/usr/cs/include $INCLUDES"
	;;
    5|SVR4)
	os_type="SYS_V"
	[ -z "$mantype" ] && mantype=V
	[ -z "$netware_type" ] && netware_type="TLI"
	if [ $hw_type = "SUN" ]
	then
	    SRCDIRS="$ANXSRC $SUPSRC $NEWRSRC $SOCSRC"
	else
	    SRCDIRS="$ALLSRC"
	fi
	if [ ! -f /usr/include/arpa/telnet.h ] ; then
	    if [ ! -f /usr/include/netinet/telnet.h ] ; then
		$cp src/inc/port/xtelnet.h src/inc/arpa/telnet.h
	    else
		$cp /usr/include/netinet/telnet.h src/inc/arpa/telnet.h
	    fi
	fi
	HWFLAG="$HWFLAG -DSVR4 -DSYS_V"
	;;
    *) 
	echo " "
	echo "**** Enter a number, please!"
	echo " "
	rp="Enter OS number:"
	. .myread
	continue
	;;
    esac
    break
done

$debug && echo "OS Type = $os_type"

########################################################################
#****************************************************************
# End of osinstall
#****************************************************************
########################################################################

$debug && echo "Running nw-install"

########################################################################
#
# nwinstall
#
# purpose: Determine Network S/W type.
#
# Edited 3/23/92 to add Concurrent Mods.
#
########################################################################

if [ -z "$netware_type" ]
then
    echo " "
    echo " "
    echo "What kind of network software does your OS have?"
    echo " "
    echo " 1. 4.[234]BSD or compatible"
    echo " 2. Excelan EXOS package"
    echo " 3. CMC package"
    echo " 4. Wollongong WINS package"
    echo " 5. None.  Use user-level SLIP (SysV / XENIX only)"
    echo " 6. TLI.  (Transport Layer Interface)"
    echo " "
    rp="Enter network software type number:"
    . .myread
    else
	ans=$netware_type
    fi

    if $debug ; then
       echo "Option response: $ans"
    fi

    while true; do
    case $ans in
    1|BSD)
	netware_type="BSD"
	;;
    2|EXOS)
	netware_type="EXOS" nettype="EXOS"
	HWFLAG="$HWFLAG -DEXOS"
	tryLIBFLAG="-lsocket"
	if [ $hw_type = "PC" -a $os_type = "XENIX" ]; then
	    # known bug in EXOS on XENIX-PC
	    htonl='need'
	    ntohl='need'
#
# clear "print warning for ntoh need" flag
#
	    warning_ntoh=false
	fi
	;;
    3|CMC)
	netware_type="CMC" nettype="CMC"
	HWFLAG="$HWFLAG -DCMC"
	tryLIBFLAG="-lcmcnet"
	;;
    4|WINS)
	netware_type="WINS" nettype="WINS"
	HWFLAG="$HWFLAG -DWINS"
	tryLIBFLAG="-lnet -lnsl_s"
	# WINS has broken sendmsg/recvmsg
	sendmsg='need'
	recvmsg='need'
	;;
    5|SLIP)
	netware_type="SLIP"
	SRCDIRS="$SRCDIRS slipd"
	HWFLAG="$HWFLAG -DSLIP"
	LIBANX_C="$LIBANX_C ip_layer.c udp_layer.c socket_layer.c
	    slip_layer.c in_cksum.c"
	LIBANX_O="$LIBANX_O ip_layer.o udp_layer.o socket_layer.o
	    slip_layer.o in_cksum.o"
	echo " " > src/inc/netinet/in.h
	echo " " > src/inc/sys/socket.h
	echo " " > src/inc/sys/time.h
	gethostbyname='need'
	gethostbyaddr='need'
	getservbyname='need'
	htonl='need'
	htons='need'
	inet_addr='need'
	inet_ntoa='need'
	ntohl='need'
	ntohs='need'
	recvfrom='need'
	recvmsg='need'
	sendmsg='need'
	sendto='need'
	;;
    6|TLI)
	netware_type="TLI" nettype="TLI"
	HWFLAG="$HWFLAG -DTLI -DTLIPOLL"
# Should this indeed be used anywhere at all?  It causes problems on
# Sequent PTX and on Solaris 2.2.
#	sockdefs='need'
#	funclist="$funclist sockdefs(0)"
	if [ "$hw_type" = "PRIME" ]
	then
	    $cp /usr/include/time.h src/inc/sys/time.h
	    $cat /usr/include/sys/bsd_time.h >> src/inc/sys/time.h
	fi
	;;
    *) 
	echo " "
	echo "**** Enter a number, please!"
	echo " "
	continue
	;;
    esac
    break
done

# 
# Part II
#
portfile=''
case $netware_type in
    CMC)
    MAPNAMES="#include \"$incdir/longnames.h\""

    portfile="#include <port/CMC.h>"

    # hack around CMC include file stupidity
    $cat << EOF                >> src/inc/config.h
/*
 * kludge for CMC's "recursive" includes
 */
#include "$incdir/types.h"
#include "$incdir/errno.h"
#include "$incdir/signal.h"
EOF
    $cat $incdir/inet.h            > src/inc/arpa/inet.h
    $cat $incdir/telnet.h            > src/inc/arpa/telnet.h
    $cat $incdir/netdb.h            > src/inc/netdb.h
    $cat $incdir/in.h            > src/inc/netinet/in.h
    $cat $incdir/socket.h            > src/inc/sys/socket.h
    echo " "                > src/inc/sys/time.h
    echo '#ifndef ANNEX_SYS_TYPES'        > src/inc/sys/types.h
    echo '#define ANNEX_SYS_TYPES'        >> src/inc/sys/types.h
    $cat /usr/include/sys/types.h        >> src/inc/sys/types.h
    echo '#endif'                >> src/inc/sys/types.h

    INCLUDES="$preincdir -I../inc"
    ;;
    WINS)
    # We currently only support the NCR/WINS combination
    # Slight modifications might be necessary for other versions
    # of the WINS package
    if [ $hw_type = "NCR" ]; then
	$cat << EOF            >> src/inc/config.h
/*
 * Need <sys/twg_config.h> for WINS
 */
#include <sys/twg_config.h>
EOF
	# put in.h where we will can find it
	$cat $incdir/sys/in.h        > src/inc/netinet/in.h

	if [ "$os_type" = "SYS_V" ]; then
	    portfile="#include <port/SYS_V.h>"
	fi
	INCLUDES="-I../inc $INCLUDES"
    else
	echo "Warning!"
	echo "WINS network package may not be supported."
    fi
    ;;
    EXOS)
    portfile="#include <port/EXOS.h>"

    INCLUDES="-I../inc $INCLUDES"
    ;;
    SLIP)
    portfile="#include <port/SLIP.h>"

    INCLUDES="-I../inc $INCLUDES"
    ;;
    TLI)
    portfile="#include <port/SYS_V.h>"

    INCLUDES="-I../inc $INCLUDES"
    ;;
    BSD)
    if [ "$os_type" = "SYS_V" ] ; then
	portfile="#include <port/SYS_V.h>"
    fi

    INCLUDES="-I../inc $INCLUDES"
    ;;
esac
####################
#******************#
# End of nwinstall #
#******************#
####################

if $debug
then
    echo "Debug information:  selected system info"
    echo "System Type  = $hw_type"
    echo "OS TYPE      = $os_type"
    echo "NETWARE TYPE = $netware_type"
fi

######################################################################
#
# Skip the following code if this is a Binary Install
#
# if usebinary = no then don't skip code 
# if usebinary = yes then skip code
######################################################################
if $usebinary
then
    $debug && echo "Skipped code not needed for a binary install."
else
    $debug && echo "Not using binary install, don't skip code."
#
# set HWFLAG with information just gained...
#
    HWFLAG="$HWFLAG -D$hw_type"


# Check for/install auxiliary libraries
    $debug && echo "Running auxlibinstall"
######################################################################
#
# auxlibinstall
#
######################################################################
    auxlib=false
    $didfixedconfig || case "$tryLIBFLAG" in
      '')
	if [ \( "$netware_type" = "BSD" -a "$os_type" != "BSD" -a "$hw_type" != "ENCORE" \) -o "$netware_type" != "BSD" ]
	then
	    echo " "
	    rp="Does your system have any auxiliary libraries for the network code? [n]"
	    . .myread
	    case "$ans" in
	      y*)
		auxlib=true
		;;
	    esac
	fi
	;;
      *)
	auxlib=true
	;;
    esac

    if $auxlib
    then
	case "$tryLIBFLAG" in
	  '')
	    dflt='' dfltstr=''
	    ;;
	  *)
	    dflt="$tryLIBFLAG"
	    dfltstr=" [$dflt] "
	    ;;
	esac
	echo " "
	echo "Enter any additional loader options for the $nettype libraries."
	echo "(ex: \"-lnet\" or \"-lsocket\")"
	rp="Loader options${dfltstr}:"
	. .myread
	LIBFLAG="$ans"

	[ "$dflt" != "" -a "$LIBFLAG" = "" ] && LIBFLAG=$dflt
	echo "(using: $LIBFLAG)"
    fi

    auxinc=false
    $didfixedconfig || case $netware_type in
      EXOS)
	auxinc=true
	incdir=`./.loc . /usr/src/exos/include/exos /usr/include/exos`
	;;
      CMC)
	auxinc=true
	incdir=`./.loc . /usr/include/CMC`
	;;
      WINS)
	auxinc=true
	incdir=`./.loc . /usr/netinclude`
	;;
      BSD)
	if [ "$hw_type" = "MIPS" -o "$hw_type" = "SGI" ]
	then
	    auxinc=true
	    incdir=`./.loc . /usr/include/bsd`
	elif [ "$os_type" != "BSD" -a "$hw_type" != "ENCORE" ]
	then
	    echo " "
	    rp="Does your system have an alternate include directory for network code [n]?"
	    . .myread
	    case "$ans" in
	      y*)
		auxinc=true
		incdir=''
		;;
	    esac
	fi
	;;
    esac

    if $auxinc
    then
# determine where auxillary include directory is
	case "$incdir" in
	  '')
	    dflt='' dfltstr=''
	    ;;
	  *)
	    dflt="$incdir"
	    dfltstr=" [$dflt]"
	    ;;
	esac
	incdir='blurfl/dyick'

	while [ ! -d "$incdir" ]
	do
	    case "$incdir" in
	      blurfl*)
		;;
	      *)
		echo "$incdir does not appear to exist." ;;
	    esac
	    echo " "
	    rp="Where are the $nettype include files located?$dfltstr"
	    . .myread
	    incdir=`./.filexp "$ans"`     
	    test "$dflt" && case "$incdir" in
	      '') incdir=$dflt ;;
	    esac
	done

	preincdir="$INCLUDES"
	INCLUDES="$INCLUDES -I$incdir"
    fi

########################
#***********************
# End of auxlibinstall
#***********************
##############################################################################
#
#
    $debug && echo "Testing for existence of compiler."

    $debug && echo "Creating config.h"
    $cat > src/inc/config.h <<EOSS
/*
 *
 * $package src/inc/config.h `$date`
 *
 * hardware "$hw_type" software "$os_type" network "$netware_type"
 *
 */
EOSS
#
######################################################################
#
#

    echo " "                >> src/inc/config.h
    for fn in $INCFILES
    do
	echo "#include <$fn>" >> src/inc/config.h
    done
    echo " "                >> src/inc/config.h
    echo "/* map function names */"        >> src/inc/config.h
    echo $MAPNAMES                >> src/inc/config.h
    echo " "                >> src/inc/config.h
    export MAPNAMES

#
######################################################################
#
    $debug && echo "Creating .ckfunc"
    echo "" > errors/ckfunc
    cat >.ckfunc <<EOX
echo "Testing function \$*" >> errors/ckfunc
cat >.ckfunc.c <<EOS
#include "config.h"
/* include these to check for macros (i.e., ntohs and friends) */
#include ".ckincs.h"
\$MAPNAMES
int
main() {
\$*
;
}
EOS
$cc -Isrc/inc $INCLUDES .ckfunc.c $LIBFLAG >> errors/ckfunc 2>&1
STATUS=\$?
if [ \$STATUS -ne 0 ]
then
	$debug && cat .ckincs.h .ckfunc.c
	echo "cc line:  $cc -Isrc/inc $INCLUDES .ckfunc.c $LIBFLAG >> errors/ckfunc 2>&1" >> errors/ckfunc
	cat .ckincs.h .ckfunc.c >> errors/ckfunc
fi
rm -f a.out .ckfunc.c
exit \$STATUS
EOX
    chmod 755 .ckfunc

#
######################################################################
#
    $debug && echo "Creating .ckincl"
    echo "" > errors/ckincl
    cat >.ckincl <<EOX
echo "Testing include directive \$*" >> errors/ckincl
cat >.ckincl.c <<EOS
#include "config.h"
/* include these to check for macros (i.e., ntohs and friends) */
#include ".ckincs.h"
\$MAPNAMES
\$*
int
main() {
printf("Hello, world.\n");
}
EOS
$cc -Isrc/inc \$INCLUDES .ckincl.c \$LIBFLAG >> errors/ckincl 2>&1
STATUS=\$?
if [ \$STATUS -ne 0 ]
then
	$debug && cat .ckincs.h .ckincl.c
	echo "cc line:  $cc -Isrc/inc \$INCLUDES .ckincl.c \$LIBFLAG >> errors/ckincl 2>&1" >> errors/ckincl
	cat .ckincs.h .ckincl.c >> errors/ckincl
fi
rm -f a.out .ckincl.c
exit \$STATUS
EOX
    chmod 755 .ckincl

#
######################################################################
#
    if $brief
    then
	echo " "
	echo " "
	echo $n "Checking for system features...$c"
    else
	echo " "
	echo "Checking your system for these features..."
    fi

#
# check for some other include files (that we can deal with)
#
# Warning:  Ultrix doesn't like to see more than one space between
#	    tokens on input to its "read" command, so do NOT try to
#	    beautify this "cat" data!
#
    echo "#include <stdio.h>" > .ckincs.h
    (
	cat << EOF
sys/types.h C
netinet/in.h C
unistd.h c "echo '' > src/inc/unistd.h"
signal.h C
sys/socket.h C
EOF
${CKBSDINC-false} && cat << EOF
strings.h C "$cat /usr/include/string.h > src/inc/strings.h"
sys/uio.h X "$cat src/inc/port/xuio.h > src/inc/sys/uio.h"
sys/wait.h X "echo '' > src/inc/sys/wait.h"
EOF
    ) |
    while read hname htype worka
    do
	$brief || echo $n "#include <$hname> $c"
	if .ckincl "#include <$hname>"
	then
	    $brief || echo "ok"
	    case "$htype" in
	    C)
		echo "#include <$hname>" >> .ckincs.h
		;;
	    c)
		echo "#include <$hname>" >> .ckincs.h
		echo "#include <$hname>" >> src/inc/config.h
		;;
	    esac
	else
	    $brief || echo $n "not found, $c"
	    $brief && echo $n "$hname not found, $c"
	    if [ -n "$worka" ]
	    then
# This portion of code has been tested on SCO Unix.  Please notify me
# if it has to change for some reason.  -- jdc.
# Also tested on Umax, Sun, SGI, Ultrix, NCR and MIPS.
		$brief || echo "attempting workaround"
		eval worka=`echo $worka`
		eval $worka
	    else
		$brief || echo "hoping I can do without it"
	    fi
	fi
    done

    for func in $funclist
    do
	tfunc=`expr "$func" : "\([^(]*\)"`
	eval val=`echo \\\$$tfunc`
	if [ "$val" = "" ]
	then
	    $brief || echo $n "$tfunc() $c"
	    if .ckfunc "$func"
	    then
		$brief || echo "ok"
		eval $tfunc='have'
	    else
		$brief || echo "not found, added to libannex"
		$brief && echo $n "$tfunc() not found, added to libannex"
		eval $tfunc='need'
	    fi
	fi
    done

    if [ "$netware_type" != "TLI" ]
    then
	for func in $sfunclist
	do
	    tfunc=`expr "$func" : "\([^(]*\)"`
	    eval val=`echo \\\$$tfunc`
	    if [ "$val" = "" ]
	    then
		$brief || echo $n "$tfunc() $c"
		if .ckfunc "$func"
		then
		    $brief || echo "ok"
		    eval $tfunc='have'
		else
		    $brief || echo "not found, added to libannex"
		    $brief && echo $n "$tfunc() not found, added to libannex"
		    eval $tfunc='need'
		fi
	    fi
	done
    fi

    rhost=''
    if [ "$gethostbyname" = "need" ]
    then
	$brief || echo $n "rhost() $c"
	if .ckfunc "rhost(0)"
	then
	    rhost="have"
	    $brief || echo "ok"
	else
	    $brief || echo "not found, added to libannex"
	    rhost='need'
	    funclist="$funclist rhost(0)"
	fi
	$brief && echo $n ".$c"
    fi

    $brief || echo " "

    for func in $funclist
    do
	tfunc=`expr "$func" : "\([^(]*\)"`
	eval val=`echo \\\$$tfunc`
	case $val in
	  need)
	    > .needsome
	    echo "" >> src/inc/config.h
	    echo "#define need_$tfunc" >> src/inc/config.h
	    echo "#define $tfunc xylo_$tfunc" >> src/inc/config.h
	    file=`awk '$1 == f { print $2 ; exit(0) }' \
		f=$tfunc src/libannex/contents`
	    eval val=`echo \\\$$file\_c`
# we may not have a .c file to map to
	    if [ -n "$file" -a "$val" != "need" ]
	    then
		LIBANX_C="$LIBANX_C $file.c"
		LIBANX_O="$LIBANX_O $file.o"
		eval $file\_c="need"
	    fi
	    ;;
	have)
	    ;;
# Convertable functions -- all we need to do is specify a wrapper to
# go around the function and convert it to some internal function.
	*)
	    echo "#define $val" >> src/inc/config.h
	    ;;
	esac
    done

    if [ "$netware_type" != "TLI" ]
    then
	for func in $sfunclist
	do
	    tfunc=`expr "$func" : "\([^(]*\)"`
	    eval val=`echo \\\$$tfunc`
	    if [ "$val" = "need" ]
	    then
		> .needsome
		echo "" >> src/inc/config.h
		echo "#define need_$tfunc" >> src/inc/config.h
		echo "#define $tfunc xylo_$tfunc" >> src/inc/config.h
		file=`awk '$1 == f { print $2 ; exit(0) }' \
		    f=$tfunc src/libannex/contents`
		eval val=`echo \\\$$file\_c`
# we may not have a .c file to map to
		if [ -n "$file" -a "$val" != "need" ]
		then
		    LIBANX_C="$LIBANX_C $file.c"
		    LIBANX_O="$LIBANX_O $file.o"
		    eval $file\_c="need"
		fi
	    fi
	done
    fi

#
# carefully check if they are missing netdb.h
#
    if .ckincl "#include <netdb.h>"
    then
	netdb=have
# I don't think this line accomplishes anything at all!  -- jdc
	MAPNAMES="$MAPNAMES
#include <netdb.h>"
    else
	> .needsome
	netdb='need'
	echo "#define need_netdb" >> src/inc/config.h
    fi

# Unisys Sequent_PTX
    if [ "$hw_type" = "U6070" ]
    then
	echo " "                                >> src/inc/config.h
	echo "#include <netdb.h>"               >> src/inc/config.h
	echo "#define strings__h"               >> src/inc/config.h
	echo " "                                >> src/inc/config.h
    fi

# Sequent PTX.  This is done so that u_char, et al, can be used.
    if [ "$hw_type" = "SEQUENT_PTX" ]
    then
	echo " "			>> src/inc/config.h
	echo "#include <sys/socket.h>"	>> src/inc/config.h
	echo " "			>> src/inc/config.h
    fi

#
# Check for additional functions, typedefs, etc
#
# Warning:  Ultrix doesn't like to see more than one space between
#	    tokens on input to its "read" command, so do NOT try to
#	    beautify this "cat" data!
#
    (
    cat << EOF
index "index(0,0)"
rindex "rindex(0,0)"
select "select(0,0,0,0,0)"
u_char "u_char foo"
u_short "u_short foo"
u_long "u_long foo"
hostent "struct hostent foo"
servent "struct servent foo"
EOF
    if [ "$netware_type" = "EXOS" ]
    then
	echo "experror experror"
    fi
    ) |
# Be careful here:  the input redirection means that variables
# set below are lost (it's a subshell).
    while read func worka
    do
# This causes the typedef name in the first column to be evaluated
# as a shell variable -- thus if "index=have" has been executed,
# we won't even test for it.  Sort of a short-cut.
	eval val=`echo \\\$$func`
	if [ "$val" = "" ] 
	then
	    $brief || echo $n "$func $c"
	    eval worka=`echo $worka`
	    if .ckfunc $worka
	    then
		$brief || echo "ok"
		eval $func="have"
	    else
		$brief || echo "not found, substituting"
		eval $func="need"
	    fi
	fi
	eval val=`echo \\\$$func`
	if [ "$val" = "need" ] 
	then
	    > .needsome
	    echo "#define need_$func" >> src/inc/config.h
	elif [ "$val" != "have" ]
	then
	    echo "#define $val" >> src/inc/config.h
	fi
	$brief && echo $n ".$c"
    done


    $debug && echo "This should be the end of checking"

fi

##############################################################################
# 
# Previous code was skipped if the install was a Binary install.
#
###############################################################################
#

#
# WARNING: Specific needs for various hosts are put here.
#
mayneedfprintf=false
case "$hw_type" in

BULL)
    cat >> src/inc/config.h << EOFBULL
#include <sys/types.h>
#define have_iovec
EOFBULL
    $debug && echo "Done with Bull check"
    ;;

# Send/recv mods for Siemens MX300 System V using socket libraries...
MX300)
    cat >> src/inc/config.h << EOSR
/* sendrecv mods for Siemens System V with sockets.. */
#define need_sendmsg
#define sendmsg xylo_sendmsg
#define need_recvmsg
#define recvmsg xylo_recvmsg
#ifndef have_msghdr
#define have_msghdr
#endif
#define need_sendto
#define sendto xylo_sendto
#define NEED_0_SENDTO
EOSR
    $debug && echo "Done with MX300 check"
    ;;

#
# Convergent and HP include a broken "struct msghdr" in their socket.h
#
CONVERGENT|HP)
    if [ "$recvmsg" = "need" -o "$sendmsg" = "need" ]
    then
	echo "#define msghdr bogus_msghdr" >> src/inc/sys/socket.h
	cat /usr/include/sys/socket.h >> src/inc/sys/socket.h
	cat >> src/inc/sys/socket.h << EOSS
#if msghdr == bogus_msghdr
#undef msghdr
#endif
EOSS
    fi
    $debug && echo "Done with Convergent and HP check"
    ;;

#
# SCO UNIX Specific
#
SCO)
    if [ "$recvmsg" = "need" -o "$sendmsg" = "need" ]
    then
	echo "#define msghdr bogus_msghdr" >> src/inc/sys/socket.h
	cat /usr/include/sys/socket.h >> src/inc/sys/socket.h
    	cat >> src/inc/sys/socket.h << EOSS
#if msghdr == bogus_msghdr
#undef msghdr
#endif
EOSS
    fi
    mayneedfprintf=true
    LIBANX_C="$LIBANX_C crypt.c"
    LIBANX_O="$LIBANX_O crypt.o"
    cat << EOFSCO > src/libannex/crypt.c
char *crypt(key,salt)
char    *key;
char    *salt;
{
	static char     buff[200];
	strcpy(buff,key);
	return buff;
}
EOFSCO
# use "other" rtelnet for SCO.  (Newrtelnet has already been linked.)
    if [ -f src/rtelnet/rtelnet.smns ]
    then
	$mv src/rtelnet/rtelnet.c src/rtelnet/rtelnet.old
	$cp src/rtelnet/rtelnet.smns src/rtelnet/rtelnet.c
    fi
    $debug && echo "Done with SCO check"
    ;; 

DPX300)
    cat >> src/inc/config.h << EODPX3
#include <sys/types.h>
#define have_iovec
EODPX3
    $debug && echo "Done with DPX300 check"
    ;;

MOTO_88K)
    (
	echo "#ifndef have_msghdr" 
	echo "#define have_msghdr"
	echo "#endif"
    ) >> src/inc/config.h
    $debug && echo "Done with Motorola 88000 check"
    ;;

AIX|SGI|MIPS)
    echo "#define NEED_SIGNED_CHARS" >> src/inc/config.h
    $debug && echo "Done with AIX, SGI and MIPS check"
    ;;

PRIME)
    if [ "$os_type" = "SVR4" ]
    then
	echo "#define NEED_SIGNED_CHARS" >> src/inc/config.h
    fi
    $debug && echo "Done with Prime check"
    ;;

DPX200)
    if [ "$recvmsg" = "need" -o "$sendmsg" = "need" ]
    then
	echo "#define msghdr bogus_msghdr" >> src/inc/sys/socket.h
	cat /usr/include/sys/socket.h >> src/inc/sys/socket.h
	cat >> src/inc/sys/socket.h << EOSS
#if msghdr == bogus_msghdr
#undef msghdr
#endif
EOSS
    fi
    cat >> src/inc/config.h << EODPX2
#include <sys/types.h>
#define have_iovec
#define NEED_0_SENDTO
EODPX2
    $debug && echo "Done with DPX200 check"
    ;;

#
# Interactive UNIX Specific
#
IUNIX)
    echo "#define EWOULDBLOCK EAGAIN" >> src/inc/config.h
    $cp /usr/include/netinet/in.h src/inc/netinet/in.h
    $cp /usr/include/sys/bsdtypes.h src/inc/sys/bsdtypes.h
    $debug && echo "Done with Interactive check"
    ;;

PYRAMID)
    if [ "$netware_type" != "BSD" ]
    then
	echo "#define NEED_SIGNED_CHARS" >> src/inc/config.h
    fi
    $debug && echo "Done with Pyramid check"
    ;;

SSFT)
    if [ -f src/rtelnet/rtelnet.ssft ]
    then
	$mv src/rtelnet/rtelnet.c src/rtelnet/rtelnet.old
	$cp src/rtelnet/rtelnet.ssft src/rtelnet/rtelnet.c
    fi
    $debug && echo "Done with StarServer check"
    ;;

*)
    $debug && echo "Done with unknown check"
    ;;
esac

if $mayneedfprintf
then
    $debug && echo "Checking for broken fprintf alignment."
    cat > .ckalign.c << EOF
#include <stdio.h>
int main(argc,argv)
int argc;
char **argv;
{ printf("%d\n",sizeof(FILE)); return 0; }
EOF
    if
	$cc -o .ckalign1 $HWFLAG .ckalign.c > errors/ckalign &&
	$cc -o .ckalign2 .ckalign.c >> errors/ckalign
    then
	s1=`./.ckalign1`
	s2=`./.ckalign2`
	if [ "$s1" != "" -a "$s1" != "$s2" ]
	then
	    $debug && echo "Fixing fprintf alignment from $s1 to ${s2}."
	    echo "#define fprintf xylo_fprintf" >> src/inc/config.h
	    LIBANX_C="$LIBANX_C fprintf.c"
	    LIBANX_O="$LIBANX_O fprintf.o"
	    cat << EOSC > src/libannex/fprintf.c
#include <stdio.h>
int
xylo_fprintf(chan,f,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16)
FILE *chan;
char *f,*a1,*a2,*a3,*a4,*a5,*a6,*a7,*a8,*a9,*a10,*a11,*a12,*a13,*a14,*a15,*a16;
{
	if (chan >= _iob && chan < _iob+_NFILE)
		chan = (FILE *)((((char *)chan-(char *)_iob)/$s1)*$s2+
			(char *)_iob);
	return fprintf(chan,f,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16);
}
EOSC
	else
	    $debug && echo "No fix for fprintf alignment required."
	fi
    else
	$debug && echo "Can't compile alignment tests.  Hope this is ok!"
    fi
    rm -f .ckalign.c .ckalign1 .ckalign2
else
    $debug && echo "Not checking for broken fprintf alignment."
fi

###############################################################################
#

$didfixedconfig || $brief || (
    #
    # issue some warnings
    #
    needs=
    [ "$ntohl" = need ] && needs="$needs ntohl"
    [ "$htonl" = need ] && needs="$needs htonl"
    [ "$ntohs" = need ] && needs="$needs ntohs"
    [ "$htons" = need ] && needs="$needs htons"
#
# if needs has been set and warning flag is set 
#   then print warnings about needs list
#
    if [ "$needs" != "" ] && $warning_ntoh
    then
	echo " "
	echo "**** Warning:"
	echo "This host requires these byte order routines: $needs"
	echo " "
	echo "The hton[ls] and ntoh[ls] routines supplied in libannex"
	echo "may not be correct for the byte ordering on this host."
	echo "Check the comments in the file src/libannex/inet.c to"
	echo "see if they will work as-is on this host."
	echo " "
    fi
)

#
###############################################################################
#

if [ -f .needsome ]
then
    # add compatibility declarations
    echo ""
    echo "/* libannex linkage */"
    echo "#include <port/libannex.h>"
    echo ""
    echo "/* and additional port linkage */"
    echo $portfile
fi >> src/inc/config.h

if [ "$netdb" != "need" ]; then
    if [ "$hw_type" = "NCR_TOWER" ]; then
	cat << EOSS > src/inc/netdb.h

/* clean up for mess in <netdb.h> on NCR Tower */
#ifdef gethostbyname
#undef gethostbyname
#endif
#ifdef getservbyname
#undef getservbyname
#endif

#include <netdb.h>

/* clean up for mess in <netdb.h> on NCR Tower */
#ifdef need_gethostbyname
#ifdef gethostbyname
#undef gethostbyname
#endif
#define gethostbyname _gethostbyname
#endif

#ifdef need_getservbyname
#ifdef getservbyname
#undef getservbyname
#endif
#define getservbyname _getservbyname
#endif
EOSS
    fi
else
    # we'll do without it (see libannex.h), but make sure #includes work
    > src/inc/netdb.h
fi

$brief && echo $n ".$c"

#
###############################################################################
#

# determine where utilities go
case "$instdir" in
'')
    dflt=`./.loc . /etc $DEFDIR /usr/$box`
    instdir='blurfl/dyick'
    ;;
*)  dflt="$instdir"
    ;;
esac

$didfixedconfig && test -d "$dflt" && instdir=$dflt

# Note that we currently compile these paths right into the binaries,
# so we have to disable this feature.  Yuck.
if $usebinary
then
    instdir="/usr/annex"
    $brief || echo "Binary install -- the $Box utilities will be placed in ${instdir}."
else
    while [ ! -d "$instdir" ]
    do
	case "$instdir" in
	blurfl*)
	    ;;
	*)
	    echo " "
	    echo "$instdir does not appear to exist."
	    ;;
	esac
	echo " "
	rp="Where do you want the $Box utilities installed? [$dflt]"
	. .myread
	instdir=`./.filexp "$ans"`
	case "$instdir" in
	'')
	    instdir=$dflt
	    ;;
	esac
    done
fi

$brief && echo $n ".$c"

#
#########################################################################
#
# This add will allow users to install the oper*, config.annex etc. files
# in any directory they wish.
#
########################################################################
# Created for SPR.285
########################################################################

# Note that we currently compile these paths right into the binaries,
# so we have to disable this feature.  Yuck.
if $usebinary
then
    USER_BFS="/usr/spool/erpcd/bfs"
    $brief || echo "Binary install -- the $Box operational images will be placed in ${USER_BFS}."
else
    $brief || echo ""
    $brief || echo "Select a directory for the $Box operational images and boot files."
    while true
    do
	rp="BFS directory name [$USER_BFS]:  "
	. .myread
	if [ -z "$ans" ]
	then
	    ans=$USER_BFS
	else
	    ans=`./.filexp $ans`
	fi
	if .mkpath $ans
	then
	    USER_BFS=$ans
	    break
	else
	    echo "********** This directory doesn't exist **********"
	    echo "Please create it prior to installing the software,"
	    echo "or enter the name of another directory to use."
	fi
    done
    $debug && echo "Using $USER_BFS for images and boot files."
fi

#
# Setup variables for man page install 
#
$debug && echo "Running mansinstall"

#############################################
#
# generic manual page handling
#
#
# determine what type of manual page scheme should be used
#
BSDMAN='/usr/man/manl /usr/man/man1 /usr/catman'
VMAN='/usr/man/u_man/man1 /usr/catman/u_man/man1 /usr/catman/index'
MANSEARCH="$BSDMAN $VMAN"

#
# NotFirstPass = false <==> FirstPass = True
#
notfirstpass=false

if $debug ; then
    echo "If didfixedconfig = true then skip setting mansrc"
    echo "Else"
    echo "    set mansrc to the diretories that exist on this system."
    echo "Fixed config : $didfixedconfig"
fi

$didfixedconfig || 
    case "$mansrc" in
    '')
	    if $debug ; then
	    echo "mansrc was null, set it"
	fi
	mansrc=`./.loc . '' $MANSEARCH`
	;;
    esac
    if $debug ; then
	echo "Determine mantype from mansrc: $mansrc"
    fi
    case "$mansrc" in
    /usr/man/manl)
	dfltmantype=1
	dfltinst=y
	manlayout=onedir
	tdflt=1
	;;
    /usr/man/man[0-9]|/usr/share/man/man[0-9]|/usr/catman|/usr/man/catman/*)
	dfltmantype=1
	dfltinst=y
	manlayout=dist
	tdflt=2
	;;
    /usr/man/u_man*|/usr/catman/[aup]_man*)
	dfltmantype=2
	dfltinst=y
	;;
    /usr/catman/index)
	dfltmantype=3
	dfltinst=n
	tdflt=1
	;;
    #
    # if none of the standard directories were found then
    # set variables so that man pages don't get installed as
    # the default option.
    #
    *)
	$notfirstpass || {
	    mantype=none 
	    mansrc='' 
	    dfltmantype=0
	    dfltinst=n
	    notfirstpass=true
	}
	;;
    esac
#
# if this is the first pass then set mantype = none, notfirstpass=true
#
#    $notfirstpass || {
#    mantype=none
#    notfirstpass=true
#    }
if $debug ; then
	echo "NotFirstPass : $notfirstpass"
	echo "Default Man type: $dfltmantype"
	echo "Man Type        : $mantype"
	echo "Man Layout      : $manlayout"
	echo "Man Source Dir  : $mansrc"
	echo "Check for which type of man install is desired/required"
fi

while true
do
    rp="Do you wish to install manual pages at this time?: [$dfltinst]"
    . .myread
    if [ -z "$ans" ]
    then
	ans=$dfltinst
    fi
    case "$ans" in
      n*|N*)
	mantype="none"
	break
	;;
      y*|Y*)
	break
	;;
      *)
	echo " "
	echo "**** Enter 'Yes' or 'No', please!"
	echo " "
	continue
	;;
    esac
done

#
# If mantype isn't set then prompt user for man-page-layout.
#
if [ -z "$mantype" ]
then
    echo " "
    echo "What kind of on-line manual page layout do you have?"
    echo "Select the most appropriate on-line manual page layout:"
    echo " "
    echo " 0. None (don't install on-line manual pages automatically)"
    echo " 1. v7/BSD (/usr/man/man? /usr/catman/man?)"
    echo " 2. SystemV (/usr/{catman,man}/[apu]_man/man?)"
    echo " 3. SystemV.4 (/usr/catman/{ANNEX,index})"
    echo " "
    while true
    do
	rp="Enter on-line manual page type #: [$dfltmantype]"
	. .myread
	#
	# set ans to dfltmantype if <return> was entered
	#
	[ "$ans" = "" ] && ans=$dfltmantype
	#
	# determine what mantype to use and directory struct.
	#
	case "$ans" in
	0)
	    mantype=none
	    break
	    ;;
	1)
	    mantype=v7
	    MANSEARCH="$BSDMAN"
	    break
	    ;;
	2)
	    mantype=V
	    MANSEARCH="$VMAN"
	    break
	    ;;
	3)
	    mantype=V4
	    MANSEARCH="$VMAN"
	    break
	    ;;
	*)
	    echo " "
	    echo "**** Enter a number, please!"
	    echo " "
	    continue
	    ;;
	esac
    done
#
# the option chosen does not equal the default option
# so clear any preset variables.
#
    if [ "$ans" != "$dfltmantype" ]
    then
	$debug && echo "Clear mansrc, manlayout, manext, tdflt."
	mansrc=''
	manlayout=''
	manext=''
	tdflt=''
    fi
fi
if $debug
then
    echo "mansrc is set to : $mansrc"
    echo "mantype is set to: $mantype"
fi

case $mantype in

#
# BSD style Man install
#
v7)
    $debug && echo "BSD Style man install"
    xmansrc='blurfl/dyick'
    #
    ### While xmansrc isn't a directory do
    #
    while [ ! -d "$xmansrc" ]
    do
	dflt="$mansrc"
	case "$xmansrc" in
	blurfl*)
	    ;;
	*)
	    echo "$xmansrc does not appear to exist."
	    ;;
	esac
#######################################
# If mandist hasn't been set then ask.
#######################################
	if [ -z "$manlayout" ]
	then
	    xonedir='all in /usr/man/manl'
	    xdist='under /usr/man in man1,man5,man8'
	    echo " "
	    echo "How should the on-line manual pages be installed?"
	    echo " "
	    echo " 0. Abort; don't install manual pages"
	    echo " 1. One directory (i.e., $xonedir)"
	    echo " 2. Multiple directories (i.e., $xdist)"
	    echo " "
	    if [ -z "$tdflt" ]
	    then
		rp="Enter manual page layout type:"
	    else
		rp="Enter manual page layout type: [$tdflt]"
	    fi
	    . .myread
	    case "$ans" in
	    0|1|2)
		;;
	    ''|*)
		ans=$tdflt
		;;
	    esac
	    case "$ans" in
	    0)
		mantype="none"
		;;
	    1)
		manlayout=onedir
		base=''
		;;
	    2)
		manlayout=dist
		[ "" != "$dflt" ] && dflt=`$expr $dflt : '\(.*\)/.*' '|' $dflt`
		base=' base'
		;;
	    *)
		continue
		;;
	    esac
	    [ "$mantype" = "none" ] && break
	fi
	echo " "
	rp="What$base directory should be used? (q=quit) [$dflt]"
	. .myread
	xmansrc=`./.filexp "$ans"`
	[ -z "$xmansrc" ]  && xmansrc=$dflt
	if [ "$xmansrc" = "q" ]
	then
	    mantype="none"
	    break
	fi
	baddir1="That does not appear to be a manual page directory,"
	baddir2="but if you insist on it, you can use it."
	baddir3="but I'll let you use it, since you insisted."
	case "$manlayout" in
	onedir)
	    case "$xmansrc" in
	    *man?|*cat?)
		;;
	    "$lastxmansrc")
		echo " "
		echo $baddir1 ; echo $baddir3
		;;
	    *)
		echo " "
		echo $baddir1 ; echo $baddir2
		lastxmansrc="$xmansrc"
		xmansrc='blurfl/dyick'
		;;
	    esac
	    ;;
	dist)
	    case "$xmansrc" in
	    *man1)
		;;
	    *man?|*cat?)
		echo " "
		echo $baddir1 ; echo $baddir2
		lastxmansrc="$xmansrc"
		xmansrc='blurfl/dyick'
		;;
	    "$lastxmansrc")
		echo " "
		echo $baddir1 ; echo $baddir3
		;;
	    *)
		xmansrc="$xmansrc/man1"
		;;
	    esac
	    ;;
	esac
    done
    mansrc="$xmansrc"
    case "$mansrc" in
    *cat*)
	echo " "
	echo "Looks like I'll be putting pre-formatted manual pages there."
	;;
    esac
    # figure out extension
    case "$manlayout" in
    onedir)
	dflt=`$expr "$mansrc" : '.*\(.\)' '|' X`
	echo " "
	echo "How are manual page extensions handled in $mansrc?"
	echo " "
	echo " 0. Abort; don't install manual pages"
	echo " 1. They use a fixed extension like \".$dflt\""
	echo " 2. They use the extension of the manual page"
	echo "    (i.e., \".1\", \".5\", \".8\" - note that this is not typical)"
	echo " "
	rp="Enter manual page extension type: [1]"
	. .myread
	case "$ans" in
	0)
	    mantype="none"
	    ;;
	2)
	    manext=''
	    ;;
	''|*)
	    echo " "
	    rp="What is the extension used? [$dflt]"
	    . .myread
	    manext=`./.filexp "$ans"`
	    [ "$manext" = "" ] && manext=$dflt
	    ;;
	esac
	;;
    dist)
	manext=''
	;;
    esac
    ;;

#
# System V man install
#
V*)
    if $debug ; then
	echo "SysV type man install"
	echo "mansrc set to : $mansrc"
    fi    
    xmansrc='blurfl/dyick'
    if [ -z "$mansrc" ]
    then
	dflt=
    else
#	dflt=`$expr $mansrc : '\(.*\)/.*' '|' $mansrc`
	dflt=`$expr $mansrc : '\(/.*/.*\)/.*' '|' $mansrc`
    fi
    while [ ! -d "$xmansrc" ]
    do
	case "$xmansrc" in
	blurfl*)
	    ;;
	*)
	    echo "$xmansrc does not appear to exist."
	    ;;
	esac
	echo " "
	if [ $mantype = "V4" ]
	then
	    manlayout=packed
	    cat << EOS
On-line manual pages will be installed in the appropriate subdirectory
(i.e., ANNEX and index) of the manual base directory.
EOS
	else
	    cat << EOS
On-line manual pages will be installed in the appropriate subdirectory
(i.e., a_man/man1, p_man/man5, u_man/man1) of the manual base directory.
If you have on-line manual page sources, it's usually /usr/man.
If you only have pre-nroff'd ("cat") manual pages, it's /usr/catman.
EOS
	fi
	echo " "
	rp="What is the manual page base directory? (q=quit) [$dflt]"
	. .myread
	xmansrc=`./.filexp "$ans"`
	[ "$xmansrc" = "" ] && xmansrc=$dflt
	if [ "$xmansrc" = "q" ]
	then
	    mantype="none"
	    break
	fi
    done
    if [ "$mantype" != "none" ]
    then
	if [ "$mantype" = "V4" ]
	then
	    mansrc="$xmansrc/ANNEX"
	else
	    if [ -d $xmansrc/u_man/man1 ]
	    then
		mansrc="$xmansrc/u_man/man1"
	    else
		mansrc="$xmansrc/u_man/cat1"
		MAN="cat"
	    fi
	fi
	case "$mansrc" in
	*cat*)
	    echo " "
	    echo "Looks like I'll be putting pre-formatted manual pages there."
	    ;;
	esac
	# everyone has "cat.1", right?
	case "$mansrc"/cat.1*.z in
	*.z)
	    manlayout=packed
	    echo " "
	    echo "Manual pages there will be packed after being installed."
	    ;;
	esac
    fi
    ;;

#
# Don't install man pages.
#
*)
    mantype="none"
    ;;
esac

if [ "$mantype" != "none" ]
then
    OTHERINSTALL="$OTHERINSTALL install-man"
    $debug && echo "Man pages requested -- install will be $OTHERINSTALL"
fi

########################
#***********************
# End of maninstall
#***********************
########################

$debug && echo "Back from MANINSTALL"

###############################################################################
#
#
# SCO addition to install binaries from tape.
#
###############################################################################

if $debug
then
    echo "Check to see if this is a binary install."
    echo "Use binary = $usebinary"
fi

if $usebinary
then
    if $debug ; then
	echo "Copy files for binary install."
	echo "(System type is $hw_type)"
	echo "Then exit."
    fi

    echo "*** Installing $package images ***"
    [ ! -d $ERPCD ] && .mkpath $ERPCD
    [ ! -d $USER_BFS ] && .mkpath $USER_BFS
    $debug && echo "Move oper images to $USER_BFS"
    for i in $OPERS ; do
	if [ -f $USER_BFS/$i ]; then
	    [ ! -d $USER_BFS/OLD ] && $mkdir $USER_BFS/OLD
	    $mv -f $USER_BFS/$i $USER_BFS/OLD/$i
	fi
	$cp bfs/$i $USER_BFS
	$chmod 444 $USER_BFS/$i
    done

    $debug && echo "Create dummy config.annex and motd"
    cd $USER_BFS ; >> config.annex ; >> motd
    cd $cwd

    if [ ! -f ${instdir}/eservices ]
    then
    	if $debug ; then
		echo "Copy eservices to $instdir"
    	fi
    	$cp ./src/erpcd/eservices $instdir
    fi
    tobuild="no"
    toinstall="no"

    if $debug ; then
	echo "Remove temporary (dot) files."
    fi
    rm -f $tempfiles

    if $debug ; then
	echo "Install correct binaries and delete others."
	echo "Hardware type = $hw_type"
    fi
    bindir="./bin/$hw_type"
    if [ "$hw_type" = "SUN" ]
    then
	if [ "$os_type" = "SYS_V" -o "$os_type" = "SVR4" ]
	then
	    bindir="./bin/SOL2"
	fi
    fi
    if [ -d $bindir ]
    then
	if $cp  $bindir/[a-z]* $instdir
	then
	    if [ -f $instdir/ch_passwd ] 
	    then
		chmod 4111 $instdir/ch_passwd
	    fi
	    echo " "
	    echo "Executing \"du -s bin/[A-Z]*\""
	    du -s bin/[A-Z]* | $sed -e 's/^/	/'
	    cat << ETEXT

To save room on your system, the above directories can be removed.  They
contain the pre-compiled binary images for the various host-based
utilities.  Since the installation appears to have succeeded, it should
now be safe to remove these.  However, if you do choose to remove these
directories, you should know that you will not be able to re-run this
script for a binary install.  (You can always restore from the
distribution kit if you need to re-run, or do a build/install.)

ETEXT
	    rp="Remove these directories?  [y/N]: "
	    . .myread
	    case $ans in
	    Y*|y*)
		rm -rf bin/[A-Z]*
		;;
	    esac
	fi
    else
	echo "Error -- compiled utilities for $hw_type are missing."
    fi
    exit 2
else

#
# If we don't want a binary install, then remove binary directories
#
    ans=`echo bin/[A-Z]*`
    if [ "$ans" = "bin/[A-Z]*" ]
    then
	$debug && echo "Binaries already removed."
    else
	$debug && echo "Not a binary install.  Removing binaries."
	echo " "
	echo "Executing \"du -s bin/[A-Z]*\""
	du -s bin/[A-Z]* | $sed -e 's/^/	/'
	cat << ETEXT

To save room on your system, the above directories can be removed.  They
contain the pre-compiled binary images for the various host-based
utilities.  Since this installation will not be making use of these
files, it should now be safe to remove them.  However, if you do choose
to remove these directories, you should know that you will not be able
to re-run this script for a binary install.  (You can always restore
from the distribution kit if you need to do a binary installation.)

ETEXT
	rp="Remove these directories?  [y/N]: "
	. .myread
	case $ans in
	Y*|y*)
	    rm -rf bin/[A-Z]*
	;;
	esac
    fi
fi

###############################################################################
#
# End of if usebinary conditional...i.e. if this is a
# SCO unix binary install then don't create all the
# install stuff.
#
###############################################################################
#
#
# Query for deleting any oper.##.enet files that will not be used
#
# We're not sure yet ... comment out this block until we *are* sure.
if false
then

while true
do
 echo " "
 echo "Would you like to remove the unused oper.##.enet images? "
 echo "Note: This will save significant disk space on your host."
 rp="y/n [n]:"
 . .myread
 case $ans in
    Y*|y*)
	echo "What type(s) of $Box do you have ?"
	echo "$Box II/IIe ?"
	rp="y/n [y]:"
	. .myread
	case $ans in
	    y*)
		;;
	    n*)
		if $debug ; then
		    echo "Removing oper.16.enet"
		fi
		rm -irf bfs/oper.16.enet
		;;
	    *) 
		;;
	esac
	echo "$Box III ?"
	rp="y/n [y]:"
	. .myread
	case $ans in
	    y*)
		;;
	    n*)
		if $debug ; then
		    echo "Removing oper.42.enet"
		fi
		rm -irf bfs/oper.42.enet
		;;
	    *) 
		;;
	esac
	echo "Micro-XL ?"
	rp="y/n [y]:"
	. .myread
	case $ans in
	    Y*|y*)
		;;
	    N*|n*)
		if $debug ; then
		    echo "Removing oper.52.enet"
		fi
		rm -irf bfs/oper.52.enet
		;;
	    *) 
		;;
	esac
	echo "Micro-ELS ?"
	rp="y/n [y]:"
	. .myread
	case $ans in
	    Y*|y*)
		;;
	    N*|n*)
		if $debug ; then
		    echo "Removing oper.55.enet"
		fi
		rm -irf bfs/oper.55.enet
		;;
	    *) 
		;;
	esac
	;;
    N*|n*)
	;;
    esac
    break
done

# End of commented-out block.
fi

#
##########################################################################
#
$brief && echo " "
echo " "
echo $n "Creating configuration files...$c"

# Check for rtelnet version being used.  Platforms which do not yet have
# a newrtelnet/machdep.* file will not link machdep.c so that we compile
# the old rtelnet.  (I'd like to do the link here, but there are still
# some damaged systems out there that don't know about symlinks.  Sigh.)
RTELDIR="newrtelnet"
if [ ! -d src/newrtelnet ]
then
    RTELDIR="rtelnet"
else
    if [ ! -f src/newrtelnet/machdep.c ]
    then
	RTELDIR="rtelnet"
    fi
fi
$nortelnet && RTELDIR=""

#
# Before we go any farther, skip any SRCDIRS that aren't there
#
NEWSRC=''
for srcdir in $SRCDIRS $RTELDIR
do
    if [ -d src/$srcdir ]
    then
	NEWSRC="$NEWSRC $srcdir"
    fi
done
SRCDIRS="$NEWSRC"

echo $n ".$c"

#
# "common" BSD/SYSV install script
#
install=$cwd/src/installer
rm -f $install
cat > $install << EOSS
case \$1 in
read*|data|*exec)
    type=\$1 ; shift ;;
precious-*)
    precious=true
    type=\`$expr \$1 : 'precious-\\(.*\\)' \\| \$1\` ; shift ;;
execsuid)
    type=execsuid ; shift;;
*)
    type=exec ;;
esac
dir=\$1
shift
for file
do
    if [ -f \$dir/\$file ]; then
        if \${precious-false}; then
            echo \$dir/\$file exists, skipping install...
            continue
        fi
        $mv -f \$dir/\$file \$dir/OLD\$file
    fi
    $cp \$file \$dir
    case \$type in
    read*)
        $chmod 444 \$dir/\$file
        ;;
    data)
        $chmod 644 \$dir/\$file
        ;;
    sysexec)
        $chmod 544 \$dir/\$file
        ;;
    exec)
        $chmod 755 \$dir/\$file
        $strip \$dir/\$file
        ;;
    execsuid)
        $strip \$dir/\$file
        $chmod 4111 \$dir/\$file
        ;;

    esac
    $chown root \$dir/\$file
done
EOSS
chmod 555 $install

echo $n ".$c"

#
###############################################################################
#

cat >src/make.config <<EOSS
#
# $package src/make.config `$date`
#

AR    = $ar
CC    = $cc
INSTALL    = $install
RANLIB  = $ranlib

RM    = $rm
SHELL    = /bin/sh

INSTALL_DIR = $instdir
CFLAGS    = $HWFLAG $INCLUDES
LIBFLAG    = $LIBFLAG
LIBANX_C = $LIBANX_C
LIBANX_O = $LIBANX_O
CH_PASSWD = $CH_PASSWD
INSTALL_INITD = $INSTALL_INITD
USER_BFS = -DBFS=\\"$USER_BFS\\"
EOSS

echo $n ".$c"

cat > src/inc/port/install_dir.h <<EOSS
/*
 * $package src/inc/port/install_dir.h `$date`
 */
$DEF INSTALL_DIR "$instdir"
EOSS

echo $n ".$c"

cat >src/Makefile <<EOSS
#
# $package src/Makefile `$date`
#

SHELL    = /bin/sh
PARALLEL = 1
SRCDIRS = $SRCDIRS
BFS    = $USER_BFS

all:    $(SRCDIRS)

install: $OTHERINSTALL
	-@sh -c 'for srcdir in $(SRCDIRS) ; \\
	do \\
	$echo "*** Installing \$\$srcdir ***" > /dev/tty ; \\
	cd \$\$srcdir ; \\
	make -f ../make.config -f Makefile install ; \\
	cd .. ; \\
	done'

install-bfs:
	@$echo "*** Installing $package images ***" > /dev/tty
	-@sh -c '\\
	    if [ ! -d $(BFS) ] ; \\
	    then \\
		$mkdir $(BFS) ; \\
	    fi ; \\
	    cd ../bfs ; \\
	    $install readonly $(BFS) oper.* ; \\
	    cd $(BFS) ; \\
	    >> config.annex ; \\
	    >> motd'

clean:
	-@sh -c 'for srcdir in $(SRCDIRS) ; \\
	do \\
	cd \$\$srcdir ; \\
	make -f ../make.config -f Makefile clean ; \\
	cd .. ; \\
	done'
EOSS

echo $n ".$c"

for i in $SRCDIRS ; do
cat >>src/Makefile <<EOSS

$i:    $i.local

$i.local:
	@$echo "*** Building $i ***" > /dev/tty
	cd $i ; make -f ../make.config -f Makefile 
EOSS
done

echo $n ".$c"

#
###############################################################################
#

case "$mantype" in
v7)
    case "$manlayout" in
    dist)
	if [ -z "$mansrc" ]
	then
	    manbase=
	else
	    manbase=`$expr $mansrc : '\(.*\)/.*' '|' $mansrc`
	fi
	manrepl='man$$ext/$$page'
	;;    
    onedir)
	manbase="$mansrc"
	if [ -z "$manext" ]
	then
	    manrepl='$$page'
	else
	    manrepl='`basename $$page .$$ext`.$(MANMAP)'
	fi
	;;
    esac
    
    case "$mansrc" in
    *cat*)
	usedir=../man/cat
	;;
    *)
	usedir=../man/src
	;;
    esac
    cat >>src/Makefile <<EOSS

MANDIR = $usedir
MANEXTS = 1 5 8
MANBASE = $manbase
MANMAP = $manext
PACKABLE = $packed

install-man:
	@$echo "*** Installing manual pages ***" > /dev/tty
	@sh -c 'cd $(MANDIR) ; for ext in $(MANEXTS) ; do \\
	for page in *.\$\$ext ; do \\
		dstname=$(MANBASE)/$manrepl ; \\
		$rm -f \$\$dstname* ; \\
		$cp \$\$page \$\$dstname ; \\
		$(PACKABLE) && $pack -f \$\$dstname ; \\
		$chmod 444 \$\$dstname* ; \\
	done ; \\
	done'
EOSS
    ;;
V)
    manbase=`$expr $mansrc : '\(.*\)/.*/.*' '|' $mansrc`
    packed=false
    case "$manlayout" in
      packed)
# for 14-char filename limits 
	packed=test' `expr $$dstname : \.\*` -le 12'
	;;
    esac
    
    case "$mansrc" in
      *cat*)
	usedir=../man/cat
	echo "" > man/prefix
	;;
      *)
	usedir=../man/src
	echo ".ds sy V" > man/prefix
	;;
    esac
    cat >>src/Makefile <<EOSS

MANDIR = $usedir
MANEXTS = 5 8
MANBASE = $manbase
MANMAP = p_man/${MAN}4 4 a_man/${MAN}1 1m
PACKABLE = $packed

install-man:
	@$echo "*** Installing manual pages ***" > /dev/tty
	@sh -c 'set $(MANMAP) ; cd $(MANDIR) ; for ext in $(MANEXTS) ; do \\
	subdir=\$\$1 subext=\$\$2 ; \\
	for page in *.\$\$ext ; do \\
		dstname=$(MANBASE)/\$\$subdir/\`basename \$\$page .\$\$ext\`.\$\$subext ; \\
		$rm -f \$\$dstname* ; \\
		$cat ../prefix \$\$page > \$\$dstname ; \\
		$(PACKABLE) && $pack -f \$\$dstname ; \\
		$chmod 444 \$\$dstname* ; \\
	done ; \\
	shift ; shift ; \\
	done'
EOSS
    ;;
V4)
    manbase=`$expr $mansrc : '\(.*\)/.*' '|' $mansrc`
    packed=false
    case "$manlayout" in
      packed)
# for 14-char filename limits 
	packed=test' `expr $$fname : \.\*` -le 12'
	;;
    esac
    
    case "$mansrc" in
      *cat*)
	usedir=../man/cat
	echo "" > man/prefix
	;;
      *)
	usedir=../man/src
	echo ".ds sy V" > man/prefix
	;;
    esac
    cat >>src/Makefile <<EOSS

MANDIR = $usedir
MANBASE = $manbase
PACKABLE = $packed

install-man:
	@$echo "*** Installing manual pages ***" > /dev/tty
	@sh -c 'cd $(MANDIR) ; \\
        if [ ! -d $(MANBASE)/ANNEX ] ; \\
	then \\
		$mkdir $(MANBASE)/ANNEX ; \\
	else \\
		$rm -f $(MANBASE)/ANNEX/* ; \\
	fi ; \\
        if [ -f $(MANBASE)/index/annex ] ; \\
	then \\
		$rm -f $(MANBASE)/index/annex ; \\
	fi ; \\
	for page in * ; \\
	do \\
		if fname=\`$expr \$\$page : "\\(.*\\)\\..*"\` ; \\
		then \\
			dstname=$(MANBASE)/ANNEX/\$\$fname ; \\
			$rm -f \$\$dstname* ; \\
			$cat ../prefix \$\$page > \$\$dstname ; \\
			if $(PACKABLE) ; \\
			then \\
				$pack -f \$\$dstname ; \\
				$echo \$\${dstname}.z >> $(MANBASE)/index/annex ; \\
			else \\
				$echo \$\$dstname >> $(MANBASE)/index/annex ; \\
			fi ; \\
			$chmod 444 \$\$dstname* ; \\
		else \\
			$echo "Cannot install \$\$fname" ; \\
		fi ; \\
	done;'
EOSS
    ;;
esac

#
###############################################################################
#

echo "complete."

notbuilt=true
notinstalled=true

if $debug
then
   echo "To Build flag = $tobuild"
fi

if $nomake
then
   tobuild="no"
fi

#
# tobuild is Y or N depending on if this is a SCO binary install,
# also it should be set to N if there is no cc on the system.
#
if [ -z "$tobuild" ]
then
    echo " "
    rp="Shall I compile the tools for you? [y]"
    . .myread
else
    ans=$tobuild
fi
case "$ans" in
n*)
    ;;
*)
    compile=true
    echo " "
    echo "Compiling the tools; output being saved in \"Build.out\""
    echo " "
    cd src
    make > ../Build.out 2>&1 && notbuilt=false
    cd ..
    if $notbuilt
    then
	cp Build.out errors
	echo " "
	echo "Compile failed.  Please report the results in the \"errors\" directory to"
	echo "your support representative."
	echo " "
    fi
    ;;
esac

if $notbuilt
then
    echo " "
    echo "Compilation of tools not completed."
    echo "To compile the tools use \"cd src ; make\""
else
    if [ -z "$toinstall" ]
    then
	echo " "
	echo "Note: you must be running as root for the next step."
	echo "      If you are not, then say \"no\" and do it by hand."
	echo " "
	rp="Shall I install the tools for you? [y]"
	. .myread
    else
	ans=$toinstall
    fi
    case "$ans" in
    n*)
	;;
    *)
	echo " "
	echo "Installing the tools; output being saved in \"Install.out\""
	echo " "
	cd src
	if [ "$hw_type" = "MX300" ]
	then
	    ucb make install > ../Install.out 2>&1 && notinstalled=false
	else
	    make install > ../Install.out 2>&1 && notinstalled=false
	fi
	cd ..
	if $notinstalled
	then
	    cp Install.out errors
	    echo " "
	    echo "Installation failed."
	    echo " "
	fi
	;;
    esac
fi

if $notinstalled
then
    echo " "
    echo "Installation not completed."
    echo "To install the tools and manual pages use \"cd src ; make install\""
fi

rm -f $tempfiles

echo " "
echo "Done."
echo " "

exit 0
