
#! /bin/sh
#    Digital TCP/IP printer daemon installation script.
#
# Installation script for the DIGITAL TCP/IP host resident software.
#
# 1) Log in as root or su root
# 2) Copy the files from the installation floppy into your installation 
#    directory.
#	cd /usr/nic
#	tar -xvf  /dev/rfd0
# 3) Execute the install script from the installation directory.
#	./tcpinst
# 4) Answer the questions and follow the instructions as directed by the
#    install script.
# 5) Test by printing a file. If you have trouble look at the troubleshooting
#    guide.
#
# The install script is straight forward and follows the simple 
# algorithm which is described as follows:
#
#   1) Verify and initialize the environment as follows:
#
#       Setup HARDWARE aliases and globals
#
#	Make sure running as root
#
#       Check that all needed DIGITAL utilities are in this directory or in a
#       subdirectory named SYSTEM_HARDWARE (for supported systems only)
#       where SYSTEM and HARDWARE are found by the uname (-s and -m) command.
#
#   2) Copy the installation files into the target directories
#      Copy the files in CWD to NICPRINT_DIR
#
#   3) Create the User specific files (Non Ultrix BSD systems only)
#	Create the named pipes
#	Create the spool dir
#
#   4) Modify /etc/printcap if needed
#
#   5) Startup the daemon process
#
#
# This script will work on any unix that understands #! and has the bourne
# shell (/bin/sh) installed. Ultrix systems have a skeletal /bin/sh. The
# set of commands below checks for /bin/sh5 and uses it to keep Ultrix and
# similar systems happy.

if [ $# -ne 1 ]
then
    if test -f /bin/sh5
    then
        exec /bin/sh5 $0 1
    fi
fi

#trap 'exit' 15

##############
# Declare some functions used by the main code seen at the end of
# this script.

yes_no () {

while :
  do
    ANSWER=""
    read ANSWER

    case "$ANSWER" in
    yes)	return 1 ;;
    y)		return 1 ;;
    no)		return 0 ;;
    n)		return 0 ;;
    *)
		$ECHONOCR "Please enter yes or no : ${nnl}"
		continue
		;;
    esac
  done

}

#set up command aliases and globals
set_commands_and_globals () {
	ECHO=echo

	SED=/bin/sed
	if [ ! -f "$SED" ] #this utility is needed by checkpath
	then
	   $ECHO "Required utility program is missing. /bin/sed not found."
	   exit 3
	fi

case "`echo 'x\c'`" in
'x\c')  ECHONOCR="echo -n"  nnl= ;;      # BSD
x)      ECHONOCR="echo"     nnl="\c" ;;  # Sys V
*)      ECHO "Can't set up echo, exiting $0." 1>&2; exit 1;;
esac

	RM=rm
        SU=su
	MKDIR=mkdir
	MKNOD=mknod
	CHOWN=chown
	CHMOD=chmod
	CP=cp
	CAT=cat
	MV=mv
	GREP=grep
	LS=ls
        PS=ps
        UNAME=uname

	for x in $SU $RM $MKDIR $MKNOD $CHOWN $CHMOD $CP $CAT $MV $SED $GREP $LS $PS
	do
	   if [ ! -f "$x" ]
	   then
		checkpath $x
		if [ "$?" = 0 ]
		then
		   exit 3
		fi
	   fi
	done

#global variables
	PRINTERS_DONE=""
        SYSTEM=""
	ADD_FILTERS="0"
	INSTALL="0"
	CWD=`pwd`
	NOW=`date`
	NICPRINT_DIR=/usr/nic
	DEVDIR=/dev/nic
	BASE_PORT_NUM=10000
	PHYS_PORT=1

	SPOOLDIR=/usr/spool
	SPOOLQ_OWNER=lp

}


