Fix install.sh not aborting on Ctrl+C or sudo failure#9
Merged
albertodebortoli merged 2 commits intomainfrom Mar 26, 2026
Merged
Conversation
Without a trap, pressing Ctrl+C during a sudo password prompt does not terminate the script. sudo catches SIGINT internally to restore terminal state and exits with a non-zero code, but bash never sees a signal-killed child and continues execution. Registering a trap on INT ensures the script always exits with code 130 (the conventional code for SIGINT-terminated processes) regardless of how the signal is handled by child processes.
…not_writeable The function silently returned non-zero exit codes to callers (wrong password, missing source file, permission denied, etc.), which allowed the script to continue in a broken state. Capturing $? immediately after the command and calling exit preserves the original exit code and ensures any failure stops the installation with a clear error message.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SIGINTtrap so the script exits with code130when the user presses Ctrl+C at any point during installation, including during thesudopassword prompt (wheresudoabsorbs the signal internally and bash would otherwise continue)sudo_if_install_dir_not_writeableso any failure (wrong password, missing file, permission denied) aborts the script immediately with a clear error message instead of silently continuing in a broken stateTest plan
install.shon a system whereINSTALL_DIRis not writable, press Ctrl+C before the password prompt appears — script exits with code130install.shon a system whereINSTALL_DIRis not writable, press Ctrl+C during the password prompt — script exits with code130install.shon a system whereINSTALL_DIRis not writable, enter a wrong password — script exits with a non-zero code and prints an errorinstall.shon a system whereINSTALL_DIRis writable — installation completes normally, no regression