diff options
author | Jonas Smedegaard <dr@jones.dk> | 2018-10-14 16:37:01 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2018-10-14 16:37:01 +0200 |
commit | 1ffacabd92a4e6a192429be87a845d2aa4c1fef9 (patch) | |
tree | 4fa18de38e8d42c1584b666a187dd5c61c064b80 /localresetpasswd | |
parent | fb47b226d0fc3a253f538557a865bae726a8c42a (diff) |
Tidy, and provide environment-overridable variables as originally intended.
Diffstat (limited to 'localresetpasswd')
-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" |