Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·480 lines (409 loc) · 15.2 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·480 lines (409 loc) · 15.2 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
#!/usr/bin/env bash
# Jac Programming Language Installer
#
# Downloads the self-contained native `jac` binary from GitHub Releases and
# puts it on your PATH. No system Python, pip, or uv is required -- the binary
# bundles its own runtime.
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/jaseci-labs/jaseci/main/scripts/install.sh | bash
#
# Options:
# --version V Install a specific release version (e.g., 2.3.1)
# --uninstall Remove Jac
# --help Print usage
#
# Examples:
# curl -fsSL ... | bash # Latest jac binary
# curl -fsSL ... | bash -s -- --version 2.3.1 # Specific version
# curl -fsSL ... | bash -s -- --uninstall # Remove Jac
set -euo pipefail
REPO="jaseci-labs/jaseci"
GITHUB_API="https://api.github.com/repos/${REPO}"
INSTALL_DIR="${HOME}/.local/bin"
INSTALL_MARKER=".jac-install"
INSTALL_MARKER_VALUE="installed-by-jaseci-labs-install-script"
# --- Defaults ---
VERSION=""
UNINSTALL=false
# Filled in by resolve_release_metadata once the release is known: the jac
# binary version its assets are named with, and every asset name it carries.
ASSET_VERSION=""
RELEASE_ASSETS=""
# --- Colors and output helpers ---
info() {
printf "\033[0;34m[jac]\033[0m %s\n" "$*"
}
warn() {
printf "\033[0;33m[jac]\033[0m %s\n" "$*" >&2
}
err() {
printf "\033[0;31m[jac]\033[0m %s\n" "$*" >&2
}
has_cmd() {
command -v "$1" &>/dev/null
}
need_cmd() {
if ! has_cmd "$1"; then
err "Required command not found: $1"
err "Please install '$1' and try again."
exit 1
fi
}
# GitHub API requests: authenticate when GITHUB_TOKEN/GH_TOKEN is set, since
# unauthenticated calls share a per-IP rate limit that CI runners exhaust.
api_curl() {
local token="${GITHUB_TOKEN:-${GH_TOKEN:-}}"
if [[ -n "$token" ]]; then
curl -fsSL -H "Authorization: Bearer ${token}" "$@"
else
curl -fsSL "$@"
fi
}
# --- Usage ---
usage() {
cat <<EOF
Jac Programming Language Installer
Downloads the self-contained native 'jac' binary (bundled runtime; no Python,
pip, or uv needed) and puts it on your PATH.
USAGE:
curl -fsSL https://raw.githubusercontent.com/jaseci-labs/jaseci/main/scripts/install.sh | bash
curl -fsSL ... | bash -s -- [OPTIONS]
OPTIONS:
--version V Install a specific release version (e.g., 2.3.1)
--uninstall Remove Jac installation
--help Print this help message
EXAMPLES:
# Latest jac binary
curl -fsSL ... | bash
# Specific version
curl -fsSL ... | bash -s -- --version 2.3.1
EOF
}
# --- Platform detection ---
detect_platform() {
local os arch
os="$(uname -s)"
arch="$(uname -m)"
case "$os" in
Linux*) OS="linux" ;;
Darwin*) OS="macos" ;;
MINGW* | MSYS* | CYGWIN*)
err "Windows detected. Windows support via PowerShell is coming soon."
err "For now, please use WSL2 and re-run this installer inside it."
exit 1
;;
*)
err "Unsupported operating system: $os"
exit 1
;;
esac
case "$arch" in
x86_64 | amd64) ARCH="x86_64" ;;
aarch64 | arm64) ARCH="aarch64" ;;
*)
err "Unsupported architecture: $arch"
exit 1
;;
esac
}
# --- Argument parsing ---
parse_args() {
while [[ $# -gt 0 ]]; do
case "$1" in
--version)
if [[ $# -lt 2 ]]; then
err "--version requires a version argument (e.g., --version 2.3.1)"
exit 1
fi
VERSION="$2"
shift 2
;;
--uninstall)
UNINSTALL=true
shift
;;
# Accepted for backward compatibility -- the binary is now the only
# distribution, so these are no-ops.
--standalone | --core)
warn "Note: '$1' is no longer needed; the native binary is the default install."
shift
;;
--help | -h)
usage
exit 0
;;
*)
err "Unknown option: $1"
usage
exit 1
;;
esac
done
}
# --- PATH helpers ---
ensure_on_path() {
if ! echo "$PATH" | tr ':' '\n' | grep -q "^${INSTALL_DIR}$"; then
export PATH="${INSTALL_DIR}:${PATH}"
fi
# Check if the install dir is in the user's shell profile
local shell_name
shell_name="$(basename "${SHELL:-/bin/bash}")"
local profile=""
case "$shell_name" in
zsh) profile="$HOME/.zshrc" ;;
bash)
if [[ -f "$HOME/.bashrc" ]]; then
profile="$HOME/.bashrc"
elif [[ -f "$HOME/.bash_profile" ]]; then
profile="$HOME/.bash_profile"
fi
;;
fish) profile="$HOME/.config/fish/config.fish" ;;
esac
if [[ -n "$profile" ]] && ! grep -q "${INSTALL_DIR}" "$profile" 2>/dev/null; then
warn ""
warn "Add ${INSTALL_DIR} to your PATH by running:"
if [[ "$shell_name" == "fish" ]]; then
warn " fish_add_path ${INSTALL_DIR}"
else
warn " echo 'export PATH=\"\$HOME/.local/bin:\$PATH\"' >> $profile"
fi
warn ""
warn "Then restart your shell or run: source $profile"
fi
}
# --- Version resolution ---
get_latest_version() {
local response
response=$(api_curl "${GITHUB_API}/releases/latest" 2>/dev/null) || {
err "Failed to query GitHub API for latest release."
err "Check your internet connection or specify a version with --version."
exit 1
}
# Extract tag_name, strip leading 'v'
local tag
tag=$(echo "$response" | grep -o '"tag_name":[[:space:]]*"[^"]*"' | sed -n '1p' | grep -o '"v[^"]*"' | tr -d '"' | sed 's/^v//')
if [[ -z "$tag" ]]; then
err "Could not determine latest version from GitHub Releases."
err "Please specify a version with --version."
exit 1
fi
echo "$tag"
}
# Reads the release once and leaves both answers in globals: ASSET_VERSION and
# RELEASE_ASSETS. Globals rather than a printed value on purpose -- a caller
# would have to run this in a command substitution to capture what it echoes,
# and a subshell's assignments are gone the moment it exits, so the asset list
# would silently arrive empty at every caller.
resolve_release_metadata() {
local release_tag="$1"
local response
response=$(api_curl "${GITHUB_API}/releases/tags/v${release_tag}" 2>/dev/null) || {
err "Failed to query GitHub API for release v${release_tag}."
exit 1
}
# Every asset name on that release, one per line. A platform's binary is
# either in here or the release genuinely has none, and the second case
# deserves a straight answer rather than a download that 404s.
RELEASE_ASSETS=$(echo "$response" | grep -o '"name":[[:space:]]*"[^"]*"' | sed -E 's/.*"([^"]*)"$/\1/')
# Find a jac-<version>-<os>-<arch> asset to extract the jac binary version
# (the jaclang version, which can differ from the jaseci release tag).
ASSET_VERSION=$(echo "$response" | grep -o '"name":[[:space:]]*"jac-[^"]*"' | sed -n '1p' | grep -oE 'jac-[0-9]+\.[0-9]+\.[0-9]+' | sed 's/^jac-//')
if [[ -z "$ASSET_VERSION" ]]; then
err "Could not determine the jac binary version from release v${release_tag} assets."
err "The native binary may not have been built yet for this release."
exit 1
fi
}
# Walks back through recent releases for the newest one that carries a binary
# for this platform, so the message below can name a version instead of waving
# at the releases page. Bounded: this only ever runs on an error path, and each
# probe is one API call. Prints the version, or nothing if it finds none.
#
# The asset match insists on a jac-<major>.<minor>.<patch>-<platform> name, so
# the rolling `dev` prerelease's jac-dev-* assets never answer for a release.
find_last_release_with_platform() {
local list tags tag body probed=0
list=$(api_curl "${GITHUB_API}/releases?per_page=20" 2>/dev/null) || return 0
tags=$(echo "$list" | grep -o '"tag_name":[[:space:]]*"[^"]*"' | sed -E 's/.*"([^"]*)"$/\1/')
while read -r tag; do
[[ -n "$tag" ]] || continue
[[ "$tag" == v* ]] || continue
[[ "$tag" != "v${VERSION}" ]] || continue
if [[ $probed -ge 8 ]]; then
break
fi
probed=$((probed + 1))
body=$(api_curl "${GITHUB_API}/releases/tags/${tag}" 2>/dev/null) || continue
if grep -qE "\"name\":[[:space:]]*\"jac-[0-9]+\.[0-9]+\.[0-9]+-${OS}-${ARCH}\"" <<< "$body"; then
echo "${tag#v}"
return 0
fi
done <<< "$tags"
}
# A release either carries this platform's binary or it does not, and the only
# useful thing to do about "it does not" is say so. There is no fallback build
# to hand an Intel Mac: the Apple Silicon binary is arm64 code that Intel
# hardware cannot execute, and Rosetta translates x86_64 onto Apple Silicon,
# not the other way round.
require_platform_asset() {
local asset="$1"
# A quiet grep may exit on the first asset; a pipe producer could then
# fail with SIGPIPE under pipefail despite the successful match.
if grep -qxF "$asset" <<< "$RELEASE_ASSETS"; then
return 0
fi
err "Release v${VERSION} ships no jac binary for ${OS}-${ARCH}."
err ""
if [[ "$OS" == "macos" && "$ARCH" == "x86_64" ]]; then
err "This release has no Intel macOS build, and there is nothing else here"
err "that will run on this machine: the macOS binary that did build is"
err "arm64 (Apple Silicon) code, and Rosetta translates in the opposite"
err "direction. So there is no way to install v${VERSION} on an Intel Mac."
err ""
info "Looking for the most recent release that does have one..."
local last
last=$(find_last_release_with_platform)
if [[ -n "$last" ]]; then
err "Install v${last} instead, the newest release with an Intel macOS build:"
err ""
err " curl -fsSL https://raw.githubusercontent.com/${REPO}/main/scripts/install.sh | bash -s -- --version ${last}"
err ""
err "Stay on it until an Intel build ships again."
else
err "No recent release carries one either. See the release list for"
err "the last version that did:"
err ""
err " https://github.com/${REPO}/releases"
fi
else
err "Pick a release that has one: https://github.com/${REPO}/releases"
fi
exit 1
}
# --- Binary installation ---
install_binary() {
need_cmd "curl"
# Resolve the release tag (the jaseci/release version).
if [[ -z "$VERSION" ]]; then
info "Fetching latest version..."
VERSION=$(get_latest_version)
info "Latest release: ${VERSION}"
fi
# The jac binary asset is named with the jaclang version, which can differ
# from the jaseci release tag.
info "Resolving jac binary version for release v${VERSION}..."
resolve_release_metadata "$VERSION"
info "jac binary version: ${ASSET_VERSION}"
local asset="jac-${ASSET_VERSION}-${OS}-${ARCH}"
# Checked against the release's own asset list before downloading, so a
# platform this release did not build gets an explanation rather than a
# 404 and a list of guesses.
require_platform_asset "$asset"
local download_url="https://github.com/${REPO}/releases/download/v${VERSION}/${asset}"
local checksum_url="${download_url}.sha256"
# Create install directory
mkdir -p "$INSTALL_DIR"
# Download to temp location. `tmpdir` is intentionally NOT `local`: the EXIT
# trap below fires after install_binary returns, so a function-local would be
# out of scope and trip `set -u` ("unbound variable") during cleanup. The
# `${tmpdir:-}` guard keeps the trap safe if we exit before it is assigned.
tmpdir=$(mktemp -d)
trap 'rm -rf "${tmpdir:-}"' EXIT
info "Downloading ${asset}..."
if ! curl -fsSL -o "${tmpdir}/${asset}" "$download_url"; then
err "Failed to download: ${download_url}"
err ""
# Not a missing-asset guess any more: require_platform_asset already
# confirmed the release lists this exact file.
err "Release v${VERSION} does list this asset, so this is most likely a"
err "network problem or a transient GitHub outage. Try again in a moment."
exit 1
fi
# Verify checksum if available
if curl -fsSL -o "${tmpdir}/${asset}.sha256" "$checksum_url" 2>/dev/null; then
info "Verifying checksum..."
local expected actual
expected=$(awk '{print $1}' "${tmpdir}/${asset}.sha256")
if has_cmd sha256sum; then
actual=$(sha256sum "${tmpdir}/${asset}" | awk '{print $1}')
elif has_cmd shasum; then
actual=$(shasum -a 256 "${tmpdir}/${asset}" | awk '{print $1}')
else
warn "Neither sha256sum nor shasum found, skipping checksum verification."
actual="$expected"
fi
if [[ "$expected" != "$actual" ]]; then
err "Checksum verification failed!"
err " Expected: ${expected}"
err " Got: ${actual}"
exit 1
fi
info "Checksum verified."
else
warn "Checksum file not available, skipping verification."
fi
# Install binary
mv "${tmpdir}/${asset}" "${INSTALL_DIR}/jac"
chmod +x "${INSTALL_DIR}/jac"
printf '%s\n' "$INSTALL_MARKER_VALUE" > "${INSTALL_DIR}/${INSTALL_MARKER}"
ensure_on_path
# Verify
if has_cmd jac; then
info ""
info "Jac installed successfully!"
info ""
info "Performing initial setup, this may take a moment..."
# No stderr redirect: the launcher narrates its one-time extract
# (payload read, sha256, live percent) on stderr -- show it.
jac || true
info ""
else
warn "Binary installed to ${INSTALL_DIR}/jac but 'jac' is not on PATH."
warn "Try restarting your shell or adding ~/.local/bin to PATH."
fi
}
# --- Uninstall ---
do_uninstall() {
local removed=false
# Remove standalone binary
if [[ -f "${INSTALL_DIR}/jac" ]]; then
info "Removing ${INSTALL_DIR}/jac..."
rm -f "${INSTALL_DIR}/jac"
removed=true
fi
if [[ -f "${INSTALL_DIR}/${INSTALL_MARKER}" ]]; then
rm -f "${INSTALL_DIR}/${INSTALL_MARKER}"
fi
# Clean up any legacy uv-managed installs from older installer versions.
if has_cmd uv; then
if uv tool list 2>/dev/null | grep -q "^jaseci "; then
info "Removing legacy jaseci (uv tool)..."
uv tool uninstall jaseci
removed=true
fi
if uv tool list 2>/dev/null | grep -q "^jaclang "; then
info "Removing legacy jaclang (uv tool)..."
uv tool uninstall jaclang
removed=true
fi
fi
if $removed; then
info "Jac has been uninstalled."
else
warn "No Jac installation found."
fi
}
# --- Main ---
main() {
parse_args "$@"
if $UNINSTALL; then
do_uninstall
exit 0
fi
detect_platform
info "Detected platform: ${OS}-${ARCH}"
install_binary
}
main "$@"