checkpath () {
#checks if commands are in the path. Returns a 1 if they are and 0 if not
#Arg1 the command to find
#
# This function requires that SED and ECHO be properly set
#
	commandtofind=$1
	pathdirs=`$ECHO $PATH |$SED -e 's/:/ /g' `
	for x in $pathdirs
	do
	   #$ECHO "Debug: Checking path $x"
	   if [ ! -d "$x" ]
	   then
		#$ECHO "Warning: Path item not found $x"
		continue
	   fi
	
	   if [ -f "${x}/${commandtofind}" ]
	   then
		#$ECHO "Debug: Command found in path. ${x}  ${commandtofind}"
		return 1
	   fi
	done
	$ECHO "Required utility not found. ${commandtofind}"
	return 0
}

	
get_system_name () {

	while :

	do 

	$ECHO ""
	$ECHO "	Select the type of system that you are installing on : "
	$ECHO ""
	$ECHO "	1)	AT&T / SVR4 i386"
	$ECHO "	2)	SCO UNIX systemV"
	$ECHO "	3)	None of the above."
	$ECHO ""
	$ECHONOCR "	Enter choice ( 1 , 2 or 3 ) -->   ${nnl}"
		read SYS_ID

		if [ \( "$SYS_ID" = 1 \) ]
		 	then
		 	SYSTEM="i386"
			return 1
		fi

		if [ \( "$SYS_ID" = 2 \) ]
		 	then
		 	SYSTEM="scosysv"
			return 1
		fi
		
		if [ \( "$SYS_ID" = 3 \) ]
		 	then
		 	return 0
		fi
		continue
	done	
	}

# insure that we're run breakn
verify_uid () {
	#$ECHO "Debug: verify_uid"

# would like to SU and continue the script, but too many problems
#        if test -z "`id | $GREP 'uid=0'`"
#        then
#           $ECHO "You must login as superuser to run this program."
#           $SU
#        fi

	if test -z "`id | $GREP 'uid=0'`"
	then
            $ECHO
            $ECHO "You must have superuser privileges to run this program."
            $ECHO
            exit 1
        fi

}

verify_target_sys () {

    SYSTEM="`$UNAME -s`"
    HARDWARE="`$UNAME -m`"

    if [ \( "$SYSTEM" != HP-UX \) -a \( "$SYSTEM" != AIX \) -a \( "$SYSTEM" != OSF1 \) -a \( "$SYSTEM" != SunOS \) ]
    then
        SYSTEM="`$UNAME -s`_`$UNAME -m`"
    fi

    if [ \( "$SYSTEM" = SunOS \) ]
    then
        RELEASE="`$UNAME -r | cut -c1`"
        $ECHO "The release is $RELEASE"

        if [ \( "$RELEASE" = 5 \) ]
        then
            SYSTEM="SunOS_5.x"
        else
            if [ \( "$RELEASE" = 4 \) ]
            then
                SYSTEM="SunOS_4.x"
            fi
        fi
    fi
    

    $ECHO
    case "$SYSTEM" in
    ULTRIX_RISC)  $ECHO "The system name is $SYSTEM" ;;
    SunOS_4.x) $ECHO "The system name is $SYSTEM" ;;
    SunOS_5.x)   $ECHO "The system name is $SYSTEM" ;;
    OSF1) 	   $ECHO "The system name is $SYSTEM" ;;
    scosysv) 	   $ECHO "The system name is $SYSTEM" ;;
    i386)  $ECHO "The system name is $SYSTEM" ;;
    HP-UX)       $ECHO "The system name is $SYSTEM" ;;
    AIX)       $ECHO "The system name is $SYSTEM" ;;
    *) 
    get_system_name 

    if [ $? = "1" ]
	then 
	return 0
	fi

	cat << EOM |more
echo $SYSTEM
Operating system $SYSTEM not recognized. If your system is not supported you
may need to port the DIGITAL TCP/IP host resident software. Source files for the
necessary utilities can be found with the installation software. 

This installation script uses the format SYSTEM_HARDWARE (eg ULTRIX_RISC) for 
its system name, where SYSTEM and HARDWARE can be displayed by the uname 
command. Executable files for supported machines can be found in the 
installation directory tree in the SYSTEM_HARDWARE subdirectory.

If you have completed the port and loaded the executables into the top level
of the installation directory, then you may continue the installation by 
answering the questions.  Otherwise terminate the script by hitting <CTRL>C

EOM

        $ECHONOCR "Does your system use the printcap file for printer setup? ${nnl}"

	yes_no
	if [ $? = "1" ]
	then
            $ECHO "Trying script as a generic BSD system ..."
            SYSTEM="BSD"
        else
            $ECHO
            $ECHO "Trying script as a generic SYSTEM V system ..."
            SYSTEM="SYSTEMV"
        fi
        $ECHO
        ;;
    esac
    $ECHO
}


