fix(github-pat-install): make it work on macOS - #26
Merged
Conversation
Two ways the script failed on a Mac, both on paths its own header documents.
`stat -c%s` / `stat -c%a` are GNU coreutils flags. BSD stat rejects them
outright ("stat: illegal option -- c"), so the "already exists" prompt and the
"wrote N bytes, mode M" confirmation both broke — the former right before
asking whether to overwrite an existing token. Replaced with file_size /
file_mode helpers selected by probing `stat -c%s` once: BSD rejects it, GNU
does not, so the Linux agent boxes keep the exact flags they had.
`IFS= read -r token` returns non-zero at EOF when the input has no trailing
newline. `pbpaste` emits none, so the documented `pbpaste | github-pat-install
<owner>` died on set -e before writing anything — exit 1, zero bytes of output,
no error message. The value was already in $token, so tolerate the EOF and let
the existing empty-token guard handle the genuinely-empty case.
Exercised on this Mac: fresh install, replace-existing (y and n), empty stdin,
and both pipe forms. Also run against a GNU-shaped stat shim to confirm the
probe still selects the -c flags.
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.
github-pat-installshipped in #25 and does not run on a Mac. Two separate failures, both on paths the script's own header documents.1.
stat -cis GNU-onlyThree call sites used it: the "already exists (N bytes)" prompt — i.e. the moment you're deciding whether to clobber an existing token — and the
wrote … (N bytes, mode M)confirmation.Replaced with
file_size/file_mode, chosen by probingstat -c%sonce. The probe is in the GNU direction deliberately: BSD rejects-cunambiguously, so Linux keeps byte-for-byte the flags it had.2.
pbpaste |died silentlyIFS= read -r tokenreturns non-zero at EOF when input has no trailing newline.pbpasteemits none (verified: clipboard read back with no0x0aterminator), soset -ekilled the script after reading the token but before writing it:No message, nothing written.
readhad already populated$token, so the fix tolerates the EOF and leans on the existing[ -n "${token:-}" ] || dieguard for genuinely-empty input.Verification
Run on this Mac against a throwaway
GITHUB_PAT_DIR, never a real token:wrote … (40 bytes, mode 600)pbpasteshape)wrote … (40 bytes, mode 600)— was silent exit 1yalready exists (39 bytes)— wasillegal optionnaborted; nothing changed, old token intacterror: no token entered; nothing changed, nothing writtenstatshim onPATH-cflags — Linux path intactshellcheckclean; pre-commit (whitespace, EOF, shellcheck, gitleaks) passed.