#!/usr/bin/env bash # On the staging VM, as stg (on promote's release VM as root, SWC_DIR its CI_HOME: scripts/ci-prod-target.sh): the pinned tools of the suite (page-tools.json: url and sha256, each download checked), # under $SWC_DIR/page/tools, each at - with the link : # node 0009's page round (page.sh) # chrome the page round and the OAuth sign-ins (oauth.signin, page.signin: scripts/oauth-signin.ts) # node's and chrome's shared libraries are the image's: the ones a binary lacks are named, then installed as # root (the target's root host, the VM itself; run as root: here) with apt, PAGE_NODE_DEBS and PAGE_CHROME_DEBS (default: Ubuntu # 24.04's names) # deno scripts/oauth-signin.ts, and the network's QR session-transfer service (qr.sh) # Usage: tools.sh ... (prints the tools directory) set -euo pipefail D=${SWC_DIR:-/home/stg/stg} R=${SWC_REPO:-${SWC_DIR:-/home/stg/stg}/suite} pins=$R/tests/compositions/staging/page-tools.json T=$D/page/tools mkdir -p "$T" pin() { jq -er --arg t "$1" --arg k "$2" 'if $k == "version" then .[$t].version else .[$t]["linux/amd64"][$k] end' "$pins"; } fetch() { local tool=$1 file=$2 curl -fsSL --retry 3 -o "$file" "$(pin "$tool" url)" echo "$(pin "$tool" sha256) $file" | sha256sum -c --quiet - } unzip_to() { python3 - "$1" "$2" <<'PY' import os, sys, zipfile with zipfile.ZipFile(sys.argv[1]) as z: for i in z.infolist(): path = z.extract(i, sys.argv[2]) mode = (i.external_attr >> 16) & 0o777 if mode and not i.is_dir(): os.chmod(path, mode) PY } # libs : the shared libraries the binary lacks, from apt as root; still lacking any fails libs() { local tool=$1 bin=$2 debs=$3 lacks missing() { ldd "$bin" | awk '/not found/ {print $1}' | sort -u | paste -sd' ' -; } lacks=$(missing) [ -z "$lacks" ] && return 0 echo "tools.sh: $tool lacks $lacks: apt as root" >&2 if [ "$(id -u)" = 0 ]; then { apt-get update -q >/dev/null; DEBIAN_FRONTEND=noninteractive apt-get install -y -q $debs >/dev/null; } >&2 else ssh -o BatchMode=yes -o ConnectTimeout=10 root@127.0.0.1 "apt-get update -q >/dev/null; DEBIAN_FRONTEND=noninteractive apt-get install -y -q $debs >/dev/null" >&2 fi lacks=$(missing) [ -z "$lacks" ] || { echo "tools.sh: $tool still lacks $lacks" >&2; exit 1; } } for tool in "$@"; do dir=$T/$tool-$(pin "$tool" version) case "$tool" in node) if [ ! -x "$dir/bin/node" ]; then rm -rf "$dir" "$dir.part" && mkdir -p "$dir.part" fetch node "$T/node.tar.xz" tar -xJf "$T/node.tar.xz" -C "$dir.part" --strip-components=1 && rm -f "$T/node.tar.xz" && mv "$dir.part" "$dir" fi libs node "$dir/bin/node" "${PAGE_NODE_DEBS:-libatomic1}" ;; deno) if [ ! -x "$dir/deno" ]; then rm -rf "$dir" "$dir.part" && mkdir -p "$dir.part" fetch deno "$T/deno.zip" unzip_to "$T/deno.zip" "$dir.part" chmod 0755 "$dir.part/deno" && rm -f "$T/deno.zip" && mv "$dir.part" "$dir" fi ;; chrome) if [ ! -x "$dir/chrome" ]; then rm -rf "$dir" "$dir.part" && mkdir -p "$dir.part" fetch chrome "$T/chrome.zip" unzip_to "$T/chrome.zip" "$dir.part" rm -f "$T/chrome.zip" && mv "$dir.part/chrome-linux64" "$dir" && rm -rf "$dir.part" fi libs chrome "$dir/chrome" "${PAGE_CHROME_DEBS:-libnss3 libnspr4 libatk1.0-0t64 libatk-bridge2.0-0t64 libatspi2.0-0t64 libcups2t64 libdbus-1-3 libdrm2 libgbm1 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libxext6 libx11-6 libxcb1 libasound2t64 libpango-1.0-0 libcairo2}" ;; *) echo "tools.sh: no tool $tool (node, chrome, deno)" >&2; exit 2 ;; esac ln -sfn "$(basename "$dir")" "$T/$tool" done echo "$T"