aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / install.sh
| 1 | #!/usr/bin/env bash |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | set -euo pipefail |
| 18 | |
| 19 | # ============================================================================== |
| 20 | # AIEN Sovereign Stack Universal Multi-OS Developer Installer |
| 21 | # Single-command install for the entire sovereign monorepo ecosystem. |
| 22 | # Free and open-source for humanity. Zero telemetry. Zero subscriptions. |
| 23 | # ============================================================================== |
| 24 | |
| 25 | echo "==================================================================" |
| 26 | echo " ⚡ AIEN Sovereign Stack: Universal Developer Installer " |
| 27 | echo "==================================================================" |
| 28 | |
| 29 | # Release mode (AIEN_RELEASE_TAG=vX.Y.Z) installs a published, signed release and |
| 30 | # needs no source tree and no network beyond the three release assets. |
| 31 | RELEASE_TAG="${AIEN_RELEASE_TAG:-}" |
| 32 | |
| 33 | ACTION="install" |
| 34 | ALLOW_DOWNGRADE=0 |
| 35 | # Opt-in model server (DGX Spark only): --with-server or AIEN_INSTALL_SERVER=1. |
| 36 | WITH_SERVER="${AIEN_INSTALL_SERVER:-0}" |
| 37 | # Opt-in model download: --with-model or AIEN_INSTALL_MODEL=1; folder: --model-dir=DIR or AIEN_MODEL_DIR. |
| 38 | WITH_MODEL="${AIEN_INSTALL_MODEL:-0}" |
| 39 | MODEL_DIR="${AIEN_MODEL_DIR:-$HOME/models/qwen3.8-27b-fp8-017b9c7a}" |
| 40 | MODEL_OK=0 # set to 1 only when model_download's sha256 check passed |
| 41 | for arg in "$@"; do |
| 42 | case "$arg" in |
| 43 | --rollback) ACTION="rollback" ;; |
| 44 | --allow-downgrade) ALLOW_DOWNGRADE=1 ;; |
| 45 | --with-server) WITH_SERVER=1 ;; |
| 46 | --with-model) WITH_MODEL=1 ;; |
| 47 | --model-dir=*) MODEL_DIR="${arg#--model-dir=}"; WITH_MODEL=1 ;; |
| 48 | -h|--help) |
| 49 | echo "usage: install.sh [--rollback] [--allow-downgrade] [--with-server] [--with-model] [--model-dir=DIR]" |
| 50 | echo " (none) source build, or with AIEN_RELEASE_TAG=vX.Y.Z a signed release install" |
| 51 | echo " --rollback switch back to the one previous release kept by the last upgrade" |
| 52 | echo " --allow-downgrade accept a release whose candidate is older than the installed one" |
| 53 | echo " --with-server also build the Qwen3.8-27B model server (aien-serve-http) on AIEN's own" |
| 54 | echo " Omega GPU engine and install it with its start script aien-serve-27b." |
| 55 | echo " DGX Spark (aarch64 Linux, NVIDIA GB10) only, source build only." |
| 56 | echo " Same as AIEN_INSTALL_SERVER=1. AIEN_PINS_DIR sets where the pinned" |
| 57 | echo " omega, physics and aienos sources are fetched (default target/pins)." |
| 58 | echo " --with-model also download the model weights the server reads: Hugging Face" |
| 59 | echo " Qwen/Qwen3.8-27B-FP8 at revision 017b9c7af6b5689d5dd426a76e0bc077eb5ca20a," |
| 60 | echo " the 81 files of docs/qwen38/qwen3.8-27b-fp8-017b9c7a.sha256 (about 30.9 GB)." |
| 61 | echo " Checks free disk first, resumes partial files when rerun, then runs" |
| 62 | echo " sha256sum -c and refuses the folder if any file does not match." |
| 63 | echo " Same as AIEN_INSTALL_MODEL=1. Source build only." |
| 64 | echo " --model-dir=DIR where the model goes (implies --with-model; default" |
| 65 | echo " ~/models/qwen3.8-27b-fp8-017b9c7a, the folder aien-serve-27b reads)." |
| 66 | echo " Same as AIEN_MODEL_DIR=DIR." |
| 67 | exit 0 ;; |
| 68 | *) echo "Error: unknown argument: $arg" >&2; exit 2 ;; |
| 69 | esac |
| 70 | done |
| 71 | |
| 72 | BIN_DIR="${AIEN_BIN_DIR:-$HOME/.local/bin}" |
| 73 | CONFIG_DIR="${AIEN_CONFIG_DIR:-$HOME/.config/sovereign}" |
| 74 | # Release layout: $REL_DIR/<first 12 hex of the package aien-cli sha256>/ holds one complete |
| 75 | # release; $REL_DIR/current is a symlink to the live one and is the only thing an install or a |
| 76 | # rollback switches (one rename). $BIN_DIR entries are stable symlinks through current. At most |
| 77 | # the live release and one previous release are kept. $RECORD lists what is installed. |
| 78 | REL_DIR="$CONFIG_DIR/releases" |
| 79 | RECORD="$CONFIG_DIR/installed.toml" |
| 80 | |
| 81 | sha256_of() { |
| 82 | if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d' ' -f1 |
| 83 | else shasum -a 256 "$1" | cut -d' ' -f1; fi |
| 84 | } |
| 85 | |
| 86 | # Test hook: AIEN_TEST_PAUSE_AT=<point> makes the installer stop there until it is killed. |
| 87 | pause_at() { |
| 88 | [[ "${AIEN_TEST_PAUSE_AT:-}" == "$1" ]] || return 0 |
| 89 | echo "[test] paused at $1" >&2 |
| 90 | while :; do sleep 1; done |
| 91 | } |
| 92 | |
| 93 | # toml_get <file> <section|""> <key>: first value of key in the [section] table ("" = top level). |
| 94 | toml_get() { |
| 95 | [[ -f "$1" ]] || return 0 |
| 96 | awk -v sec="$2" -v key="$3" ' |
| 97 | /^\[.*\]$/ { cur = substr($0, 2, length($0) - 2); next } |
| 98 | cur == sec { |
| 99 | i = index($0, " = "); if (i == 0) next |
| 100 | k = substr($0, 1, i - 1); gsub(/"/, "", k) |
| 101 | if (k == key) { v = substr($0, i + 3); gsub(/^"|"$/, "", v); print v; exit } |
| 102 | }' "$1" |
| 103 | } |
| 104 | |
| 105 | # toml_lines <file> <section>: the raw lines of one table. |
| 106 | toml_lines() { |
| 107 | [[ -f "$1" ]] || return 0 |
| 108 | awk -v sec="$2" ' |
| 109 | /^\[.*\]$/ { cur = substr($0, 2, length($0) - 2); next } |
| 110 | cur == sec && NF { print }' "$1" |
| 111 | } |
| 112 | |
| 113 | # verify_release_dir <dir>: every file listed in release.toml [files] exists with its digest, |
| 114 | # nothing else is present, and the recorded aien-cli digest is that of bin/aien. |
| 115 | verify_release_dir() { |
| 116 | local d="$1" line f want n=0 have aien |
| 117 | [[ -f "$d/release.toml" ]] || { echo " no release.toml in $d" >&2; return 1; } |
| 118 | while IFS= read -r line; do |
| 119 | f="${line%%\" = \"*}"; f="${f#\"}" |
| 120 | want="${line##*\" = \"}"; want="${want%\"}" |
| 121 | case "$f" in /*|*..*) echo " unsafe path in release.toml: $f" >&2; return 1 ;; esac |
| 122 | [[ -f "$d/$f" && ! -L "$d/$f" ]] || { echo " missing file: $f" >&2; return 1; } |
| 123 | [[ "$(sha256_of "$d/$f")" == "$want" ]] || { echo " digest mismatch: $f" >&2; return 1; } |
| 124 | n=$((n + 1)) |
| 125 | done < <(toml_lines "$d/release.toml" files) |
| 126 | [[ "$n" -gt 0 ]] || { echo " release.toml lists no files" >&2; return 1; } |
| 127 | have="$(find "$d" \( -type f -o -type l \) ! -path "$d/release.toml" | grep -c . || true)" |
| 128 | [[ "$have" -eq "$n" ]] || { echo " $have files present, $n listed" >&2; return 1; } |
| 129 | aien="$(toml_get "$d/release.toml" "" aien-cli-sha256)" |
| 130 | [[ "$aien" =~ ^[0-9a-f]{64}$ && "$(sha256_of "$d/bin/aien")" == "$aien" ]] \ |
| 131 | || { echo " aien-cli-sha256 in release.toml is not the digest of bin/aien" >&2; return 1; } |
| 132 | } |
| 133 | |
| 134 | # Switch $REL_DIR/current to <id> with one rename. |
| 135 | set_current() { |
| 136 | local id="$1" tmp="$REL_DIR/.current.new.$$" |
| 137 | rm -f "$REL_DIR"/.current.new.* # leftovers of an interrupted switch; never live |
| 138 | rm -f "$tmp" |
| 139 | ln -s "$id" "$tmp" |
| 140 | pause_at pre-rename |
| 141 | if mv --help 2>&1 | grep -q -- ' -T'; then mv -T "$tmp" "$REL_DIR/current"; else mv -fh "$tmp" "$REL_DIR/current"; fi |
| 142 | } |
| 143 | |
| 144 | # bin name as installed (the archive keeps crate names for two of them). |
| 145 | installed_name() { |
| 146 | case "$1" in spark-cockpit-rs) echo spark-cockpit ;; cortex-rs) echo cortex ;; *) echo "$1" ;; esac |
| 147 | } |
| 148 | |
| 149 | # link_bins <old-id|""> <new-id>: BIN_DIR entries are symlinks through current; links for |
| 150 | # binaries that the new release no longer ships are removed. |
| 151 | link_bins() { |
| 152 | local old="$1" new="$2" b name tmp |
| 153 | mkdir -p "$BIN_DIR" |
| 154 | if [[ -n "$old" && -d "$REL_DIR/$old/bin" ]]; then |
| 155 | for b in "$REL_DIR/$old/bin/"*; do |
| 156 | [[ -e "$REL_DIR/$new/bin/$(basename "$b")" ]] && continue |
| 157 | name="$(installed_name "$(basename "$b")")" |
| 158 | if [[ -L "$BIN_DIR/$name" && "$(readlink "$BIN_DIR/$name")" == "$REL_DIR/current/bin/"* ]]; then rm -f "$BIN_DIR/$name"; fi |
| 159 | done |
| 160 | fi |
| 161 | for b in "$REL_DIR/$new/bin/"*; do |
| 162 | name="$(installed_name "$(basename "$b")")" |
| 163 | [[ ! -d "$BIN_DIR/$name" || -L "$BIN_DIR/$name" ]] || { echo "Error: $BIN_DIR/$name is a directory" >&2; exit 1; } |
| 164 | tmp="$BIN_DIR/.$name.new.$$" |
| 165 | rm -f "$tmp" |
| 166 | ln -s "$REL_DIR/current/bin/$(basename "$b")" "$tmp" |
| 167 | mv -f "$tmp" "$BIN_DIR/$name" |
| 168 | echo " - $name -> $BIN_DIR/$name" |
| 169 | done |
| 170 | } |
| 171 | |
| 172 | # write_record <current-id> <previous-id|""> <action>: rewrite installed.toml atomically. |
| 173 | write_record() { |
| 174 | local cur="$1" prev="$2" action="$3" now id at sc tmp="$CONFIG_DIR/.installed.toml.new.$$" |
| 175 | now="$(date -u +%Y-%m-%dT%H:%M:%SZ)" |
| 176 | { |
| 177 | echo 'schema = "AienInstalledV1"' |
| 178 | echo "current = \"$cur\"" |
| 179 | echo "previous = \"$prev\"" |
| 180 | echo "last-action = \"$action\"" |
| 181 | echo "last-action-at = \"$now\"" |
| 182 | for id in "$cur" "$prev"; do |
| 183 | [[ -n "$id" ]] || continue |
| 184 | at="$(toml_get "$RECORD" "version.$id" installed-at)" |
| 185 | echo |
| 186 | echo "[version.$id]" |
| 187 | echo "candidate = \"$(toml_get "$REL_DIR/$id/release.toml" "" candidate)\"" |
| 188 | echo "aien-cli-sha256 = \"$(toml_get "$REL_DIR/$id/release.toml" "" aien-cli-sha256)\"" |
| 189 | echo "installed-at = \"${at:-$now}\"" |
| 190 | sc="$(toml_get "$RECORD" "version.$id" signature-check)" |
| 191 | [[ "$action" != install || "$id" != "$cur" || -z "${SIG_CHECK:-}" ]] || sc="$SIG_CHECK" |
| 192 | [[ -z "$sc" ]] || echo "signature-check = \"$sc\"" |
| 193 | if [[ -n "$(toml_lines "$REL_DIR/$id/release.toml" model)" ]]; then |
| 194 | echo |
| 195 | echo "[version.$id.model]" |
| 196 | toml_lines "$REL_DIR/$id/release.toml" model |
| 197 | fi |
| 198 | done |
| 199 | } > "$tmp" |
| 200 | mv -f "$tmp" "$RECORD" |
| 201 | } |
| 202 | |
| 203 | # Keep only the live and the previous release. |
| 204 | prune_releases() { |
| 205 | local keep1="$1" keep2="$2" d |
| 206 | for d in "$REL_DIR"/*/; do |
| 207 | d="$(basename "$d")" |
| 208 | [[ "$d" == current || "$d" == "$keep1" || "$d" == "$keep2" ]] || rm -rf "${REL_DIR:?}/$d" |
| 209 | done |
| 210 | } |
| 211 | |
| 212 | cand_num() { [[ "$1" =~ ^CAND-([0-9]+)$ ]] && echo "${BASH_REMATCH[1]}" || true; } |
| 213 | |
| 214 | # activate_release <extracted-package-dir>: verify, stage, then switch with one rename. |
| 215 | activate_release() { |
| 216 | local x="$1" aien id cand cur curcand a b stage |
| 217 | echo "[*] Verifying every package file against release.toml" |
| 218 | verify_release_dir "$x" || { echo "Error: package does not match its release.toml. Nothing was installed." >&2; exit 1; } |
| 219 | aien="$(toml_get "$x/release.toml" "" aien-cli-sha256)"; id="${aien:0:12}" |
| 220 | cand="$(toml_get "$x/release.toml" "" candidate)" |
| 221 | mkdir -p "$REL_DIR" |
| 222 | cur="$(toml_get "$RECORD" "" current)" |
| 223 | if [[ -n "$cur" ]]; then |
| 224 | curcand="$(toml_get "$RECORD" "version.$cur" candidate)" |
| 225 | if [[ "$cand" != "$curcand" && "$ALLOW_DOWNGRADE" != 1 ]]; then |
| 226 | a="$(cand_num "$cand")"; b="$(cand_num "$curcand")" |
| 227 | if [[ -z "$a" || -z "$b" || "$a" -lt "$b" ]]; then |
| 228 | echo "Error: package candidate '$cand' is not known to be newer than installed '$curcand'. Use --allow-downgrade to install it anyway. Nothing was installed." >&2 |
| 229 | exit 1 |
| 230 | fi |
| 231 | fi |
| 232 | fi |
| 233 | rm -rf "$REL_DIR"/.stage.* # leftovers of an interrupted install; never live |
| 234 | if [[ -d "$REL_DIR/$id" ]]; then |
| 235 | if verify_release_dir "$REL_DIR/$id" && cmp -s "$x/release.toml" "$REL_DIR/$id/release.toml"; then |
| 236 | echo "[+] Release $id is already staged and complete" |
| 237 | else |
| 238 | echo "Error: $REL_DIR/$id exists but is incomplete or differs from this package. It was not overwritten. Remove it and rerun. Nothing was installed." >&2 |
| 239 | exit 1 |
| 240 | fi |
| 241 | else |
| 242 | stage="$REL_DIR/.stage.$id.$$" |
| 243 | mkdir -p "$stage" |
| 244 | local line f first=1 |
| 245 | while IFS= read -r line; do |
| 246 | f="${line%%\" = \"*}"; f="${f#\"}" |
| 247 | mkdir -p "$stage/$(dirname "$f")" |
| 248 | cp "$x/$f" "$stage/$f" |
| 249 | if [[ "$first" == 1 ]]; then first=0; pause_at mid-copy; fi |
| 250 | done < <(toml_lines "$x/release.toml" files) |
| 251 | cp "$x/release.toml" "$stage/release.toml" |
| 252 | pause_at after-copy |
| 253 | chmod 755 "$stage/bin/"* |
| 254 | echo "[*] Verifying the staged copy" |
| 255 | verify_release_dir "$stage" || { echo "Error: staged copy is not complete. Nothing was installed." >&2; exit 1; } |
| 256 | mv "$stage" "$REL_DIR/$id" |
| 257 | pause_at before-swap |
| 258 | fi |
| 259 | set_current "$id" |
| 260 | pause_at after-swap |
| 261 | echo "[+] Live release is now $id (candidate $cand); binaries:" |
| 262 | link_bins "$cur" "$id" |
| 263 | pause_at after-links |
| 264 | if [[ -n "$cur" && "$cur" != "$id" ]]; then |
| 265 | write_record "$id" "$cur" install |
| 266 | prune_releases "$id" "$cur" |
| 267 | else |
| 268 | write_record "$id" "$(toml_get "$RECORD" "" previous)" install |
| 269 | prune_releases "$id" "$(toml_get "$RECORD" "" previous)" |
| 270 | fi |
| 271 | } |
| 272 | |
| 273 | do_rollback() { |
| 274 | local cur prev |
| 275 | cur="$(toml_get "$RECORD" "" current)"; prev="$(toml_get "$RECORD" "" previous)" |
| 276 | [[ -n "$cur" && -n "$prev" ]] || { echo "Error: no previous release is recorded in $RECORD. Nothing to roll back to." >&2; exit 1; } |
| 277 | [[ -d "$REL_DIR/$prev" ]] || { echo "Error: previous release $prev is missing from $REL_DIR." >&2; exit 1; } |
| 278 | verify_release_dir "$REL_DIR/$prev" || { echo "Error: previous release $prev failed verification. Nothing was changed." >&2; exit 1; } |
| 279 | set_current "$prev" |
| 280 | pause_at after-swap |
| 281 | echo "[+] Rolled back: live release is now $prev (was $cur); binaries:" |
| 282 | link_bins "$cur" "$prev" |
| 283 | write_record "$prev" "$cur" rollback |
| 284 | } |
| 285 | |
| 286 | if [[ "$ACTION" == "rollback" ]]; then |
| 287 | do_rollback |
| 288 | exit 0 |
| 289 | fi |
| 290 | |
| 291 | # ------------------------------------------------------------------------------ |
| 292 | # Model server (--with-server): checks first, so nothing is changed on a machine |
| 293 | # that cannot run it. Every failure says what is wrong in plain words and stops. |
| 294 | # ------------------------------------------------------------------------------ |
| 295 | # The NVIDIA open kernel module version whose headers physics vendors (the only one tested). |
| 296 | AIEN_EXPECTED_NVIDIA_DRIVER="580.173.02" |
| 297 | server_die() { |
| 298 | echo "" >&2 |
| 299 | echo "Error (model server): $*" >&2 |
| 300 | echo "Nothing was built or installed for the model server." >&2 |
| 301 | exit 1 |
| 302 | } |
| 303 | server_warn() { echo "[!] Warning (model server): $*" >&2; } |
| 304 | |
| 305 | server_preflight() { |
| 306 | echo "[*] Model server: checking this machine" |
| 307 | [[ -z "$RELEASE_TAG" ]] || server_die "--with-server builds from source and cannot be combined with AIEN_RELEASE_TAG (no signed release contains the server). Unset AIEN_RELEASE_TAG." |
| 308 | local os arch |
| 309 | os="$(uname -s)"; arch="$(uname -m)" |
| 310 | [[ "$os" == Linux && "$arch" == aarch64 ]] \ |
| 311 | || server_die "the model server only runs on an NVIDIA DGX Spark (aarch64 Linux with the GB10 chip). This machine is $os $arch." |
| 312 | local t missing="" |
| 313 | for t in git curl cc make ar nm; do |
| 314 | command -v "$t" >/dev/null 2>&1 || missing="$missing $t" |
| 315 | done |
| 316 | [[ -z "$missing" ]] || server_die "these programs are needed and were not found:$missing. On DGX OS / Ubuntu: sudo apt install git curl build-essential binutils" |
| 317 | # Test hook (scripts/test-install.sh only): skip the driver, device and memory checks, which a |
| 318 | # test machine cannot fake. Never set this for a real install. |
| 319 | if [[ "${AIEN_TEST_SERVER_SKIP_HW_CHECKS:-}" == 1 ]]; then |
| 320 | echo "[test] model server: driver, device and memory checks SKIPPED (AIEN_TEST_SERVER_SKIP_HW_CHECKS=1)" >&2 |
| 321 | return 0 |
| 322 | fi |
| 323 | # The Omega engine talks to the NVIDIA kernel driver directly (no CUDA toolkit, no nvcc). |
| 324 | local drv="" |
| 325 | if [[ -r /proc/driver/nvidia/version ]]; then |
| 326 | drv="$(grep -o '[0-9]\{3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' /proc/driver/nvidia/version | head -n 1 || true)" |
| 327 | fi |
| 328 | if [[ -z "$drv" ]] && command -v nvidia-smi >/dev/null 2>&1; then |
| 329 | drv="$(nvidia-smi --query-gpu=driver_version --format=csv,noheader 2>/dev/null | head -n 1 | tr -d '[:space:]' || true)" |
| 330 | fi |
| 331 | [[ -n "$drv" ]] || server_die "no NVIDIA driver found (no /proc/driver/nvidia/version and no nvidia-smi). Install the NVIDIA open kernel driver $AIEN_EXPECTED_NVIDIA_DRIVER and reboot." |
| 332 | if [[ "$drv" != "$AIEN_EXPECTED_NVIDIA_DRIVER" ]]; then |
| 333 | server_warn "NVIDIA driver is $drv; the engine is only tested with $AIEN_EXPECTED_NVIDIA_DRIVER. It may fail to start or give wrong results." |
| 334 | else |
| 335 | echo " NVIDIA driver $drv (tested version)" |
| 336 | fi |
| 337 | local dev ok=0 |
| 338 | for dev in /dev/nvidiactl /dev/nvidia0 /dev/nvidia-uvm; do |
| 339 | [[ -e "$dev" ]] || server_die "$dev does not exist: the NVIDIA driver is not fully loaded (try: sudo modprobe nvidia-uvm, or reboot)." |
| 340 | [[ -r "$dev" && -w "$dev" ]] || server_die "$dev is not readable and writable by $(id -un). Add yourself to the group that owns it ($(stat -c %G "$dev" 2>/dev/null || echo unknown)) or fix its permissions." |
| 341 | ok=$((ok + 1)) |
| 342 | done |
| 343 | echo " GPU device files: $ok readable and writable" |
| 344 | local avail_kib |
| 345 | avail_kib="$(awk '/^MemAvailable:/ {print $2}' /proc/meminfo 2>/dev/null || echo 0)" |
| 346 | # The loader needs 41,305 MiB + 8,192 MiB kept free = 49,497 MiB (48.3 GiB) of MemAvailable at |
| 347 | # load (crates/aien-serve-http/src/qwen38_engine.rs). It re-checks after it gets the GPU lock. |
| 348 | # A running server on the current build peaked at about 36.7 GiB (evidence/qwen38-serve-memory-20261019). |
| 349 | if [[ "${avail_kib:-0}" -lt $((49497 * 1024)) ]]; then |
| 350 | server_warn "only $((avail_kib / 1024)) MiB of memory is free now; the 27B server's loader needs 49,497 MiB (48.3 GiB) free when it starts, and checks again when it gets the GPU lock." |
| 351 | else |
| 352 | echo " free memory: $((avail_kib / 1024 / 1024)) GiB" |
| 353 | fi |
| 354 | echo "[+] Model server: machine checks passed" |
| 355 | } |
| 356 | |
| 357 | # server_build: fetch the pinned Omega sources, build aien-serve-http against the real GPU engine, |
| 358 | # refuse a CPU stub, install it and its start script. Runs from the source checkout. |
| 359 | server_build() { |
| 360 | local pins="${AIEN_PINS_DIR:-$SOURCE_ROOT/target/pins}" |
| 361 | local out="${CARGO_TARGET_DIR:-$SOURCE_ROOT/target}/release/aien-serve-http" |
| 362 | echo "[*] Model server: fetching the pinned omega, physics and aienos sources into $pins" |
| 363 | bash "$SOURCE_ROOT/scripts/pins.sh" --gpu "$pins" \ |
| 364 | || server_die "scripts/pins.sh --gpu failed (see the lines above). Check the network and that git can reach github.com." |
| 365 | [[ -f "$pins/env.sh" ]] || server_die "scripts/pins.sh did not write $pins/env.sh." |
| 366 | # shellcheck disable=SC1091 |
| 367 | . "$pins/env.sh" |
| 368 | [[ "${AIEN_REQUIRE_NATIVE_LIBS:-}" == 1 && -n "${AIEN_OMEGA_DIR:-}" ]] \ |
| 369 | || server_die "$pins/env.sh does not select the GPU engine (AIEN_OMEGA_DIR unset)." |
| 370 | echo "[*] Model server: building aien-serve-http (release, links AIEN's Omega GPU library; this takes a while)" |
| 371 | cargo build --locked --release -p aien-serve-http \ |
| 372 | || server_die "cargo build of aien-serve-http failed (see the lines above)." |
| 373 | [[ -x "$out" ]] || server_die "the build finished but $out is missing." |
| 374 | local info |
| 375 | info="$("$out" --version 2>&1)" || server_die "$out --version failed: $info" |
| 376 | if ! grep -q '^omega gpu engine: native' <<<"$info" || ! grep -q '^qwen38 engine: native' <<<"$info"; then |
| 377 | echo "$info" >&2 |
| 378 | server_die "the built server has only the CPU stub, not the Omega GPU engine. It was NOT installed." |
| 379 | fi |
| 380 | mkdir -p "$BIN_DIR" |
| 381 | cp "$out" "$BIN_DIR/.aien-serve-http.new.$$" |
| 382 | chmod 755 "$BIN_DIR/.aien-serve-http.new.$$" |
| 383 | mv -f "$BIN_DIR/.aien-serve-http.new.$$" "$BIN_DIR/aien-serve-http" |
| 384 | cp "$SOURCE_ROOT/tools/serve-27b.sh" "$BIN_DIR/.aien-serve-27b.new.$$" |
| 385 | chmod 755 "$BIN_DIR/.aien-serve-27b.new.$$" |
| 386 | mv -f "$BIN_DIR/.aien-serve-27b.new.$$" "$BIN_DIR/aien-serve-27b" |
| 387 | echo "[+] Model server installed:" |
| 388 | echo " - aien-serve-http -> $BIN_DIR/aien-serve-http" |
| 389 | echo " - aien-serve-27b -> $BIN_DIR/aien-serve-27b (start script)" |
| 390 | sed 's/^/ /' <<<"$info" |
| 391 | } |
| 392 | |
| 393 | # ------------------------------------------------------------------------------ |
| 394 | # Model download (--with-model): Qwen3.8-27B-FP8 at one fixed revision, file by file |
| 395 | # from the list of 81 files and sha256 values shipped in docs/qwen38/. Free disk is |
| 396 | # checked before anything is cloned or built; the download resumes partial files |
| 397 | # (<file>.part) when rerun; at the end sha256sum -c must pass for every file. |
| 398 | # ------------------------------------------------------------------------------ |
| 399 | AIEN_MODEL_REPO="Qwen/Qwen3.8-27B-FP8" |
| 400 | AIEN_MODEL_REV="017b9c7af6b5689d5dd426a76e0bc077eb5ca20a" |
| 401 | AIEN_MODEL_LIST="docs/qwen38/qwen3.8-27b-fp8-017b9c7a.sha256" |
| 402 | # Sum of the 81 file sizes (docs/qwen38/README.md) plus 2 GB of room. |
| 403 | AIEN_MODEL_BYTES=30890049597 |
| 404 | AIEN_MODEL_MARGIN_BYTES=2000000000 |
| 405 | model_die() { |
| 406 | echo "" >&2 |
| 407 | echo "Error (model download): $*" >&2 |
| 408 | exit 1 |
| 409 | } |
| 410 | |
| 411 | sha256_check() { |
| 412 | if command -v sha256sum >/dev/null 2>&1; then sha256sum -c --quiet "$1" |
| 413 | else shasum -a 256 -c --quiet "$1"; fi |
| 414 | } |
| 415 | |
| 416 | # Bytes free on the file system that will hold $1 (the nearest folder of $1 that exists). |
| 417 | free_bytes_for() { |
| 418 | local d="$1" |
| 419 | while [[ ! -d "$d" ]]; do d="$(dirname "$d")"; done |
| 420 | df -Pk "$d" | awk 'NR == 2 { printf "%.0f\n", $4 * 1024 }' |
| 421 | } |
| 422 | |
| 423 | model_preflight() { |
| 424 | echo "[*] Model download: checking curl, sha256 and free disk for $MODEL_DIR" |
| 425 | [[ -z "$RELEASE_TAG" ]] || model_die "--with-model needs the source checkout (it reads the checksum list from it) and cannot be combined with AIEN_RELEASE_TAG. Unset AIEN_RELEASE_TAG." |
| 426 | command -v curl >/dev/null 2>&1 || model_die "curl is needed and was not found. On DGX OS / Ubuntu: sudo apt install curl" |
| 427 | command -v sha256sum >/dev/null 2>&1 || command -v shasum >/dev/null 2>&1 \ |
| 428 | || model_die "sha256sum is needed and was not found. On DGX OS / Ubuntu: sudo apt install coreutils" |
| 429 | local need have free |
| 430 | if [[ -n "${AIEN_TEST_MODEL_NEED_BYTES:-}" ]]; then |
| 431 | # Test hook (scripts/test-install.sh only): a fixed need instead of the model's size. |
| 432 | echo "[test] model download: need set to $AIEN_TEST_MODEL_NEED_BYTES bytes (AIEN_TEST_MODEL_NEED_BYTES)" >&2 |
| 433 | need="$AIEN_TEST_MODEL_NEED_BYTES" |
| 434 | else |
| 435 | # What is already in the folder from an earlier run does not need room again. |
| 436 | have=0 |
| 437 | [[ ! -d "$MODEL_DIR" ]] || have=$(( $(du -sk "$MODEL_DIR" | cut -f1) * 1024 )) |
| 438 | need=$((AIEN_MODEL_BYTES + AIEN_MODEL_MARGIN_BYTES - have)) |
| 439 | [[ "$need" -ge "$AIEN_MODEL_MARGIN_BYTES" ]] || need="$AIEN_MODEL_MARGIN_BYTES" |
| 440 | fi |
| 441 | free="$(free_bytes_for "$MODEL_DIR")" |
| 442 | [[ "$free" -ge "$need" ]] \ |
| 443 | || model_die "not enough free disk for the model: $((free / 1000000000)) GB free where $MODEL_DIR goes, $((need / 1000000000 + 1)) GB needed (30.9 GB of weights plus 2 GB of room, less what is already there). Free some space or choose another folder with --model-dir=DIR. Nothing was downloaded." |
| 444 | echo " free disk: $((free / 1000000000)) GB, needed: $((need / 1000000000 + 1)) GB" |
| 445 | echo "[+] Model download: checks passed" |
| 446 | } |
| 447 | |
| 448 | # model_download: fetch every listed file into $MODEL_DIR, then sha256sum -c all of them. |
| 449 | model_download() { |
| 450 | local list="$SOURCE_ROOT/$AIEN_MODEL_LIST" |
| 451 | local base="${AIEN_MODEL_BASE_URL:-https://huggingface.co/$AIEN_MODEL_REPO/resolve/$AIEN_MODEL_REV}" |
| 452 | [[ -f "$list" ]] || model_die "the checksum list $AIEN_MODEL_LIST is missing from the checkout." |
| 453 | mkdir -p "$MODEL_DIR" |
| 454 | echo "[*] Model download: $AIEN_MODEL_REPO at revision $AIEN_MODEL_REV into $MODEL_DIR" |
| 455 | local sha f n=0 fetched=0 |
| 456 | while read -r sha f; do |
| 457 | [[ "$sha" =~ ^[0-9a-f]{64}$ && -n "$f" ]] || model_die "bad line in $AIEN_MODEL_LIST: $sha $f" |
| 458 | case "$f" in /*|*..*) model_die "unsafe file name in $AIEN_MODEL_LIST: $f" ;; esac |
| 459 | n=$((n + 1)) |
| 460 | # A complete file from an earlier run is kept (the sha256 check below judges it); |
| 461 | # <file>.part is an interrupted download and is resumed where it stopped. |
| 462 | if [[ -f "$MODEL_DIR/$f" && ! -e "$MODEL_DIR/$f.part" ]]; then continue; fi |
| 463 | mkdir -p "$(dirname "$MODEL_DIR/$f")" |
| 464 | if [[ -s "$MODEL_DIR/$f.part" ]]; then |
| 465 | echo " resuming $f ($(du -k "$MODEL_DIR/$f.part" | cut -f1) KiB already here)" |
| 466 | else |
| 467 | echo " fetching $f" |
| 468 | fi |
| 469 | if ! curl --proto '=https,file' --fail --location --silent --show-error \ |
| 470 | --retry 5 --retry-delay 5 -C - -o "$MODEL_DIR/$f.part" "$base/$f"; then |
| 471 | # curl refuses to resume a .part that is already complete; accept it if it matches. |
| 472 | [[ -f "$MODEL_DIR/$f.part" && "$(sha256_of "$MODEL_DIR/$f.part")" == "$sha" ]] \ |
| 473 | || model_die "download of $f failed (see the curl line above). What arrived is kept in $MODEL_DIR/$f.part; rerun the installer to resume." |
| 474 | fi |
| 475 | mv -f "$MODEL_DIR/$f.part" "$MODEL_DIR/$f" |
| 476 | fetched=$((fetched + 1)) |
| 477 | done < "$list" |
| 478 | [[ "$n" -gt 0 ]] || model_die "$AIEN_MODEL_LIST lists no files." |
| 479 | echo "[*] Model download: $fetched of $n files fetched now; checking all $n with sha256sum -c" |
| 480 | local out bad |
| 481 | if ! out="$(cd "$MODEL_DIR" && sha256_check "$list" 2>&1)"; then |
| 482 | echo "$out" >&2 |
| 483 | # Set mismatched files aside so a rerun fetches them fresh. |
| 484 | bad=0 |
| 485 | while IFS= read -r f; do |
| 486 | [[ -n "$f" && -f "$MODEL_DIR/$f" ]] || continue |
| 487 | mv -f "$MODEL_DIR/$f" "$MODEL_DIR/$f.mismatch" |
| 488 | bad=$((bad + 1)) |
| 489 | done < <(sed -n 's/: FAILED.*$//p' <<<"$out") |
| 490 | model_die "the model folder does not match the shipped checksums ($bad file(s) set aside as <file>.mismatch, listed above). Do not start the server on it. Rerun the installer to fetch those files again." |
| 491 | fi |
| 492 | echo "[+] Model download: all $n files match $AIEN_MODEL_LIST" |
| 493 | MODEL_OK=1 |
| 494 | } |
| 495 | |
| 496 | [[ "$WITH_SERVER" != 1 ]] || server_preflight |
| 497 | [[ "$WITH_MODEL" != 1 ]] || model_preflight |
| 498 | |
| 499 | # Release signing keys, pinned here so a release can be verified with nothing but this file and the assets |
| 500 | # (offline). scripts/test-install-release.sh checks both lines against their files in docs/release/. |
| 501 | # AIEN_RELEASE_SIGNER is the dedicated offline public-release key (Drake ruling 1, sc#385). It equals the key line of |
| 502 | # docs/release/allowed_signers. PLACEHOLDER: it is empty until the key ceremony (docs/release/KEY_CEREMONY.md) |
| 503 | # produces the key, so until then nothing can verify, or be recorded, as a public release. |
| 504 | AIEN_RELEASE_SIGNER='' |
| 505 | # AIEN_INTERNAL_TEST_SIGNER is the old key that signed internal test release v0.1.1. It equals |
| 506 | # docs/release/internal_test_signers. Anything it signs installs as signature_check internal-test-key, never release. |
| 507 | AIEN_INTERNAL_TEST_SIGNER='aien-release ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID6WDVy2x8aV80ag10iPonS4J8k4seWrgsi5cuq8AIZJ' |
| 508 | |
| 509 | # Run from a checkout, or bootstrap one when the script is piped to Bash for a |
| 510 | # source build. Release mode runs without a checkout. |
| 511 | INSTALL_WORKSPACE="" |
| 512 | SOURCE_ROOT="" |
| 513 | if [[ -n "${AIEN_SOURCE_DIR:-}" ]]; then |
| 514 | SOURCE_ROOT="$(cd "$AIEN_SOURCE_DIR" && pwd)" |
| 515 | elif [[ -f "${BASH_SOURCE[0]:-}" && -f "$(dirname "${BASH_SOURCE[0]}")/Cargo.toml" ]]; then |
| 516 | SOURCE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 517 | elif [[ -z "$RELEASE_TAG" ]]; then |
| 518 | INSTALL_WORKSPACE="$(mktemp -d "${TMPDIR:-/tmp}/aien-install.XXXXXX")" |
| 519 | trap 'rm -rf "$INSTALL_WORKSPACE"' EXIT |
| 520 | git clone --quiet https://github.com/aien-dev/aien-sovereign-core-mv.git "$INSTALL_WORKSPACE/core" |
| 521 | git -C "$INSTALL_WORKSPACE/core" checkout --quiet "${AIEN_REV:-main}" |
| 522 | SOURCE_ROOT="$INSTALL_WORKSPACE/core" |
| 523 | fi |
| 524 | if [[ -n "$SOURCE_ROOT" ]]; then |
| 525 | [[ -f "$SOURCE_ROOT/Cargo.toml" ]] || { echo "AIEN source manifest is missing" >&2; exit 1; } |
| 526 | cd "$SOURCE_ROOT" |
| 527 | echo "[*] Source commit: $(git rev-parse HEAD 2>/dev/null || echo unknown)" |
| 528 | else |
| 529 | echo "[*] Release mode without a source tree: $RELEASE_TAG" |
| 530 | fi |
| 531 | # Where the EN2 imprint comes from: the checkout, or the release archive (set below). |
| 532 | IMPRINT_SRC="${SOURCE_ROOT:+$SOURCE_ROOT/imprints/en2-trinity}" |
| 533 | |
| 534 | OS="$(uname -s | tr "[:upper:]" "[:lower:]")" |
| 535 | ARCH="$(uname -m)" |
| 536 | |
| 537 | case "$ARCH" in |
| 538 | x86_64|amd64) TARGET_ARCH="x86_64" ;; |
| 539 | aarch64|arm64) TARGET_ARCH="aarch64" ;; |
| 540 | *) echo "Error: Unsupported CPU architecture: $ARCH"; exit 1 ;; |
| 541 | esac |
| 542 | |
| 543 | case "$OS" in |
| 544 | linux) TARGET_OS="linux" ;; |
| 545 | darwin) TARGET_OS="macos" ;; |
| 546 | *) echo "Error: Unsupported operating system: $OS"; exit 1 ;; |
| 547 | esac |
| 548 | |
| 549 | echo "[*] Detected Platform: $TARGET_OS ($TARGET_ARCH)" |
| 550 | |
| 551 | # Release asset names: linux uses x86_64 or aarch64, macOS uses arm64. |
| 552 | RELEASE_ARCH="$TARGET_ARCH" |
| 553 | [[ "$TARGET_OS" != macos || "$TARGET_ARCH" != aarch64 ]] || RELEASE_ARCH="arm64" |
| 554 | |
| 555 | # Release mode (AIEN_RELEASE_TAG=vX.Y.Z): install a published, signed release |
| 556 | # instead of building from source. Fails closed: nothing is installed unless |
| 557 | # SHA256SUMS.txt carries a valid signature and the archive matches its listed checksum. |
| 558 | # The signature class is decided by WHICH key verified, never by what the artifact says: |
| 559 | # release the public-release key pinned above (AIEN_RELEASE_SIGNER; empty until the key ceremony) |
| 560 | # internal-test-key the old internal test key (AIEN_INTERNAL_TEST_SIGNER) |
| 561 | # dry-run-key a throwaway signer file the caller names in AIEN_DRY_RUN_SIGNERS (AIEN_ALLOWED_SIGNERS is the |
| 562 | # older name of the same switch); only for dry runs and tests |
| 563 | # A package whose release.toml says dry-run = true is refused when it verifies as release. |
| 564 | # The class is written to installed.toml (signature-check) and to $CONFIG_DIR/install-receipt.json. |
| 565 | |
| 566 | SIG_CHECK="" |
| 567 | # verify_sums <signers-file> <dir>: true when SHA256SUMS.txt.sig is a valid aien-release signature for that file. |
| 568 | verify_sums() { |
| 569 | ssh-keygen -Y verify -f "$1" -I aien-release -n aien-release -s "$2/SHA256SUMS.txt.sig" < "$2/SHA256SUMS.txt" >/dev/null 2>&1 |
| 570 | } |
| 571 | |
| 572 | # write_receipt <tag> <asset> <dir> <files-verified>: install-receipt.json for the live release (atomic). |
| 573 | write_receipt() { |
| 574 | local tag="$1" asset="$2" d="$3" n="$4" id cli dry tmp="$CONFIG_DIR/.install-receipt.json.new.$$" |
| 575 | id="$(readlink "$REL_DIR/current")" |
| 576 | cli="$(toml_get "$REL_DIR/$id/release.toml" "" aien-cli-sha256)" |
| 577 | dry=false; [[ "$(toml_get "$REL_DIR/$id/release.toml" "" dry-run)" != true ]] || dry=true |
| 578 | { |
| 579 | echo '{' |
| 580 | echo ' "schema": "AienInstallReceiptV1",' |
| 581 | echo " \"signature_check\": \"$SIG_CHECK\"," |
| 582 | echo " \"dry_run\": $dry," |
| 583 | echo " \"tag\": \"$tag\"," |
| 584 | echo " \"artifact\": \"$asset\"," |
| 585 | echo " \"artifact_sha256\": \"$(sha256_of "$d/$asset")\"," |
| 586 | echo " \"sha256sums_sha256\": \"$(sha256_of "$d/SHA256SUMS.txt")\"," |
| 587 | echo " \"signer_fingerprint\": \"$SIGNER_FP\"," |
| 588 | echo " \"release_id\": \"$id\"," |
| 589 | echo " \"candidate\": \"$(toml_get "$REL_DIR/$id/release.toml" "" candidate)\"," |
| 590 | echo " \"files_verified\": $n," |
| 591 | echo " \"cli_sha256\": \"$cli\"," |
| 592 | echo " \"daemon_sha256\": \"$cli\"," |
| 593 | echo " \"installed_at\": \"$(date -u +%Y-%m-%dT%H:%M:%SZ)\"" |
| 594 | echo '}' |
| 595 | } > "$tmp" |
| 596 | mv -f "$tmp" "$CONFIG_DIR/install-receipt.json" |
| 597 | } |
| 598 | |
| 599 | install_release() { |
| 600 | local tag="$1" |
| 601 | [[ "$tag" =~ ^[A-Za-z0-9._-]+$ ]] || { echo "Error: release tag '$tag' has characters other than letters, digits, dot, dash, underscore" >&2; exit 1; } |
| 602 | command -v ssh-keygen >/dev/null 2>&1 || { echo "Error: ssh-keygen is required to verify the release signature" >&2; exit 1; } |
| 603 | command -v curl >/dev/null 2>&1 || { echo "Error: curl is required to download the release" >&2; exit 1; } |
| 604 | local base="${AIEN_RELEASE_BASE_URL:-https://github.com/aien-dev/aien-sovereign-core-mv/releases/download/$tag}" |
| 605 | local asset="sovereign-${TARGET_OS}-${RELEASE_ARCH}.tar.gz" |
| 606 | DL_DIR="" |
| 607 | DL_DIR="$(mktemp -d "${TMPDIR:-/tmp}/aien-release.XXXXXX")" |
| 608 | trap 'rm -rf "$DL_DIR"; [[ -z "$INSTALL_WORKSPACE" ]] || rm -rf "$INSTALL_WORKSPACE"' EXIT |
| 609 | local dry_signers="${AIEN_DRY_RUN_SIGNERS:-${AIEN_ALLOWED_SIGNERS:-}}" |
| 610 | [[ -z "$dry_signers" || -f "$dry_signers" ]] || { echo "Error: dry-run signer file not found: $dry_signers" >&2; exit 1; } |
| 611 | echo "[*] Downloading $tag: $asset, SHA256SUMS.txt, SHA256SUMS.txt.sig" |
| 612 | local f |
| 613 | for f in SHA256SUMS.txt SHA256SUMS.txt.sig "$asset"; do |
| 614 | if ! curl --proto '=https,file' --fail --silent --show-error --location -o "$DL_DIR/$f" "$base/$f" 2> "$DL_DIR/.curl.err"; then |
| 615 | [[ "$f" != SHA256SUMS.txt.sig ]] || { echo "Error: SHA256SUMS.txt.sig is missing: refusing an unsigned release (no signature). Nothing was installed." >&2; exit 1; } |
| 616 | cat "$DL_DIR/.curl.err" >&2; echo "Error: could not download $f from $base" >&2; exit 1 |
| 617 | fi |
| 618 | done |
| 619 | echo "[*] Verifying the signature on SHA256SUMS.txt" |
| 620 | SIG_CHECK=""; SIGNER_FP="" |
| 621 | local kf="$DL_DIR/.signer" |
| 622 | if [[ -n "$AIEN_RELEASE_SIGNER" ]]; then |
| 623 | printf '%s\n' "$AIEN_RELEASE_SIGNER" > "$kf" |
| 624 | ! verify_sums "$kf" "$DL_DIR" || SIG_CHECK=release |
| 625 | fi |
| 626 | if [[ -z "$SIG_CHECK" ]]; then |
| 627 | printf '%s\n' "$AIEN_INTERNAL_TEST_SIGNER" > "$kf" |
| 628 | ! verify_sums "$kf" "$DL_DIR" || SIG_CHECK=internal-test-key |
| 629 | fi |
| 630 | if [[ -z "$SIG_CHECK" && -n "$dry_signers" ]]; then |
| 631 | cp "$dry_signers" "$kf" |
| 632 | ! verify_sums "$kf" "$DL_DIR" || SIG_CHECK=dry-run-key |
| 633 | fi |
| 634 | if [[ -z "$SIG_CHECK" ]]; then |
| 635 | [[ -n "$AIEN_RELEASE_SIGNER" ]] || echo " (no public-release key is pinned yet: the key ceremony has not happened, see docs/release/KEY_CEREMONY.md)" >&2 |
| 636 | echo "Error: SHA256SUMS.txt signature is NOT valid for any accepted key. Nothing was installed." >&2; exit 1 |
| 637 | fi |
| 638 | SIGNER_FP="$(awk 'NF >= 3 && $1 !~ /^#/ { print $2" "$3; exit }' "$kf" | ssh-keygen -lf - 2>/dev/null | awk '{ print $2 }' || true)" |
| 639 | rm -f "$kf" |
| 640 | echo "[+] signature_check: $SIG_CHECK" |
| 641 | local want got |
| 642 | want="$(awk -v a="$asset" '$2 == a || $2 == "*" a { print $1 }' "$DL_DIR/SHA256SUMS.txt")" |
| 643 | [[ "$(printf '%s\n' "$want" | grep -c .)" -eq 1 ]] \ |
| 644 | || { echo "Error: $asset is not listed exactly once in the signed SHA256SUMS.txt" >&2; exit 1; } |
| 645 | got="$(sha256_of "$DL_DIR/$asset")" |
| 646 | [[ "$want" == "$got" ]] \ |
| 647 | || { echo "Error: checksum mismatch for $asset (signed $want, downloaded $got). Nothing was installed." >&2; exit 1; } |
| 648 | echo "[+] Signature and checksum verified for $asset" |
| 649 | mkdir -p "$DL_DIR/x" "$BIN_DIR" |
| 650 | tar -xzf "$DL_DIR/$asset" -C "$DL_DIR/x" |
| 651 | [[ -d "$DL_DIR/x/bin" ]] || { echo "Error: archive has no bin/ directory" >&2; exit 1; } |
| 652 | if [[ "$SIG_CHECK" == release && ( "$(toml_get "$DL_DIR/x/release.toml" "" dry-run)" == true \ |
| 653 | || "$(toml_get "$DL_DIR/x/release.toml" "" candidate)" == NOT-RELEASABLE ) ]]; then |
| 654 | echo "Error: this package is labelled dry-run but carries a release signature; a dry run is never a release. Nothing was installed." >&2 |
| 655 | exit 1 |
| 656 | fi |
| 657 | [[ ! -d "$DL_DIR/x/imprints/en2-trinity" ]] || IMPRINT_SRC="$DL_DIR/x/imprints/en2-trinity" |
| 658 | activate_release "$DL_DIR/x" |
| 659 | write_receipt "$tag" "$asset" "$DL_DIR" "$(toml_lines "$REL_DIR/current/release.toml" files | grep -c .)" |
| 660 | echo "[+] Install receipt: $CONFIG_DIR/install-receipt.json (signature_check: $SIG_CHECK)" |
| 661 | } |
| 662 | |
| 663 | # Verify Rust Toolchain (source builds only) |
| 664 | if [[ -z "$RELEASE_TAG" ]] && ! command -v cargo >/dev/null 2>&1; then |
| 665 | echo "[!] Cargo not found. Installing Rust toolchain via rustup..." |
| 666 | curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y |
| 667 | source "$HOME/.cargo/env" |
| 668 | fi |
| 669 | |
| 670 | BIN_DIR="${AIEN_BIN_DIR:-$HOME/.local/bin}" |
| 671 | CONFIG_DIR="${AIEN_CONFIG_DIR:-$HOME/.config/sovereign}" |
| 672 | IMPRINT_DIR="$CONFIG_DIR/imprints/en2" |
| 673 | |
| 674 | mkdir -p "$BIN_DIR" "$CONFIG_DIR" "$IMPRINT_DIR" |
| 675 | |
| 676 | # Ensure ~/.local/bin is in PATH for current and future shells |
| 677 | if [[ ":$PATH:" != *":$BIN_DIR:"* ]]; then |
| 678 | export PATH="$BIN_DIR:$PATH" |
| 679 | fi |
| 680 | |
| 681 | if [[ "${AIEN_INSTALL_NO_PROFILE:-0}" != "1" ]]; then |
| 682 | for RC in "$HOME/.zshrc" "$HOME/.bashrc" "$HOME/.profile"; do |
| 683 | if [ -f "$RC" ]; then |
| 684 | if ! grep -Fq '$HOME/.local/bin' "$RC"; then |
| 685 | echo "export PATH=\"\$HOME/.local/bin:\$PATH\"" >> "$RC" |
| 686 | fi |
| 687 | fi |
| 688 | done |
| 689 | fi |
| 690 | |
| 691 | if [[ -n "$RELEASE_TAG" ]]; then |
| 692 | install_release "$RELEASE_TAG" |
| 693 | else |
| 694 | echo "[*] Building Core Monorepo Binaries (High-Performance Release Mode)..." |
| 695 | echo " - aien-cli (Universal Terminal CLI & Orchestrator)" |
| 696 | echo " - spark-cockpit-rs (3D Sovereign Glass Cockpit Server)" |
| 697 | echo " - cortex-rs (Canonical Memory & Vector Store)" |
| 698 | echo " - spark-supervisor (Resilient Process Supervisor)" |
| 699 | echo " - spark-debugger (Zero-Leak Health & Telemetry Auditor)" |
| 700 | echo " - spark-harness (5-Layer Verification Engine)" |
| 701 | echo " - spark-crumbs (Blake3 Scent & Action Vector Tracker)" |
| 702 | echo " - spark-aegis (Defensive Boundary & Containment Engine)" |
| 703 | |
| 704 | # The workspace holds both crates/spark-crumbs and the git-pinned copy its dependents use (the release candidate |
| 705 | # pins that revision in Cargo.lock), so a bare `-p spark-crumbs` is ambiguous (L055). Name the in-repo crate by path. |
| 706 | cargo build --locked --release -p aien-cli -p spark-cockpit-rs -p cortex-rs -p spark-supervisor -p spark-debugger -p spark-harness -p "path+file://$PWD/crates/spark-crumbs" -p spark-aegis |
| 707 | |
| 708 | echo "[*] Installing Binaries to $BIN_DIR..." |
| 709 | cp target/release/aien-cli "$BIN_DIR/aien" |
| 710 | cp target/release/spark-cockpit-rs "$BIN_DIR/spark-cockpit" |
| 711 | cp target/release/cortex-rs "$BIN_DIR/cortex" |
| 712 | cp target/release/spark-supervisor "$BIN_DIR/spark-supervisor" |
| 713 | cp target/release/spark-debugger "$BIN_DIR/spark-debugger" |
| 714 | cp target/release/spark-harness "$BIN_DIR/spark-harness" |
| 715 | cp target/release/spark-crumbs "$BIN_DIR/spark-crumbs" |
| 716 | cp target/release/spark-aegis "$BIN_DIR/spark-aegis" |
| 717 | chmod +x "$BIN_DIR/aien" "$BIN_DIR/spark-cockpit" "$BIN_DIR/cortex" "$BIN_DIR/spark-supervisor" "$BIN_DIR/spark-debugger" "$BIN_DIR/spark-harness" "$BIN_DIR/spark-crumbs" "$BIN_DIR/spark-aegis" |
| 718 | |
| 719 | echo "[+] Binaries successfully linked:" |
| 720 | echo " - aien -> $BIN_DIR/aien" |
| 721 | echo " - spark-cockpit -> $BIN_DIR/spark-cockpit" |
| 722 | echo " - cortex -> $BIN_DIR/cortex" |
| 723 | echo " - spark-supervisor -> $BIN_DIR/spark-supervisor" |
| 724 | echo " - spark-debugger -> $BIN_DIR/spark-debugger" |
| 725 | echo " - spark-harness -> $BIN_DIR/spark-harness" |
| 726 | echo " - spark-crumbs -> $BIN_DIR/spark-crumbs" |
| 727 | echo " - spark-aegis -> $BIN_DIR/spark-aegis" |
| 728 | fi |
| 729 | |
| 730 | if [[ "$WITH_SERVER" == 1 ]]; then |
| 731 | server_build |
| 732 | fi |
| 733 | |
| 734 | if [[ "$WITH_MODEL" == 1 ]]; then |
| 735 | model_download |
| 736 | fi |
| 737 | |
| 738 | echo "[*] Initializing Sovereign Operator Profile..." |
| 739 | if [ ! -f "$CONFIG_DIR/operator.toml" ]; then |
| 740 | GIT_NAME="$(git config user.name 2>/dev/null || echo "Sovereign Operator")" |
| 741 | GIT_EMAIL="$(git config user.email 2>/dev/null || echo "operator@local")" |
| 742 | |
| 743 | cat << CFG > "$CONFIG_DIR/operator.toml" |
| 744 | [operator] |
| 745 | name = "$GIT_NAME" |
| 746 | email = "$GIT_EMAIL" |
| 747 | handle = "operator" |
| 748 | sign_commits = false |
| 749 | |
| 750 | [engine] |
| 751 | mode = "max" |
| 752 | api_base_url = "http://127.0.0.1:18006/v1" |
| 753 | api_key = "" |
| 754 | model_id = "atlas-lightning-omni" |
| 755 | max_port = 18006 |
| 756 | context_window = 32768 |
| 757 | temperature = 0.7 |
| 758 | CFG |
| 759 | echo "[+] Generated default configuration at $CONFIG_DIR/operator.toml" |
| 760 | else |
| 761 | echo "[+] Existing configuration found at $CONFIG_DIR/operator.toml" |
| 762 | fi |
| 763 | |
| 764 | echo "[*] Installing Free EN2 Trinity Imprint..." |
| 765 | if [[ -n "$IMPRINT_SRC" && -d "$IMPRINT_SRC" ]]; then |
| 766 | cp -r "$IMPRINT_SRC"/* "$IMPRINT_DIR/" |
| 767 | echo "[+] EN2 Trinity Imprint installed locally to $IMPRINT_DIR" |
| 768 | fi |
| 769 | |
| 770 | echo "==================================================================" |
| 771 | if [[ "$MODEL_OK" == 1 ]]; then |
| 772 | echo " ⚡ Portable binaries installed. Access-token provisioning remains." |
| 773 | echo " Model: Qwen3.8-27B-FP8 downloaded and checked in $MODEL_DIR; see docs/FIRST_RUN.md for the rest." |
| 774 | else |
| 775 | echo " ⚡ Portable binaries installed. Model and access-token provisioning remain." |
| 776 | echo " The installer does not provision a model unless run with --with-model; see docs/FIRST_RUN.md." |
| 777 | fi |
| 778 | echo "==================================================================" |
| 779 | echo " Primary Command: aien" |
| 780 | echo "" |
| 781 | echo " Quickstart (full steps: docs/FIRST_RUN.md):" |
| 782 | echo " aien compose desk-key --create 1 # Create the approval desk key; aien start refuses without it" |
| 783 | echo " aien start # Starts Cortex, Cockpit, and background daemons" |
| 784 | echo " aien status # Real-time health, ports, and memory status" |
| 785 | echo " aien cockpit # Launches Sovereign Glass Cockpit in browser" |
| 786 | echo " aien chat # Interactive sovereign terminal pairing" |
| 787 | echo " aien aegis # Run defensive boundary security audit" |
| 788 | echo " aien doctor # System diagnostic and TPM key vault audit" |
| 789 | echo "==================================================================" |
| 790 | if [[ "$WITH_SERVER" == 1 ]]; then |
| 791 | echo " Model server (Qwen3.8-27B on the Omega engine):" |
| 792 | if [[ "$WITH_MODEL" == 1 ]]; then |
| 793 | echo " 1. Weights downloaded and checked in $MODEL_DIR" |
| 794 | else |
| 795 | echo " 1. Download and check the weights (about 31 GB): rerun with --with-model, or by hand:" |
| 796 | echo " Hugging Face Qwen/Qwen3.8-27B-FP8, revision 017b9c7af6b5689d5dd426a76e0bc077eb5ca20a" |
| 797 | echo " into ~/models/qwen3.8-27b-fp8-017b9c7a" |
| 798 | fi |
| 799 | echo " 2. aien-serve-27b # starts it on http://127.0.0.1:18091/v1 and prints how to stop it" |
| 800 | echo " (MODEL_DIR, PORT and BIN override the defaults; aien-serve-27b --help)" |
| 801 | [[ "$WITH_MODEL" != 1 || "$MODEL_DIR" == "$HOME/models/qwen3.8-27b-fp8-017b9c7a" ]] \ |
| 802 | || echo " Your model folder is not the default: start it with MODEL_DIR=$MODEL_DIR aien-serve-27b" |
| 803 | echo "==================================================================" |
| 804 | fi |