#
#####Message Texts######
set mesg1 = "Please enter the name of the user to be changed:"
set mesg2a = "User id "
set mesg2b = " not found, please check and try again."
set mesg3 = "Please enter new numeric id number, (default is "
set mesg4a = "User id number "
set mesg4b = " is already taken, please select another."
set mesg5 = "Please enter new numeric group id number (default is 10): "
set mesg6 = "The updating of the user's files is now occuring in the background."
set mesg7b = ")."
########################
cp modify modify.sav				# prepare to restore modify
						# get specific login name 
echo -n $mesg1' '
scanname:
set name = ($<)
if ($#name == 0) then
	goto scanname
endif
						# tell awk what name to match
						# make sure this user exists
awk '{FS=":"} {print $1}' /etc/passwd > foo
fgrep -s $name foo
if ($status == 1) then
	echo -n $mesg2a $name $mesg2b' '
	goto scanname
endif

awk '{FS=":"} {print $3}' /etc/passwd > foo
set i = 2
loop:
	fgrep -s $i foo
	if ($status != 1) then
		set i = `expr $i + 1`
		goto loop
	endif	# not reached
						# get unique login number 
echo -n $mesg3$i$mesg7b
scanuid:
set uid = ($<)
if ($#uid == 0) then
	set uid = $i
endif
						# check uid for uniqueness
fgrep -s $uid foo
if ($status != 1) then
	echo -n $mesg4a $uid $mesg4b' '
	goto scanuid
endif
						# get new group number 
echo -n $mesg5' '
set gid = ($<)
if ($#gid == 0) then
	set gid = '10'
endif
						#set up new entry
sed s/xx/$name/g modify > temp
sed s/uid/$uid/g temp > modify
sed s/gid/$gid/g modify > temp
mv temp modify
awk -f modify /etc/passwd > hold	# put new entry in temporary holding
sed /$name\:/d /etc/passwd > temp	# remove old user entry from passwd file
mv temp /etc/passwd
cat hold >> /etc/passwd			# add new entry to pass file
/bin/rm hold					# remove temporary holding area
/bin/rm foo					# remove temporary holding area
mv modify.sav modify			# restore modify		
					# update dirs and files owned by user	
echo $mesg6
find / -user $uid -exec chown -f $uid {} \; &
find / -user $uid -exec chgrp -f $gid {} \; &