# Verify that the executables needed to install and print are here!
# If a needed tool is not in this (the install) directory OR in the
# SYSTEM_HARDWARE subdirectory abort the installation.
# 
check_utilities () {
     BUNDLE=""

     if [ \( "$SYSTEM" = ULTRIX_RISC \) ]
     then
         BUNDLE="nicfilter infilter nsconfig outfilter psbanner psfilter"
     fi

     if [ \( "$SYSTEM" = SunOS_5.x \) -o \( "$SYSTEM" = i386 \) ]
     then
         BUNDLE="nicfilter infilter nsconfig"
     fi

     if [ \( "$SYSTEM" = HP-UX \) -o \( "$SYSTEM" = AIX \) -o \( "$SYSTEM" = scosysv \) ]

     then
         BUNDLE="nic_print nsconfig"
     fi

     if [ \( "$SYSTEM" = SunOS_4.x \) -o \( "$SYSTEM" = OSF1 \) ] 

     then
         BUNDLE="nic_print infilter nsconfig outfilter psbanner psfilter"
     fi



   exec 4<&1                    # Throw away output from these commands
   exec 5<&2
   exec > /dev/null 2>&1

     for x in $BUNDLE
     do
             $CP $CWD/$SYSTEM/$x $CWD/
         
	if test -z "`$LS $CWD/$x`"
         then
             exec 1<&4 
             exec 2<&5 

cat << EOM |more

ERROR : N.I.C Installation aborted. Required utilities are missing.

The following executables are required before installation is possible :

	${BUNDLE}

If this is a supported system these executables should be supplied with 
the installation software in the directory $SYSTEM. If this is not a 
supported system the source code for the host resident software must 
be ported before installation can be completed. 

EOM

	     exit 3
	 fi

     done

     exec 1<&4 
     exec 2<&5 

}


