#!/bin/sh set -eu version=0.2.0 base=${AGENTSOCKET_RELEASE_URL:-https://agentsocket.xyz/releases/$version} case "$(uname -s)" in Darwin) os=darwin;; Linux) os=linux;; *) echo 'Use the PowerShell installer on Windows.' >&2; exit 1;; esac case "$(uname -m)" in arm64|aarch64) arch=arm64;; x86_64|amd64) arch=x64;; *) echo 'Unsupported CPU architecture.' >&2; exit 1;; esac name=agentsocket-$os-$arch tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT HUP INT TERM curl -fsSL "$base/$name" -o "$tmp/$name" curl -fsSL "$base/SHA256SUMS" -o "$tmp/SHA256SUMS" expected=$(awk -v name="$name" '$2==name {print $1}' "$tmp/SHA256SUMS") [ ${#expected} -eq 64 ] || { echo 'Release checksum missing.' >&2; exit 1; } if command -v sha256sum >/dev/null 2>&1; then actual=$(sha256sum "$tmp/$name" | awk '{print $1}'); else actual=$(shasum -a 256 "$tmp/$name" | awk '{print $1}'); fi [ "$actual" = "$expected" ] || { echo 'Release checksum verification failed.' >&2; exit 1; } bin=${AGENTSOCKET_INSTALL_DIR:-} if [ -z "$bin" ]; then case ":$PATH:" in *":$HOME/.local/bin:"*) bin=$HOME/.local/bin;; esac if [ -z "$bin" ]; then previous_ifs=$IFS; IFS=: for candidate in $PATH; do case "$candidate" in "$HOME"/*|/usr/local/bin) if [ -d "$candidate" ] && [ -w "$candidate" ]; then if [ "$os" = darwin ]; then owner_uid=$(stat -f '%u' "$candidate"); mode=$(stat -f '%Lp' "$candidate"); else owner_uid=$(stat -c '%u' "$candidate"); mode=$(stat -c '%a' "$candidate"); fi case "$mode" in *2|*3|*6|*7) continue;; esac if [ "$owner_uid" = "$(id -u)" ]; then bin=$candidate; break; fi fi;; esac done IFS=$previous_ifs fi bin=${bin:-$HOME/.local/bin} fi mkdir -p "$bin"; chmod 755 "$tmp/$name"; mv "$tmp/$name" "$bin/agentsocket" # This installer is explicitly requested to make the command available in future shells. case ":$PATH:" in *":$bin:"*) ;; *) escaped=$(printf '%s' "$bin" | sed "s/'/'\\\\''/g") line="export PATH='$escaped':\$PATH" for profile in "$HOME/.profile" "$HOME/.bashrc" "$HOME/.zshrc"; do if ! [ -f "$profile" ] || ! grep -F "$line" "$profile" >/dev/null 2>&1; then printf '\n# AgentSocket CLI\n%s\n' "$line" >> "$profile"; fi done ;; esac "$bin/agentsocket" --help >/dev/null printf 'AgentSocket %s installed. Open a new terminal, then run:\n agentsocket login\n agentsocket connect\nCurrent terminal: %s/agentsocket login\n' "$version" "$bin"