#!/bin/bash

set -e

OS="$(uname -s)"
ARCH="$(uname -m)"

case "$OS" in
    Linux)
        BINARY_NAME="outpost67-linux"
        LATEST_URL="https://cli.outpost67.xyz/latest/linux"
        ;;
    Darwin)
        BINARY_NAME="outpost67-macos"
        LATEST_URL="https://cli.outpost67.xyz/latest/macos"
        ;;
    *)
        echo "Unsupported OS: $OS"
        exit 1
        ;;
esac

INSTALL_DIR="/usr/local/bin"
BIN_NAME="outpost67"

echo "Detected OS: $OS"
echo "Downloading latest binary from $LATEST_URL..."

curl -L -o "$BIN_NAME" "$LATEST_URL"

chmod +x "$BIN_NAME"

echo "Installing to $INSTALL_DIR (requires sudo)..."
sudo mv "$BIN_NAME" "$INSTALL_DIR/$BIN_NAME"

echo "Installation complete! Try running '$BIN_NAME --help'"
