#!/bin/sh # AgentAway host installer: curl -fsSL https://agentaway.xnngs.cn/install.sh | sh # # Downloads the host (one JavaScript file) from the AgentAway CDN, checks its SHA-256, puts an `agentaway` # command on the PATH, then runs it: it checks the machine, starts the host in the background (launchd on # macOS, a systemd user service on Linux) and shows a pairing code. Running this again updates the host; # pairings, the host's identity and its relay are kept. # # Source: onestack one-web/apps/agentawayxnngscn/public/install.sh; the host is published by # .claude/skills/deploy/agentaway/release-host.sh (docs/apps/agentaway/doc.mdx, the host's install section). # everything in a function: a download cut short runs nothing main() { set -eu CDN=${AGENTAWAY_CDN:-https://cn2.xnngs.cn/agentaway/host} HOME_DIR=${AGENTAWAY_HOME:-$HOME/.agentaway} say() { printf '%s\n' "$*"; } fail() { printf 'AgentAway: %s\n' "$*" >&2 exit 1 } case $(uname -s) in Darwin | Linux) ;; *) fail "this machine is $(uname -s): the host runs on macOS and Linux (on Windows, in WSL)" ;; esac command -v curl >/dev/null 2>&1 || fail "curl is needed" command -v node >/dev/null 2>&1 || fail "Node.js 22.5 or newer is needed: install it (https://nodejs.org), then run this again" NODE=$(command -v node) "$NODE" -e 'const [a, b] = process.versions.node.split(".").map(Number); process.exit(a > 22 || (a === 22 && b >= 5) ? 0 : 1)' || fail "Node.js 22.5 or newer is needed, this is $("$NODE" -v): update it, then run this again" latest=$(curl -fsSL "$CDN/latest.json?t=$(date +%s)") || fail "could not reach $CDN" read_json() { printf '%s' "$latest" | "$NODE" -e "let s='';process.stdin.on('data',d=>s+=d).on('end',()=>console.log(JSON.parse(s)['$1']))"; } version=$(read_json version) file=$(read_json file) sha=$(read_json sha256) mkdir -p "$HOME_DIR/cache" "$HOME_DIR/bin" chmod 700 "$HOME_DIR" host="$HOME_DIR/cache/agentaway-$version.mjs" say "Downloading AgentAway $version" curl -fsSL "$CDN/$file" -o "$host.part" || fail "could not download $CDN/$file" got=$("$NODE" -e "console.log(require('crypto').createHash('sha256').update(require('fs').readFileSync(process.argv[1])).digest('hex'))" "$host.part") [ "$got" = "$sha" ] || { rm -f "$host.part" fail "the download does not match its checksum: try again" } mv "$host.part" "$host" # older downloads are not needed for old in "$HOME_DIR"/cache/agentaway-*.mjs; do [ "$old" = "$host" ] || rm -f "$old"; done # the copy the command runs; the background service keeps its own copy at the same place cp "$host" "$HOME_DIR/bin/agentaway.js.part" && mv "$HOME_DIR/bin/agentaway.js.part" "$HOME_DIR/bin/agentaway.js" # an ES module named .js: Node before 22.7 reads it as one only when its folder says so printf '{ "type": "module" }\n' >"$HOME_DIR/bin/package.json" # the `agentaway` command: the first folder on the PATH this user can write, else ~/.local/bin dir= for d in "$HOME/.local/bin" "$HOME/bin" /opt/homebrew/bin /usr/local/bin; do case ":$PATH:" in *":$d:"*) [ -d "$d" ] && [ -w "$d" ] && dir=$d && break ;; esac done on_path=yes if [ -z "$dir" ]; then dir="$HOME/.local/bin" on_path=no mkdir -p "$dir" fi cat >"$dir/agentaway" <&2; exit 1; } exec "$NODE" "$HOME_DIR/bin/agentaway.js" "\$@" EOF chmod 755 "$dir/agentaway" say "Command: $dir/agentaway" if [ $on_path = no ]; then say " $dir is not on your PATH. Add it, then open a new terminal:" say " echo 'export PATH=\"$dir:\$PATH\"' >> ~/.$(basename "${SHELL:-sh}")rc" fi say "" # not the copy above: installing the service copies the file it is run from over that one # the pipe this script came through is not the terminal: give the host the terminal, when there is one if [ -t 1 ] && { : /dev/null; then exec "$NODE" "$host"