-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathinstall.sh
More file actions
101 lines (81 loc) · 2.51 KB
/
install.sh
File metadata and controls
101 lines (81 loc) · 2.51 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/sh
set -e
# CoinGecko CLI installer
# Usage: curl -sSfL https://raw.githubusercontent.com/coingecko/coingecko-cli/main/install.sh | sh
REPO="coingecko/coingecko-cli"
BINARY="cg"
INSTALL_DIR="/usr/local/bin"
detect_os() {
case "$(uname -s)" in
Linux*) echo "linux" ;;
Darwin*) echo "darwin" ;;
MINGW*|MSYS*|CYGWIN*) echo "windows" ;;
*) echo "unsupported"; exit 1 ;;
esac
}
detect_arch() {
case "$(uname -m)" in
x86_64|amd64) echo "amd64" ;;
arm64|aarch64) echo "arm64" ;;
*) echo "unsupported"; exit 1 ;;
esac
}
OS=$(detect_os)
ARCH=$(detect_arch)
echo "Detected: ${OS}/${ARCH}"
# Get latest release tag
LATEST=$(curl -sSf "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$LATEST" ]; then
echo "Error: could not determine latest release"
exit 1
fi
echo "Latest release: ${LATEST}"
VERSION="${LATEST#v}"
EXT="tar.gz"
if [ "$OS" = "windows" ]; then
EXT="zip"
fi
FILENAME="${BINARY}_${VERSION}_${OS}_${ARCH}.${EXT}"
URL="https://github.com/${REPO}/releases/download/${LATEST}/${FILENAME}"
CHECKSUMS_URL="https://github.com/${REPO}/releases/download/${LATEST}/checksums.txt"
TMPDIR=$(mktemp -d)
trap 'rm -rf "$TMPDIR"' EXIT
echo "Downloading ${URL}..."
curl -sSfL "$URL" -o "${TMPDIR}/${FILENAME}"
echo "Downloading checksums..."
curl -sSfL "$CHECKSUMS_URL" -o "${TMPDIR}/checksums.txt"
echo "Verifying checksum..."
EXPECTED=$(grep "${FILENAME}" "${TMPDIR}/checksums.txt" | awk '{print $1}')
if [ -z "$EXPECTED" ]; then
echo "Error: checksum not found for ${FILENAME}"
exit 1
fi
if command -v sha256sum >/dev/null 2>&1; then
ACTUAL=$(sha256sum "${TMPDIR}/${FILENAME}" | awk '{print $1}')
elif command -v shasum >/dev/null 2>&1; then
ACTUAL=$(shasum -a 256 "${TMPDIR}/${FILENAME}" | awk '{print $1}')
else
echo "Error: no sha256sum or shasum found — cannot verify download integrity"
exit 1
fi
if [ "$EXPECTED" != "$ACTUAL" ]; then
echo "Error: checksum mismatch!"
echo " Expected: ${EXPECTED}"
echo " Actual: ${ACTUAL}"
exit 1
fi
echo "Checksum verified."
echo "Extracting..."
if [ "$EXT" = "tar.gz" ]; then
tar -xzf "${TMPDIR}/${FILENAME}" -C "$TMPDIR"
else
unzip -q "${TMPDIR}/${FILENAME}" -d "$TMPDIR"
fi
echo "Installing to ${INSTALL_DIR}/${BINARY}..."
if [ -w "$INSTALL_DIR" ]; then
mv "${TMPDIR}/${BINARY}" "${INSTALL_DIR}/${BINARY}"
else
sudo mv "${TMPDIR}/${BINARY}" "${INSTALL_DIR}/${BINARY}"
fi
chmod +x "${INSTALL_DIR}/${BINARY}"
echo "Installed ${BINARY} ${LATEST} to ${INSTALL_DIR}/${BINARY}"