From 93b26f5fa645c97cac6935aea09513b1c32f6e3f Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Thu, 26 Aug 2010 15:58:43 +0200 Subject: Support @-prefixed groups in localadduser. --- localadduser | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'localadduser') diff --git a/localadduser b/localadduser index 4d62ed4..398e080 100755 --- a/localadduser +++ b/localadduser @@ -34,6 +34,9 @@ shift for chunk in $@; do case $chunk in + @*) + groupchunks="${groupchunks:+$groupchunks }$chunk" + ;; *@*) other="${other:+$other }$chunk" ;; @@ -63,6 +66,20 @@ if [ -n "$phone_area" ]; then exit1 "Area code provided without trailing phonenumber!" fi +for groupchunk in $groupchunks; do + group="$(echo "$groupchunk" | perl -pe 's/^@//;')" + if echo "$group" | perl -ne '/^[a-z][a-z0-9_-]*$/ and exit 1;'; then + exit1 "Group \"$group\" contains illegal characters!" + fi + if ! members="$(getent group "$group")"; then + exit1 "Group \"$group\" does not exist!" + fi + if echo "$members" | perl -pe 's/.*://; s/,/\n/g' | grep -Fxq "$u"; then + exit1 "Group \"$group\" already contains user \"$u\"!" + fi + groups="${groups:+$groups }$group" +done + if [ ! "$interactive" -gt 0 ]; then quiet="--quiet" fi @@ -75,6 +92,10 @@ else eval $simulate sudo "/usr/sbin/adduser --disabled-login \"$u\"" fi +for group in $groups; do + eval $simulate sudo "/usr/sbin/adduser $quiet \"$u\" \"$group\"" +done + eval $simulate localresetpasswd "$u" #vecho "Account \"$u\" created succesfully! Password is $pass" -- cgit v1.2.3