switch to -u,--user to force a specific user

This commit is contained in:
Jérémy Lecour 2023-10-09 16:05:12 +02:00 committed by Jérémy Lecour
parent 1cbe1a6c1e
commit 8a7cf0a941
Signed by: jlecour
SSH key fingerprint: SHA256:h+5LgHRKwN9lS0SsdVR5yZPeFlJE4Mt+8UtL4CcP8dY
2 changed files with 32 additions and 7 deletions

View file

@ -5,10 +5,14 @@ and this project **does not adhere to [Semantic Versioning](http://semver.org/sp
### Added ### Added
* Force a user name with `-u,--user` option (default is still `logname(1)`).
### Changed ### Changed
### Deprecated ### Deprecated
* `--autosysadmin` is replaced by `--user autosysadmin`
### Removed ### Removed
### Fixed ### Fixed

View file

@ -47,7 +47,7 @@ Options
--no-evocheck disable evocheck execution --no-evocheck disable evocheck execution
--auto use "auto" mode --auto use "auto" mode
--no-auto use "manual" mode (default) --no-auto use "manual" mode (default)
--autosysadmin author change as autosysadmin -u, --user=USER force USER value (default: logname(1))
-v, --verbose increase verbosity -v, --verbose increase verbosity
-n, --dry-run actions are not executed -n, --dry-run actions are not executed
--help print this message and exit --help print this message and exit
@ -109,7 +109,7 @@ get_begin_date() {
get_ip() { get_ip() {
ip=$(get_who | cut -d" " -f6 | sed -e "s/^(// ; s/)$//") ip=$(get_who | cut -d" " -f6 | sed -e "s/^(// ; s/)$//")
if is_autosysadmin || [ "${ip}" = ":0" ]; then if is_autosysadmin || [ "${ip}" = ":0" ]; then
ip="localhost" ip="localhost"
elif [ -z "${ip}" ]; then elif [ -z "${ip}" ]; then
ip="unknown (no tty)" ip="unknown (no tty)"
@ -127,8 +127,8 @@ get_now() {
} }
get_user() { get_user() {
if is_autosysadmin; then if [ -n "${USER}" ]; then
echo autosysadmin echo "${USER}"
else else
logname logname
fi fi
@ -193,7 +193,7 @@ print_session_data() {
} }
is_autosysadmin() { is_autosysadmin() {
test "${AUTOSYSADMIN}" -eq 1 test "${USER}" = "autosysadmin"
} }
is_repository_readonly() { is_repository_readonly() {
@ -404,7 +404,7 @@ AUTO=${AUTO:-"0"}
EVOCHECK=${EVOCHECK:-"0"} EVOCHECK=${EVOCHECK:-"0"}
GIT_STATUS_MAX_LINES=${GIT_STATUS_MAX_LINES:-20} GIT_STATUS_MAX_LINES=${GIT_STATUS_MAX_LINES:-20}
API_ENDPOINT=${API_ENDPOINT:-""} API_ENDPOINT=${API_ENDPOINT:-""}
AUTOSYSADMIN=${AUTOSYSADMIN:-0} USER=${USER:-""}
# initialize variables # initialize variables
MESSAGE="" MESSAGE=""
@ -483,8 +483,29 @@ while :; do
AUTO=1 AUTO=1
;; ;;
--autosysadmin) --autosysadmin)
# Deprecated, backward compatibility
# author change as autosysadmin # 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) -n|--dry-run)
# disable actual commands # disable actual commands