set_file_mode () {

	$CHMOD 755 $CWD/*
	$CHMOD 666 $CWD/*.c
	$CHMOD 666 $CWD/*.h
	$CHMOD 666 $CWD/nicprint.conf

}


# copy the files from CWD into NICPRINT_DIR
# Now the NICPRINT_DIR directory is empty and we can move the files out 
# of the current directory into NICPRINT_DIR.
# 
copy_parts_to_nicprint () {
   $ECHO
   $ECHO "Copying $CWD to ${NICPRINT_DIR}"
   exec 4<&1                    # Throw away output from these commands
   exec 5<&2
   exec > /dev/null 2>&1

	for x in $CWD/*
	do
	   #$ECHO "	Copying $x to ${NICPRINT_DIR}"
	   $CP $x ${NICPRINT_DIR}/
	done

   exec 1<&4 
   exec 2<&5 
}

#create a character device with the same major/minor #'s as /dev/null
#for AIX output to go to (it is simultaneously sent to the named pipe
#via the backend program

create_null_dev () {
        #$ECHO Check existence
        if [ ! -p "/dev/${1}" ]
        then
           #$ECHO making a character device with same major/minor as /dev/null
           $MKNOD /dev/${1} c 2 2
        fi

        #$ECHO create null device
}

#create a named pipe
create_npipe () {
	if [ ! -d "${DEVDIR}" ]
	then
	   #$ECHO making the dev directory
	   $MKDIR ${DEVDIR}
	fi
	#$ECHO Check existence
	if [ ! -p "${DEVDIR}/${1}" ]
        then
	   #$ECHO making the named pipe
	   $MKNOD ${DEVDIR}/${1} p

           if [ \( "$SYSTEM" = BSD \) -o \( "$SYSTEM" = ULTRIX_RISC \) -o \( "$SYSTEM" = SunOS_4.x \) -o \( "$SYSTEM" = OSF1 \) ]
           then
# CHMOD is not essential and may fail on some systems so hide output from user
   exec 4<&1                              # Throw away output from commands
   exec 5<&2
   exec > /dev/null 2>&1
	       $CHOWN daemon ${DEVDIR}/${1}
   exec 1<&4 
   exec 2<&5 
	       $CHMOD 666 ${DEVDIR}/${1}
           fi

           if [ \( "$SYSTEM" = AIX \) ]
	   then
               $CHMOD 666 ${DEVDIR}/${1}
           fi

	   if [ \( "$SYSTEM" = HP-UX \) -o \( "$SYSTEM" = SYSTEMV \) -o \( "$SYSTEM" = scosysv \) ]
           then
# CHMOD is not essential and may fail on some systems so hide output from user
   exec 4<&1                              # Throw away output from commands
   exec 5<&2
   exec > /dev/null 2>&1
	       $CHOWN lp ${DEVDIR}/${1}
   exec 1<&4 
   exec 2<&5 
	       $CHMOD 600 ${DEVDIR}/${1}
           fi

	fi
	#$ECHO create npipe returning
}


#Create a spool dir
create_spool_dir () {
	if [ ! -d ${SPOOLDIR}/${1} ]
        then
	   $MKDIR ${SPOOLDIR}/${1}
	   $CHOWN daemon ${SPOOLDIR}/${1}
	fi
}

#
# Place the nicprint_conf file in the spool directory with
# <printer name> <printer port> as the contents of the file.
#

init_nconfig () {
cat << EOM > ${SPOOLDIR}/${PNAME}/nicprint_conf
EOM
}

display_answers () {

$ECHO ""
$ECHO ""
$ECHO "You have entered the following information for your network interface card :"
$ECHO ""

if [ -n "$NP_NAME" ]
then
	$ECHONOCR "  Nodename of the network interface card :	${nnl}"
	$ECHO $NP_NAME
fi

if [ -n "$PNAME" ]
then
	$ECHONOCR "  Printer name to be used by this printer :	${nnl}"
	$ECHO "$PNAME"
fi

}


get_nodename () {
	$ECHO ""
	$ECHONOCR "Enter the IP nodename of this network interface card.  ? ${nnl}"
	read NP_NAME
}

get_printername () {
	$ECHO ""
	$ECHONOCR "Enter the printer name to be used by this printer? ${nnl}"
	read PNAME
}

get_queuename () {
	$ECHO ""
	QNAME=$PNAME
	$ECHO "The queue for this printer will be named as $QNAME after this installation"
}

generate_ultrix_printcap () {
	if [ -f "/tmp/DIGITALpcap$$" ]
	then
	   rm -f /tmp/DIGITALpcap$$
	fi

	$ECHO
	$ECHO "The sample printcap entry shown below has been created for"
	$ECHO "your printer in the file /tmp/DIGITALpcap$$."
	$ECHO
	$ECHO "#"
	$ECHO "# This printcap entry is automatically generated for the network interface card product"
	$ECHO "# The input filter supplied, called infilter, can be replaced"
	$ECHO "# by your own special purpose filter."
	$ECHO "#" > /tmp/DIGITALpcap$$
	$ECHO "# This printcap entry is automatically generated for the network interface card product" >> /tmp/DIGITALpcap$$
	$ECHO "# The input filter supplied, called infilter, can be replaced" >> /tmp/DIGITALpcap$$
	$ECHO "# by your own special purpose filter." >> /tmp/DIGITALpcap$$
	
	$ECHO "${PNAME}|NIC printer :\\"
	$ECHO "	:lp=/dev/null:\\"
	$ECHO "	:if=${NICPRINT_DIR}/infilter|${NICPRINT_DIR}/nicfilter ${NP_NAME} ${PORT_NUM}:\\"
	$ECHO "	:of=${NICPRINT_DIR}/outfilter:\\"
	$ECHO "	:sd=${SPOOLDIR}/${QNAME}:"
	$ECHO "${PNAME}|NICPrint printer :\\" >> /tmp/DIGITALpcap$$
	$ECHO "	:lp=/dev/null:\\" >> /tmp/DIGITALpcap$$
	$ECHO "	:if=${NICPRINT_DIR}/infilter|${NICPRINT_DIR}/nicfilter ${NP_NAME} ${PORT_NUM}:\\" >> /tmp/DIGITALpcap$$
	$ECHO "	:of=${NICPRINT_DIR}/outfilter:\\" >> /tmp/DIGITALpcap$$
	$ECHO "	:sd=${SPOOLDIR}/${QNAME}:" >> /tmp/DIGITALpcap$$
	$ECHO "#" >> /tmp/DIGITALpcap$$
	$ECHO "#"
}

generate_simp_printcap () {
	if [ -f "/tmp/DIGITALpcap$$" ]
	then
	   rm -f /tmp/DIGITALpcap$$
	fi

	$ECHO
	$ECHO "The sample printcap entry shown below has been created for"
	$ECHO "your printer in the file /tmp/DIGITALpcap$$."
	$ECHO
	$ECHO "#"
	$ECHO "# This printcap entry is automatically generated for the network interface card product"
	$ECHO "# Simple input and output filters are provided for your convenience."
	$ECHO "#" > /tmp/DIGITALpcap$$
	$ECHO "# This printcap entry is automatically generated for the network interface card product" >> /tmp/DIGITALpcap$$
	$ECHO "#" > /tmp/DIGITALpcap$$
	if [ $ADD_FILTERS = "0" ] 
	then
	   $ECHO "${PNAME}|NIC printer :\\"
	   $ECHO "	:lp=${DEVDIR}/${PNAME}:\\"
	   $ECHO " 	:if=${NICPRINT_DIR}/infilter:\\"
	   $ECHO "#	:of=${NICPRINT_DIR}/outfilter:\\"
	   $ECHO "	:sd=${SPOOLDIR}/${QNAME}:"
	   $ECHO "${PNAME}|NIC printer :\\" >> /tmp/DIGITALpcap$$
	   $ECHO "	:lp=${DEVDIR}/${PNAME}:\\" >> /tmp/DIGITALpcap$$
	   $ECHO " 	:if=${NICPRINT_DIR}/infilter:\\" >> /tmp/DIGITALpcap$$
	   $ECHO "#	:of=${NICPRINT_DIR}/outfilter:\\" >> /tmp/DIGITALpcap$$
	   $ECHO "	:sd=${SPOOLDIR}/${QNAME}:" >> /tmp/DIGITALpcap$$
	else
	   $ECHO "${PNAME}|NIC printer :\\" >> /tmp/DIGITALpcap$$
	   $ECHO "${PNAME}|NIC printer :\\"
	   $ECHO "	:lp=${DEVDIR}/${PNAME}:\\"
	   $ECHO "	:lp=${DEVDIR}/${PNAME}:\\" >> /tmp/DIGITALpcap$$
	   $ECHO "	:sd=${SPOOLDIR}/${QNAME}:\\"
	   $ECHO "	:of=${NICPRINT_DIR}/outfilter:"
	   $ECHO "	:sd=${SPOOLDIR}/${QNAME}:\\" >> /tmp/DIGITALpcap$$
	   $ECHO "	:of=${NICPRINT_DIR}/outfilter:" >> /tmp/DIGITALpcap$$
	fi
	$ECHO "#" >> /tmp/DIGITALpcap$$
	$ECHO "#"
}

try_append_simp_printcap () {
        $ECHO
        $ECHO "This entry can be appended automatically to your /etc/printcap file."
        $ECHO
	$ECHONOCR "Would you like to perform this action? (yes,y,no,n) ? ${nnl}"
	yes_no
	if [ $? = "1" ]
	then
	   $CP /etc/printcap /etc/oldprintcap
	   $CAT /etc/oldprintcap /tmp/DIGITALpcap$$ > /etc/printcap
	   $ECHO
	   $ECHO /etc/printcap has been updated.
	   $ECHO
	else
	   $ECHO
	   $ECHO "/etc/printcap is not modified."
	   $ECHO
	fi
}


start_daemon() {

   exec 4<&1                              # Throw away output from commands
   exec 5<&2
   exec > /dev/null 2>&1
    if test -z "`$PS -ef |$GREP \"nic_print ${DEVDIR}/$PNAME $NP_NAME $PORT_NUM\" |$GREP -v grep`"
    then
        if test -z "`$PS -ax |$GREP \"nic_print ${DEVDIR}/$PNAME $NP_NAME $PORT_NUM\" |$GREP -v grep`"
        then
   exec 1<&4 
   exec 2<&5 
           $ECHO "Starting printer daemon :"
           $ECHO
           $ECHO "        ${NICPRINT_DIR}/nic_print ${DEVDIR}/$PNAME $NP_NAME $PORT_NUM&"
           ${NICPRINT_DIR}/nic_print ${DEVDIR}/$PNAME $NP_NAME $PORT_NUM&
        else
   exec 1<&4 
   exec 2<&5 
           $ECHO "WARNING : Printer $PNAME already has a daemon serving it"
           $ECHO
           $ECHO "You may have already configured printer $PNAME. If you have"
           $ECHO "installed a new DIGITAL TCP/IP release or changed the printer"
	   $ECHO "configuration you may need to kill the existing daemon and"
	   $ECHO "restart it with the command :"
           $ECHO
           $ECHO "	${NICPRINT_DIR}/nic_print ${DEVDIR}/$PNAME $NP_NAME $PORT_NUM&"
           $ECHO
           $ECHO "The current version of the installation script DOES NOT check"
           $ECHO "for duplicate entries in the /etc/printcap file."
        fi
    else
   exec 1<&4 
   exec 2<&5 
        $ECHO "WARNING : Printer $PNAME already has a daemon serving it"
        $ECHO
    fi
}

tell_user_ultrix_instructs () {

cat << EOM |more

Printer $PNAME now has a logical connection to network interface card, host $NP_NAME. 
You should test to make sure that the network interface card will properly
communicate with this host before attempting to print. 
Refer to the TCP/IP Installation chapter of the N.I.C. Owners Manual for further information.


If there are any problems refer to the trouble shooting guide.

EOM
}

tell_user_sysV_instructs () {

cat << EOM |more

TCP/IP installation completed successfully.

Before you can use your network interface card, the printer 
interface program that is to be used by this printer must be edited 
to redirect output to the nicfilter program. Printers may then be 
configured using the lpadmin maintenance command.

Refer to the System V Solaris section in the TCP/IP Installation 
chapter of the N.I.C. Owners Manual for further information.


EOM
}

tell_user_final_instructs () {

cat << EOM |more

Printer $PNAME now has a logical connection through ${DEVDIR}/$PNAME to 
the network interface card, host $NP_NAME. You should test to make sure 
that the network interface card will properly communicate with this host before 
attempting to print. Refer to the TCP/IP Installation chapter of the 
N.I.C. Owners Manual for further information. 
If there are any problems refer to the trouble shooting guide.


EOM
}


final_message () {

    $ECHO
    if test -n "$PRINTERS_DONE"
    then
    	$ECHO "Printer(s) $PRINTERS_DONE configured successfully."
        $ECHO
    fi

    $ECHO "Exiting installation script."
    $ECHO
}


howto_autostart () {
cat << EOM |more

You may want to have the system automatically start the printer 
daemon for your new printer. Edit the file rc.local and add the 
following directly after the lpd entry.

 
 if [-f /usr/nic/nic_print]; then
 	/usr/nic/nic_print  /dev/nic/printername   hostname  port#
 	echo -n ' nic_print'

this is for 1 printer.  for additional printers you would need multiple entries.

If you cannot connect to the network interface card check the files:
 	/etc/hosts
 	/etc/ethers
 	/etc/rc.local for the rarpd startup.

 If you make changes to hostnames or addresses and you have yellowpages 
 runnings you must reconfigure the yellow pages to reflect these changes. 

EOM
}

###########################################################
#
# MAIN 
#
	#initialize the world
	set_commands_and_globals 	#Setup command aliases and globals
	verify_target_sys		#Find out what system we are running on
	verify_uid 			#Make sure running as root


	#Just check that we are OK to run before asking a bunch of questions
	#dont do any real work until user is happy with setup.

	if [ -d "$NICPRINT_DIR" ]
	then
	   if [ "$CWD" != "$NICPRINT_DIR" ]
	   then
	      $ECHO ""
	      $ECHO "You are not in the directory ${NICPRINT_DIR}. To configure"
	      $ECHO "additional printers cd ${NICPRINT_DIR} and restart this script."
	      $ECHO ""
	      $ECHO "If you would like to install new DIGITAL TCP/IP software you must"
	      $ECHO "remove ${NICPRINT_DIR} and restart this script."
	      $ECHO ""
	      exit 3
	   fi
	fi

	check_utilities                 #Verify that all the nic executables 
	                                #are in place
	set_file_mode                   #Verify all files in install directory 
	                                #have right permissions

	# If System V Solaris setup and configuration must be done by hand.
	# So just get executables to the right place
	if [ \( "$SYSTEM" = SunOS_5.x \) -o \( "$SYSTEM" = i386 \) ]
	then
		if [ ! -d "$NICPRINT_DIR" ]
		then
			#Create the NIC dir and copy the files
	   $ECHO "Installing the basic network interface card product from $CWD"
			$MKDIR $NICPRINT_DIR
			copy_parts_to_nicprint
		fi	

		tell_user_sysV_instructs
		exit 0
	fi

    while :              # loop until user has no more devices to configure
      do

	# in the real version we will read in the current nicprint_config
	# file and then go into a command loop. 

	# get names from the user (i.e. printer name, ip etc)
	
        get_nodename
        get_printername
        get_queuename
	
        display_answers
        $ECHO
        $ECHONOCR "Do you want to accept this configuration (yes,y,no,n) ? ${nnl}"

	yes_no
	if [ $? = "0" ]
        then
            $ECHO ""
            $ECHONOCR "Do you want to configure additional printers (yes,y,no,n) ? ${nnl}"

	    yes_no
	    if [ $? = "1" ]
            then
                continue
            else
		final_message
                exit 1
            fi
        fi

        $ECHO
	#if you are not in /usr/nic and the software has not already been 
	#copied then the script will try to
	#create /usr/nic and copy the files in the local dir to /usr/nic

    if [ $INSTALL = "0" ] 
    then
	if [ -d "$NICPRINT_DIR" ]
	then
	   if [ "$CWD" != "$NICPRINT_DIR" ]
	   then
	      $ECHO ""
	      $ECHO "You are not in the directory ${NICPRINT_DIR}."
	      $ECHO "To re-install you must remove ${NICPRINT_DIR}"
	      exit 3
	   fi
	else
	   $ECHO "Installing the basic network interface card product from $CWD"
	   $MKDIR $NICPRINT_DIR         #Create the NIC dir
	   copy_parts_to_nicprint	#Copy the files in CWD to NICPRINT_DIR
	fi	
    fi

    INSTALL="1"             # All software is installed in /usr/nic

	# If this is ULTRIX or sys5 solaris, no named pipe needed ...
        if [ \( "$SYSTEM" != ULTRIX_RISC \) -a \( "$SYSTEM" != SunOS_5.x \) -a \( "$SYSTEM" != i386 \) ]
        then
	    create_npipe $PNAME
	if [ \( "$SYSTEM" = AIX \) ]
		then 
		create_null_dev $PNAME
		fi
	fi

        PORT_NUM=`expr $BASE_PORT_NUM + $PHYS_PORT`

        # Unless we are a BSD style unix we do not need a spool dir or printcap
        if [ \( "$SYSTEM" = BSD \) -o \( "$SYSTEM" = ULTRIX_RISC \) -o \( "$SYSTEM" = SunOS_4.x \) -o \( "$SYSTEM" = OSF1 \) ]

        then
            create_spool_dir $QNAME

            if [ \( "$SYSTEM" = ULTRIX_RISC \) ]
            then
	        generate_ultrix_printcap $PNAME $QNAME 
            else
	        generate_simp_printcap $PNAME $QNAME 
            fi
	    try_append_simp_printcap
        fi

	# Unless this is ULTRIX or SunOS_5.x, install the DIGITAL daemon for 
	# this printer
        if [ \( "$SYSTEM" != ULTRIX_RISC \) -a \( "$SYSTEM" != SunOS_5.x \) -a \( "$SYSTEM" != i386 \) ]
        then
	    start_daemon
	fi

	# If this is ULTRIX, we output slightly different instructions ...
        if [ \( "$SYSTEM" = ULTRIX_RISC \) ]
        then
	    tell_user_ultrix_instructs
        else
            tell_user_final_instructs
        fi

        if test -z "$PRINTERS_DONE"
        then
	    PRINTERS_DONE="$PNAME"
	else
	    PRINTERS_DONE="$PRINTERS_DONE, $PNAME"
	fi

        $ECHO ""
        $ECHONOCR "Do you want to configure additional printers (yes,y,no,n) ? ${nnl}"

	yes_no
	if [ $? = "0" ]
        then
            break
        fi

    done

    final_message

    exit 0

