Add "auto" mode

This commit is contained in:
Jérémy Lecour 2019-03-12 23:29:25 +01:00 committed by Jérémy Lecour
parent 0a6a45066d
commit ca9c7ec654

View file

@ -33,12 +33,14 @@ Usage: evomaintenance
Options
-m, --message=MESSAGE set the message from the command line
--mail enable the mail hook
--mail enable the mail hook (default)
--no-mail disable the mail hook
--db enable the database hook
--db enable the database hook (default)
--no-db disable the database hook
--commit enable the commit hook
--commit enable the commit hook (default)
--no-commit disable the commit hook
--auto use "auto" mode
--no-auto use "manual" mode (default)
-v, --verbose increase verbosity
-n, --dry-run actions are not executed
--help print this message and exit
@ -148,6 +150,7 @@ HOOK_COMMIT: ${HOOK_COMMIT}
HOOK_DB: ${HOOK_DB}
HOOK_MAIL: ${HOOK_MAIL}
DRY_RUN: ${DRY_RUN}
AUTO: ${AUTO}
***********************************
END
@ -244,6 +247,7 @@ HOOK_DB=${HOOK_DB:-"1"}
HOOK_MAIL=${HOOK_MAIL:-"1"}
DRY_RUN=${DRY_RUN:-"0"}
VERBOSE=${VERBOSE:-"0"}
AUTO=${AUTO:-"0"}
# initialize variables
MESSAGE=""
@ -304,6 +308,14 @@ while :; do
# enable mail hook
HOOK_MAIL=1
;;
--no-auto)
# use "manual" mode
AUTO=0
;;
--auto)
# use "auto" mode
AUTO=1
;;
-n|--dry-run)
# disable actual commands
DRY_RUN=1
@ -397,14 +409,62 @@ if [ "${DRY_RUN}" != "1" ]; then
hook_log
fi
if [ "${INTERACTIVE}" = "1" ]; then
if [ "${INTERACTIVE}" = "1" ] && [ "${AUTO}" = "0" ]; then
if [ "${HOOK_COMMIT}" = "1" ] || [ "${HOOK_MAIL}" = "1" ] || [ "${HOOK_DB}" = "1" ]; then
printf "Actions to execute:\n"
if [ "${HOOK_COMMIT}" = "1" ]; then
printf "* commit changes in repositories\n"
fi
if [ "${HOOK_MAIL}" = "1" ]; then
printf "* send mail to %s\n" "${EVOMAINTMAIL}"
fi
if [ "${HOOK_DB}" = "1" ]; then
printf "* save metadata to the database\n"
fi
echo ""
answer=""
while :; do
printf "> Let's continue? [Y,n,i,?] "
read -r answer
case $answer in
[Yy]|"" )
# force "auto" mode, but keep hooks settings
AUTO=1
break
;;
[Nn] )
# force "auto" mode, and disable all hooks
HOOK_COMMIT=0
HOOK_MAIL=0
HOOK_DB=0
AUTO=1
break
;;
[Ii] )
# force "manual" mode
AUTO=0
break
;;
* )
printf "y - yes, execute actions and exit\n"
printf "n - no, don't execute actions and exit\n"
printf "i - switch to interactive mode\n"
printf "? - print this help\n"
;;
esac
done
fi
fi
if [ "${INTERACTIVE}" = "1" ] && [ "${AUTO}" = "0" ]; then
# Commit hook
if [ -n "${GIT_STATUSES}" ] && [ "${HOOK_COMMIT}" = "1" ]; then
printf "/!\ There are some uncommited changes.\n%s\n\n" "${GIT_STATUSES}"
y="Y"; n="n"
answer=""
while true; do
while :; do
printf "> Do you want to commit the changes? [%s] " "${y},${n}"
read -r answer
case $answer in
@ -435,7 +495,7 @@ if [ "${INTERACTIVE}" = "1" ]; then
y="y"; n="N"
fi
answer=""
while true; do
while :; do
printf "> Do you want to send an email to <%s>? [%s] " "${EVOMAINTMAIL}" "${y},${n},e"
read -r answer
case $answer in
@ -472,7 +532,7 @@ if [ "${INTERACTIVE}" = "1" ]; then
y="y"; n="N"
fi
answer=""
while true; do
while :; do
printf "> Do you want to insert your message into the database? [%s] " "${y},${n}"
read -r answer
case $answer in
@ -494,7 +554,9 @@ if [ "${INTERACTIVE}" = "1" ]; then
;;
esac
done
else
fi
if [ "${INTERACTIVE}" = "0" ] || [ "${AUTO}" = "1" ]; then
if [ "${HOOK_COMMIT}" = "1" ]; then
hook_commit
fi