#!/usr/bin/env bash
# NextWeb CLI installer (BSD). Uses Linux x86_64 or aarch64 artifacts when applicable.
set -euo pipefail

CS_URL="${NEXTWEB_CONTENT_SERVER_URL:-http://localhost:4003}"
ARCH="$(uname -m)"
case "$ARCH" in
  amd64|x86_64) SLUG=x86_64 ;;
  aarch64|arm64) SLUG=aarch64 ;;
  *)
    echo "Unsupported architecture: $ARCH. Open ${CS_URL}/bin/manifest.json for options." >&2
    exit 1
    ;;
esac

DEST="${1:-./nextweb}"
echo "Downloading NextWeb (${SLUG}) from ${CS_URL} ..."
curl -fsSL "${CS_URL}/bin/${SLUG}/nextweb-latest" -o "$DEST"
chmod +x "$DEST"
echo "Installed: $DEST"
