#!/usr/bin/env bash set -euo pipefail REPO_URL="https://gitea.nikos-dev.keskikuja.site/niko/ai-superpower.git" REPO_NAME="ai-superpower" RAW_URL="https://gitea.nikos-dev.keskikuja.site/niko/ai-superpower/raw/branch/main/apply.sh" # ── Bootstrap mode (curl | bash) ───────────────────────────────────────────── # BASH_SOURCE[0] is empty when piped through bash if [[ -z "${BASH_SOURCE[0]:-}" ]]; then DEV_ROOT="$PWD" # capture before exec replaces the process TARGET="$DEV_ROOT/$REPO_NAME" EXTRA_FLAGS="${1:-}" # pass through --update if provided if [[ -d "$TARGET" ]]; then PREV_COMMIT="$(git -C "$TARGET" rev-parse --short HEAD 2>/dev/null || echo "")" echo "\u2192 updating $REPO_NAME ..." git -C "$TARGET" pull || { echo "\u2717 git pull failed"; exit 1; } else PREV_COMMIT="" echo "\u2192 cloning $REPO_NAME into $TARGET ..." git clone "$REPO_URL" "$TARGET" || { echo "\u2717 git clone failed"; exit 1; } fi # Pass DEV_ROOT and PREV_COMMIT explicitly exec bash "$TARGET/apply.sh" --bootstrapped "$DEV_ROOT" ${EXTRA_FLAGS:+"$EXTRA_FLAGS"} "$PREV_COMMIT" fi # ── Guard — block direct invocation ────────────────────────────────────────── if [[ "${1:-}" != "--bootstrapped" ]]; then echo "✗ do not run this script directly." echo " run from your dev root folder:" echo "" echo " curl -fsSL $RAW_URL | bash # full setup" echo " curl -fsSL $RAW_URL | bash -s -- --update # update instructions only" echo "" exit 1 fi # ── Local mode ──────────────────────────────────────────────────────────────── SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" DEV_ROOT="${2:?DEV_ROOT not passed — re-run via curl}" AI_TARGET="$SCRIPT_DIR/.ai" TEMPLATE_MARKER="