: "
  CDC-114 XENIX R1.0

  10/19/82

  add_user will add user name in /etc/passwd and also create user directory.

"

:                                       disable XENIX interrupt signal
trap "continue" 2

clear.sh
echo -n "
ADD USER NAME

"

echo -n "Enter Log-in ID (1 - 8 lower case characters) : "
read user_id
idct="`echo $user_id | wc -c`"
if test -z "$user_id" -o $idct -gt 9
       then
            echo -n "Log-in ID is not valid.
Press NEW LINE or RETURN to continue. "
            read nline
            exit
       else
            junk2=`echo "$user_id" |grep -c "\ "`
            if test "$junk2" != "0"
            then
                 echo -n "Log-in ID is not valid.
Press NEW LINE or RETURN to continue. "
                 read nline
                 exit
            fi
            junk=`sed -n -e "/^$user_id:/p" /etc/passwd`
            if test -n "$junk"
                   then
                        echo "Log-in ID already exists.
Press NEW LINE or RETURN to continue. "
                        read nline
                        exit
            fi
fi
echo -n "Enter Description (1 - 40 characters) : "
read user_des
dct="`echo $user_des | wc -c`"
if test $dct -gt 41
then
     echo -n "Invalid description : more than 40 characters entered.
Press NEW LINE or RETURN to continue. "
     read nl
     exit
fi
temp=yes
while test "$temp"
do
clear.sh
echo -n "
Enter Group ID

  1     = System Maintenance
  2-4   = Reserved
  5     = Financial Management System
  6     = Word Processor 
  7     = Spread Sheet
  8     = XENIX
  9-255 = Other

 Enter ID : "
u_prog=""
xenix=yes
read grp_id
if test "$grp_id" -gt "255" -o "$grp_id" -lt "1"
       then
            echo -n "Group ID should be between 1 and 255.
Press NEW LINE or RETURN to continue. "
            read nline
       else
case $grp_id in
   1|8)
         temp="";;
   2|3|4)  echo "
These numbers are reserved.
Please enter other number in the list.  
Press NEW LINE or RETURN to continue. "
           read nline ;;
   *)  echo -n "
       Permission to access XENIX (y or n)? "
       read flag
       if test $flag = "n"
          then u_prog=/menus/menu.sh
               xenix=no
       fi
       temp="";;
esac
fi
done

:                    Display user difinition
echo -n "
User Definition

Name        : $user_id
Description : $user_des
Group ID    : $grp_id
XENIX       : $xenix

Add user (y or n)? "
read flag2
if test "$flag2" != "y"
then
	trap 2
	echo -n "user $user_id is not added.
Press NEW LINE or RETURN to continue. "
       read nline
	exit
fi
lastuid=`sort -t: +2n /etc/passwd| tail -1|sed -e 's/.*:.*:\(.*\):.*:.*:.*:/\1/'`
uid=`expr $lastuid + 1`
if test "$uid" -gt "255"
	then
	echo -n "User ID exceeds the limit. 
Please check /etc/passwd file. 
Press NEW LINE or RETURN to continue. "
       read nline
	exit
fi

dir=/usr/$user_id
pwent="$user_id::$uid:$grp_id:$user_des:$dir:$u_prog"

:                    Add user name to /etc/passwd
echo $pwent >>/etc/passwd

:                    Create user directory
mkdir $dir
emenu=/menus/menu.sh
echo $emenu >>$dir/.profile
chmod 755 $dir
chown $user_id $dir $dir/.profile
echo -n "user $user_id is added.
Press NEW LINE  or RETURN to continue. "
read nline
