:
#	%Z% %M% %I% %E% %Q%
#
#	Copyright (C) The Santa Cruz Operation, 1988, 1989, 1990.
#	This Module contains Proprietary Information of
#	The Santa Cruz Operation, and should be treated as Confidential.
#

# setmmdf - SCO UNIX v3.2 MMDF Initialization
#
#   Current functionality:
#	set node name in mmdftailor file and run dbmbuild
#
PATH=/bin:/usr/bin:/etc:/.mitdir:/MIT/.mitdir:.
export PATH

# Define return values
: ${OK=0} ${FAIL=1} ${STOP=10} ${HALT=11}

mmdfdir=/usr/mmdf
tabledir=/usr/mmdf/table

TRAPMSG="<Del> key pressed or program killed.  Exiting."

#
# Function definitions
#
# Prompt for yes or no answer - returns non-zero for no
getyn() {
	while	echo "\n$* (y/n) \c"
	do	read yn rest
		case $yn in
		[yY])	return 0 			;;
		[nN])	return 1			;;
		*)	echo "Please answer y or n" 	;;
		esac
	done
}

# Prompt with mesg, return non-zero on q
prompt() {
	while	echo "\n${mesg}or enter q to quit: \c"
	do	read cmd
		case $cmd in
		+x|-x)	set $cmd					;;
		Q|q)	return 1					;;
		!*)	eval `expr "$cmd" : "!\(.*\)"`			;;
		"")	# If there is an argument use it as the default
			# else loop until 'cmd' is set
			[ "$1" ] && { 
				cmd=$1
				return 0
			}
			: continue
			;;
		*)	return 0					;;
		esac
	done
}

# put the system name into the routing tables
dotables() 
{
	cd $tabledir
	for i in local.chn root.dom uucp.chn uucp.dom
	do
	    sed "s/scosysv/$systemid/g" <$i >$i.new && mv $i $i- && mv $i.new $i
	done
}

# main

trap 'echo "$TRAPMSG" >&2 ; exit $STOP' 1 2 3 15

cd $mmdfdir

systemid=`uname -n`

getyn "Your system name is set to $systemid.  Do you wish
the mail system to use a different name?" && {
	# answered yes
	mesg="Input your machine's name, "
	prompt || exit $STOP
	systemid=$cmd
}

uname -n >/etc/systemid

echo "
The mail system uses $systemid.UUCP as the local
machine name.  If you want to change this name, 
edit the /usr/mmdf/mmdftailor file, and any files
in the /usr/mmdf/table directory containing the old
system name.  Then run /usr/mmdf/table/dbmbuild.
\nPress <Return> to continue. \c"
read key
( sed "s/scosysv/$systemid/g"   <mmdftailor  >mmdftailor.new )  \
	&& mv mmdftailor mmdftailor- \
	&& mv mmdftailor.new mmdftailor \
	&& chown mmdf mmdftailor \
	&& chgrp mmdf mmdftailor \
	&& cd $tabledir \
	&& dotables \
	&& ./dbmbuild \
	&& chown mmdf * \
	&& chgrp mmdf *

exit $?
