#!/bin/sh # AppShip Studio agent — install (or update) and start, for macOS and Linux. No admin rights needed. # curl -fsSL https://bestaso.app/agent/install.sh | sh # Everything goes to ~/.appship-studio-agent: a private Node.js if yours is missing or older than 22, and the agent. # The agent connects Studio on the web (https://bestaso.app/app/) to the projects and store keys on this computer; # it listens on 127.0.0.1 only. Remove it any time: rm -rf ~/.appship-studio-agent set -eu SITE="https://bestaso.app" DIR="$HOME/.appship-studio-agent" mkdir -p "$DIR/bin" say() { printf '\033[1m%s\033[0m\n' "$*"; } fail() { printf 'Error: %s\n' "$*" >&2; exit 1; } command -v curl >/dev/null || fail "curl is needed." command -v tar >/dev/null || fail "tar is needed." # 1. Node.js 22+: use yours, or download the official build once (checked against nodejs.org's checksums). NODE="" if command -v node >/dev/null && [ "$(node -p 'process.versions.node.split(".")[0]' 2>/dev/null || echo 0)" -ge 22 ]; then NODE="$(command -v node)" elif [ -x "$DIR/node/bin/node" ]; then NODE="$DIR/node/bin/node" else case "$(uname -s)" in Darwin) os=darwin ;; Linux) os=linux ;; *) fail "Unsupported system: $(uname -s)" ;; esac case "$(uname -m)" in arm64|aarch64) arch=arm64 ;; x86_64|amd64) arch=x64 ;; *) fail "Unsupported processor: $(uname -m)" ;; esac say "Downloading Node.js 22 (one time, about 30 MB)..." base="https://nodejs.org/dist/latest-v22.x" sums="$(curl -fsSL "$base/SHASUMS256.txt")" file="$(printf '%s\n' "$sums" | awk -v p="-$os-$arch.tar.gz" '$2 ~ p"$" {print $2; exit}')" [ -n "$file" ] || fail "No Node.js build for $os-$arch." tmp="$(mktemp -d)" curl -fsSL "$base/$file" -o "$tmp/node.tar.gz" want="$(printf '%s\n' "$sums" | awk -v f="$file" '$2 == f {print $1}')" got="$( (shasum -a 256 "$tmp/node.tar.gz" 2>/dev/null || sha256sum "$tmp/node.tar.gz") | awk '{print $1}')" [ "$want" = "$got" ] || fail "Node.js download did not match its checksum." rm -rf "$DIR/node" && mkdir -p "$DIR/node" tar -xzf "$tmp/node.tar.gz" -C "$DIR/node" --strip-components 1 rm -rf "$tmp" NODE="$DIR/node/bin/node" fi NPM="$(dirname "$NODE")/npm" [ -x "$NPM" ] || NPM="npm" # 2. The agent package, from https://bestaso.app (only when a newer one is published). latest="$(curl -fsSL "$SITE/agent/version.txt")" current="$(cat "$DIR/version.txt" 2>/dev/null || echo none)" if [ "$latest" != "$current" ]; then say "Installing AppShip Studio agent ${latest}..." curl -fsSL "$SITE/agent/appship-studio-agent-$latest.tgz" -o "$DIR/agent.tgz" PATH="$(dirname "$NODE"):$PATH" "$NPM" install --prefix "$DIR/app" --omit=dev --no-audit --no-fund --no-update-notifier --loglevel=error "$DIR/agent.tgz" >/dev/null rm -f "$DIR/agent.tgz" printf '%s\n' "$latest" > "$DIR/version.txt" fi # 3. A launcher, so next time it is just: ~/.appship-studio-agent/bin/appship-studio-agent cat > "$DIR/bin/appship-studio-agent" <