From b06eecc53bafcab4f0183f6b116468e95d2ff692 Mon Sep 17 00:00:00 2001 From: Christoph Date: Sun, 1 Sep 2019 03:58:10 +0200 Subject: [PATCH] install_update_dovecot.sh: Remove crontab while updating dovecot. --- install_update_dovecot.sh | 75 +++++++++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 7 deletions(-) diff --git a/install_update_dovecot.sh b/install_update_dovecot.sh index 86d547d..687ae91 100755 --- a/install_update_dovecot.sh +++ b/install_update_dovecot.sh @@ -27,6 +27,8 @@ log_file="$(mktemp)" backup_date="$(date +%Y-%m-%d-%H%M)" +_backup_crontab_file="/tmp/crontab_root.${backup_date}" + rc_done="\033[71G[ \033[32mdone\033[m ]" rc_failed="\033[71G[ \033[31m\033[1mfailed\033[m ]" rc_skipped="\033[71G[ \033[33m\033[1mskipped\033[m ]" @@ -36,6 +38,30 @@ rc_wait="\033[71G[ \033[5m\033[1m..\033[m ]" # ------------- # - Functions an Variable # ------------- +clean_up() { + + + if [[ -f "$_backup_crontab_file" ]]; then + + echononl "(Re)Install previously saved crontab from '$_backup_crontab_file'.." + + crontab $_backup_crontab_file >> $log_file 2>&1 + + if [[ $? -eq 0 ]]; then + echo -e "$rc_done" + else + echo -e "$rc_failed" + error "$(cat $log_file)" + fi + + fi + + # Perform program exit housekeeping + rm -f $log_file + blank_line + exit $1 +} + echononl(){ echo X\\c > /tmp/shprompt$$ @@ -53,7 +79,7 @@ fatal(){ echo "" echo -e "\t\033[31m\033[1m Skript wird abgebrochen\033[m\033[m\n" rm -f $log_file - exit 1 + clean_up 1 } error(){ @@ -68,6 +94,11 @@ warn(){ echo "" } +blank_line() { + echo "" +} + + # - Support systemd ? # - if [[ "X$(which systemd)" = "X" ]]; then @@ -596,10 +627,42 @@ if $_new ; then fi +if $update ; then + + # - Deaktiviere Cronjobs + # - + echo "" + echononl "\tBackup Crontab (user toot) to '$_backup_crontab_file'" + crontab -l > $_backup_crontab_file 2> $log_file + if [[ $? -eq 0 ]]; then + echo -e "$rc_done" + else + echo -e "$rc_failed" + error "Backup Crontab to '$_backup_crontab_file' failed" + + # If no crontab was present, the backup file contains + # th string "no crontab fo root". Better to delete the + # backup crontab file.. + # + rm -f $_backup_crontab_file + fi + + echononl "\tRemove crontab for user root.." + crontab -r > $log_file 2>&1 + if [[ $? -eq 0 ]]; then + echo -e "$rc_done" + else + echo -e "$rc_failed" + error "" + fi + +fi + + + ## ----------------- ## --- Stop dovecot if running -echo "" echononl "\tStop dovecot service.." if ps ax 2> /dev/null | grep -q -E "/usr/local/dovecot[0-9.-]*/sbin/dovecot" > /dev/null 2>&1 ; then if $systemd_support ; then @@ -665,7 +728,7 @@ else fi echononl "\tCompile Dovecot Sources.." -make > ${_log_dir}/dovecot-${_version}-make.log 2>&1 || exit 1 +make > ${_log_dir}/dovecot-${_version}-make.log 2>&1 || clean_up 1 if [ "$?" = 0 ]; then echo -e "$rc_done" else @@ -673,7 +736,7 @@ else fatal Compiling dovecot failed fi echononl "\tInstall Dovecot into Folder /usr/local/dovecot-${_version}" -make install > ${_log_dir}/dovecot-${_version}-install.log 2>&1 || exit 1 +make install > ${_log_dir}/dovecot-${_version}-install.log 2>&1 || clean_up 1 if [ "$?" = 0 ]; then echo -e "$rc_done" else @@ -3628,7 +3691,5 @@ If you are running dovecot on a Virtual Guest System, you have to do that on the Host (Root) System. " -echo "" -rm -f "$log_file" -exit +clean_up 0