#!/bin/sh # C-suite: puts the setup tool (one file, aim.mjs) in this folder and starts the setup. # # curl -fsSL https://app.csuite.is/install.sh | sh # curl -fsSL https://app.csuite.is/install.sh | sh -s -- --signup api,web (how accounts are made in this product: any of # web, api, cli, mcp, agent; handed on to the setup) # curl -fsSL https://app.csuite.is/install.sh | sh -s -- --download-only (or AIM_DOWNLOAD_ONLY=1: download and check, start nothing) # # What it does: # 1. checks that Node 18 or newer is here; # 2. downloads https://app.csuite.is/cli/aim.mjs into this folder; # 3. checks the file's SHA-256 against the one written below (the tool this platform serves now); # 4. runs: node aim.mjs setup --platform https://app.csuite.is (with --signup, when one was given) # That prints a link for a person to open. It opens no browser and changes none of your code. # Under a coding agent it stops there and says which command to run next. # What it never does: no sudo, no package install, nothing written outside this folder, nothing more is # handed to a shell. An aim.mjs that is already here and is a different file is left alone. # The whole script is one function, called on its last line with an end mark: a download that was cut off # anywhere, in the middle of that line too, runs nothing. # To undo: node aim.mjs uninstall (or delete aim.mjs). aim_install() { set -eu origin='https://app.csuite.is' want='d9a7805f041cab3bada7a2b1be4ddd535ed261aee29f91a4311254388929a387' only="${AIM_DOWNLOAD_ONLY:-}" signup='' value='' last='' for arg in "$@"; do last=$arg; done if [ "$last" != '--end-of-script' ]; then echo "install.sh: this copy of the script is not complete. Nothing was done. Download it again." >&2; exit 1; fi for arg in "$@"; do if [ -n "$value" ]; then signup=$arg; value=''; [ -n "$signup" ] || signup='-'; continue; fi case "$arg" in --download-only) only=1 ;; --signup) value=1 ;; --end-of-script) ;; *) echo "install.sh: unknown option: $arg (the options are --signup and --download-only)" >&2; exit 2 ;; esac done # --signup is handed to the tool as one word, and only when it is small letters and commas: nothing a shell reads. case "$signup" in *[!a-z,]*) echo "install.sh: --signup takes a list like api,web (any of web, api, cli, mcp, agent). Nothing was done." >&2; exit 2 ;; esac stop() { echo "install.sh: $*" >&2; exit 1; } sum() { node -e 'const c=require("crypto"),f=require("fs");process.stdout.write(c.createHash("sha256").update(f.readFileSync(process.argv[1])).digest("hex"))' "$1"; } command -v node >/dev/null 2>&1 || stop "Node.js was not found. Install Node 18 or newer, then run this again." major=$(node -p 'process.versions.node.split(".")[0]' 2>/dev/null || echo 0) case "$major" in ''|*[!0-9]*) major=0 ;; esac [ "$major" -ge 18 ] || stop "Node 18 or newer is needed. This is Node $(node -v 2>/dev/null || echo unknown)." if [ -e ./aim.mjs ] || [ -L ./aim.mjs ]; then if [ -L ./aim.mjs ] || [ ! -f ./aim.mjs ]; then stop "aim.mjs is here and is not a plain file. Nothing was changed."; fi have=$(sum ./aim.mjs) || stop "aim.mjs is here and could not be read. Nothing was changed." [ "$have" = "$want" ] || stop "A different aim.mjs is already in this folder. It was left alone. Move it away or delete it, then run this again." echo "aim.mjs is already here and is the tool this platform serves." else [ -w . ] || stop "This folder cannot be written to." tmp="./.aim-download.$$" trap 'rm -f "$tmp"' EXIT trap 'exit 1' HUP INT TERM if command -v curl >/dev/null 2>&1; then curl -fsSL "$origin/cli/aim.mjs" -o "$tmp" || stop "Could not download $origin/cli/aim.mjs" elif command -v wget >/dev/null 2>&1; then wget -q -O "$tmp" "$origin/cli/aim.mjs" || stop "Could not download $origin/cli/aim.mjs" else stop "curl or wget is needed to download the tool." fi got=$(sum "$tmp") || stop "The download could not be read." [ "$got" = "$want" ] || stop "The downloaded file is not the tool this platform names (its SHA-256 differs). Nothing was installed. Try again in a minute." mv "$tmp" ./aim.mjs trap - EXIT HUP INT TERM echo "Downloaded and checked: aim.mjs (SHA-256 $want)" fi if [ -n "$only" ]; then echo "Nothing was started. Next: node aim.mjs setup --platform $origin${signup:+ --signup $signup}" exit 0 fi code=0 # A person at a terminal: the tool reads the terminal and waits for the Allow. A coding agent's shell: it prints # the link and stops at once (the tool's exit code 3). if [ -t 1 ] && (exec /dev/null; then node ./aim.mjs setup --platform "$origin" ${signup:+--signup} ${signup:+"$signup"}