#!/usr/bin/env bash # ZoarkBot Linux Installer # Usage: curl -sSL https://get.zoarkai.org | bash # bash install-linux.sh [LICENSE_KEY] set -euo pipefail INSTALL_DIR="${ZOARKBOT_INSTALL_DIR:-$HOME/.zoarkbot}" BIN_DIR="${ZOARKBOT_BIN_DIR:-$HOME/.local/bin}" LICENSE_SERVER="${ZOARKBOT_LICENSE_SERVER:-https://license.zoarkai.org}" RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m' CYAN='\033[0;36m'; BOLD='\033[1m'; NC='\033[0m' info() { echo -e "${CYAN}[zoarkbot]${NC} $*"; } ok() { echo -e "${GREEN}[✓]${NC} $*"; } warn() { echo -e "${YELLOW}[!]${NC} $*"; } die() { echo -e "${RED}[✗]${NC} $*" >&2; exit 1; } echo -e "\n${BOLD} ZoarkBot Installer${NC} · https://app.zoarkai.org\n" # ── Auto-install Node.js 22 if missing or too old ───────────────────────────── _install_node_linux() { info "Installing Node.js 22 via NodeSource..." if command -v apt-get >/dev/null 2>&1; then curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - \ && sudo apt-get install -y nodejs elif command -v dnf >/dev/null 2>&1; then curl -fsSL https://rpm.nodesource.com/setup_22.x | sudo bash - \ && sudo dnf install -y nodejs else die "Cannot auto-install Node.js. Install Node.js 22+ from https://nodejs.org then re-run." fi } # ── Node.js check ───────────────────────────────────────────────────────────── if ! command -v node >/dev/null 2>&1; then warn "Node.js not found — installing Node.js 22..." _install_node_linux fi NODE_MAJOR=$(node -e "process.stdout.write(process.versions.node.split('.')[0])") if [[ "$NODE_MAJOR" -lt 22 ]]; then warn "Node.js $(node --version) found — need 22+. Upgrading..." _install_node_linux fi ok "Node.js $(node --version)" # ── License key ──────────────────────────────────────────────────────────────── LICENSE_KEY="${1:-${ZOARKBOT_LICENSE_KEY:-}}" if [[ -z "$LICENSE_KEY" ]]; then echo -n " License key (from app.zoarkai.org): " read -r LICENSE_KEY fi LICENSE_KEY="${LICENSE_KEY^^}" if [[ ! "$LICENSE_KEY" =~ ^ZOARKBOT-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}$ ]]; then die "Invalid key format. Expected: ZOARKBOT-XXXX-XXXX-XXXX-XXXX" fi # ── Get signed download URL ──────────────────────────────────────────────────── info "Validating license..." HTTP_RESP=$(curl -sf --max-time 15 \ "${LICENSE_SERVER}/v1/account/download-url?os=linux&license_key=${LICENSE_KEY}") \ || die "Cannot reach license server. Check your connection." DOWNLOAD_URL=$(echo "$HTTP_RESP" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['url'])" 2>/dev/null) \ || die "License validation failed. Verify your key at app.zoarkai.org" # Validate URL is HTTPS before following it if [[ "$DOWNLOAD_URL" != https://* ]]; then die "License server returned an unsafe download URL. Aborting." fi ok "License valid" # ── Download ────────────────────────────────────────────────────────────────── info "Downloading ZoarkBot for Linux..." TMP=$(mktemp -d); trap 'rm -rf "$TMP"' EXIT curl -fL --proto '=https' --tlsv1.2 --progress-bar -o "$TMP/zoarkbot.tar.gz" "$DOWNLOAD_URL" \ || die "Download failed. Please try again." # Verify tarball is a valid gzip archive before extracting if ! python3 -c "import gzip,sys; gzip.open('$TMP/zoarkbot.tar.gz').read(1)" 2>/dev/null; then die "Downloaded file is corrupt or not a valid archive." fi # ── Install ─────────────────────────────────────────────────────────────────── info "Installing to ${INSTALL_DIR}..." rm -rf "${INSTALL_DIR}/dist" "${INSTALL_DIR}/node_modules" # clean old version mkdir -p "$INSTALL_DIR" tar -xzf "$TMP/zoarkbot.tar.gz" -C "$INSTALL_DIR" # ── Wrapper ─────────────────────────────────────────────────────────────────── mkdir -p "$BIN_DIR" cat > "$BIN_DIR/zoarkbot" </dev/null; then printf '\nexport PATH="%s:$PATH"\n' "$BIN_DIR" >> "$RC" break fi done export PATH="${BIN_DIR}:$PATH" # ── Activate ────────────────────────────────────────────────────────────────── info "Activating license on this machine..." node "${INSTALL_DIR}/zoarkbot.mjs" license activate "$LICENSE_KEY" \ || warn "Auto-activation failed. Run: zoarkbot license activate ${LICENSE_KEY}" ok "ZoarkBot installed successfully!" echo "" echo -e " ${BOLD}zoarkbot gateway${NC} — start the AI gateway" echo -e " ${BOLD}zoarkbot mc${NC} — open Mission Control" echo "" warn "Reload shell or run: export PATH=\"${BIN_DIR}:\$PATH\""