-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
102 lines (87 loc) · 2.51 KB
/
Copy pathinstall.sh
File metadata and controls
102 lines (87 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
102
#!/bin/sh
# install.sh — bridge-cli installer
# Usage: curl -fsSL https://github.com/AFK-surf/bridge-cli/releases/latest/download/install.sh | sh
#
# Wraps all logic in install() so the script is safe against partial downloads.
set -e
BASE_URL="https://github.com/AFK-surf/bridge-cli/releases/latest/download"
BINARY_NAME="bridge-cli"
install() {
# ---- detect platform ----
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Darwin)
PLATFORM="aarch64-apple-darwin"
;;
Linux)
case "$ARCH" in
aarch64|arm64) PLATFORM="aarch64-linux-musl" ;;
x86_64) PLATFORM="x86_64-linux-musl" ;;
*)
echo "bridge-cli: unsupported Linux architecture: $ARCH" >&2
exit 1
;;
esac
;;
*)
echo "bridge-cli: unsupported OS: $OS" >&2
exit 1
;;
esac
BIN_URL="${BASE_URL}/${BINARY_NAME}-${PLATFORM}"
SHA_URL="${BIN_URL}.sha256"
# ---- pick install dir ----
if [ -w /usr/local/bin ]; then
INSTALL_DIR="/usr/local/bin"
else
INSTALL_DIR="${HOME}/.local/bin"
mkdir -p "$INSTALL_DIR"
fi
DEST="${INSTALL_DIR}/${BINARY_NAME}"
TMP="$(mktemp)"
TMP_SHA="$(mktemp)"
# shellcheck disable=SC2064
trap "rm -f '$TMP' '$TMP_SHA'" EXIT INT TERM
# ---- download ----
echo "Downloading bridge-cli for ${PLATFORM}..."
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$BIN_URL" -o "$TMP"
curl -fsSL "$SHA_URL" -o "$TMP_SHA"
elif command -v wget >/dev/null 2>&1; then
wget -qO "$TMP" "$BIN_URL"
wget -qO "$TMP_SHA" "$SHA_URL"
else
echo "bridge-cli: neither curl nor wget found" >&2
exit 1
fi
# ---- verify checksum ----
EXPECTED="$(awk '{print $1}' "$TMP_SHA")"
if command -v sha256sum >/dev/null 2>&1; then
ACTUAL="$(sha256sum "$TMP" | awk '{print $1}')"
elif command -v shasum >/dev/null 2>&1; then
ACTUAL="$(shasum -a 256 "$TMP" | awk '{print $1}')"
else
echo "bridge-cli: warning: no sha256 tool found, skipping checksum verification" >&2
ACTUAL="$EXPECTED"
fi
if [ "$ACTUAL" != "$EXPECTED" ]; then
echo "bridge-cli: checksum mismatch (expected $EXPECTED, got $ACTUAL)" >&2
exit 1
fi
# ---- install ----
chmod +x "$TMP"
mv "$TMP" "$DEST"
echo "Installed bridge-cli to ${DEST}"
# ---- PATH hint ----
case ":${PATH}:" in
*":${INSTALL_DIR}:"*) ;;
*)
echo ""
echo " Note: ${INSTALL_DIR} is not in your PATH."
echo " Add it with:"
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
;;
esac
}
install