3 # Written: November 6th, 1994
4 # Copyright (C) 1994 by Michael Reifenberger
6 # Permission to copy or use this software for any purpose is granted
7 # provided that this message stay intact, and at this location (e.g. no
8 # putting your name on top after doing something trivial like reindenting
9 # it, just to make it look like you wrote it!).
11 ########################
12 # First set some globals
22 #########################
23 # Some Functions we need.
25 ###########################
26 # Show the User all options
29 adduser -h Prints help
30 adduser -i For interactively adding users
33 adduser [-u UserName][-g GroupName][-s Shell]"
36 ##########################
37 # Get the next free UserID
41 for i in `cut -f 3 -d : /etc/master.passwd | cut -c 2- | sort -n`; do
42 if [ $i -lt $xx ]; then
43 elif [ $i -eq $xx ]; then xx=`expr $xx + 1`
44 else uid=$xx; return 0
48 #######################################################
49 # Get the next free GroupID or the GroupID of GroupName
54 if grep -q \^$gname: /etc/group; then
55 gid=`grep \^$gname: /etc/group | cut -f 3 -d:`
58 for i in `cut -f 3 -d : /etc/group | cut -c 2- | sort -n`; do
59 if [ $i -lt $xx ]; then
60 elif [ $i -eq $xx ]; then xx=`expr $xx + 1`
61 else gid=$xx; return 0
66 ##########################################
67 # Ask the User interactively what he wants
69 dialog --title "Add New User Name" --clear \
70 --inputbox "Please specify a login name for the user:\n\
71 Hit [return] for a default of <$uname>" -1 -1 2> /tmp/i.$$
75 if [ x`cat /tmp/i.$$` != x ]; then
76 uname=`cat /tmp/i.$$`; fi;;
80 if grep -q \^$uname: /etc/master.passwd; then
81 error "Username $uname already exists."
84 dialog --title "Group Name" --clear \
85 --inputbox "Which group should $uname belong to?\n\
86 Hit [return] for default of <$gname>" -1 -1 2> /tmp/i.$$
90 if [ x`cat /tmp/i.$$` != x ]; then
91 gname=`cat /tmp/i.$$`; fi;;
95 dialog --title "Login Shell" --clear \
96 --inputbox "Please specify which login shell\n<$uname> should use\n\
97 Hit [return] for default of <$shell>" -1 -1 2> /tmp/i.$$
101 if [ x`cat /tmp/i.$$` != x ]; then
102 shell=`cat /tmp/i.$$`; fi;;
115 ###################################
116 # Parse the commandline for options
117 set -- `getopt hiu:g:s: $*`
127 interact; shift; iflag=yes; break;;
129 uname=$2; shift; shift;;
131 gname=$2; shift; shift;;
133 shell=$2; shift; shift;;
140 #####################
141 # This is no Edituser
142 if grep -q \^$uname: /etc/master.passwd; then
143 error "This user already exists in the master password file.\n
144 Use 'chpass' to edit an existing user rather than adduser.."
154 if [ $needgentry = "YES" ]; then
155 echo "$gname:*:$gid:$uname" >> /etc/group
159 mkdir -p -m755 /home/$uname
160 if [ ! -d /home/$uname ]; then
161 error "Could not create /home/$uname"
164 for xx in /usr/share/skel/*; do
165 cp $xx /home/$uname/.`basename $xx | cut -f 2 -d .`
168 #####################
169 # Make the User happy
170 if [ ! -x $shell ]; then
171 message "There is no <$shell> shell, using /bin/sh instead.\n
172 If you wish, you can change this choice later with 'chpass'"
174 elif ! grep -q $shell /etc/shells; then
175 echo $shell >> /etc/shells
176 echo "<$shell> added to /etc/shells"
178 echo "$uname:*:$uid:$gid::0:0:User &:/home/$uname:$shell" >> /etc/master.passwd
179 pwd_mkdb /etc/master.passwd
180 chown -R $uname.$gname /home/$uname
181 chmod -R 644 /home/$uname
182 chmod 755 /home/$uname