Skip to content

Installer robustness: setup.sh exec-after-rm + uninstall.sh CONFIG_PREFIX guard#368

Open
ooonea wants to merge 3 commits into
lynxthecat:masterfrom
ooonea:fix/installer-robustness
Open

Installer robustness: setup.sh exec-after-rm + uninstall.sh CONFIG_PREFIX guard#368
ooonea wants to merge 3 commits into
lynxthecat:masterfrom
ooonea:fix/installer-robustness

Conversation

@ooonea

@ooonea ooonea commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Two small installer hygiene fixes (one per file, one commit each).

setup.sh: don't rm -rf "${tmp}" right before exec'ing it

The non-self-replacing restart branch removed ${tmp} and then
exec "${tmp}/setup.sh", so the exec always failed with ENOENT and aborted the
restart, leaving a half-finished install. Dropped the premature rm; the
EXIT/INT/TERM trap still removes ${tmp} if the exec fails. (Narrow reach:
only downloads predating the SELF_REPLACING marker take this branch.)

uninstall.sh: guard cd "${CONFIG_PREFIX}"

Under set -eu, cd "${CONFIG_PREFIX}" aborted the whole uninstall when the
config dir didn't exist (configs already removed, a re-run after a partial
uninstall, or a Merlin/custom prefix that diverges from SCRIPT_PREFIX), leaving
cake-autorate.sh/lib.sh/etc. on disk. Guarded so program-file removal still
runs.

sh -n / shellcheck -x clean (the pre-existing SC2310 infos in setup.sh are
unrelated and untouched).

ooonea added 2 commits June 21, 2026 10:23
The non-self-replacing restart branch ran 'rm -rf "${tmp}"' and then
'exec "${tmp}/setup.sh"', so the exec always failed with ENOENT and aborted
the restart, leaving a half-finished install. Drop the premature rm; the
EXIT/INT/TERM trap removes ${tmp} if the exec fails.
Under set -eu, 'cd "${CONFIG_PREFIX}"' aborted the whole uninstall when the
config dir did not exist (configs already removed, a re-run after a partial
uninstall, or a custom/Merlin prefix that diverges from SCRIPT_PREFIX), leaving
cake-autorate.sh/lib.sh/etc. on disk. Guard the cd so program-file removal still
runs.
@lynxthecat lynxthecat requested a review from rany2 June 22, 2026 12:55
@lynxthecat

Copy link
Copy Markdown
Owner

@rany2 does this look OK to merge to you? @ooonea's other PRs seemed good to me.

@rany2

rany2 commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

@lynxthecat It seems fine but for setup.sh I would drop self-replacing support entirely. For uninstall.sh I think it would be better to guard the entire thing with if [ -d ${CONFIG_PREFIX} ] same with every block that does a cd.

@lynxthecat

Copy link
Copy Markdown
Owner

Thoughts @ooonea?

setup.sh (per @rany2): rather than rip out self-replacing wholesale (a deliberate
mechanism whose removal is a separate design call), delete only the broken `else`
branch. It fires solely when the *downloaded* setup.sh lacks the marker -- i.e.
installing a pre-self-replacing (pre-2024) version -- so instead of fixing the
rm-then-exec, drop it: a marker-less download now falls through and installs the
downloaded files with the current setup.sh. The modern marker path is untouched.

uninstall.sh (per @rany2): guard *every* cd with [ -d ... ], not just CONFIG_PREFIX
-- the two SCRIPT_PREFIX blocks are folded under one [ -d "${SCRIPT_PREFIX}" ]
(dropping the redundant second cd). A missing prefix means nothing to remove there,
so the block is skipped instead of aborting the rest of the uninstall under set -eu.
@ooonea

ooonea commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

@rany2 thanks for the review — both addressed in the latest commit.

uninstall.sh — agreed, that's cleaner than my partial fix. Every cd is now guarded with [ -d … ] (both CONFIG_PREFIX and SCRIPT_PREFIX); if a prefix is absent there's nothing to remove there, so the block is skipped rather than aborting the rest of the uninstall under set -eu. I also folded the two consecutive cd "${SCRIPT_PREFIX}" blocks into one (the second cd was redundant).

setup.sh — I'd rather not rip out self-replacing wholesale in a robustness PR: the …SUPPORT_SELF_REPLACING handshake is deliberate, and removing it is a design call that's yours to make (ideally its own PR). But the only broken part is the else branch, and it's effectively dead — it fires only when the downloaded setup.sh lacks the marker, i.e. when installing a pre-marker (pre-2024) version. So instead of fixing the rm-then-exec there, I've deleted the dead else branch: a marker-less download now falls through and installs the downloaded files with the current setup.sh, rather than exec'ing an ancient one. The modern self-replacing path (marker present → exec) is untouched.

Happy to remove self-replacing entirely as a separate PR if you'd both prefer — just say the word.

@lynxthecat

Copy link
Copy Markdown
Owner

@rany2 how about now?

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.

3 participants