summaryrefslogtreecommitdiff
path: root/localadduser
diff options
context:
space:
mode:
authorJonas <dr@jones.dk>2013-11-16 16:42:12 +0100
committerJonas <dr@jones.dk>2013-11-16 16:42:12 +0100
commitde91cb7bfb38a9ad14f2f4c614cbcef51e5c8e69 (patch)
treed8f18665aa6a561c1bb7e236a86fd86bd9b21252 /localadduser
parent8fdbfa672945f45614d6b11c0b229757145d1a84 (diff)
Avoid sudo when executing as root.
Diffstat (limited to 'localadduser')
-rwxr-xr-xlocaladduser9
1 files changed, 6 insertions, 3 deletions
diff --git a/localadduser b/localadduser
index 213d4d9..576714b 100755
--- a/localadduser
+++ b/localadduser
@@ -120,12 +120,15 @@ if [ ! "$interactive" -gt 0 ]; then
quiet="--quiet"
fi
+sudo=sudo
+[ "$(id -u)" -ne 0 ] || sudo=
+
# adduser is too pessimistic on --gecos size
-eval $simulate sudo "/usr/sbin/adduser $quiet --disabled-login --gecos \"\" \"$u\""
-eval $simulate sudo "/usr/sbin/usermod -c \"$fullname,$office,$office_phone,$home_phone,$other\" \"$u\""
+eval $simulate $sudo "/usr/sbin/adduser $quiet --disabled-login --gecos \"\" \"$u\""
+eval $simulate $sudo "/usr/sbin/usermod -c \"$fullname,$office,$office_phone,$home_phone,$other\" \"$u\""
for group in $groups; do
- eval $simulate sudo "/usr/sbin/adduser $quiet \"$u\" \"$group\""
+ eval $simulate $sudo "/usr/sbin/adduser $quiet \"$u\" \"$group\""
done
eval $simulate localresetpasswd "$u"