Skip to content

Commit 3e0c980

Browse files
committed
fix(install): prefer shasum on macOS to avoid BSD sha256sum incompatibility
BSD sha256sum on macOS does not support --check/--status flags (GNU only). Use $OS (already set by detect_platform) to prefer shasum -a 256 on darwin, falling back to sha256sum on Linux and shasum as a final fallback. Fixes #33
1 parent 5249ac1 commit 3e0c980

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

install.sh

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,26 @@ download_binary() {
6666

6767
info "Verifying checksum..."
6868
local binary_name="nexus-${OS}-${ARCH}"
69-
if command -v sha256sum &>/dev/null; then
70-
# Extract expected hash for this binary and verify
71-
local expected
72-
expected=$(awk -v name="$binary_name" '$2 == name {print $1}' "$checksum_file")
73-
if [ -z "$expected" ]; then
69+
local expected
70+
expected=$(awk -v name="$binary_name" '$2 == name {print $1}' "$checksum_file")
71+
if [ -z "$expected" ]; then
72+
rm -f "$dest" "$checksum_file"
73+
fail "Checksum entry for $binary_name not found in checksums.txt"
74+
fi
75+
76+
# On macOS, BSD sha256sum does not support --check/--status; prefer shasum -a 256.
77+
# On Linux, prefer sha256sum (GNU coreutils).
78+
if [ "$OS" = "darwin" ] && command -v shasum &>/dev/null; then
79+
echo "$expected $dest" | shasum -a 256 --check --status || {
7480
rm -f "$dest" "$checksum_file"
75-
fail "Checksum entry for $binary_name not found in checksums.txt"
76-
fi
81+
fail "Checksum verification failed — binary may be corrupted or tampered with"
82+
}
83+
elif command -v sha256sum &>/dev/null; then
7784
echo "$expected $dest" | sha256sum --check --status || {
7885
rm -f "$dest" "$checksum_file"
7986
fail "Checksum verification failed — binary may be corrupted or tampered with"
8087
}
8188
elif command -v shasum &>/dev/null; then
82-
local expected
83-
expected=$(awk -v name="$binary_name" '$2 == name {print $1}' "$checksum_file")
84-
if [ -z "$expected" ]; then
85-
rm -f "$dest" "$checksum_file"
86-
fail "Checksum entry for $binary_name not found in checksums.txt"
87-
fi
8889
echo "$expected $dest" | shasum -a 256 --check --status || {
8990
rm -f "$dest" "$checksum_file"
9091
fail "Checksum verification failed — binary may be corrupted or tampered with"

0 commit comments

Comments
 (0)