From 463555475b762ce3701cceef9ccdf559495851ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Lecour?= Date: Thu, 7 Mar 2019 23:26:24 +0100 Subject: [PATCH] Add dry-run option --- evomaintenance.sh | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/evomaintenance.sh b/evomaintenance.sh index 65eb50b..a1075d8 100755 --- a/evomaintenance.sh +++ b/evomaintenance.sh @@ -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