#!/bin/sh # Copyright (c) 2026 kosa8. All rights reserved. Proprietary; see LICENSE. # kosa8 installer. # # curl -fsSL https://kosa8.com/install | sh # # Detects your platform, downloads the matching release, checks it against the # published SHA-256 sums, and puts it on your PATH. # # What it will NOT do quietly: pretend kosa8 runs everywhere. The part that # actually runs sandboxes needs Apple's Virtualization framework on an Apple # Silicon Mac, or KVM and Cloud Hypervisor on Linux (x86-64 or arm64). On # anything else (an Intel Mac) this installs the command-line tool alone, to # drive a machine that can, and tells you so, because finding that out after # installing is worse than being told now. set -eu REPO="AzmxAI/kosa8-releases" BINDIR="${KOSA8_BINDIR:-/usr/local/bin}" # A trailing slash would make the PATH check below compare /x//kosa8. [ "$BINDIR" = / ] || BINDIR="${BINDIR%/}" # Colour only on a terminal: in a CI log or a file the escapes are noise. if [ -t 2 ] && [ -z "${NO_COLOR:-}" ] && [ "${TERM:-}" != dumb ]; then c_warn=$(printf '\033[33m'); c_err=$(printf '\033[31m'); c_off=$(printf '\033[0m') else c_warn=''; c_err=''; c_off='' fi say() { printf '%s\n' "$1"; } info() { printf ' %s\n' "$1"; } warn() { printf '%s %s%s\n' "$c_warn" "$1" "$c_off" >&2; } die() { printf '%serror:%s %s\n' "$c_err" "$c_off" "$1" >&2; exit 1; } need() { command -v "$1" >/dev/null 2>&1 || die "$1 is required but not installed${2:+ ($2)}"; } need curl "Alpine: apk add curl; Debian/Ubuntu: sudo apt-get install curl" need tar # ---- work out what to fetch ------------------------------------------------- os=$(uname -s) arch=$(uname -m) case "$arch" in aarch64|arm64|armv8*) arch=arm64 ;; x86_64|amd64) arch=amd64 ;; esac # A shell under Rosetta reports x86_64 on an Apple Silicon Mac, which would # install the Intel build: the command-line tool alone, with no engine, on a # machine that can run one. Ask the hardware instead. if [ "$os" = Darwin ] && [ "$arch" = amd64 ] && [ "$(sysctl -n hw.optional.arm64 2>/dev/null)" = 1 ]; then arch=arm64 fi full_runtime=no case "$os/$arch" in Darwin/arm64) asset_os=darwin; ext=zip; full_runtime=yes ;; Darwin/amd64) asset_os=darwin; ext=zip ;; Linux/arm64|Linux/amd64) asset_os=linux; ext=tar.gz; full_runtime=linux ;; *) die "unsupported platform: $os/$arch (kosa8 needs macOS or Linux; on Windows use the PowerShell installer at https://kosa8.com/install.ps1)" ;; esac # ---- resolve the version ---------------------------------------------------- version="${KOSA8_VERSION:-}" if [ -z "$version" ]; then # Resolve the latest tag from the redirect on /releases/latest rather than # the API. The API is rate-limited per IP, so on a CI runner, behind # corporate NAT, or on any shared address it answers 403 and the install # fails for a reason that has nothing to do with the user. The redirect is # plain HTTP with no such limit. version=$(curl -fsSLI -o /dev/null -w '%{url_effective}' \ "https://github.com/$REPO/releases/latest" 2>/dev/null | sed -n 's#.*/tag/##p') if [ -z "$version" ]; then # Fall back to the API, which may still work when the redirect does not. version=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" 2>/dev/null \ | sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p' | head -1) fi [ -n "$version" ] || die "could not determine the latest version; set KOSA8_VERSION to a release tag from https://github.com/$REPO/releases (for example KOSA8_VERSION=v0.23.0) and retry" fi # Tags are v-prefixed; KOSA8_VERSION=0.18.0 means v0.18.0, not a 404. version="v${version#v}" num="${version#v}" asset="kosa8_${num}_${asset_os}_${arch}.${ext}" base="https://github.com/$REPO/releases/download/$version" say "" say " kosa8 $version — $os/$arch" say "" # ---- download and verify ---------------------------------------------------- tmp=$(mktemp -d 2>/dev/null || mktemp -d -t kosa8) cleanup() { rm -rf "$tmp"; } # EXIT alone runs on a normal end; on Ctrl-C a trap that only cleaned up # would carry on installing after the handler returned. trap cleanup EXIT trap 'cleanup; exit 130' INT trap 'cleanup; exit 143' TERM info "downloading $asset" curl -fsSL -o "$tmp/$asset" "$base/$asset" \ || die "could not download $asset — check https://github.com/$REPO/releases" # The checksum is the whole point of scripting this rather than telling people # to click a link: verify before anything is unpacked or run. Every release # publishes checksums.txt, so a missing file or a missing line is not a gap to # shrug past — it is exactly what a tampered or truncated release looks like, # and "continuing without verification" would install it anyway. curl -fsSL -o "$tmp/checksums.txt" "$base/checksums.txt" \ || die "could not download checksums.txt for $version — refusing to install unverified" # The signature over checksums.txt. Releases from v0.22.0 on are signed with # kosa8's release key, an SSH signature (checksums.txt.sshsig) that # `ssh-keygen -Y verify` checks: OpenSSH 8.1 or later, already on macOS and # most Linux systems. The key is pinned here, and published at # https://kosa8.com/keys/ and in docs.kosa8.com/guides/verify-release/; a # signature that verifies against any key would prove only that somebody # signed something. ssh-keygen is not a requirement for installing: without # it the checksums are still enforced, and you are told the signature went # unchecked rather than left to assume it was. SIGNER='release@kosa8.com' SIGNER_KEY='ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGvgqE9gNsJGHbsCDkJVKCk807NCjJKZrYcuDCfa12RC' SIG_NAMESPACE='kosa8-release' # Older releases were signed keyless with cosign by a GitHub Actions workflow, # whose identity is pinned for them. SIGNER_IDENTITY='^https://github\.com/AzmxAI/azmx-ai/\.github/workflows/kosa8-signed-release\.yml@refs/.+$' SIGNER_ISSUER='https://token.actions.githubusercontent.com' if curl -fsSL -o "$tmp/checksums.txt.sshsig" "$base/checksums.txt.sshsig" 2>/dev/null; then if ! command -v ssh-keygen >/dev/null 2>&1; then warn "ssh-keygen is not installed, so the release signature was not checked (the checksum still is)" warn " install OpenSSH 8.1 or later to verify it (Debian/Ubuntu: openssh-client; Alpine: openssh-keygen)" else printf '%s namespaces="%s" %s\n' "$SIGNER" "$SIG_NAMESPACE" "$SIGNER_KEY" > "$tmp/allowed_signers" if out=$(ssh-keygen -Y verify -f "$tmp/allowed_signers" -I "$SIGNER" -n "$SIG_NAMESPACE" \ -s "$tmp/checksums.txt.sshsig" < "$tmp/checksums.txt" 2>&1); then info "signature verified (kosa8 release key)" elif printf '%s' "$out" | grep -Eqi "illegal option|unknown option|usage:"; then # OpenSSH before 8.1 has no -Y verify: as good as not installed. warn "this ssh-keygen cannot check signatures (OpenSSH 8.1 or later can), so the release signature was not checked (the checksum still is)" else die "the signature on checksums.txt does not verify — refusing to install" fi fi elif curl -fsSL -o "$tmp/checksums.txt.sig" "$base/checksums.txt.sig" 2>/dev/null; then if ! command -v cosign >/dev/null 2>&1; then warn "cosign is not installed, so the release signature was not checked (the checksum still is)" warn " install cosign to verify it: https://docs.sigstore.dev/cosign/installation" else curl -fsSL -o "$tmp/checksums.txt.pem" "$base/checksums.txt.pem" \ || die "checksums.txt is signed but its certificate is missing — refusing to install" cosign verify-blob \ --certificate "$tmp/checksums.txt.pem" \ --signature "$tmp/checksums.txt.sig" \ --certificate-identity-regexp "$SIGNER_IDENTITY" \ --certificate-oidc-issuer "$SIGNER_ISSUER" \ "$tmp/checksums.txt" >/dev/null 2>&1 \ || die "the signature on checksums.txt does not verify — refusing to install" info "signature verified" fi else info "this release has no signature over checksums.txt, so only the SHA-256 checksum is checked" fi # Exact name, whole field: `grep " $asset$"` with the name taken as a regex # would let the dots match anything; awk compares the string itself. expected=$(awk -v a="$asset" '$2 == a || $2 == "*" a { print $1; exit }' "$tmp/checksums.txt") [ -n "$expected" ] || die "checksums.txt has no entry for $asset — refusing to install unverified" if command -v sha256sum >/dev/null 2>&1; then actual=$(sha256sum "$tmp/$asset" | awk '{print $1}') elif command -v shasum >/dev/null 2>&1; then actual=$(shasum -a 256 "$tmp/$asset" | awk '{print $1}') else # Without a hashing tool the check below would report a "mismatch". die "sha256sum or shasum is needed to verify the download (Debian/Ubuntu: coreutils; Alpine: busybox or coreutils)" fi [ "$actual" = "$expected" ] || die "checksum mismatch for $asset — refusing to install" info "checksum verified" # ---- unpack ----------------------------------------------------------------- if [ "$ext" = "zip" ]; then need unzip unzip -qo "$tmp/$asset" -d "$tmp/x" else # -o: the files are owned by whoever runs this, never by the uid stored # in the archive (as root, tar would otherwise restore that uid). mkdir -p "$tmp/x" && tar -xzof "$tmp/$asset" -C "$tmp/x" fi # ---- install ---------------------------------------------------------------- # as_root runs a command with sudo, when this user cannot write to BINDIR. as_root() { if [ "$(id -u)" = 0 ]; then "$@" elif command -v sudo >/dev/null 2>&1; then sudo "$@" else die "writing to $BINDIR needs root, and sudo is not installed; rerun as root, or install for yourself: KOSA8_BINDIR=\$HOME/.local/bin" fi } # Copied in under a temporary name and renamed over the old binary. A rename # replaces a running kosa8d cleanly where writing into it fails ("text file # busy"), so running this again to upgrade works with the daemon up, and a # copy cut off half-way never leaves half a binary on the PATH. install_one() { src="$1" [ -f "$src" ] || return 0 name=$(basename "$src") chmod 0755 "$src" if [ -w "$BINDIR" ]; then cp "$src" "$BINDIR/.$name.new" mv -f "$BINDIR/.$name.new" "$BINDIR/$name" else info "writing $name to $BINDIR needs sudo" as_root cp "$src" "$BINDIR/.$name.new" as_root chown 0:0 "$BINDIR/.$name.new" 2>/dev/null || true as_root mv -f "$BINDIR/.$name.new" "$BINDIR/$name" fi info "installed $name" } mkdir -p "$BINDIR" 2>/dev/null || as_root mkdir -p "$BINDIR" # File capabilities belong to the file, and the rename below gives kosa8d a # new one: the network capabilities a person granted the old daemon would # silently go, and the next sandbox would fail with "Operation not # permitted". Note whether the old one had them, and put them back. SETCAP_ARGS="cap_net_admin,cap_net_raw+ep" had_caps=no if [ "$os" = Linux ] && [ -e "$BINDIR/kosa8d" ] && command -v getcap >/dev/null 2>&1 \ && getcap "$BINDIR/kosa8d" 2>/dev/null | grep -q cap_net_admin; then had_caps=yes fi install_one "$tmp/x/kosa8" if [ "$full_runtime" != no ]; then install_one "$tmp/x/kosa8d" fi if [ "$had_caps" = yes ]; then # as_root dies without sudo; check first so a missing sudo is a warning. if command -v setcap >/dev/null 2>&1 && { [ "$(id -u)" = 0 ] || command -v sudo >/dev/null 2>&1; } \ && as_root setcap "$SETCAP_ARGS" "$BINDIR/kosa8d"; then info "re-applied kosa8d's network capabilities (cap_net_admin, cap_net_raw)" else warn "the new kosa8d does not have the network capabilities the old one had; sandboxes fail until you run:" warn " sudo setcap $SETCAP_ARGS \"$BINDIR/kosa8d\"" fi fi # ---- confirm and explain ---------------------------------------------------- # `kosa8 self-update` runs this with KOSA8_SELF_UPDATE=1: an upgrade needs the # warnings above (PATH, capabilities) and nothing else, not the whole # first-install walkthrough again. kosa8 itself says "Updated to vX". if [ "${KOSA8_SELF_UPDATE:-}" = 1 ]; then case ":$PATH:" in *":$BINDIR:"*) ;; *) warn "$BINDIR is not on your PATH" ;; esac exit 0 fi # Sign-in is in the browser: `kosa8 login` opens it, and creates the account # (with a card on file) for someone new. SIGNIN="kosa8 login" say "" found=$(command -v kosa8 2>/dev/null || true) case ":$PATH:" in *":$BINDIR:"*) on_path=yes ;; *) on_path=no ;; esac if [ "$on_path" = no ]; then warn "$BINDIR is not on your PATH — add it to your shell profile:" warn " export PATH=\"$BINDIR:\$PATH\"" [ -z "$found" ] || warn " (until then \`kosa8\` runs the one at $found)" say "" elif [ "$found" != "$BINDIR/kosa8" ]; then # An older kosa8 earlier on the PATH would keep answering `kosa8`, and # `kosa8 version` would look as if this install had done nothing. warn "another kosa8, at $found, comes before $BINDIR on your PATH, so \`kosa8\` still runs that one." warn " remove it, or put $BINDIR first: export PATH=\"$BINDIR:\$PATH\"" say "" fi if [ "$full_runtime" = linux ]; then # The Linux engine runs each sandbox under Cloud Hypervisor on KVM. Say # what is missing now, rather than at the first `kosa8 run`. missing="" [ -r /dev/kvm ] && [ -w /dev/kvm ] || missing="$missing /dev/kvm is not usable: enable virtualization, then: sudo usermod -aG kvm \$USER (and log in again)" # The Cloud Hypervisor release kosa8 is tested with, pinned by version # and digest (the same pin as `kosa8 wsl setup`, internal/cli/wsl.go). # Distribution packages are often older. Printed, not run: it needs sudo. CH_VERSION=v53.0 CH_SHA256_AMD64=448af3d4e59b22c2987f7df94c213ad40fb53a10d437e42b5ee6c4fce7c29ecc CH_SHA256_ARM64=f192b510eea1c710cbc439d716bb0573c223fc463dbe3e6523788a2b7ef62850 CH_URL="https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/$CH_VERSION" if [ "$arch" = amd64 ]; then ch_asset=cloud-hypervisor-static ch_sum=$CH_SHA256_AMD64 else ch_asset=cloud-hypervisor-static-aarch64 ch_sum=$CH_SHA256_ARM64 fi ch_hint="curl -fsSLo /tmp/ch $CH_URL/$ch_asset && echo \"$ch_sum /tmp/ch\" | sha256sum -c && sudo install -m 0755 /tmp/ch /usr/local/bin/cloud-hypervisor" command -v cloud-hypervisor >/dev/null 2>&1 || missing="$missing cloud-hypervisor is not installed. kosa8 is tested with $CH_VERSION: $ch_hint" command -v virtiofsd >/dev/null 2>&1 || [ -x /usr/libexec/virtiofsd ] || missing="$missing virtiofsd is not installed (Debian/Ubuntu: sudo apt-get install virtiofsd)" if [ -n "$missing" ]; then warn "Installed. Before kosa8 can run sandboxes here:$missing" say "" fi if [ "$arch" = arm64 ]; then # linuxgate: the arm64 engine is off unless KOSA8_LINUX_ENGINE=1, # because it has not run on real KVM hardware yet. Say so here # rather than promise a `kosa8 run` that will refuse. warn "On arm64 Linux the local engine is experimental and off by default." warn " To try it, start the daemon with KOSA8_LINUX_ENGINE=1 (below). Or drive" warn " another machine (kosa8 worker join), or use kosa8 Cloud (kosa8 cloud sandbox create)." say "" DAEMON_START="KOSA8_LINUX_ENGINE=1 kosa8 daemon start" else DAEMON_START="kosa8 daemon start" fi say " Next: sign in (opens your browser to sign up or sign in)," say " give the daemon its two network capabilities, start it, and run one:" say "" say " $SIGNIN" say " sudo setcap $SETCAP_ARGS \"\$(command -v kosa8d)\"" say " $DAEMON_START" say " kosa8 run alpine echo hi" say "" say " kosa8 doctor checks all of this." elif [ "$full_runtime" = yes ]; then say " Next: sign in (opens your browser to sign up or sign in)," say " start the daemon, and run one:" say "" say " $SIGNIN" say " kosa8 daemon start" say " kosa8 run alpine echo hi" say "" say " kosa8 doctor checks this machine if anything fails." else say " Installed the command-line tool." say "" warn "This machine cannot run containers itself." say " kosa8 needs an Apple Silicon Mac or a Linux machine to do the actual" say " work. On that machine run \`kosa8 worker pair --url …\`, then here:" say "" say " kosa8 worker join k8w1.…" say " kosa8 ps" fi say "" say " kosa8 login signs in, or creates your account, in your browser. Starter" say " is free with no card (\$10 of kosa8 Cloud usage, no time limit); plans from \$29" say " a month. No browser here? kosa8 login --no-browser prints a link" say " and a code to open on any device. One account covers the CLI, the desktop" say " app, app.kosa8.com and kosa8 Cloud. Plans: https://kosa8.com/pricing/" say " Docs: https://docs.kosa8.com" say " The kosa8 weekly (agent security, every Monday): https://kosa8.com/blog/" say ""