2 # Copyright (c) 2000,2004 Matthias S. Benkmann <article AT winterdrache DOT de>
3 # You may do everything with this code except misrepresent its origin.
4 # PROVIDED `AS IS' WITH ABSOLUTELY NO WARRANTY OF ANY KIND!
7 # This is a primitive script to serve as useradd until the real useradd
8 # has been installed. It has little error checking, so don't pass it anything
9 # stupid or it'll mess up your /etc/passwd and/or /etc/group file.
12 if [ $# -ne 13 -o z$1 != z-c -o z$3 != z-d -o z$5 != z-g -o z$7 != z-G -o z$9 != z-s -o z${11} != z-u ]; then
13 echo 1>&2 USAGE: useradd -c description -d home -g maingroup -G addgroup -s shell -u uid login
17 #test if user already exists
18 grep "^${13}:.*" /etc/passwd
20 echo 1>&2 $0: User does already exist
24 g=`grep ^${6}:.\* /etc/group | cut -d : -f 3 -`
25 if [ z${g} = z ]; then
26 echo 1>&2 $0: Group ${6} does not exist!
30 grep ^${8}:.\* /etc/group >/dev/null || \
32 echo 1>&2 $0: Group ${8} does not exist!
37 cp /etc/passwd /tmp/passwd123456
38 echo "${13}:x:${12}:$g:$2:$4:/bin/bash" \
39 | sort -t : -k3,3n -m /tmp/passwd123456 - > /etc/passwd
42 cp /etc/group /tmp/group123456
43 sed -e 's/^\('"${8}"':[^:]*:[0-9]*:..*\)$/\1,'"${13}"'/' \
44 -e 's/^\('"${8}"':[^:]*:[0-9]*\):$/\1:'"${13}"'/' \
45 /tmp/group123456 >/etc/group