#!/usr/bin/env bash
set -euo pipefail

# Cross-platform wrapper to run installers or show instructions.
# Usage: ./run_installers.sh [--preview]

PREVIEW=0
if [ "${1:-}" = "--preview" ]; then PREVIEW=1; fi

is_wsl() {
  grep -qi microsoft /proc/version 2>/dev/null || grep -qi microsoft /proc/sys/kernel/osrelease 2>/dev/null
}

echo "Cross-platform installer helper"
if is_wsl; then
  echo "Detected WSL/Ubuntu environment."
  if [ "$PREVIEW" -eq 1 ]; then
    echo "Preview mode: showing installers to be executed by install_clis_wsl.sh"
    sed -n '1,120p' install_clis_wsl.sh
    exit 0
  fi
  read -rp "Run the interactive WSL installer (install_clis_wsl.sh)? [y/N]: " ans
  case "$ans" in
    [Yy]*) bash -i ./install_clis_wsl.sh ;;
    *) echo "Cancelled by user."; exit 0 ;;
  esac
else
  echo "Not in WSL. Recommended flows:"
  echo "- Run this from Windows PowerShell using WSL: wsl bash -ic 'cd /mnt/d/SANDBOX/mygh/learning_ai_devops_tools && bash -i ./install_clis_wsl.sh'"
  echo "- On macOS or Linux, inspect install_clis_wsl.sh and run it in a bash login shell after review."
  exit 0
fi
