summaryrefslogtreecommitdiff
path: root/localadduser
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2010-08-26 15:58:43 +0200
committerJonas Smedegaard <dr@jones.dk>2010-08-26 15:58:43 +0200
commit93b26f5fa645c97cac6935aea09513b1c32f6e3f (patch)
treec70544efc79b75707d1797b7d0f9708dfc1973bc /localadduser
parentefa2b9f1f3d1763bd7eb5a38b24091bbd2e4afb6 (diff)
Support @-prefixed groups in localadduser.
Diffstat (limited to 'localadduser')
-rwxr-xr-xlocaladduser21
1 files changed, 21 insertions, 0 deletions
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"