# User Administration Menu
#
# Created:	 05-Sep-87
# Modified Date: 07-Nov-87
#
# Created By:	 Sandy Marshall
# Modified By:	 Sandy Marshall

# Edit DEFAULT as needed:
DEFAULT="q"

# Edit TITLE as needed:
TITLE="			  User Administration"

if [ "`echo -n`" = "-n" ]
then
	NLF1=""
	NLF2="\c"
else
	NLF1="-n"
	NLF2=""
fi

while true
do

t=`pwd`
s=`date '+%a %h %d, 19%y'`
clear=`tput clear`

echo $clear

# SHOW ==================================================

cat << TBLOCK
$TITLE

TBLOCK
echo "Present Directory: $t		Date: $s \n"
cat << SHOWEND
			a. Add a User
			b. Change a User's Information
			c. Remove a User
			d. Change a User's Password

			q. Return to previous menu		? Help

SHOWEND
#
# Add additional lines before 'SHOWEND' and
# add corresponding entries in 'SELECT' below:
# <tab><letter(s)><tab><description"	# format for additional lines
#
# Use blank lines for visual grouping.
#

# ENTER ==================================================

echo $NLF1 "

			       Select [$DEFAULT] :  $NLF2"
read SELECT

if [ -z "$SELECT" ]
then
	SELECT=$DEFAULT
fi

DEFAULT=$SELECT
RT="0"

echo $clear

# SELECT ==================================================

case $SELECT in
	a)	echo "				Add a User\n\n"
		sh /usr/bin/addusr.sh
		EXERR=0						;;

	b)	echo "			Change User Information\n"
		cat >> /usr/tmp/passtmp<<!

  Name    UID GID               Information                     Shell

!
		awk -F: '{ printf "%8s %3s %3s %30s", $1, $3, $4, $5
		printf " %30s\n", $7 }' /etc/passwd >> /usr/tmp/passtmp
		pg /usr/tmp/passtmp
		rm /usr/tmp/passtmp
		sh /usr/bin/change.sh	
		EXERR=0						;;

	c)	echo "				Remove a User\n\n"
		sh /usr/bin/rmusr.sh
		EXERR=0						;;

	d)	user=`geteuser`
		if [ "$user" -eq 0 ]
		then	echo "Enter login name: \c"
			read x
			if test -n "$x"
			then	passwd $x
				EXERR=$?
				continue
			fi
		fi
		passwd
		EXERR=$?					;;

	\?)	sh /usr/bin/user.help
		EXERR=0
		RT=1						;;
	
	q)	exit $EXERR					;;


esac

if [ "$EXERR" != "0" ]
then
	echo $NLF1 " Exit error: $EXERR	$NLF2	"
	echo $NLF1 "  Press <RETURN> to continue:  $NLF2"
	read OK
else
	if [ "$RT" = "1" ]
	then
		echo $NLF1 " \n Press <RETURN> to continue:  $NLF2"
		read OK
	fi
fi

done
