diff options
-rwxr-xr-x | localadduser | 9 | ||||
-rwxr-xr-x | localdeluser | 5 | ||||
-rwxr-xr-x | localpasswd | 5 | ||||
-rwxr-xr-x | localresetpasswd | 5 | ||||
-rwxr-xr-x | localresetpasswdexpiry | 5 |
5 files changed, 22 insertions, 7 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" diff --git a/localdeluser b/localdeluser index e6b6b6f..640d87b 100755 --- a/localdeluser +++ b/localdeluser @@ -11,4 +11,7 @@ # TODO: Only allow deleting regular users # -exec sudo /usr/sbin/adduser $1 +sudo=sudo +[ "$(id -u)" -ne 0 ] || sudo= + +exec $sudo /usr/sbin/adduser $1 diff --git a/localpasswd b/localpasswd index c216bf7..790f10f 100755 --- a/localpasswd +++ b/localpasswd @@ -11,4 +11,7 @@ # TODO: Only allow handling regular users # -exec sudo /usr/bin/passwd $1 +sudo=sudo +[ "$(id -u)" -ne 0 ] || sudo= + +exec $sudo /usr/bin/passwd $1 diff --git a/localresetpasswd b/localresetpasswd index 17f41fe..638e047 100755 --- a/localresetpasswd +++ b/localresetpasswd @@ -39,8 +39,11 @@ vecho -n "Generating random password..." pass=$(randompass) vecho " Done!" +sudo=sudo +[ "$(id -u)" -ne 0 ] || sudo= + vecho -n "Applying new password to account $u..." -echo "$u:$pass" | eval $simulate sudo "/usr/sbin/chpasswd" +echo "$u:$pass" | eval $simulate $sudo "/usr/sbin/chpasswd" vecho " Done!" eval $simulate localresetpasswdexpiry "$u" diff --git a/localresetpasswdexpiry b/localresetpasswdexpiry index 6d01eb2..93b26e7 100755 --- a/localresetpasswdexpiry +++ b/localresetpasswdexpiry @@ -30,6 +30,9 @@ vecho() { u=$1 shift +sudo=sudo +[ "$(id -u)" -ne 0 ] || sudo= + vecho -n "Set password aging for $u (expire: $pass_expire, warn: $pass_warn, lastday: $pass_lastday)..." -eval $simulate sudo "/usr/bin/chage -M$pass_expire -W$pass_warn -d$pass_lastday \"$u\"" +eval $simulate $sudo "/usr/bin/chage -M$pass_expire -W$pass_warn -d$pass_lastday \"$u\"" vecho " Done!" |