diff options
-rwxr-xr-x | localresetpasswd | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/localresetpasswd b/localresetpasswd index 638e047..6cf8f60 100755 --- a/localresetpasswd +++ b/localresetpasswd @@ -12,24 +12,25 @@ # TODO: Support overriding options in /etc/local file # -set -e +set -eu -pass_len=11 +# these are overridable as environment variables +WORD_LENGTH=${WORD_LENGTH:-11} +VERBOSE=${VERBOSE:-yes} +SIMULATE=${SIMULATE:-} -verbose=1 -#simulate=true -interactive=0 +simulate=${SIMULATE:+true} # echo something, but only if in verbose mode vecho() { - test -n "$verbose" && echo "$@" >&2 + test -n "$VERBOSE" && echo "$@" >&2 } randompass() { - gpw 1 $pass_len 2>&- || - pwgen $pass_len 1 2>&- || - tr -d '[\000-\057][\072-\100][\133-\140][\173-\377]' < /dev/urandom | - dd bs=$pass_len count=1 2>&- + gpw 1 "$WORD_LENGTH" 2>&- || + pwgen "$WORD_LENGTH" 1 2>&- || + tr -d '\000-\057\072-\100\133-\140\173-\377' < /dev/urandom | + dd bs="$WORD_LENGTH" count=1 2>&- } u=$1 @@ -43,9 +44,9 @@ 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" | $simulate $sudo "/usr/sbin/chpasswd" vecho " Done!" -eval $simulate localresetpasswdexpiry "$u" +$simulate localresetpasswdexpiry "$u" vecho "New password is $pass" |