
#	AT&T: #ident	"bnu.admin:adddevice	2.19"
#ident	"@(#)bne.admin:adddevice	25.1"


# This shell is used to construct Devices file entries
#
# Direct contty - 4800 direct
# ACU Develcon vent 1200 develcon vent ventel
# Develcon contty - Any develcon
#
PACKAGE="Basic Networking Utilities"
FIRST=true

DEVICES=/usr/lib/uucp/Devices
DEVCONFIG=/usr/lib/uucp/Devconfig
DIALERS=/usr/lib/uucp/Dialers
INITTAB=/etc/inittab
PATH=:/bin:/usr/bin:/usr/lbin
XDIR=$MENUTOP/menu/packagemgmt/uucpmgmt
AWKF=/usr/tmp/awk.$$
cd $XDIR

flags="-qq -k$$"
trap exit 1 2 15

if [ -f "$DEVICES" -a \( ! -w "$DEVICES" -o ! -r "$DEVICES" \) ]; then
	admerr $0 "Can't write and read '$DEVICES'\nCan't do add operation!\n"
	exit
fi

if [ ! -f "$DIALERS" -o ! -r "$DIALERS" ]; then
	admerr $0 "Can't read '$DIALERS'\nCan't do add operation!\n"
	exit
fi

echo "
This procedure is used to add entries to the
$PACKAGE '$DEVICES' file.
"

defdevice=att2212c
devicelist="`( echo 'TLI network' ; egrep -v '(^#.*|^[ 	]*$|^nls[ 	])' $DIALERS | sed -e 's%[ 	].*%%' ) | sort -u -f  | nl`"

while $FIRST || chkyn ${flags} -f 'Add another entry to the Devices file?' || break
do
FIRST=false

LINE=
DEV=`chkyn ${flags} -fer -Dcontty "Enter the port name (for /dev/contty enter-  contty).
(default contty)[q]:  "  \
	'^[0-9a-z]\{1,14\}$' 'Port name is 1-8 lower case letters and digits '`

if [ ! -c /dev/$DEV ]; then
	echo "
**WARNING** There is no '/dev/$DEV' on this system!
SEE your Owners Manual to see how
to add '/dev/$DEV' before adding the device to
the '$DEVICES' file.
"
	exit
fi


grep "^[^# 	].*[ 	]$DEV[ 	]" $DEVICES >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "\nThe following entries currently exist for $DEV in '$DEVICES':\n"
grep "^[^# 	].*[ 	]$DEV[ 	]" $DEVICES | while read a
		do /bin/sh _deviceprint $a
	done

    if `chkyn ${flags} -f "
Do you want to delete them before continuing"`
    then
	echo
	ed $DEVICES <<-! > /dev/null 2>&1
		H
		g/$DEV/d
		w
		q
	!
    fi

fi

TYPE=`chkyn ${flags} -fec -D${defdevice} "Enter the device type to call on.
Select one from the list:
${devicelist}
(default ${defdevice})[q]:  "  ${devicelist}`

if [ "${TYPE}" != "${defdevice}" ]
then
	echo "\$0 ~ /^ *${TYPE}.*TLI network.*/ { printf \"TLIS\\\\n\";exit }\n\$1 ~ /^ *${TYPE}/	{ print \$2 }" >${AWKF}
	TYPE="`echo "${devicelist}" | awk -F\	 -f ${AWKF}`"
	rm ${AWKF}
fi

case "$TYPE" in
rixon | penril | ventel | att2212c | att2224 | att4000 | TLIS)
;;

*)
SPEED=`chkyn ${flags} -efc -D1200 "
Enter the speed at which you want to call:
1200 300 1800 2400 4800 9600 19200 38400
(default 1200):  "  1200 300 1800 2400 4800 9600 19200 38400`
;;

esac


case "$TYPE" in
rixon | penril | ventel | att2212c | att4000)
LINE="ACU $DEV - 1200 $TYPE \\T
ACU $DEV - 300 $TYPE \\T"
;;

hayes)
LINE="ACU $DEV - $SPEED hayes"
;;

att2224 )
LINE="ACU $DEV - 2400 $TYPE \\T
ACU $DEV - 1200 $TYPE \\T
ACU $DEV - 300 $TYPE \\T"
;;

801)
DDEV=`chkyn ${flags} -fer "Enter the 801 dialer port name (for /dev/cua0 enter cua0) [q]:  "  \
	'^[0-9a-z]\{1,14\}$' 'Port name is 1-8 lower case letters and digits '`

LINE="ACU $DEV $DDEV $SPEED $TYPE \\T"
;;

develcon)
LINE="Develcon $DEV - $SPEED develcon \\D"
;;

micom)
LINE="Micom $DEV - $SPEED micom \\D"
;;

direct)
LINE="Direct $DEV - $SPEED direct \\D"
;;

TLIS)
NAME=`chkyn ${flags} -ref -h'?' -H"
This is the name of the network associated with device '${DEV}'.
This network must conform to the AT&T Transport Interface." \
		"
Enter the name of the TLI network associated with device '${DEV}'.
Network name: [?]" \
		'[a-zA-Z].*' 'The network name must begin with a letter.'`

LINE="$NAME,eg $DEV - - TLIS \\D" ;;

*)
if chkyn ${flags} -f -h'?' -H" 
If this device dials a phone number, type 'yes'.
Otherwise, type 'no'." \
	"
Is the device type '${TYPE}' an autodialer?" 
	
then
	LINE="ACU $DEV - $SPEED $TYPE \\T"
else
	LINE="$TYPE $DEV - $SPEED $TYPE \\D"
fi
;;

esac


echo "\nThis is the Device entry generated for device '$DEV':"
cat <<! | while read a; do /bin/sh _deviceprint $a; done
$LINE
!

if  chkyn ${flags} -f \
	'Do you want to add this entry to the Devices file?'
then
	cat <<-! >>$DEVICES
		$LINE
	!
	echo "**** Device '$DEV' has been added to the '$DEVICES' file ****\n"

	if [ "$TYPE" = "TLIS" ]
	then
		grep "^[^#].*device=${NAME}" $DEVCONFIG >/dev/null  2>&1
		if [ $? != 0 ]
		then
			echo "

If the '${NAME}' network is a STREAMS network, you should edit the file
'${DEVCONFIG}' and, following the examples in that file, create
an entry describing the STREAMS modules to be pushed for the '${NAME}' network.
"
		fi
	fi

else
	continue
fi

if [ "$TYPE" = "TLIS" ]
then
	continue
else
	chown uucp /dev/$DEV 2>/dev/null
	chmod 644 /dev/$DEV 2>/dev/null
	entry=`grep "[ 	]$DEV[ 	]" $INITTAB 2>/dev/null`
	if [ $? -ne 0 ]; then
	echo "\nThere is no entry for $DEV in $INITTAB.
If '$DEV' is to be used for bidirectional traffic,
an entry will be required in '$INITTAB'.\n"

	chkyn ${flags} -f "
Do you want to add an entry for '$DEV' now?" || continue
echo "
Entering add port operation for '$DEV'\n"
	/bin/sh addport $DEV
	fi
fi

done
