Mercurial > pkg
view previous-work/more_control_helpers/sbin/useradd @ 30:f1d0574937b5
minor cosmetic changes.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 15 Jan 2013 03:56:59 +0000 |
parents | d6bef198ae71 |
children |
line wrap: on
line source
1 #!/bin/bash2 # 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!6 #7 # This is a primitive script to serve as useradd until the real useradd8 # has been installed. It has little error checking, so don't pass it anything9 # stupid or it'll mess up your /etc/passwd and/or /etc/group file.10 #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 ]; then13 echo 1>&2 USAGE: useradd -c description -d home -g maingroup -G addgroup -s shell -u uid login14 exit 115 fi17 #test if user already exists18 grep "^${13}:.*" /etc/passwd19 if [ $? -eq 0 ]; then20 echo 1>&2 $0: User does already exist21 exit 122 fi24 g=`grep ^${6}:.\* /etc/group | cut -d : -f 3 -`25 if [ z${g} = z ]; then26 echo 1>&2 $0: Group ${6} does not exist!27 exit 128 fi30 grep ^${8}:.\* /etc/group >/dev/null || \31 {32 echo 1>&2 $0: Group ${8} does not exist!33 exit 134 }37 cp /etc/passwd /tmp/passwd12345638 echo "${13}:x:${12}:$g:$2:$4:${10}" \39 | sort -t : -k3,3n -m /tmp/passwd123456 - > /etc/passwd42 cp /etc/group /tmp/group12345643 sed -e 's/^\('"${8}"':[^:]*:[0-9]*:..*\)$/\1,'"${13}"'/' \44 -e 's/^\('"${8}"':[^:]*:[0-9]*\):$/\1:'"${13}"'/' \45 /tmp/group123456 >/etc/group