#       @(#) mkuser 3.0 15may94 Morgan_Davis @(#)
#
#	WARNING! This script is called as a ROOT process from adduser!
#		 The effective runtime user is NOT the user being created!
#
#       Usage: mkuser login gid uid First Last home shell flags
#       $argv[x] = 0    1    2   3    4    5    6     7   [8..11]
#
#       Flags: scripts netmail sig welcome
#       $flag[x] = 0      1     2     3

unset exit; echo "now creating an account for $argv[4] $argv[5]"
echo "This may take a while.  Please be patient..."
set user=$argv[1] flag="$argv[8] $argv[9] $argv[10] $argv[11]"
alias cpi "cp $/etc/default/!\^; setfile -a I !\^"

# Create directories, then go home
mkdir $argv[6] $/adm/$user; cd $argv[6]

# Copy shell scripts
if $flag[0] = 1 then
    if -f $/etc/default/login then cpi login
    if -f $/etc/default/cshrc then cpi cshrc
endif

# Disable net access if necessary
if $flag[1] = 0 then netauth -r $user

# Create signature if desired
if $flag[2] = 1 then mksig $user

# Send welcome letter
if $flag[3] = 1 and -f $/etc/default/mail then
    echo "Sending you a personal message from the sysop..."
    rcp -aqs "Welcome to $host!" -f sysop $/etc/default/mail $user
    sendmail
endif

# Copy additional files as needed
if -f $/etc/default/mailrc then cpi mailrc

# Run setenv
echo -n "^MPress ENTER to adjust your terminal preferences "
read it; setenv -u $user

# All done, force sign-on
echo -n "^MPress ENTER to try out your new account "
read it; exec login
