bootstrap
Adom Hydrogen (Linux)
Public Made by Adomby adom
The Linux platform layer for Adom Hydrogen: Ubuntu, Debian and Fedora, the workspace and the computer.
main
John Lauer
Publish 0.1.3
446c8b3
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
#!/bin/bash
# The workspace half of adom/hydrogen-linux-bootstrap. Hydrogen on Linux runs this after every
# package convergence (hydrogen-setup linux_skills.rs) and the package runs it on install. It
# converges the Adom-Workspace machine (Ubuntu 24.04) for Linux Hydrogen, with the workspace's own
# passwordless sudo, and prints one summary line. Idempotent: a converged machine costs a few checks.
set -u
log=(); need_update=1
apt_i() { if [ $need_update = 1 ]; then sudo -n apt-get update -qq >/dev/null 2>&1; need_update=0; fi
sudo -n env DEBIAN_FRONTEND=noninteractive apt-get install -y -q --no-install-recommends "$@" >/dev/null 2>&1; }
sudo -n true 2>/dev/null || { echo "linux-platform: no passwordless sudo in the workspace; nothing changed"; exit 0; }
# 1. ffmpeg with libx264 (AI runs that make video; the Windows image has it).
if ! ffmpeg -hide_banner -encoders 2>/dev/null | grep -q libx264; then
apt_i ffmpeg && log+=("ffmpeg installed") || log+=("ffmpeg FAILED")
fi
if ffmpeg -hide_banner -loglevel error -f lavfi -i testsrc=size=64x64:rate=10 -t 0.5 -c:v libx264 -pix_fmt yuv420p -y /tmp/.hlb-x264.mp4 2>/dev/null; then x264=ok; else x264=FAIL; fi
rm -f /tmp/.hlb-x264.mp4
# 1b. Chrome's runtime libraries, so headless Chrome runs in the workspace (hero-studio, page
# renders, @puppeteer/browsers downloads); the golden image has none of them (m5-ubuntu 2026-11-15).
CHROME_LIBS="libnspr4 libnss3 libasound2t64 libatk-bridge2.0-0t64 libatk1.0-0t64 libcups2t64 libdrm2 libgbm1 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libpango-1.0-0 libcairo2 libgtk-3-0t64"
miss=""; for l in $CHROME_LIBS; do dpkg -s "$l" >/dev/null 2>&1 || miss="$miss $l"; done
if [ -n "$miss" ]; then apt_i $miss && log+=("Chrome runtime libraries") || log+=("Chrome libraries FAILED"); fi
# 2. en_US.UTF-8 (the hl VMs and many cloud images start with C.UTF-8 only).
if ! locale -a 2>/dev/null | grep -qi '^en_US\.utf8$'; then
{ apt_i locales && sudo -n locale-gen en_US.UTF-8 >/dev/null 2>&1 && sudo -n update-locale LANG=en_US.UTF-8 >/dev/null 2>&1; } && log+=("en_US.UTF-8 locale") || log+=("locale FAILED")
fi
# 3. earlyoom, as in the Windows workspace: a runaway build is stopped before the machine freezes.
if ! systemctl is-active -q earlyoom 2>/dev/null; then
{ command -v earlyoom >/dev/null 2>&1 || apt_i earlyoom; } && sudo -n systemctl enable --now earlyoom >/dev/null 2>&1 && log+=("earlyoom on") || log+=("earlyoom not started")
fi
# 3b. WHAT earlyoom MAY STOP (DIR-151403-30275, Debian 13 on 6 GB: it stopped code-server's
# extension host three times, which runs every AI chat; the host is named MainThread and has
# the highest OOM score in the workspace). Never: code-server (MainThread), Hydrogen, the
# desktop, the AI CLIs. First: compilers, linkers, cargo, ffmpeg. Written once; a changed line
# restarts earlyoom.
EOOM_ARGS='-r 3600 -m 4 -s 10 --avoid (^|/)(init|systemd|sshd|MainThread|code-server|adom-hydrogen|hydrogen|gnome-shell|Xwayland|Xorg|cinnamon|plasmashell|kwin_wayland|claude|codex|kimi|agy|adom-bridge)$ --prefer (^|/)(cc1|cc1plus|cc1obj|rustc|ld|ld[.]lld|ld[.]gold|lld|mold|clang|clang[+][+]|gcc|g[+][+]|cargo|make|ninja|ffmpeg|esbuild|tsc|webpack|kicad-cli)$'
if [ -f /etc/default/earlyoom ] && ! grep -qF -- "$EOOM_ARGS" /etc/default/earlyoom; then
printf '# Adom Hydrogen (adom/hydrogen-linux-bootstrap): what earlyoom may stop, and what first.\nEARLYOOM_ARGS="%s"\n' "$(printf '%s' "$EOOM_ARGS")" | sudo -n tee /etc/default/earlyoom >/dev/null \
&& sudo -n systemctl restart earlyoom >/dev/null 2>&1 && log+=("earlyoom spares VS Code and the AIs") || log+=("earlyoom config FAILED")
fi
# 4. Node 20 or later (DIR-151401-7897): the golden image's Node is 18.19, and tools need 20+
# (@puppeteer/browsers, hero-studio, current npm packages). The official Node 22 LTS build
# from nodejs.org, checked against its SHASUMS256.txt, unpacked to /usr/local/lib/nodejs and
# linked in /usr/local/bin (ahead of /usr/bin). No script is downloaded and run; the apt Node
# stays; code-server keeps its own Node.
nmaj=$(node -p 'process.versions.node.split(".")[0]' 2>/dev/null || echo 0)
if [ "${nmaj:-0}" -lt 20 ]; then
nd=$(mktemp -d); base=https://nodejs.org/dist/latest-v22.x
if curl -fsSL "$base/SHASUMS256.txt" -o "$nd/SUMS" && f=$(grep -oE 'node-v22[0-9.]+-linux-x64\.tar\.xz' "$nd/SUMS" | head -1) && [ -n "$f" ] \
&& curl -fsSL "$base/$f" -o "$nd/$f" && (cd "$nd" && grep " $f\$" SUMS | sha256sum -c --status) \
&& sudo -n mkdir -p /usr/local/lib/nodejs && sudo -n tar -xJf "$nd/$f" -C /usr/local/lib/nodejs \
&& d=/usr/local/lib/nodejs/${f%.tar.xz} && for b in node npm npx corepack; do sudo -n ln -sfn "$d/bin/$b" /usr/local/bin/$b; done; then
hash -r; log+=("Node $(/usr/local/bin/node -v 2>/dev/null)")
else log+=("Node 22 FAILED (still $(node -v 2>/dev/null))"); fi
rm -rf "$nd"
fi
# 5. The AIs' sign-in pages open without VS Code's "Do you want to open the external website?"
# (Kimi on Debian 13, DIR-151403-30275). code-server reads its trusted link domains from its
# product.json; Adom's and the four AIs' sign-in sites are added (merged, idempotent; active at
# the next code-server start).
PJ=/usr/lib/code-server/lib/vscode/product.json
if [ -f "$PJ" ]; then
r=$(sudo -n python3 - "$PJ" <<'PYJ' 2>/dev/null
import json, os, sys
p = sys.argv[1]; d = json.load(open(p))
want = ["https://*.adom.inc", "https://kimi.ai", "https://*.kimi.ai", "https://kimi.com", "https://*.kimi.com", "https://*.moonshot.cn",
"https://claude.ai", "https://*.claude.ai", "https://*.anthropic.com", "https://auth.openai.com", "https://chatgpt.com", "https://*.openai.com",
"https://accounts.google.com", "https://antigravity.google", "https://*.antigravity.google"]
have = d.get("linkProtectionTrustedDomains") or []
add = [w for w in want if w not in have]
if add:
d["linkProtectionTrustedDomains"] = have + add
t = p + ".hlb-tmp"; json.dump(d, open(t, "w"), indent="\t"); os.chmod(t, 0o644); os.replace(t, p)
print("added")
PYJ
)
[ "$r" = added ] && log+=("AI sign-in sites trusted in VS Code")
fi
echo "linux-platform: libx264 $x264; tz $(cat /etc/timezone 2>/dev/null || echo ?); ${log[*]:-already converged}"