-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·284 lines (248 loc) · 9.06 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·284 lines (248 loc) · 9.06 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#!/usr/bin/env bash
# Install script for the Clerk CLI.
# Downloads a pre-compiled binary from GitHub Releases, or installs from local build artifacts.
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/clerk/cli/main/install.sh | bash
# curl -fsSL https://raw.githubusercontent.com/clerk/cli/main/install.sh | bash -s -- --canary
# curl -fsSL https://raw.githubusercontent.com/clerk/cli/main/install.sh | bash -s -- --version v0.1.0-canary.v20260313145959
# ./install.sh --local # install from dist/artifacts/
# ./install.sh --local --artifacts-dir ./build # install from custom path
#
# Environment variables:
# CLERK_INSTALL_DIR — directory to install to (default: /usr/local/bin, or ~/.local/bin if not writable)
set -euo pipefail
REPO="clerk/cli"
BINARY_NAME="clerk"
INSTALL_DIR="${CLERK_INSTALL_DIR:-}"
CHANNEL=""
VERSION=""
LOCAL=false
ARTIFACTS_DIR=""
# ─── Parse arguments ───────────────────────────────────────────────────────────
while [[ $# -gt 0 ]]; do
case "$1" in
--canary)
CHANNEL="canary"
shift
;;
--version)
if [ $# -lt 2 ] || [[ "$2" == -* ]]; then
echo "Error: --version requires a value (e.g. --version v0.1.0)" >&2
exit 1
fi
VERSION="$2"
shift 2
;;
--version=*)
VERSION="${1#--version=}"
shift
;;
--install-dir)
if [ $# -lt 2 ] || [[ "$2" == -* ]]; then
echo "Error: --install-dir requires a value (e.g. --install-dir /usr/local/bin)" >&2
exit 1
fi
INSTALL_DIR="$2"
shift 2
;;
--install-dir=*)
INSTALL_DIR="${1#--install-dir=}"
shift
;;
--local)
LOCAL=true
shift
;;
--artifacts-dir)
if [ $# -lt 2 ] || [[ "$2" == -* ]]; then
echo "Error: --artifacts-dir requires a value (e.g. --artifacts-dir ./build)" >&2
exit 1
fi
ARTIFACTS_DIR="$2"
LOCAL=true
shift 2
;;
--artifacts-dir=*)
ARTIFACTS_DIR="${1#--artifacts-dir=}"
LOCAL=true
shift
;;
--help|-h)
echo "Install the Clerk CLI"
echo ""
echo "Usage:"
echo " install.sh [options]"
echo ""
echo "Options:"
echo " --canary Install the latest canary release"
echo " --version <tag> Install a specific version (e.g. v0.1.0)"
echo " --install-dir <path> Directory to install to"
echo " --local Install from local build artifacts (dist/artifacts/)"
echo " --artifacts-dir <path> Path to local artifacts directory (implies --local)"
echo " -h, --help Show this help"
exit 0
;;
*)
echo "Unknown option: $1" >&2
exit 1
;;
esac
done
# ─── Detect platform ──────────────────────────────────────────────────────────
detect_target() {
local os arch libc=""
case "$(uname -s)" in
Darwin) os="darwin" ;;
Linux) os="linux" ;;
MINGW*|MSYS*|CYGWIN*) os="win32" ;;
*)
echo "Error: unsupported operating system: $(uname -s)" >&2
exit 1
;;
esac
case "$(uname -m)" in
x86_64|amd64) arch="x64" ;;
arm64|aarch64) arch="arm64" ;;
*)
echo "Error: unsupported architecture: $(uname -m)" >&2
exit 1
;;
esac
# Detect musl on Linux
if [ "$os" = "linux" ]; then
if ldd --version 2>&1 | grep -qi musl; then
libc="-musl"
elif command -v ldd >/dev/null 2>&1; then
libc="" # glibc
elif [ -f /etc/alpine-release ]; then
libc="-musl"
fi
# The musl binary dynamically links libstdc++ and libgcc_s (Bun embeds
# JavaScriptCore which is C++). These are not shipped by default on
# Alpine and other minimal musl distros.
if [ "$libc" = "-musl" ]; then
local missing=""
if ! ldconfig -p 2>/dev/null | grep -q libstdc++ && ! [ -f /usr/lib/libstdc++.so.6 ]; then
missing="libstdc++"
fi
if ! ldconfig -p 2>/dev/null | grep -q libgcc_s && ! [ -f /usr/lib/libgcc_s.so.1 ]; then
missing="${missing:+$missing, }libgcc"
fi
if [ -n "$missing" ]; then
echo "Error: missing required shared libraries: ${missing}" >&2
echo "" >&2
echo "The Clerk CLI binary requires libstdc++ and libgcc to run." >&2
if [ -f /etc/alpine-release ]; then
echo "Install them with: apk add libstdc++ libgcc" >&2
else
echo "Install the libstdc++ and libgcc packages for your distribution." >&2
fi
exit 1
fi
fi
fi
echo "${os}-${arch}${libc}"
}
TARGET="$(detect_target)"
EXT=""
if [[ "$TARGET" == win32-* ]]; then
EXT=".exe"
fi
echo "Detected platform: ${TARGET}"
# ─── Resolve source ───────────────────────────────────────────────────────────
TMPDIR=$(mktemp -d)
trap 'rm -rf "$TMPDIR"' EXIT
if [ "$LOCAL" = true ]; then
# ─── Local artifacts ─────────────────────────────────────────────────────────
if [ -z "$ARTIFACTS_DIR" ]; then
ARTIFACTS_DIR="dist/artifacts"
fi
LOCAL_BINARY="${ARTIFACTS_DIR}/${TARGET}/${BINARY_NAME}${EXT}"
if [ ! -f "$LOCAL_BINARY" ]; then
echo "Error: no binary found at ${LOCAL_BINARY}" >&2
echo "Run 'bun run build:compile:all' or 'bun run scripts/build.ts --target=${TARGET}' first." >&2
exit 1
fi
cp "$LOCAL_BINARY" "${TMPDIR}/${BINARY_NAME}${EXT}"
chmod +x "${TMPDIR}/${BINARY_NAME}${EXT}"
# Read version from the binary itself
TAG=$("${TMPDIR}/${BINARY_NAME}${EXT}" --version 2>/dev/null || echo "local")
echo "Installing Clerk CLI ${TAG} from local artifacts..."
else
# ─── GitHub Releases ─────────────────────────────────────────────────────────
# TODO: remove token/auth header once the repo is public
_TOKEN=$(gh auth token 2>/dev/null || true)
_AUTH=()
if [ -n "$_TOKEN" ]; then
_AUTH=(-H "Authorization: token ${_TOKEN}")
fi
if [ -n "$VERSION" ]; then
TAG="$VERSION"
if [[ "$TAG" != v* ]]; then
TAG="v${TAG}"
fi
elif [ "$CHANNEL" = "canary" ]; then
TAG=$(gh release list --repo "$REPO" --limit 20 --json tagName,isPrerelease \
--jq '[.[] | select(.isPrerelease and (.tagName | contains("canary")))][0].tagName // empty' 2>/dev/null || true)
if [ -z "$TAG" ]; then
TAG=$(curl -fsSL "${_AUTH[@]}" "https://api.github.com/repos/${REPO}/releases" \
| grep -o '"tag_name": *"[^"]*canary[^"]*"' \
| head -1 \
| cut -d'"' -f4 || true)
fi
if [ -z "$TAG" ]; then
echo "Error: no canary release found" >&2
exit 1
fi
else
TAG=$(curl -fsSL "${_AUTH[@]}" "https://api.github.com/repos/${REPO}/releases/latest" \
| grep -o '"tag_name": *"[^"]*"' \
| cut -d'"' -f4 || true)
if [ -z "$TAG" ]; then
echo "Error: no stable release found" >&2
exit 1
fi
fi
echo "Installing Clerk CLI ${TAG}..."
ASSET_NAME="clerk-${TARGET}${EXT}"
# TODO: switch to the direct URL once the repo is public:
# curl -fsSL -o ... "https://github.com/${REPO}/releases/download/${TAG}/${ASSET_NAME}"
ASSET_URL=$(curl -fsSL "${_AUTH[@]}" \
"https://api.github.com/repos/${REPO}/releases/tags/${TAG}" \
| grep -B20 "\"name\": \"${ASSET_NAME}\"" \
| grep '"url"' | tail -1 | grep -o 'https://[^"]*')
if [ -z "$ASSET_URL" ]; then
echo "Error: asset ${ASSET_NAME} not found in release ${TAG}" >&2
echo "Check that this platform is supported and the release exists." >&2
exit 1
fi
echo "Downloading ${ASSET_NAME} from release ${TAG}..."
if ! curl -fsSL "${_AUTH[@]}" -H "Accept: application/octet-stream" \
-o "${TMPDIR}/${BINARY_NAME}${EXT}" "$ASSET_URL"; then
echo "Error: failed to download binary for ${TARGET} from release ${TAG}" >&2
exit 1
fi
chmod +x "${TMPDIR}/${BINARY_NAME}${EXT}"
fi
# ─── Install binary ───────────────────────────────────────────────────────────
if [ -z "$INSTALL_DIR" ]; then
if [ -w /usr/local/bin ]; then
INSTALL_DIR="/usr/local/bin"
else
INSTALL_DIR="${HOME}/.local/bin"
fi
fi
mkdir -p "$INSTALL_DIR"
mv "${TMPDIR}/${BINARY_NAME}${EXT}" "${INSTALL_DIR}/${BINARY_NAME}${EXT}"
echo ""
echo "Clerk CLI ${TAG} installed to ${INSTALL_DIR}/${BINARY_NAME}${EXT}"
# Check if install dir is in PATH
if ! echo "$PATH" | tr ':' '\n' | grep -qx "$INSTALL_DIR"; then
echo ""
echo "Warning: ${INSTALL_DIR} is not in your PATH."
echo "Add it to your shell profile:"
echo " export PATH=\"${INSTALL_DIR}:\$PATH\""
fi
echo ""
"${INSTALL_DIR}/${BINARY_NAME}${EXT}" --version