From 8234c2d9f311f062c6a65f44c1af1550ae68783e Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 16 Sep 2026 14:10:47 +0200 Subject: [PATCH] fix: add EXIT trap to ensure encryption flag and temp files are cleaned up on crash --- recover_bad_signature.sh | 7 ++++++- recreate_bad_signature.sh | 6 +++++- restore_bad_signature.sh | 6 +++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/recover_bad_signature.sh b/recover_bad_signature.sh index 40032a0..7a46191 100755 --- a/recover_bad_signature.sh +++ b/recover_bad_signature.sh @@ -148,6 +148,8 @@ restore_encryption_flag() { clean_up() { # Perform program exit housekeeping + # Clear EXIT trap first so that the exit below does not fire it again. + trap - EXIT restore_encryption_flag [[ -n "$recovery_php_file" ]] && rm -f "$recovery_php_file" 2> /dev/null rm -rf "$LOCK_DIR" @@ -1179,7 +1181,10 @@ su -c "$PHP_BIN $INSTALL_DIR/occ config:system:set encryption_skip_signature_che if [[ $? -eq 0 ]] ; then echo_ok _encryption_flag_changed=true - trap 'restore_encryption_flag; clean_up 1' SIGHUP SIGINT SIGTERM + # Trap signals AND normal/abnormal exit so that the encryption flag + # and temp files are always cleaned up — even on a syntax error or + # an unexpected crash (EXIT fires for any bash exit, including errors). + trap 'clean_up 1' SIGHUP SIGINT SIGTERM EXIT else echo_failed fatal "Could not enable encryption_skip_signature_check: $(cat "$log_file")" diff --git a/recreate_bad_signature.sh b/recreate_bad_signature.sh index 0c85c12..f44cfe6 100755 --- a/recreate_bad_signature.sh +++ b/recreate_bad_signature.sh @@ -183,6 +183,8 @@ usage() { clean_up() { # Perform program exit housekeeping + # Clear EXIT trap first so that the exit below does not fire it again. + trap - EXIT [[ -n "$recreate_php_file" ]] && rm -f "$recreate_php_file" 2> /dev/null rm -rf "$LOCK_DIR" blank_line @@ -751,7 +753,9 @@ fi # - if mkdir "$LOCK_DIR" 2> /dev/null ; then - trap clean_up SIGHUP SIGINT SIGTERM + # Trap signals AND normal/abnormal exit so that temp files and the + # lock directory are always removed — even on an unexpected crash. + trap 'clean_up 1' SIGHUP SIGINT SIGTERM EXIT else diff --git a/restore_bad_signature.sh b/restore_bad_signature.sh index f20f876..c976a7a 100755 --- a/restore_bad_signature.sh +++ b/restore_bad_signature.sh @@ -167,6 +167,8 @@ usage() { clean_up() { # Perform program exit housekeeping + # Clear EXIT trap first so that the exit below does not fire it again. + trap - EXIT [[ -n "$restore_php_file" ]] && rm -f "$restore_php_file" 2> /dev/null rm -rf "$LOCK_DIR" blank_line @@ -781,7 +783,9 @@ if mkdir "$LOCK_DIR" 2> /dev/null ; then # - Remove lockdir when the script finishes, or when it receives a signal # - - trap clean_up SIGHUP SIGINT SIGTERM + # Trap signals AND normal/abnormal exit so that temp files and the + # lock directory are always removed — even on an unexpected crash. + trap 'clean_up 1' SIGHUP SIGINT SIGTERM EXIT else