installer
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
# Toolchain installer: detect the host, install pinned tools into $OUT_BIN, report
|
||||
# host actions it will not perform (no sudo, no apt). Usually via `make deps`.
|
||||
# Usage: deps.sh [detect [all] | list | verify [core|dev] | fetch [core|dev] [--to DIR] | install [core|dev]
|
||||
# | manifest NAME | manifests [--to DIR]]
|
||||
# | manifest NAME | manifests [--to DIR] | snapshot [DIR]]
|
||||
# Notes: docs/notes/deps.md
|
||||
|
||||
set -euo pipefail
|
||||
@@ -27,6 +27,14 @@ abspath() {
|
||||
|
||||
OUT_BIN="${OUT_BIN:-$HOME/.local/bin}"
|
||||
HOST_ROOT="${HOST_ROOT:-/}"
|
||||
# A host fixture (docs/notes/installer-testing.md) is a root whose kernel files stand in
|
||||
# for this machine's; UNAME_S does the same for the one fact a file cannot carry.
|
||||
if [ "$HOST_ROOT" != / ]; then
|
||||
if [ -r "$HOST_ROOT/proc/meminfo" ]; then MEMINFO="${MEMINFO:-$HOST_ROOT/proc/meminfo}"; fi
|
||||
if [ -r "$HOST_ROOT/proc/sys/vm/overcommit_memory" ]; then
|
||||
OVERCOMMIT_FILE="${OVERCOMMIT_FILE:-$HOST_ROOT/proc/sys/vm/overcommit_memory}"
|
||||
fi
|
||||
fi
|
||||
DEPS_SOURCE="${DEPS_SOURCE:-upstream}"
|
||||
DEPS_ARTIFACTORY_URL="${DEPS_ARTIFACTORY_URL:-}"
|
||||
BAKED_BIN="${BAKED_BIN:-/opt/rig/bin}"
|
||||
@@ -138,7 +146,7 @@ docker_pkg() {
|
||||
|
||||
# Windows outside WSL (Git Bash, MSYS, Cygwin) fails confusingly; name it instead.
|
||||
require_linux() {
|
||||
case "$(uname -s)" in
|
||||
case "${UNAME_S:-$(uname -s)}" in
|
||||
MINGW*|MSYS*|CYGWIN*)
|
||||
cat >&2 <<'EOF'
|
||||
This has to run inside WSL, not Git Bash / MSYS / Cygwin.
|
||||
@@ -157,7 +165,7 @@ EOF
|
||||
esac
|
||||
}
|
||||
|
||||
is_wsl() { grep -qi microsoft /proc/version 2>/dev/null; }
|
||||
is_wsl() { grep -qi microsoft "$(host_file /proc/version)" 2>/dev/null; }
|
||||
|
||||
detect() {
|
||||
echo "host"
|
||||
@@ -765,6 +773,54 @@ fetch_manifests() { # [--to DIR]
|
||||
done
|
||||
}
|
||||
|
||||
# ── snapshot: this machine as a host fixture ───────────────────────────────
|
||||
# Writes what detect reads, cut down to what it needs — never the environment, the
|
||||
# home directory or the host name — plus the lines detect prints for it. A fact of
|
||||
# one machine: keep it with an overlay or in rig's local/, never in rig itself, and
|
||||
# replay it with ctrl/hosttest.sh. Notes: docs/notes/installer-testing.md
|
||||
snapshot() {
|
||||
local dest r f
|
||||
dest="$(abspath "${1:-host-snapshot}")"
|
||||
if [ -n "$(ls -A "$dest" 2>/dev/null)" ]; then
|
||||
echo "snapshot: $dest already holds something — pick an empty directory" >&2
|
||||
exit 1
|
||||
fi
|
||||
r="$dest/root"
|
||||
mkdir -p "$r/etc" "$r/proc/sys/vm"
|
||||
f=$(host_file /etc/os-release)
|
||||
if [ -r "$f" ]; then grep -E '^(PRETTY_NAME|NAME|VERSION_ID|ID|ID_LIKE)=' "$f" > "$r/etc/os-release"; fi
|
||||
# The kernel release says WSL or not; the full build string names build hosts.
|
||||
echo "Linux version $(awk '{print $3; exit}' "$(host_file /proc/version)" 2>/dev/null || uname -r)" > "$r/proc/version"
|
||||
grep -E '^(MemTotal|MemAvailable|SwapTotal|SwapFree):' "${MEMINFO:-/proc/meminfo}" > "$r/proc/meminfo"
|
||||
cat "${OVERCOMMIT_FILE:-/proc/sys/vm/overcommit_memory}" > "$r/proc/sys/vm/overcommit_memory" 2>/dev/null || true
|
||||
f=$(host_file /etc/wsl.conf)
|
||||
if [ -r "$f" ]; then
|
||||
# Section headers and the two keys detect reads; a [user] default= names a person.
|
||||
grep -E '^[[:space:]]*(\[[a-z0-9]+\]|systemd[[:space:]]*=|generateResolvConf[[:space:]]*=)' "$f" > "$r/etc/wsl.conf" || true
|
||||
fi
|
||||
f=$(ls "$HOST_ROOT"/mnt/c/Users/*/.wslconfig 2>/dev/null | head -1 || true)
|
||||
if [ -n "$f" ] && grep -qE '^\s*memory\s*=' "$f"; then
|
||||
mkdir -p "$r/mnt/c/Users/user"
|
||||
{ echo "[wsl2]"; grep -E '^\s*memory\s*=' "$f"; } > "$r/mnt/c/Users/user/.wslconfig"
|
||||
fi
|
||||
{
|
||||
echo "# for the record; not replayed"
|
||||
echo "arch=$(arch)"
|
||||
echo "glibc=$(ldd --version 2>/dev/null | head -1 | grep -oE '[0-9]+\.[0-9]+$' || echo unknown)"
|
||||
echo "taken=$(date -u +%Y-%m-%d)"
|
||||
} > "$dest/facts.txt"
|
||||
# The lines the fixture itself decides, as detect prints them for it now.
|
||||
{
|
||||
echo "# Written by deps.sh snapshot: what detect said about this machine."
|
||||
env -u MEMINFO -u OVERCOMMIT_FILE HOST_ROOT="$r" bash "./$(basename "${BASH_SOURCE[0]}")" detect all 2>/dev/null \
|
||||
| grep -E '^ (distro|memory|overcommit|systemd|resolv\.conf|wslconfig) |^ ! systemd|^ - resolv\.conf' \
|
||||
| sed 's/^ /+ /'
|
||||
} > "$dest/expect.txt"
|
||||
echo "wrote $dest"
|
||||
(cd "$dest" && find . -type f | sort | sed 's|^\./| |')
|
||||
echo "keep it with an overlay or in rig's local/, never in rig; replay it with rig's hosttest.sh"
|
||||
}
|
||||
|
||||
# Baked mode copies binaries already in the image, so it needs no downloader.
|
||||
need_downloads() {
|
||||
require_amd64
|
||||
@@ -781,10 +837,12 @@ case "$cmd" in
|
||||
manifest) need_downloads
|
||||
fetch_manifest "${1:?usage: $0 manifest <METALLB|CERT_MANAGER|METRICS_SERVER>}" "$MANIFESTS_HOME" ;;
|
||||
manifests) need_downloads; fetch_manifests "$@" ;;
|
||||
snapshot) snapshot "${1:-}" ;;
|
||||
*) echo "usage: $0 [detect [all]|list|verify|fetch|install|manifest NAME|manifests]" >&2
|
||||
echo " install [core|dev] (default dev)" >&2
|
||||
echo " fetch [core|dev] [--to DIR]" >&2
|
||||
echo " manifests [--to DIR] the addons' pinned manifests, verified" >&2
|
||||
echo " snapshot [DIR] this machine as a host fixture (no secrets)" >&2
|
||||
echo " OUT_BIN=<dir> overrides the install directory" >&2
|
||||
exit 1 ;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user