diff --git a/CHANGELOG.md b/CHANGELOG.md index 4234e48..1682406 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,14 @@ and this project **does not adhere to [Semantic Versioning](http://semver.org/sp ### Added +* Force a user name with `-u,--user` option (default is still `logname(1)`). + ### Changed ### Deprecated +* `--autosysadmin` is replaced by `--user autosysadmin` + ### Removed ### Fixed diff --git a/evomaintenance.sh b/evomaintenance.sh index da57b94..8e1e283 100755 --- a/evomaintenance.sh +++ b/evomaintenance.sh @@ -47,7 +47,7 @@ Options --no-evocheck disable evocheck execution --auto use "auto" mode --no-auto use "manual" mode (default) - --autosysadmin author change as autosysadmin + -u, --user=USER force USER value (default: logname(1)) -v, --verbose increase verbosity -n, --dry-run actions are not executed --help print this message and exit @@ -109,7 +109,7 @@ get_begin_date() { get_ip() { ip=$(get_who | cut -d" " -f6 | sed -e "s/^(// ; s/)$//") - if is_autosysadmin || [ "${ip}" = ":0" ]; then + if is_autosysadmin || [ "${ip}" = ":0" ]; then ip="localhost" elif [ -z "${ip}" ]; then ip="unknown (no tty)" @@ -127,8 +127,8 @@ get_now() { } get_user() { - if is_autosysadmin; then - echo autosysadmin + if [ -n "${USER}" ]; then + echo "${USER}" else logname fi @@ -193,7 +193,7 @@ print_session_data() { } is_autosysadmin() { - test "${AUTOSYSADMIN}" -eq 1 + test "${USER}" = "autosysadmin" } is_repository_readonly() { @@ -404,7 +404,7 @@ AUTO=${AUTO:-"0"} EVOCHECK=${EVOCHECK:-"0"} GIT_STATUS_MAX_LINES=${GIT_STATUS_MAX_LINES:-20} API_ENDPOINT=${API_ENDPOINT:-""} -AUTOSYSADMIN=${AUTOSYSADMIN:-0} +USER=${USER:-""} # initialize variables MESSAGE="" @@ -483,8 +483,29 @@ while :; do AUTO=1 ;; --autosysadmin) + # Deprecated, backward compatibility # author change as autosysadmin - AUTOSYSADMIN=1 + printf 'WARNING: "--autosysadmin" is deprecated, use "--user autosysadmin".\n' >&2 + USER="autosysadmin" + ;; + -u|--user) + # user options, with value speparated by space + if [ -n "$2" ]; then + USER=$2 + shift + else + printf 'ERROR: "--user" requires a non-empty option argument.\n' >&2 + exit 1 + fi + ;; + --user=?*) + # message options, with value speparated by = + USER=${1#*=} + ;; + --user=) + # message options, without value + printf 'ERROR: "--user" requires a non-empty option argument.\n' >&2 + exit 1 ;; -n|--dry-run) # disable actual commands