diff 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
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/previous-work/more_control_helpers/sbin/useradd	Tue Jan 08 11:45:01 2013 +0000
     1.3 @@ -0,0 +1,45 @@
     1.4 +#!/bin/bash
     1.5 +# Copyright (c) 2000,2004 Matthias S. Benkmann <article AT winterdrache DOT de>
     1.6 +# You may do everything with this code except misrepresent its origin.
     1.7 +# PROVIDED `AS IS' WITH ABSOLUTELY NO WARRANTY OF ANY KIND!
     1.8 +
     1.9 +#
    1.10 +# This is a primitive script to serve as useradd until the real useradd
    1.11 +# has been installed. It has little error checking, so don't pass it anything
    1.12 +# stupid or it'll mess up your /etc/passwd and/or /etc/group file.
    1.13 +#
    1.14 +
    1.15 +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
    1.16 +echo 1>&2 USAGE: useradd -c description -d home -g maingroup -G addgroup -s shell -u uid login 
    1.17 +exit 1
    1.18 +fi
    1.19 +
    1.20 +#test if user already exists
    1.21 +grep "^${13}:.*" /etc/passwd 
    1.22 +if [ $? -eq 0 ]; then
    1.23 +  echo 1>&2 $0: User does already exist
    1.24 +  exit 1
    1.25 +fi       
    1.26 +
    1.27 +g=`grep ^${6}:.\* /etc/group | cut -d : -f 3 -`
    1.28 +if [ z${g} = z ]; then
    1.29 +  echo 1>&2 $0: Group ${6} does not exist!
    1.30 +  exit 1
    1.31 +fi
    1.32 +
    1.33 +grep ^${8}:.\* /etc/group >/dev/null || \
    1.34 +{
    1.35 +  echo 1>&2 $0: Group ${8} does not exist!
    1.36 +  exit 1
    1.37 +}
    1.38 +
    1.39 +
    1.40 +cp /etc/passwd /tmp/passwd123456
    1.41 +echo "${13}:x:${12}:$g:$2:$4:${10}" \
    1.42 +| sort -t : -k3,3n -m /tmp/passwd123456 - > /etc/passwd
    1.43 +
    1.44 +
    1.45 +cp /etc/group /tmp/group123456
    1.46 +sed  -e 's/^\('"${8}"':[^:]*:[0-9]*:..*\)$/\1,'"${13}"'/' \
    1.47 +     -e 's/^\('"${8}"':[^:]*:[0-9]*\):$/\1:'"${13}"'/' \
    1.48 +     						/tmp/group123456 >/etc/group