#!/usr/bin/env bash
# Install llm-pentest binary from GitHub releases
# Usage: curl -fsSL https://raw.githubusercontent.com/jcazako/llm-pentest/main/install.sh | bash
set -euo pipefail

REPO="jcazako/llm-pentest"

OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
ARCH="$(uname -m)"

case "$OS" in
  linux*)  OS="linux" ;;
  darwin*) OS="macos" ;;
  *)       echo "Unsupported OS: $OS"; exit 1 ;;
esac

case "$ARCH" in
  x86_64|amd64) ARCH="amd64" ;;
  arm64|aarch64) ARCH="arm64" ;;
  *)             echo "Unsupported arch: $ARCH"; exit 1 ;;
esac

TARGET="${OS}-${ARCH}"
LATEST=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name"' | cut -d'"' -f4)

URL="https://github.com/${REPO}/releases/download/${LATEST}/llm-pentest-${TARGET}"
INSTALL_DIR="${HOME}/.local/bin"

echo "Installing llm-pentest ${LATEST} (${TARGET})..."
mkdir -p "$INSTALL_DIR"
curl -fsSL "$URL" -o "${INSTALL_DIR}/llm-pentest"
chmod +x "${INSTALL_DIR}/llm-pentest"

echo "Installed to ${INSTALL_DIR}/llm-pentest"
if [[ ":$PATH:" != *":${INSTALL_DIR}:"* ]]; then
  echo "Add to PATH: export PATH=\"${INSTALL_DIR}:\$PATH\""
fi
