okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
cd9745050
main
1#!/bin/sh 2# Strata Terminal: one-line installer for Linux (x86_64, and ARM64 on the NVIDIA DGX Spark) and macOS (Apple silicon). 3# 4# curl -fsSL --connect-timeout 15 --max-time 120 https://github.com/Niko1221/Strata/releases/latest/download/install.sh -o install.sh && sh install.sh 5# 6# What it does, in order (and nothing else): 7# 1. finds out which computer this is (system, processor, graphics card) so it can fetch the right archive; 8# 2. downloads the Terminal archive named in the release folder's install-manifest.txt and checks its SHA-256 against it; 9# 3. unpacks it into ${XDG_DATA_HOME:-~/.local/share}/strata/terminal/<version> (no administrator rights, nothing outside your home); 10# 4. checks the release's signed feed with the Terminal it just unpacked (`strata update --check`); if that check fails, it removes 11# what it unpacked and stops; 12# 5. puts a `strata` link in ~/.local/bin and prints: Installed. Run: strata launch 13# 14# The engine (the part that talks to your graphics card) and the model are NOT part of this: `strata launch` fetches the engine for 15# your card the first time you choose a model, from the same release folder, signed. 16# 17# <feed> is where the release folder is hosted: GitHub Releases of Niko1221/Strata (the "latest" release's files), built in as the default. 18# Set STRATA_FEED to another folder (a URL) to use that instead, for example a local test feed: STRATA_FEED=http://127.0.0.1:8099 sh install.sh 19# 20# Settings (all optional): STRATA_FEED, STRATA_DATA_DIR (default ~/.local/share/strata), STRATA_BIN_DIR (default ~/.local/bin), 21# STRATA_INSTALL_TEST_TRUST=1 (a test feed: also fetch <feed>/test-trust.json and trust only that key for the check in step 4). 22set -eu 23 24FEED =" ${ STRATA_FEED :-https://github.com/Niko1221/Strata/releases/latest/download} " 25FEED =" ${ FEED %/} " 26DATA_DIR =" ${ STRATA_DATA_DIR :-${ XDG_DATA_HOME :- $ HOME /.local/share}/strata} " 27BIN_DIR =" ${ STRATA_BIN_DIR :- $ HOME /.local/bin} " 28 29say () {printf '%s\n' " $ *" ; } 30die () {printf 'strata installer: %s\n' " $ *" >&2;exit 1; } 31 32[ -n" $ FEED " ] ||die "this installer does not know where the Strata release folder is. Set STRATA_FEED to its address and run it again, for example: STRATA_FEED=https://example.org/strata sh install.sh" 33 34# Everything below is one function, called on the last line: a download that stops half-way is a syntax error (nothing runs), not a half installer. 35main () { 36# ---- tools 37# The network rule (strata_control/netpolicy.py): a server that does not answer is given up after 15 s and one more try, and a download stops 38# only when no data comes for 60 s (a slow line that works is never cut). A refused connection or no DNS answer fails at once. 39if command -v curl> /dev/null2 >&1;then 40fetch () {curl -fsSL --connect-timeout 15--speed-limit 1--speed-time 60--retry 1--retry-delay 2-o " $ 2 " " $ 1 " ; } 41elif command -v wget> /dev/null2 >&1;then 42if wget --help 2 >&1| grep -q -- '--connect-timeout' ;then # GNU wget 43fetch () {wget -q --dns-timeout=15 --connect-timeout=15 --read-timeout=60 --tries=2 --waitretry=2 -O " $ 2 " " $ 1 " ; } 44else # BusyBox wget: one read timeout only 45fetch () {wget -q -T 60-O " $ 2 " " $ 1 " ; } 46fi 47else 48die "neither curl nor wget is installed, so nothing can be downloaded. Install one (for example: sudo apt install curl) and run this again." 49fi 50if command -v sha256sum> /dev/null2 >&1;then 51sha () {sha256sum " $ 1 " | cut -d ' ' -f1 ; } 52elif command -v shasum> /dev/null2 >&1;then 53sha () {shasum -a 256" $ 1 " | cut -d ' ' -f1 ; } 54else 55die "no sha256sum or shasum was found, so the download cannot be checked. Install coreutils and run this again." 56fi 57command -v tar> /dev/null2 >&1 ||die "tar is not installed; install it and run this again." 58 59# ---- 1. this computer 60os =$( uname -s ) ;arch =$( uname -m ) 61case " $ os - $ arch " in 62 Linux-x86_64| Linux-amd64)platform =linux-x86_64 ;; 63 Darwin-arm64| Darwin-aarch64)platform =macos-arm64 ;; 64 Linux-aarch64| Linux-arm64)platform =linux-aarch64 ;;# the NVIDIA DGX Spark (GB10); the note below says so for any other ARM computer 65 Darwin-x86_64)die "this Mac has an Intel processor. Strata for Mac needs Apple silicon (M1 or newer), so it could not run a model here." ;; 66 *)die "this computer ( $ os $ arch ) has no Strata Terminal. Supported: Linux x86_64 with an NVIDIA or AMD card, Linux ARM64 on an NVIDIA DGX Spark, macOS on Apple silicon (Windows: use install.ps1)." ;; 67esac 68gpu ="" 69if command -v nvidia-smi> /dev/null2 >&1;then 70# only a clean answer is a card name: a driver that is not loaded prints an error sentence (on stdout, exit status 9) 71gpu =$( nvidia-smi --query-gpu=name --format=csv,noheader 2 > /dev/null) ||gpu ="" 72gpu =$( printf '%s' " $ gpu " | head -1 ) 73case " $ gpu " in *[Ff]ailed*| *NVIDIA-SMI*| *"couldn't communicate" *| *"No devices" *)gpu ="" ;;esac 74 [ -n" $ gpu " ]&& gpu ="NVIDIA $ gpu " 75fi 76if [ -z" $ gpu " ]&& [" $ os " = Linux ]&& command -v lspci> /dev/null2 >&1;then 77# the PCI class decides, not a word anywhere in the line (an SSD sold as "3D NAND" is not a graphics card) 78gpu =$( lspci 2 > /dev/null | grep -iE '^[^ ]+ (vga compatible controller|3d controller|display controller)[^:]*:' | head -1 | sed 's/^[^ ]* [^:]*: *//' || true ) 79fi 80if [ -z" $ gpu " ]&& [" $ os " = Darwin ];then 81gpu =$( system_profiler SPDisplaysDataType 2 > /dev/null | sed -n 's/^ *Chipset Model: //p' | head -1 || true ) 82fi 83say "Strata Terminal installer" 84say " This computer: $ os $ arch ( $ platform ) ${ gpu :+, graphics: $ gpu } " 85if [" $ platform " = linux-aarch64 ];then # recommend, never force: the Terminal installs on any ARM Linux, its engine is for one machine 86case " $ gpu " in 87 *GB10*) ;; 88 *)say " Note: Strata's engine for ARM Linux is built and tested on the NVIDIA DGX Spark (GB10) only. This computer reports ${ gpu :-no NVIDIA graphics} : the Terminal installs, but 'strata launch' may find no engine for it." ;; 89esac 90fi 91say " Release folder: $ FEED " 92 93# ---- 2. download and check 94work =$( mktemp -d " ${ TMPDIR :-/tmp} /strata-install.XXXXXX" ) ||die "cannot make a temporary folder" 95trap 'rm -rf "$work"' EXIT INT TERM 96host =$( printf '%s' " $ FEED " | sed -n 's#^[A-Za-z][A-Za-z0-9+.-]*://\([^/:]*\).*#\1#p' ) 97host =${ host :- $ FEED } 98fetch " $ FEED /install-manifest.txt" " $ work /manifest.txt" ||die " $ host did not answer (or this computer is offline), so the installer could not start. Check that this computer can open https:// $ host , then run the same line again. Nothing was installed." 99line =$( awk -v p= " $ platform " '$1 == p { print; exit }' " $ work /manifest.txt" ) 100 [ -n" $ line " ] ||die "this release has no Terminal for $ platform ." 101set -- $ line 102version =$ 2 ;rel =$ 3 ;want =$ 4 103say " Terminal $ version ($(( ${ 5 :-0} / 1048576 )) MB)" 104say "Downloading…" 105fetch " $ FEED / $ rel " " $ work /terminal.tar.gz" ||die "the download stopped: $ host did not answer, or no data came for 60 seconds. Run the same line again; nothing was installed." 106got =$( sha " $ work /terminal.tar.gz" ) 107 [" $ got " =" $ want " ] ||die "the download does not match the release's checksum (got $ got , wanted $ want ). It was not installed; try again, and if it repeats the release folder is damaged." 108say " Checksum ok." 109 110# ---- 3. unpack 111dest =" $ DATA_DIR /terminal/ $ version " 112mkdir -p " $ DATA_DIR /terminal" " $ BIN_DIR " 113rm -rf " $ dest .incoming" ;mkdir -p " $ dest .incoming" 114tar -xzf " $ work /terminal.tar.gz" -C " $ dest .incoming" ||die "the archive could not be unpacked (is the disk full?). Nothing was installed." 115if [ ! -f" $ dest .incoming/bin/strata" ];then # an archive with one top folder (a terminal archive instead of the feed's control package) 116inner =$( ls -d " $ dest .incoming" /*/ 2 > /dev/null | head -1 ) 117if [ -n" $ inner " ]&& [ -f" ${ inner } bin/strata" ];then 118mv " ${ inner %/} " " $ dest .inner" && rm -rf " $ dest .incoming" && mv " $ dest .inner" " $ dest .incoming" 119fi 120fi 121 [ -f" $ dest .incoming/bin/strata" ] || {rm -rf " $ dest .incoming" ;die "the archive does not look like a Strata Terminal (no bin/strata). Nothing was installed." ; } 122chmod +x" $ dest .incoming/bin/strata" 2 > /dev/null ||true 123 124# ---- 4. the signed feed, checked with the Terminal just unpacked 125if [" ${ STRATA_INSTALL_TEST_TRUST :-} " = 1 ];then 126fetch " $ FEED /test-trust.json" " $ work /test-trust.json" || {rm -rf " $ dest .incoming" ;die "the test feed has no test-trust.json" ; } 127STRATA_UPDATE_TRUSTED_KEYS =" $ work /test-trust.json" ;export STRATA_UPDATE_TRUSTED_KEYS 128fi 129say "Checking the release's signature…" 130if !" $ dest .incoming/bin/strata" update--check --no-engine --feed " $ FEED " > " $ work /check.txt" 2 >&1;then 131sed -e 's/^/ /' " $ work /check.txt" >&2 132rm -rf " $ dest .incoming" 133die "the release folder's signed feed could not be verified, so nothing was installed. The reason is printed above; if it names a newer feed already accepted here, use the newest release folder, or follow the step it gives. If you trust this source and see no such reason, ask its owner to publish a signed feed." 134fi 135say " Signature ok." 136 137# ---- 5. in place 138rm -rf " $ dest " 139mv " $ dest .incoming" " $ dest " 140ln -sfn " $ dest " " $ DATA_DIR /terminal/current" 141ln -sf " $ DATA_DIR /terminal/current/bin/strata" " $ BIN_DIR /strata" 142case ": $ PATH :" in 143 *": $ BIN_DIR :" *)say "Installed. Run: strata launch" ;; 144 *)say "Installed. Run: $ BIN_DIR /strata launch" 145say " (To type just 'strata', add this line to your shell profile: export PATH=\" $ BIN_DIR :\$PATH\")" ;; 146esac 147} 148 149main " $ @"