# Remove a User
# Copyright 1986 L/F Technologies, Carson City, Nevada
#
# Created:	 10-Dec-86
# Modified Date: 08-Oct-87
#
# Created By:	 Rodger Lakey
# Modified By:	 Sandy Marshall
#

while :
do
	echo "Enter login name: \c"
	read LOGNAME
	if [ -n "$LOGNAME" ]
	then	ID=`grep "^$LOGNAME:" /etc/passwd | awk -F: '{ printf("%s ",$3) }'`
		if [ "$ID" -lt "100" ]
		then
			echo "\nThat name either does not exist, or is a privileged user"
			echo "Please try another\n"
		else	break
		fi
	else	exit 1
	fi
done

HOMEDIR=`grep "^$LOGNAME:" /etc/passwd  | awk -F: '{ printf("%s",$6) }'`
OWNER=`/bin/ls -do $HOMEDIR | awk '{ printf("%s",$3) }'`
if [ "$OWNER" != "$LOGNAME" ]
then	echo "\nUser $LOGNAME is NOT the owner of home directory $HOMEDIR"
	echo "The directory will not be removed"
else	echo "\nType \"yes\" to remove all files for this person: \c"
	read ANS
	if [ "$ANS" = "yes" ]
	then
		rm -rf $HOMEDIR
	fi
fi

if mkdir /etc/ptmp		# fails if passwd command is running
then
	cp /etc/passwd /etc/opasswd
	chmod 444 /etc/opasswd
	LOGNAME='^'$LOGNAME
	grep -v $LOGNAME /etc/passwd > /tmp/TMp$$
	mv -f /tmp/TMp$$ /etc/passwd
	chmod 444 /etc/passwd
	rmdir /etc/ptmp
else	echo "/etc/passwd file in use, try again later"
fi
