-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·151 lines (134 loc) · 4.33 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·151 lines (134 loc) · 4.33 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/sh
set -eu
# Socket Patch installer
# Usage:
# curl -fsSL https://raw.githubusercontent.com/SocketDev/socket-patch/main/scripts/install.sh | sh
#
# Override the version that gets installed by exporting SOCKET_PATCH_VERSION:
# curl -fsSL .../install.sh | SOCKET_PATCH_VERSION=3.0.0 sh
REPO="SocketDev/socket-patch"
BINARY="socket-patch"
VERSION="${SOCKET_PATCH_VERSION:-latest}"
# Detect platform
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Darwin)
case "$ARCH" in
arm64) TARGET="aarch64-apple-darwin" ;;
x86_64) TARGET="x86_64-apple-darwin" ;;
*) echo "Error: unsupported architecture: $ARCH" >&2; exit 1 ;;
esac
;;
Linux)
# Detect libc: musl or glibc
detect_libc() {
if ldd --version 2>&1 | grep -qi musl; then
echo "musl"
return
fi
# `[ -e ]` cannot take a glob (SC2144): with several matches it is a
# syntax error, with none it tests the literal pattern. Loop instead.
for loader in /lib/ld-musl-*.so.1; do
if [ -e "$loader" ]; then
echo "musl"
return
fi
done
echo "gnu"
}
LIBC="$(detect_libc)"
case "$ARCH" in
x86_64)
if [ "$LIBC" = "musl" ]; then TARGET="x86_64-unknown-linux-musl"
else TARGET="x86_64-unknown-linux-gnu"; fi ;;
aarch64)
if [ "$LIBC" = "musl" ]; then TARGET="aarch64-unknown-linux-musl"
else TARGET="aarch64-unknown-linux-gnu"; fi ;;
armv7l)
if [ "$LIBC" = "musl" ]; then TARGET="arm-unknown-linux-musleabihf"
else TARGET="arm-unknown-linux-gnueabihf"; fi ;;
i686)
if [ "$LIBC" = "musl" ]; then TARGET="i686-unknown-linux-musl"
else TARGET="i686-unknown-linux-gnu"; fi ;;
*) echo "Error: unsupported architecture: $ARCH" >&2; exit 1 ;;
esac
;;
*)
echo "Error: unsupported OS: $OS" >&2
exit 1
;;
esac
# Detect downloader
if command -v curl >/dev/null 2>&1; then
download() { curl -fsSL -o "$1" "$2"; }
elif command -v wget >/dev/null 2>&1; then
download() { wget -qO "$1" "$2"; }
else
echo "Error: curl or wget is required" >&2
exit 1
fi
# Locate a SHA-256 implementation. shasum and sha256sum cover macOS + Linux.
if command -v shasum >/dev/null 2>&1; then
sha256() { shasum -a 256 "$1" | awk '{print $1}'; }
elif command -v sha256sum >/dev/null 2>&1; then
sha256() { sha256sum "$1" | awk '{print $1}'; }
else
echo "Error: shasum or sha256sum is required for integrity verification" >&2
exit 1
fi
# Pick install directory
if [ -w /usr/local/bin ]; then
INSTALL_DIR="/usr/local/bin"
else
INSTALL_DIR="${HOME}/.local/bin"
mkdir -p "$INSTALL_DIR"
fi
# Create temp dir with cleanup
TMPDIR="$(mktemp -d)"
trap 'rm -rf "$TMPDIR"' EXIT
# Pick the release path. "latest" resolves on GitHub's side; tagged versions are
# served from /releases/download/v<version>/.
if [ "$VERSION" = "latest" ]; then
BASE_URL="https://github.com/${REPO}/releases/latest/download"
else
BASE_URL="https://github.com/${REPO}/releases/download/v${VERSION#v}"
fi
ARCHIVE="${BINARY}-${TARGET}.tar.gz"
ARCHIVE_URL="${BASE_URL}/${ARCHIVE}"
SHA_URL="${BASE_URL}/SHA256SUMS"
echo "Downloading ${ARCHIVE}..."
download "${TMPDIR}/${ARCHIVE}" "${ARCHIVE_URL}"
echo "Downloading SHA256SUMS..."
download "${TMPDIR}/SHA256SUMS" "${SHA_URL}"
# Verify the tarball matches the published checksum before extraction. The
# SHA256SUMS file follows the standard "<hex> <filename>" format, one line
# per release artifact.
EXPECTED="$(awk -v a="${ARCHIVE}" '$2 == a || $2 == "*"a {print $1; exit}' "${TMPDIR}/SHA256SUMS")"
if [ -z "${EXPECTED}" ]; then
echo "Error: no checksum entry for ${ARCHIVE} in SHA256SUMS" >&2
exit 1
fi
ACTUAL="$(sha256 "${TMPDIR}/${ARCHIVE}")"
if [ "${EXPECTED}" != "${ACTUAL}" ]; then
echo "Error: checksum mismatch for ${ARCHIVE}" >&2
echo " expected: ${EXPECTED}" >&2
echo " actual: ${ACTUAL}" >&2
exit 1
fi
tar xzf "${TMPDIR}/${ARCHIVE}" -C "${TMPDIR}"
# Install
install -m 755 "${TMPDIR}/${BINARY}" "${INSTALL_DIR}/${BINARY}"
echo "Installed ${BINARY} to ${INSTALL_DIR}/${BINARY}"
# Print version
"${INSTALL_DIR}/${BINARY}" --version 2>/dev/null || true
# Warn if not on PATH
case ":${PATH}:" in
*":${INSTALL_DIR}:"*) ;;
*)
echo ""
echo "Warning: ${INSTALL_DIR} is not on your PATH."
echo "Add it with:"
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
;;
esac