-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·83 lines (70 loc) · 2.32 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·83 lines (70 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh
# Install script for hey CLI
# Usage: curl -fsSL https://raw.githubusercontent.com/basecamp/hey-cli/main/install.sh | sh
set -eu
REPO="basecamp/hey-cli"
BINARY="hey"
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
# Detect platform
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
ARCH="$(uname -m)"
case "$ARCH" in
x86_64|amd64) ARCH="amd64" ;;
aarch64|arm64) ARCH="arm64" ;;
*) echo "Unsupported architecture: $ARCH" >&2; exit 1 ;;
esac
case "$OS" in
darwin) OS="darwin" ;;
linux) OS="linux" ;;
*) echo "Unsupported OS: $OS" >&2; exit 1 ;;
esac
# macOS uses universal binary
if [ "$OS" = "darwin" ]; then
ARCH="all"
fi
# Get latest release
LATEST=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name"' | sed -E 's/.*"v?([^"]+)".*/\1/')
if [ -z "$LATEST" ]; then
echo "Could not determine latest release" >&2
exit 1
fi
ARCHIVE="${BINARY}_${LATEST}_${OS}_${ARCH}.tar.gz"
URL="https://github.com/$REPO/releases/download/v${LATEST}/${ARCHIVE}"
CHECKSUM_URL="https://github.com/$REPO/releases/download/v${LATEST}/checksums.txt"
TMPDIR="$(mktemp -d)"
trap 'rm -rf "$TMPDIR"' EXIT
echo "Downloading $BINARY v$LATEST for $OS/$ARCH..."
curl -fsSL "$URL" -o "$TMPDIR/$ARCHIVE"
# Verify checksum
echo "Verifying checksum..."
curl -fsSL "$CHECKSUM_URL" -o "$TMPDIR/checksums.txt"
EXPECTED=$(grep -F -- "$ARCHIVE" "$TMPDIR/checksums.txt" | awk '{print $1}')
if [ -z "$EXPECTED" ]; then
echo "Checksum for $ARCHIVE not found in checksums.txt" >&2
exit 1
fi
if [ -n "$EXPECTED" ]; then
if command -v sha256sum >/dev/null 2>&1; then
ACTUAL=$(sha256sum "$TMPDIR/$ARCHIVE" | awk '{print $1}')
elif command -v shasum >/dev/null 2>&1; then
ACTUAL=$(shasum -a 256 "$TMPDIR/$ARCHIVE" | awk '{print $1}')
else
echo "Warning: no sha256sum or shasum available, skipping checksum verification" >&2
ACTUAL="$EXPECTED"
fi
if [ "$ACTUAL" != "$EXPECTED" ]; then
echo "Checksum mismatch!" >&2
echo "Expected: $EXPECTED" >&2
echo "Got: $ACTUAL" >&2
exit 1
fi
fi
# Extract and install
tar -xzf "$TMPDIR/$ARCHIVE" -C "$TMPDIR"
if [ -w "$INSTALL_DIR" ]; then
install "$TMPDIR/$BINARY" "$INSTALL_DIR/$BINARY"
else
echo "Installing to $INSTALL_DIR (requires sudo)..."
sudo install "$TMPDIR/$BINARY" "$INSTALL_DIR/$BINARY"
fi
echo "$BINARY v$LATEST installed to $INSTALL_DIR/$BINARY"