-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathinstall.sh
More file actions
207 lines (182 loc) · 5.8 KB
/
install.sh
File metadata and controls
207 lines (182 loc) · 5.8 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/sh -e
RESET="\\033[0m"
RED="\\033[31;1m"
GREEN="\\033[32;1m"
YELLOW="\\033[33;1m"
BLUE="\\033[34;1m"
WHITE="\\033[37;1m"
echo_green() {
[ -z "${SILENT}" ] && printf "%b%s%b\\n" "${GREEN}" "$1" "${RESET}"
return 0
}
echo_red() {
printf "%b%s%b\\n" "${RED}" "$1" "${RESET}"
}
echo_yellow() {
[ -z "${SILENT}" ] && printf "%b%s%b\\n" "${YELLOW}" "$1" "${RESET}"
return 0
}
echo_blue() {
[ -z "${SILENT}" ] && printf "%b%s%b\\n" "${BLUE}" "$1" "${RESET}"
return 0
}
echo_white() {
[ -z "${SILENT}" ] && printf "%b%s%b\\n" "${WHITE}" "$1" "${RESET}"
return 0
}
echo_em() {
[ -z "${SILENT}" ] && echo " $1"
}
OS=$(uname -s)
ARCH=$(uname -m)
# Check if we need musl (glibc < 2.38 or musl-based system like Alpine)
needs_musl() {
if ! command -v ldd >/dev/null 2>&1; then
return 1
fi
# Check if it's a musl-based system (e.g., Alpine)
if ldd --version 2>&1 | grep -q musl; then
return 0
fi
# Check glibc version
GLIBC_VERSION=$(ldd --version 2>/dev/null | sed -n '1s/.* \\([0-9][0-9]*\\.[0-9][0-9]*\\)$/\\1/p')
[ -n "${GLIBC_VERSION}" ] || GLIBC_VERSION="0.0"
GLIBC_MAJOR=$(echo "${GLIBC_VERSION}" | cut -d. -f1)
GLIBC_MINOR=$(echo "${GLIBC_VERSION}" | cut -d. -f2)
# Need musl if glibc < 2.38
if [ "${GLIBC_MAJOR}" -lt 2 ] 2>/dev/null || \
{ [ "${GLIBC_MAJOR}" -eq 2 ] && [ "${GLIBC_MINOR}" -lt 38 ]; } 2>/dev/null; then
return 0
fi
return 1
}
TARGET=
if [ "${OS}" = "Linux" ]
then
if [ "${ARCH}" = "x86_64" -o "${ARCH}" = "amd64" ]
then
if needs_musl; then
TARGET="s2-x86_64-unknown-linux-musl.zip"
else
TARGET="s2-x86_64-unknown-linux-gnu.zip"
fi
elif [ "${ARCH}" = "aarch64" -o "${ARCH}" = "arm64" ]
then
if needs_musl; then
TARGET="s2-aarch64-unknown-linux-musl.zip"
else
TARGET="s2-aarch64-unknown-linux-gnu.zip"
fi
fi
elif [ "${OS}" = "Darwin" ]
then
if [ "${ARCH}" = "x86_64" -o "${ARCH}" = "amd64" ]
then
TARGET="s2-x86_64-apple-darwin.zip"
elif [ "${ARCH}" = "aarch64" -o "${ARCH}" = "arm64" ]
then
TARGET="s2-aarch64-apple-darwin.zip"
fi
elif echo "${OS}" | grep -qE '^(MINGW|MSYS|CYGWIN)'
then
echo_red "Platform not supported by install.sh."
echo_em "${OS} on ${ARCH}"
echo_white "Windows users: download a Windows zip from the GitHub releases
or install via Cargo (cargo install --locked s2-cli)."
exit 1
fi
if [ -z "${TARGET}" ]
then
echo_red "Platform not supported."
echo_em "${OS} on ${ARCH}"
echo_white "It looks like this platform is not supported. We're sorry about that.
Visit https://github.com/s2-streamstore/s2 to file an issue, and build
from source."
exit 1
fi
REPO="${S2_REPO:-s2-streamstore/s2}"
if [ -n "${VERSION}" ]
then
case "${VERSION}" in
s2-cli-v*) TAG="${VERSION}" ;;
v*) TAG="s2-cli-${VERSION}" ;;
*) TAG="s2-cli-v${VERSION}" ;;
esac
else
TAG=$(curl -sSL "https://github.com/${REPO}/releases?q=s2-cli&expanded=true" \
| grep -o 'releases/tag/s2-cli-v[^"]*' \
| head -1 \
| grep -o 's2-cli-v[^"]*')
if [ -z "${TAG}" ]; then
echo_red "Failed to determine latest s2-cli release."
exit 1
fi
fi
S2_VERSION="${TAG}"
DOWNLOAD_URI="download/${TAG}"
BIN_PATH="${HOME}/.s2/bin"
test -d "${BIN_PATH}" || mkdir -p "${BIN_PATH}"
DOWNLOAD_PATH=`mktemp`
PWD=`pwd`
URL="https://github.com/${REPO}/releases/${DOWNLOAD_URI}/${TARGET}"
echo_blue "Installing S2 CLI"
echo_em "S2 Version: ${S2_VERSION}"
curl --progress-bar -fSL "${URL}" -o "${DOWNLOAD_PATH}" \
&& unzip -o -d "${BIN_PATH}" "${DOWNLOAD_PATH}" >/dev/null \
&& chmod a+x "${BIN_PATH}/s2" \
|| exit 1
rm -f "${DOWNLOAD_PATH}"
echo_blue "Successfully downloaded"
EXISTING_S2_PATH=$(command -v s2 2>/dev/null || true)
NEEDS_PATH_UPDATE=
if [ -n "${EXISTING_S2_PATH}" ] && [ "${EXISTING_S2_PATH}" != "${BIN_PATH}/s2" ]
then
NEEDS_PATH_UPDATE=1
echo_yellow "WARNING: Found existing s2 at ${EXISTING_S2_PATH}"
echo_em "New binary is at ${BIN_PATH}/s2"
fi
# Add the bin to $PATH if it doesn't exist or isn't taking precedence.
# Thanks to Pulumi install script for the inspiration.
if [ -z "${EXISTING_S2_PATH}" ] || [ -n "${NEEDS_PATH_UPDATE}" ]; then
SHELL_NAME=$(basename "${SHELL}")
PROFILE_FILE=""
if [ "${SHELL_NAME}" = "bash" ]
then
if [ "${OS}" = "Darwin" ]
then
if [ -e "${HOME}/.bash_profile" ]; then
PROFILE_FILE="${HOME}/.bash_profile"
elif [ -e "${HOME}/.bashrc" ]; then
PROFILE_FILE="${HOME}/.bashrc"
fi
else
if [ -e "${HOME}/.bashrc" ]; then
PROFILE_FILE="${HOME}/.bashrc"
elif [ -e "${HOME}/.bash_profile" ]; then
PROFILE_FILE="${HOME}/.bash_profile"
fi
fi
elif [ "${SHELL_NAME}" = "zsh" ]
then
if [ -e "${ZDOTDIR:-$HOME}/.zshrc" ]; then
PROFILE_FILE="${ZDOTDIR:-$HOME}/.zshrc"
fi
fi
if [ -n "${PROFILE_FILE}" ]; then
LINE_TO_ADD="export PATH=\"${BIN_PATH}:\\$PATH\""
if ! grep -q "${BIN_PATH}" "${PROFILE_FILE}"; then
echo_white "Adding ${BIN_PATH} to \\$PATH in ${PROFILE_FILE}"
printf "\\n# add S2 to the PATH\\n%s\\n" "${LINE_TO_ADD}" >> "${PROFILE_FILE}"
else
echo_yellow "WARNING: ${BIN_PATH} is already in your PATH."
[ -n "${EXISTING_S2_PATH}" ] && echo_em "Ensure ${BIN_PATH} appears before ${EXISTING_S2_PATH}"
fi
echo_yellow "WARNING: Please restart your shell or add ${BIN_PATH} to your \\$PATH"
else
echo_yellow "WARNING: Please add ${BIN_PATH} to your \\$PATH"
fi
fi
echo_green "S2 CLI installed as"
echo_em "${BIN_PATH}/s2"
echo_green "Get started with S2:"
echo_em "https://s2.dev/docs/quickstart"