Skip to content

install.sh: Stop the install on Ctrl-C - #3111

Open
huacnlee wants to merge 1 commit into
mainfrom
agent/T-11052-install-ctrl-c
Open

huacnlee wants to merge 1 commit into
mainfrom
agent/T-11052-install-ctrl-c

Conversation

@huacnlee

Copy link
Copy Markdown
Member

Summary

Pressing Ctrl-C after curl -fsSL https://nsh.dev/install.sh | sh started did nothing: the spinner kept spinning and the download kept going.

Two things combined:

  • step runs the download, checksum and extract in the background ("$@" &) so it can draw the spinner. A non-interactive shell starts background commands with SIGINT ignored, so Ctrl-C never reached curl/tar.
  • The script's trap 'rm -rf "$work"' EXIT INT TERM handled SIGINT by removing the temporary directory without exiting, so the shell went back to the spinner loop.

Now:

  • An INT/TERM trap kills the step running under the spinner, clears the spinner line, removes the temporary directory and exits with 130/143. The EXIT trap still cleans up on normal exit and on fail.
  • The trap is installed before any step, and pid is reset once a step finishes, so the trap never kills an unrelated process.
  • verify now runs as a subshell function (verify() ( ... )) instead of wrapping the whole step call in ( ... ), so the spinner runs in the main shell and the trap sees its pid.

No change to output, flags or the non-terminal path (CI/logs), where steps already run in the foreground.

Verification

On macOS (arm64), with a small pty harness that runs cat install.sh | <shell> -s and sends ^C through the terminal, like a user pressing Ctrl-C:

main this PR
sh (bash 3.2 as sh), Ctrl-C while downloading still running 15 s later, curl keeps downloading exits immediately, status 130
dash (Linux /bin/sh), Ctrl-C while downloading — exits immediately, status 130
bash, Ctrl-C while downloading — exits immediately, status 130
Ctrl-C during checksum/extract — exits within 0.3 s, status 130

After each interrupted run there is no leftover curl/shasum/tar process and no leftover temporary directory.

Without Ctrl-C, a full install still succeeds both in a terminal (spinner + ✓ lines) and without one (plain lines), installing nsh 0.6.1.

Not run on a Linux machine; dash was exercised on macOS instead.

🤖 Generated with Claude Code

🤖 Noop (lead) · AI agent acting for @huacnlee

The download, checksum and extract steps run in the background under the
spinner. A non-interactive shell starts background commands with SIGINT
ignored, and the INT trap only removed the temporary directory without
exiting, so Ctrl-C left the spinner and curl running until the download
finished.

Ctrl-C (and SIGTERM) now stops the running step, removes the temporary
directory and exits with 130 (143).

Agent: lead
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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