#!/bin/bash # useradd script till shadow is installed. # It *only* accepts the syntax mentioned. # No sanity checks are performed. if [ "$#" -ne 15 -a "$#" -ne 13 ] then echo "Usage: `basename $0` -O UID_MIN= -O UID_MAX= -c -d -g [ -G ] -s /bin/bash " echo "Note: No sanity checks are performed." exit 1 fi T_UID_MIN=`expr "x$2" : 'x[^=]*=\(.*\)'` shift 2 T_UID_MAX=`expr "x$2" : 'x[^=]*=\(.*\)'` shift 2 T_DESC="$2" shift 2 T_HOME=$2 shift 2 PGROUP=$2 shift 2 T_SGROUP= if [ "$1" = "-G" ] then T_SGROUP=$2 shift 2 fi T_USER=$3 T_UIDS=`cut -d : -f 3 /etc/passwd | sort -n` T_UID=0 for U in $T_UIDS do if [ $U -ge $T_UID_MAX ] then break fi if [ $U -ge $T_UID_MIN ] then T_UID=$U fi done if [ $T_UID -eq 0 ] then T_UID=$T_UID_MIN else T_UID=`expr $T_UID + 1` fi PGROUP_GID=`grep ^$PGROUP:.\* /etc/group | cut -d : -f 3 -` echo "$T_USER:x:$T_UID:$PGROUP_GID:$T_DESC:$T_HOME:/bin/bash" >> /etc/passwd if [ "x$T_SGROUP" != "x" ] then sed -i -e 's/^\('"$T_SGROUP"':[^:]*:[0-9]*:..*\)$/\1,'"$T_USER"'/' -e 's/^\('"$T_SGROUP"':[^:]*:[0-9]*\):$/\1:'"$T_USER"'/' /etc/group fi