Skip to content

Fix install.sh not aborting on Ctrl+C or sudo failure#9

Merged
albertodebortoli merged 2 commits intomainfrom
fix/install-interrupt-and-sudo-error-handling
Mar 26, 2026
Merged

Fix install.sh not aborting on Ctrl+C or sudo failure#9
albertodebortoli merged 2 commits intomainfrom
fix/install-interrupt-and-sudo-error-handling

Conversation

@albertodebortoli
Copy link
Copy Markdown
Member

@albertodebortoli albertodebortoli commented Mar 26, 2026

Summary

  • Add a SIGINT trap so the script exits with code 130 when the user presses Ctrl+C at any point during installation, including during the sudo password prompt (where sudo absorbs the signal internally and bash would otherwise continue)
  • Add exit code checking inside sudo_if_install_dir_not_writeable so any failure (wrong password, missing file, permission denied) aborts the script immediately with a clear error message instead of silently continuing in a broken state

Test plan

Scenario Evidence
Run install.sh on a system where INSTALL_DIR is not writable, press Ctrl+C before the password prompt appears — script exits with code 130 image
Run install.sh on a system where INSTALL_DIR is not writable, press Ctrl+C during the password prompt — script exits with code 130 image
Run install.sh on a system where INSTALL_DIR is not writable, enter a wrong password — script exits with a non-zero code and prints an error image
Run install.sh on a system where INSTALL_DIR is writable — installation completes normally, no regression image

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.
@albertodebortoli albertodebortoli merged commit 54ee614 into main Mar 26, 2026
2 checks passed
@albertodebortoli albertodebortoli deleted the fix/install-interrupt-and-sudo-error-handling branch March 26, 2026 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant