Add real interactive mode
The message can be given as an option, as stdin or interactively.
This commit is contained in:
parent
293c38fb83
commit
b9da112b6d
|
@ -103,7 +103,7 @@ hook_commit() {
|
|||
GIT_COMMITS=$(printf "%s\n%s : %s" "${GIT_COMMITS}" "${GIT_DIR}" "${STATS}" | sed -e '/^$/d')
|
||||
else
|
||||
${GIT_BIN} add --all
|
||||
${GIT_BIN} commit --message "${TEXTE}" --author="${USER} <${USER}@evolix.net>" --quiet
|
||||
${GIT_BIN} commit --message "${MESSAGE}" --author="${USER} <${USER}@evolix.net>" --quiet
|
||||
# Add the SHA to the log file if something has been committed
|
||||
SHA=$(${GIT_BIN} rev-parse --short HEAD)
|
||||
STATS=$(${GIT_BIN} show --stat | tail -1)
|
||||
|
@ -126,9 +126,8 @@ hook_commit() {
|
|||
}
|
||||
|
||||
hook_db() {
|
||||
# SQL_TEXTE=`echo "${TEXTE}" | sed "s/'/\\\\\\'/g ; s@/@\\\\\/@g ; s@\\&@et@g"`
|
||||
SQL_TEXTE=$(echo "${TEXTE}" | sed "s/'/''/g")
|
||||
PG_QUERY="INSERT INTO evomaint(hostname,userid,ipaddress,begin_date,end_date,details) VALUES ('${HOSTNAME}','${USER}','${IP}','${BEGIN_DATE}',now(),'${SQL_TEXTE}')"
|
||||
SQL_DETAILS=$(echo "${MESSAGE}" | sed "s/'/''/g")
|
||||
PG_QUERY="INSERT INTO evomaint(hostname,userid,ipaddress,begin_date,end_date,details) VALUES ('${HOSTNAME}','${USER}','${IP}','${BEGIN_DATE}',now(),'${SQL_DETAILS}')"
|
||||
|
||||
if [ "${DRY_RUN}" = "1" ]; then
|
||||
echo "\n\n********** DB query **************\n${PG_QUERY}\n***********************************"
|
||||
|
@ -138,7 +137,7 @@ hook_db() {
|
|||
}
|
||||
|
||||
hook_mail() {
|
||||
MAIL_TEXTE=$(echo "${TEXTE}" | sed -e "s@/@\\\\\/@g ; s@&@\\\\&@")
|
||||
MAIL_TEXTE=$(echo "${MESSAGE}" | sed -e "s@/@\\\\\/@g ; s@&@\\\\&@")
|
||||
MAIL_GIT_COMMITS=$(echo "${GIT_COMMITS}" | sed -e "s@/@\\\\\/@g ; s@&@\\\\&@")
|
||||
MAIL_CONTENT=$(cat /usr/share/scripts/evomaintenance.tpl | \
|
||||
sed -e "s/__TO__/${EVOMAINTMAIL}/ ; s/__HOSTNAME__/${HOSTNAME_TEXT}/ ; s/__USER__/${USER}/ ; s/__BEGIN_DATE__/${BEGIN_DATE}/ ; s/__END_DATE__/${END_DATE}/ ; s/__GIT_COMMITS__/${MAIL_GIT_COMMITS}/ ; s/__TEXTE__/${MAIL_TEXTE}/ ; s/__IP__/${IP}/ ; s/__FULLFROM__/${FULLFROM}/ ; s/__FROM__/${FROM}/ ; s/__URGENCYFROM__/${URGENCYFROM}/ ; s/__URGENCYTEL__/${URGENCYTEL}/")
|
||||
|
@ -162,12 +161,29 @@ test -f /etc/evomaintenance.cf && . /etc/evomaintenance.cf
|
|||
[ -n "${DRY_RUN}" ] || DRY_RUN=0
|
||||
|
||||
# Parse options
|
||||
# based on https://gist.github.com/deshion/10d3cb5f88a21671e17a
|
||||
while :; do
|
||||
case $1 in
|
||||
# -h|-\?|--help) # Call a "show_help" function to display a synopsis, then exit.
|
||||
# show_help
|
||||
# exit
|
||||
# ;;
|
||||
-m|--message) # Takes an option argument, ensuring it has been specified.
|
||||
if [ -n "$2" ]; then
|
||||
MESSAGE=$2
|
||||
shift
|
||||
else
|
||||
printf 'ERROR: "--message" requires a non-empty option argument.\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
--message=?*)
|
||||
MESSAGE=${1#*=} # Delete everything up to "=" and assign the remainder.
|
||||
;;
|
||||
--message=) # Handle the case of an empty --file=
|
||||
printf 'ERROR: "--message" requires a non-empty option argument.\n' >&2
|
||||
exit 1
|
||||
;;
|
||||
--no-commit) # Takes an option argument
|
||||
OPT_COMMIT=0
|
||||
;;
|
||||
|
@ -208,6 +224,8 @@ done
|
|||
set -u
|
||||
|
||||
# Gather information
|
||||
MESSAGE=""
|
||||
|
||||
HOSTNAME_TEXT=$(get_complete_hostname)
|
||||
# TTY=$(get_tty)
|
||||
# WHO=$(get_who)
|
||||
|
@ -244,11 +262,19 @@ if test -x "${GIT_BIN}"; then
|
|||
fi
|
||||
fi
|
||||
|
||||
# get input from stdin
|
||||
echo "> Please, enter details about your maintenance"
|
||||
read TEXTE
|
||||
if [ -t 0 ]; then
|
||||
INTERACTIVE=1
|
||||
else
|
||||
INTERACTIVE=0
|
||||
fi
|
||||
|
||||
if test -z "${TEXTE}"; then
|
||||
if [ -z "${MESSAGE}" -a "${INTERACTIVE}" = "1" ]; then
|
||||
# get input from stdin
|
||||
echo "> Please, enter details about your maintenance"
|
||||
read MESSAGE
|
||||
fi
|
||||
|
||||
if test -z "${MESSAGE}"; then
|
||||
echo "no value..."
|
||||
exit 1
|
||||
fi
|
||||
|
@ -260,7 +286,7 @@ User : $USER
|
|||
IP : $IP
|
||||
Begin : $BEGIN_DATE
|
||||
End : $END_DATE
|
||||
Message : $TEXTE
|
||||
Message : $MESSAGE
|
||||
END
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue