Add dry-run option

This commit is contained in:
Jérémy Lecour 2019-03-07 23:26:24 +01:00
parent d9fedcdbcf
commit 463555475b

View file

@ -142,6 +142,7 @@ test -f /etc/evomaintenance.cf && . /etc/evomaintenance.cf
[ -n "${OPT_COMMIT}" ] || OPT_COMMIT=1
[ -n "${OPT_DB}" ] || OPT_DB=1
[ -n "${OPT_MAIL}" ] || OPT_MAIL=1
[ -n "${DRY_RUN}" ] || DRY_RUN=0
# Parse options
while :; do
@ -168,6 +169,9 @@ while :; do
--mail) # Takes an option argument
OPT_MAIL=1
;;
-n|--dry-run) # Takes an option argument
DRY_RUN=1
;;
--) # End of all options.
shift
break
@ -253,13 +257,21 @@ read enter
echo "----------- $(get_now) ---------------" >> "${LOGFILE}"
echo "${BLOB}" >> "${LOGFILE}"
# git commit
[ "${OPT_COMMIT}" = "1" ] && hook_commit
if [ "${DRY_RUN}" = "1" ]; then
echo
echo "[DRY-RUN] Options:"
echo "OPT_COMMIT: ${OPT_COMMIT}"
echo "OPT_DB: ${OPT_DB}"
echo "OPT_MAIL: ${OPT_MAIL}"
# insert into PG
[ "${OPT_DB}" = "1" ] && hook_db
exit 2
else
# git commit
[ "${OPT_COMMIT}" = "1" ] && hook_commit
# insert into PG
[ "${OPT_DB}" = "1" ] && hook_db
# send mail
[ "${OPT_MAIL}" = "1" ] && hook_mail
# send mail
[ "${OPT_MAIL}" = "1" ] && hook_mail
exit 0
exit 0
fi