Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·241 lines (221 loc) · 11.4 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·241 lines (221 loc) · 11.4 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
#!/usr/bin/env bash
# Install opencode, Cline CLI and Bun built for old x86-64 CPUs (Core 2, Pentium Dual-Core, Celeron, Athlon 64 X2,
# Phenom II, ...), and make the Antigravity CLI usable on them.
#
# curl -fsSL https://raw.githubusercontent.com/Ulmaria/legacy-cpu-agents/main/install.sh | bash
# curl -fsSL .../install.sh | bash -s -- opencode cline # only some of: bun opencode cline agy
#
# Installs into ~/.local/bin (override with LEGACY_BIN_DIR). Any x86_64 Linux with glibc 2.17+: Debian/Ubuntu/Mint,
# Arch, Fedora and openSUSE get QEMU (for agy) from their package manager when it is needed.
set -euo pipefail
REPO=Ulmaria/legacy-cpu-agents
BIN=${LEGACY_BIN_DIR:-$HOME/.local/bin}
SHARE=${LEGACY_SHARE_DIR:-$HOME/.local/share/legacy-cpu-agents}
tools=("$@")
[ ${#tools[@]} -gt 0 ] || tools=(bun opencode cline agy)
say() { printf '\033[1m==>\033[0m %s\n' "$*"; }
warn() { printf '\033[33mwarning:\033[0m %s\n' "$*" >&2; }
die() { printf '\033[31merror:\033[0m %s\n' "$*" >&2; exit 1; }
# Install packages with whichever package manager this distro has. <pacman name> <apt name> <dnf name> <zypper name>
pkg_install() {
if command -v pacman >/dev/null; then
# A stale package database names versions the mirrors have already deleted (404s). pacman still
# succeeds if one mirror has the file, so hide that noise; if none has it, sync and upgrade
# (Arch doesn't support -Sy without -u: a partial upgrade can break the system).
sudo pacman -S --needed --noconfirm "$1" 2>/dev/null || {
say "pacman's package database is out of date; running a full system upgrade (pacman -Syu) to get $1"
sudo pacman -Syu --needed --noconfirm "$1"
}
elif command -v apt-get >/dev/null; then sudo apt-get update && sudo apt-get install -y "$2"
elif command -v dnf >/dev/null; then sudo dnf install -y "$3"
elif command -v zypper >/dev/null; then sudo zypper --non-interactive install "$4"
else return 1
fi
}
[ "$(uname -s)" = Linux ] || die "this installer is for Linux"
[ "$(uname -m)" = x86_64 ] || die "needs a 64-bit x86 CPU and a 64-bit (amd64) Linux; found $(uname -m)"
command -v curl >/dev/null || die "install curl first (Arch: sudo pacman -S curl; Debian/Ubuntu: sudo apt-get install curl)"
command -v tar >/dev/null || die "install tar first"
flags=$(grep -m1 '^flags' /proc/cpuinfo || true)
model=$(grep -m1 '^model name' /proc/cpuinfo | cut -d: -f2- | sed 's/^ *//' || true)
missing=""
for f in ssse3 sse4_1 sse4_2 popcnt avx avx2; do grep -qw "$f" <<<"$flags" || missing="$missing $f"; done
say "CPU: ${model:-unknown}"
say "CPU lacks:${missing:- nothing relevant (the official builds would work here too)}"
grep -qw cx16 <<<"$flags" || warn "this CPU has no CMPXCHG16B; the legacy builds need it (every Core 2 / Athlon 64 X2 has it)"
mkdir -p "$BIN" "$SHARE"
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
# Newest release whose tag starts with $1 (the API lists releases newest first).
# The list is fetched once (prepare) and shared by every tool.
latest_tag() {
grep -o "\"tag_name\": *\"$1[^\"]*\"" "$tmp/releases.json" | head -1 | cut -d'"' -f4
}
# fetch <tag> <asset> <sums asset>: download into $tmp and check its sha256 against the release's sums file.
fetch() {
local base="https://github.com/$REPO/releases/download/$1"
curl -fsSL --retry 3 -o "$tmp/$2" "$base/$2"
if curl -fsSL -o "$tmp/$3" "$base/$3" 2>/dev/null; then
(cd "$tmp" && grep " $2\$" "$3" | sha256sum -c --quiet -) || die "checksum mismatch for $2"
fi
}
# Each tool has a download_<tool> (run for all tools at once, see below) and an install_<tool> that uses the file.
download_bun() {
local tag; tag=$(latest_tag bun-v) || true
[ -n "$tag" ] || die "no legacy bun release found in $REPO"
fetch "$tag" bun-linux-x64-legacy.tgz SHA256SUMS
echo "$tag" > "$tmp/bun.tag"
}
install_bun() {
say "bun ($(cat "$tmp/bun.tag"))"
tar -xzf "$tmp/bun-linux-x64-legacy.tgz" -C "$tmp"
install -m755 "$tmp/package/bin/bun" "$BIN/bun"
ln -sf bun "$BIN/bunx"
"$BIN/bun" --version
}
download_opencode() {
local tag; tag=$(latest_tag opencode-v) || true
[ -n "$tag" ] || die "no legacy opencode release found in $REPO"
fetch "$tag" opencode-linux-x64-legacy.tar.gz opencode-SHA256SUMS
echo "$tag" > "$tmp/opencode.tag"
}
install_opencode() {
say "opencode ($(cat "$tmp/opencode.tag"))"
tar -xzf "$tmp/opencode-linux-x64-legacy.tar.gz" -C "$tmp"
install -m755 "$tmp/opencode" "$BIN/opencode"
# `opencode upgrade` would fetch the official build (SSE4.2/AVX2): keep its update check quiet.
"$BIN/opencode" --version
}
download_cline() {
local tag; tag=$(latest_tag cline-v) || true
[ -n "$tag" ] || die "no legacy cline release found in $REPO"
fetch "$tag" cline-linux-x64-legacy.tar.gz cline-SHA256SUMS
echo "$tag" > "$tmp/cline.tag"
}
install_cline() {
say "cline ($(cat "$tmp/cline.tag"))"
rm -rf "$SHARE/cline" && mkdir -p "$SHARE/cline"
tar -xzf "$tmp/cline-linux-x64-legacy.tar.gz" -C "$SHARE/cline"
ln -sf "$SHARE/cline/cli-linux-x64/bin/cline" "$BIN/cline"
"$BIN/cline" --version
}
# probe_rc <cmd...>: run it with no output and print its exit status (132 = SIGILL). On old CPUs agy is expected to
# crash here, and bash reports a crashed child ("Illegal instruction (core dumped)") on its own stderr, sometimes
# only after the command's redirections are gone. Run it in a subshell whose stderr is /dev/null for good: the
# report goes there, and the subshell itself exits normally, so this shell has nothing to report.
probe_rc() {
(exec 2>/dev/null; "$@" >/dev/null </dev/null && echo 0 || echo $?)
}
# Antigravity CLI is closed source, so it cannot be rebuilt. If the official binary runs here, use it directly;
# if it dies with an illegal instruction (it needs SSE4.1/SSE4.2/POPCNT), run it through QEMU's user-mode
# emulator, which provides those instructions in software. The binary itself is the official, unmodified one.
download_agy() {
local ver
ver=$(curl -fsSL "https://api.github.com/repos/google-antigravity/antigravity-cli/releases/latest" |
grep -o '"tag_name": *"[^"]*"' | head -1 | cut -d'"' -f4)
[ -n "$ver" ] || die "could not find the latest Antigravity CLI release"
curl -fsSL --retry 3 -o "$tmp/agy.tar.gz" \
"https://github.com/google-antigravity/antigravity-cli/releases/download/$ver/agy_cli_linux_x64.tar.gz"
echo "$ver" > "$tmp/agy.tag"
}
install_agy() {
local dir=$SHARE/agy
say "Antigravity CLI ($(cat "$tmp/agy.tag"), official build)"
rm -rf "$dir" && mkdir -p "$dir"
tar -xzf "$tmp/agy.tar.gz" -C "$dir"
[ -x "$dir/antigravity" ] || die "unexpected Antigravity archive layout"
[ -e "$BIN/agy" ] && [ ! -e "$BIN/agy.official-backup" ] && mv "$BIN/agy" "$BIN/agy.official-backup"
local rc; rc=$(probe_rc "$dir/antigravity" --version)
if [ $rc -eq 0 ]; then
ln -sf "$dir/antigravity" "$BIN/agy"
say "agy runs natively on this CPU"
else
# 132 = SIGILL, the expected result on old CPUs; anything else is unusual, so show it.
if [ "$rc" -eq 132 ]; then say "agy will run through QEMU (normal on this CPU: the official build needs SSE4.1/SSE4.2)"
else say "agy did not start natively (exit $rc); setting it up to run through QEMU"
fi
if ! command -v qemu-x86_64 >/dev/null; then
say "installing QEMU user-mode emulation (needs sudo)"
pkg_install qemu-user qemu-user qemu-user qemu-linux-user ||
die "could not install QEMU; install your distro's qemu-user package (it provides qemu-x86_64) and run this again"
fi
cat >"$BIN/agy" <<EOF
#!/bin/sh
# Antigravity CLI through QEMU: the official binary needs SSE4.1/SSE4.2/POPCNT, which this CPU lacks.
exec qemu-x86_64 -cpu max "$dir/antigravity" "\$@"
EOF
chmod +x "$BIN/agy"
"$BIN/agy" --version || die "agy did not start even under QEMU; please open an issue at https://github.com/$REPO"
fi
}
# Download everything at the same time, then install one by one.
for i in "${!tools[@]}"; do
case "${tools[$i]}" in
antigravity) tools[i]=agy ;;
bun | opencode | cline | agy) ;;
*) die "unknown tool '${tools[$i]}' (choose from: bun opencode cline agy)" ;;
esac
done
say "downloading ${tools[*]} (all at once)"
# GitHub limits anonymous API calls per address (shared addresses run out); a token in GITHUB_TOKEN lifts that.
auth=()
[ -z "${GITHUB_TOKEN:-}" ] || auth=(-H "Authorization: Bearer $GITHUB_TOKEN")
curl -fsSL --retry 3 "${auth[@]}" -o "$tmp/releases.json" "https://api.github.com/repos/$REPO/releases?per_page=100" ||
die "could not list the releases of $REPO (GitHub may be limiting this address: try again in a few minutes)"
pids=()
for t in "${tools[@]}"; do "download_$t" & pids+=($!); done
failed=0
for pid in "${pids[@]}"; do wait "$pid" || failed=1; done
[ $failed = 0 ] || die "a download failed (see above); check the connection and run this again"
for t in "${tools[@]}"; do
case "$t" in
bun) install_bun ;;
opencode) install_opencode ;;
cline) install_cline ;;
agy | antigravity) install_agy ;;
*) die "unknown tool '$t' (choose from: bun opencode cline agy)" ;;
esac
done
# Official installers put their own directory in front of PATH from ~/.bashrc (opencode: ~/.opencode/bin, Bun:
# ~/.bun/bin, npm: its global bin), so an earlier opencode/cline/bun would still win over these. Re-append one line
# at the very end of each shell rc file on every run: the last line to prepend wins.
marker='# legacy-cpu-agents: keep the old-CPU builds first on PATH'
for rc in "$HOME/.bashrc" "$HOME/.zshrc"; do
[ -f "$rc" ] || [ "$rc" = "$HOME/.bashrc" ] || continue
touch "$rc"
# Drop our previous marker line and the export after it, then append them again.
awk -v m="$marker" '$0 == m { skip = 1; next } skip { skip = 0; next } { print }' "$rc" >"$tmp/rc" && cat "$tmp/rc" >"$rc"
printf '%s\nexport PATH="%s:$PATH"\n' "$marker" "$BIN" >>"$rc"
done
# fish (the default shell of some desktops, e.g. illogical-impulse on Arch) doesn't read ~/.bashrc: same idea in
# its config.fish, with fish's own command for putting a directory first.
fish_rc=${XDG_CONFIG_HOME:-$HOME/.config}/fish/config.fish
if command -v fish >/dev/null || [ -f "$fish_rc" ]; then
mkdir -p "$(dirname "$fish_rc")"
touch "$fish_rc"
awk -v m="$marker" '$0 == m { skip = 1; next } skip { skip = 0; next } { print }' "$fish_rc" >"$tmp/rc" && cat "$tmp/rc" >"$fish_rc"
printf '%s\nfish_add_path --move --prepend "%s"\n' "$marker" "$BIN" >>"$fish_rc"
fi
# Every other copy of the installed tools that PATH can reach, and how to remove it.
removal_hint() { # <tool> <path>
local real; real=$(readlink -f "$2" 2>/dev/null || echo "$2")
case "$real" in
*/node_modules/*) case "$1" in opencode) echo "npm uninstall -g opencode-ai" ;; *) echo "npm uninstall -g $1" ;; esac ;;
"$HOME/.opencode/"*) echo "rm -rf ~/.opencode (and delete the ~/.opencode/bin PATH line in ~/.bashrc)" ;;
"$HOME/.bun/bin/"*) [ "$1" = bun ] && echo "rm ~/.bun/bin/bun ~/.bun/bin/bunx" || echo "bun remove -g ${1/opencode/opencode-ai}" ;;
"$HOME"/*) echo "rm '$2'" ;;
*) echo "sudo rm '$2'" ;;
esac
}
found=0
for t in "${tools[@]}"; do
[ "$t" = antigravity ] && t=agy
[ "$t" = agy ] && continue
while IFS= read -r p; do
[ -n "$p" ] && [ "$p" != "$BIN/$t" ] || continue
[ $found = 1 ] || warn "older copies are still installed (they crash on this CPU). New terminals use the old-CPU builds anyway, but you can remove them:"
found=1
printf ' %-34s remove with: %s\n' "$p" "$(removal_hint "$t" "$p")" >&2
done < <(type -ap "$t" 2>/dev/null | awk '!seen[$0]++')
done
say "done. Open a NEW terminal (or run: hash -r; export PATH=\"$BIN:\$PATH\"), then check with: which -a opencode cline"