add support for autosysadmin

This commit is contained in:
Brice Waegeneire 2022-05-31 18:19:58 +02:00
parent 4ef8878bcf
commit 95b45bac8e
1 changed files with 21 additions and 3 deletions

View File

@ -97,13 +97,22 @@ get_who() {
}
get_begin_date() {
printf "%s %s" "$(date "+%Y")" "$(get_who | cut -d" " -f3,4,5)"
# XXX Begin end date isn't applicable when used in autosysadmin,
# so we use the same one as the end date.
if [ "${AUTOSYSADMIN}" -eq 1 ]; then
get_end_date
else
printf "%s %s" "$(date "+%Y")" "$(get_who | cut -d" " -f3,4,5)"
fi
}
get_ip() {
ip=$(get_who | cut -d" " -f6 | sed -e "s/^(// ; s/)$//")
[ -z "${ip}" ] && ip="unknown (no tty)"
[ "${ip}" = ":0" ] && ip="localhost"
if [ "${AUTOSYSADMIN}" -eq 1 ] || [ "${ip}" = ":0" ]; then
ip="localhost"
elif [ -z "${ip}" ]; then
ip="unknown (no tty)"
fi
echo "${ip}"
}
@ -116,6 +125,14 @@ get_now() {
date +"%Y-%m-%dT%H:%M:%S%z"
}
get_user() {
if [ "${AUTOSYSADMIN}" -eq 1 ]; then
echo autosysadmin
else
logname
fi
}
get_complete_hostname() {
REAL_HOSTNAME=$(get_fqdn)
if [ "${HOSTNAME}" = "${REAL_HOSTNAME}" ]; then
@ -382,6 +399,7 @@ AUTO=${AUTO:-"0"}
EVOCHECK=${EVOCHECK:-"0"}
GIT_STATUS_MAX_LINES=${GIT_STATUS_MAX_LINES:-20}
API_ENDPOINT=${API_ENDPOINT:-""}
AUTOSYSADMIN=${AUTOSYSADMIN:-0}
# initialize variables
MESSAGE=""