comparison previous-work/more_control_helpers/sbin/useradd @ 1:d6bef198ae71

add work by Matthias S. Benkmann which is the inspiration for this project.
author Robert McIntyre <rlm@mit.edu>
date Tue, 08 Jan 2013 11:45:01 +0000
parents
children
comparison
equal deleted inserted replaced
0:0b7a589f6e9a 1:d6bef198ae71
1 #!/bin/bash
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!
5
6 #
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.
10 #
11
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
14 exit 1
15 fi
16
17 #test if user already exists
18 grep "^${13}:.*" /etc/passwd
19 if [ $? -eq 0 ]; then
20 echo 1>&2 $0: User does already exist
21 exit 1
22 fi
23
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!
27 exit 1
28 fi
29
30 grep ^${8}:.\* /etc/group >/dev/null || \
31 {
32 echo 1>&2 $0: Group ${8} does not exist!
33 exit 1
34 }
35
36
37 cp /etc/passwd /tmp/passwd123456
38 echo "${13}:x:${12}:$g:$2:$4:${10}" \
39 | sort -t : -k3,3n -m /tmp/passwd123456 - > /etc/passwd
40
41
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