install.sh 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333
  1. #!/usr/bin/env bash
  2. #############################################################################
  3. # OpenAgents Installer
  4. # Interactive installer for OpenCode agents, commands, tools, and plugins
  5. #
  6. # Compatible with:
  7. # - macOS (bash 3.2+)
  8. # - Linux (bash 3.2+)
  9. # - Windows (Git Bash, WSL)
  10. #############################################################################
  11. set -e
  12. # Detect platform
  13. PLATFORM="$(uname -s)"
  14. case "$PLATFORM" in
  15. Linux*) PLATFORM="Linux";;
  16. Darwin*) PLATFORM="macOS";;
  17. CYGWIN*|MINGW*|MSYS*) PLATFORM="Windows";;
  18. *) PLATFORM="Unknown";;
  19. esac
  20. # Colors for output (disable on Windows if not supported)
  21. if [ "$PLATFORM" = "Windows" ] && [ -z "$WT_SESSION" ] && [ -z "$ConEmuPID" ]; then
  22. # Basic Windows terminal without color support
  23. RED=''
  24. GREEN=''
  25. YELLOW=''
  26. BLUE=''
  27. MAGENTA=''
  28. CYAN=''
  29. BOLD=''
  30. NC=''
  31. else
  32. RED='\033[0;31m'
  33. GREEN='\033[0;32m'
  34. YELLOW='\033[1;33m'
  35. BLUE='\033[0;34m'
  36. MAGENTA='\033[0;35m'
  37. CYAN='\033[0;36m'
  38. BOLD='\033[1m'
  39. NC='\033[0m' # No Color
  40. fi
  41. # Configuration
  42. REPO_URL="https://github.com/darrenhinde/OpenAgents"
  43. BRANCH="${OPENCODE_BRANCH:-main}" # Allow override via environment variable
  44. RAW_URL="https://raw.githubusercontent.com/darrenhinde/OpenAgents/${BRANCH}"
  45. # Registry URL - supports local fallback for development
  46. # Priority: 1) REGISTRY_URL env var, 2) Local registry.json, 3) Remote GitHub
  47. if [ -n "$REGISTRY_URL" ]; then
  48. # Use explicitly set REGISTRY_URL (for testing)
  49. :
  50. elif [ -f "./registry.json" ]; then
  51. # Use local registry.json if it exists (for development)
  52. REGISTRY_URL="file://$(pwd)/registry.json"
  53. else
  54. # Default to remote GitHub registry
  55. REGISTRY_URL="${RAW_URL}/registry.json"
  56. fi
  57. INSTALL_DIR="${OPENCODE_INSTALL_DIR:-.opencode}" # Allow override via environment variable
  58. TEMP_DIR="/tmp/opencode-installer-$$"
  59. # Cleanup temp directory on exit (success or failure)
  60. trap 'rm -rf "$TEMP_DIR" 2>/dev/null || true' EXIT INT TERM
  61. # Global variables
  62. SELECTED_COMPONENTS=()
  63. INSTALL_MODE=""
  64. PROFILE=""
  65. NON_INTERACTIVE=false
  66. CUSTOM_INSTALL_DIR="" # Set via --install-dir argument
  67. #############################################################################
  68. # Utility Functions
  69. #############################################################################
  70. jq_exec() {
  71. local output
  72. output=$(jq -r "$@")
  73. local ret=$?
  74. printf "%s\n" "$output" | tr -d '\r'
  75. return $ret
  76. }
  77. print_header() {
  78. echo -e "${CYAN}${BOLD}"
  79. echo "╔════════════════════════════════════════════════════════════════╗"
  80. echo "║ ║"
  81. echo "║ OpenAgents Installer v1.0.0 ║"
  82. echo "║ ║"
  83. echo "╚════════════════════════════════════════════════════════════════╝"
  84. echo -e "${NC}"
  85. }
  86. print_success() {
  87. echo -e "${GREEN}✓${NC} $1"
  88. }
  89. print_error() {
  90. echo -e "${RED}✗${NC} $1"
  91. }
  92. print_info() {
  93. echo -e "${BLUE}ℹ${NC} $1"
  94. }
  95. print_warning() {
  96. echo -e "${YELLOW}⚠${NC} $1"
  97. }
  98. print_step() {
  99. echo -e "\n${MAGENTA}${BOLD}▶${NC} $1\n"
  100. }
  101. #############################################################################
  102. # Path Handling (Cross-Platform)
  103. #############################################################################
  104. normalize_and_validate_path() {
  105. local input_path="$1"
  106. local normalized_path
  107. # Handle empty path
  108. if [ -z "$input_path" ]; then
  109. echo ""
  110. return 1
  111. fi
  112. # Expand tilde to $HOME (works on Linux, macOS, Windows Git Bash)
  113. if [[ $input_path == ~* ]]; then
  114. normalized_path="${HOME}${input_path:1}"
  115. else
  116. normalized_path="$input_path"
  117. fi
  118. # Convert backslashes to forward slashes (Windows compatibility)
  119. normalized_path="${normalized_path//\\//}"
  120. # Remove trailing slashes
  121. normalized_path="${normalized_path%/}"
  122. # If path is relative, make it absolute based on current directory
  123. if [[ ! "$normalized_path" = /* ]] && [[ ! "$normalized_path" =~ ^[A-Za-z]: ]]; then
  124. normalized_path="$(pwd)/${normalized_path}"
  125. fi
  126. echo "$normalized_path"
  127. return 0
  128. }
  129. validate_install_path() {
  130. local path="$1"
  131. local parent_dir
  132. # Get parent directory
  133. parent_dir="$(dirname "$path")"
  134. # Check if parent directory exists
  135. if [ ! -d "$parent_dir" ]; then
  136. print_error "Parent directory does not exist: $parent_dir"
  137. return 1
  138. fi
  139. # Check if parent directory is writable
  140. if [ ! -w "$parent_dir" ]; then
  141. print_error "No write permission for directory: $parent_dir"
  142. return 1
  143. fi
  144. # If target directory exists, check if it's writable
  145. if [ -d "$path" ] && [ ! -w "$path" ]; then
  146. print_error "No write permission for directory: $path"
  147. return 1
  148. fi
  149. return 0
  150. }
  151. get_global_install_path() {
  152. # Return platform-appropriate global installation path
  153. case "$PLATFORM" in
  154. macOS)
  155. # macOS: Use XDG standard (consistent with Linux)
  156. echo "${HOME}/.config/opencode"
  157. ;;
  158. Linux)
  159. echo "${HOME}/.config/opencode"
  160. ;;
  161. Windows)
  162. # Windows Git Bash/WSL: Use same as Linux
  163. echo "${HOME}/.config/opencode"
  164. ;;
  165. *)
  166. echo "${HOME}/.config/opencode"
  167. ;;
  168. esac
  169. }
  170. #############################################################################
  171. # Dependency Checks
  172. #############################################################################
  173. check_bash_version() {
  174. # Check bash version (need 3.2+)
  175. local bash_version="${BASH_VERSION%%.*}"
  176. if [ "$bash_version" -lt 3 ]; then
  177. echo "Error: This script requires Bash 3.2 or higher"
  178. echo "Current version: $BASH_VERSION"
  179. echo ""
  180. echo "Please upgrade bash or use a different shell:"
  181. echo " macOS: brew install bash"
  182. echo " Linux: Use your package manager to update bash"
  183. echo " Windows: Use Git Bash or WSL"
  184. exit 1
  185. fi
  186. }
  187. check_dependencies() {
  188. print_step "Checking dependencies..."
  189. local missing_deps=()
  190. if ! command -v curl &> /dev/null; then
  191. missing_deps+=("curl")
  192. fi
  193. if ! command -v jq &> /dev/null; then
  194. missing_deps+=("jq")
  195. fi
  196. if [ ${#missing_deps[@]} -ne 0 ]; then
  197. print_error "Missing required dependencies: ${missing_deps[*]}"
  198. echo ""
  199. echo "Please install them:"
  200. case "$PLATFORM" in
  201. macOS)
  202. echo " brew install ${missing_deps[*]}"
  203. ;;
  204. Linux)
  205. echo " Ubuntu/Debian: sudo apt-get install ${missing_deps[*]}"
  206. echo " Fedora/RHEL: sudo dnf install ${missing_deps[*]}"
  207. echo " Arch: sudo pacman -S ${missing_deps[*]}"
  208. ;;
  209. Windows)
  210. echo " Git Bash: Install via https://git-scm.com/"
  211. echo " WSL: sudo apt-get install ${missing_deps[*]}"
  212. echo " Scoop: scoop install ${missing_deps[*]}"
  213. ;;
  214. *)
  215. echo " Use your package manager to install: ${missing_deps[*]}"
  216. ;;
  217. esac
  218. exit 1
  219. fi
  220. print_success "All dependencies found"
  221. }
  222. #############################################################################
  223. # Registry Functions
  224. #############################################################################
  225. fetch_registry() {
  226. print_step "Fetching component registry..."
  227. mkdir -p "$TEMP_DIR"
  228. # Handle local file:// URLs
  229. if [[ "$REGISTRY_URL" == file://* ]]; then
  230. local local_path="${REGISTRY_URL#file://}"
  231. if [ -f "$local_path" ]; then
  232. cp "$local_path" "$TEMP_DIR/registry.json"
  233. print_success "Using local registry: $local_path"
  234. else
  235. print_error "Local registry not found: $local_path"
  236. exit 1
  237. fi
  238. else
  239. # Fetch from remote URL
  240. if ! curl -fsSL "$REGISTRY_URL" -o "$TEMP_DIR/registry.json"; then
  241. print_error "Failed to fetch registry from $REGISTRY_URL"
  242. exit 1
  243. fi
  244. print_success "Registry fetched successfully"
  245. fi
  246. }
  247. get_profile_components() {
  248. local profile=$1
  249. jq_exec ".profiles.${profile}.components[]?" "$TEMP_DIR/registry.json"
  250. }
  251. get_component_info() {
  252. local component_id=$1
  253. local component_type=$2
  254. jq_exec ".components.${component_type}[]? | select(.id == \"${component_id}\")" "$TEMP_DIR/registry.json"
  255. }
  256. # Helper function to get the correct registry key for a component type
  257. get_registry_key() {
  258. local type=$1
  259. # Most types are pluralized, but 'config' stays singular
  260. case "$type" in
  261. config) echo "config" ;;
  262. *) echo "${type}s" ;;
  263. esac
  264. }
  265. # Helper function to convert registry path to installation path
  266. # Registry paths are like ".opencode/agent/foo.md"
  267. # We need to replace ".opencode" with the actual INSTALL_DIR
  268. get_install_path() {
  269. local registry_path=$1
  270. # Strip leading .opencode/ if present
  271. local relative_path="${registry_path#.opencode/}"
  272. # Return INSTALL_DIR + relative path
  273. echo "${INSTALL_DIR}/${relative_path}"
  274. }
  275. resolve_dependencies() {
  276. local component=$1
  277. local type="${component%%:*}"
  278. local id="${component##*:}"
  279. # Get the correct registry key (handles singular/plural)
  280. local registry_key
  281. registry_key=$(get_registry_key "$type")
  282. # Get dependencies for this component
  283. local deps
  284. deps=$(jq_exec ".components.${registry_key}[] | select(.id == \"${id}\") | .dependencies[]?" "$TEMP_DIR/registry.json" 2>/dev/null || echo "")
  285. if [ -n "$deps" ]; then
  286. for dep in $deps; do
  287. # Add dependency if not already in list
  288. local found=0
  289. for existing in "${SELECTED_COMPONENTS[@]}"; do
  290. if [ "$existing" = "$dep" ]; then
  291. found=1
  292. break
  293. fi
  294. done
  295. if [ "$found" -eq 0 ]; then
  296. SELECTED_COMPONENTS+=("$dep")
  297. # Recursively resolve dependencies
  298. resolve_dependencies "$dep"
  299. fi
  300. done
  301. fi
  302. }
  303. #############################################################################
  304. # Installation Mode Selection
  305. #############################################################################
  306. check_interactive_mode() {
  307. # Check if stdin is a terminal (not piped from curl)
  308. if [ ! -t 0 ]; then
  309. print_header
  310. print_error "Interactive mode requires a terminal"
  311. echo ""
  312. echo "You're running this script in a pipe (e.g., curl | bash)"
  313. echo "For interactive mode, download the script first:"
  314. echo ""
  315. echo -e "${CYAN}# Download the script${NC}"
  316. echo "curl -fsSL https://raw.githubusercontent.com/darrenhinde/OpenAgents/main/install.sh -o install.sh"
  317. echo ""
  318. echo -e "${CYAN}# Run interactively${NC}"
  319. echo "bash install.sh"
  320. echo ""
  321. echo "Or use a profile directly:"
  322. echo ""
  323. echo -e "${CYAN}# Quick install with profile${NC}"
  324. echo "curl -fsSL https://raw.githubusercontent.com/darrenhinde/OpenAgents/main/install.sh | bash -s essential"
  325. echo ""
  326. echo "Available profiles: essential, developer, business, full, advanced"
  327. echo ""
  328. cleanup_and_exit 1
  329. fi
  330. }
  331. show_install_location_menu() {
  332. check_interactive_mode
  333. clear
  334. print_header
  335. local global_path
  336. global_path=$(get_global_install_path)
  337. echo -e "${BOLD}Choose installation location:${NC}\n"
  338. echo -e " ${GREEN}1) Local${NC} - Install to ${CYAN}.opencode/${NC} in current directory"
  339. echo " (Best for project-specific agents)"
  340. echo ""
  341. echo -e " ${BLUE}2) Global${NC} - Install to ${CYAN}${global_path}${NC}"
  342. echo " (Best for user-wide agents available everywhere)"
  343. echo ""
  344. echo -e " ${MAGENTA}3) Custom${NC} - Enter exact path"
  345. echo " Examples:"
  346. case "$PLATFORM" in
  347. Windows)
  348. echo " ${CYAN}C:/Users/username/my-agents${NC} or ${CYAN}~/my-agents${NC}"
  349. ;;
  350. *)
  351. echo " ${CYAN}/home/username/my-agents${NC} or ${CYAN}~/my-agents${NC}"
  352. ;;
  353. esac
  354. echo ""
  355. echo " 4) Back / Exit"
  356. echo ""
  357. read -p "Enter your choice [1-4]: " location_choice
  358. case $location_choice in
  359. 1)
  360. INSTALL_DIR=".opencode"
  361. print_success "Installing to local directory: .opencode/"
  362. sleep 1
  363. ;;
  364. 2)
  365. INSTALL_DIR="$global_path"
  366. print_success "Installing to global directory: $global_path"
  367. sleep 1
  368. ;;
  369. 3)
  370. echo ""
  371. read -p "Enter installation path: " custom_path
  372. if [ -z "$custom_path" ]; then
  373. print_error "No path entered"
  374. sleep 2
  375. show_install_location_menu
  376. return
  377. fi
  378. local normalized_path
  379. normalized_path=$(normalize_and_validate_path "$custom_path")
  380. if [ $? -ne 0 ]; then
  381. print_error "Invalid path"
  382. sleep 2
  383. show_install_location_menu
  384. return
  385. fi
  386. if ! validate_install_path "$normalized_path"; then
  387. echo ""
  388. read -p "Continue anyway? [y/N]: " continue_choice
  389. if [[ ! $continue_choice =~ ^[Yy] ]]; then
  390. show_install_location_menu
  391. return
  392. fi
  393. fi
  394. INSTALL_DIR="$normalized_path"
  395. print_success "Installing to custom directory: $INSTALL_DIR"
  396. sleep 1
  397. ;;
  398. 4)
  399. cleanup_and_exit 0
  400. ;;
  401. *)
  402. print_error "Invalid choice"
  403. sleep 2
  404. show_install_location_menu
  405. return
  406. ;;
  407. esac
  408. }
  409. show_main_menu() {
  410. check_interactive_mode
  411. clear
  412. print_header
  413. echo -e "${BOLD}Choose installation mode:${NC}\n"
  414. echo " 1) Quick Install (Choose a profile)"
  415. echo " 2) Custom Install (Pick individual components)"
  416. echo " 3) List Available Components"
  417. echo " 4) Exit"
  418. echo ""
  419. read -p "Enter your choice [1-4]: " choice
  420. case $choice in
  421. 1) INSTALL_MODE="profile" ;;
  422. 2) INSTALL_MODE="custom" ;;
  423. 3) list_components; read -p "Press Enter to continue..."; show_main_menu ;;
  424. 4) cleanup_and_exit 0 ;;
  425. *) print_error "Invalid choice"; sleep 2; show_main_menu ;;
  426. esac
  427. }
  428. #############################################################################
  429. # Profile Installation
  430. #############################################################################
  431. show_profile_menu() {
  432. clear
  433. print_header
  434. echo -e "${BOLD}Available Installation Profiles:${NC}\n"
  435. # Essential profile
  436. local essential_name
  437. essential_name=$(jq_exec '.profiles.essential.name' "$TEMP_DIR/registry.json")
  438. local essential_desc
  439. essential_desc=$(jq_exec '.profiles.essential.description' "$TEMP_DIR/registry.json")
  440. local essential_count
  441. essential_count=$(jq_exec '.profiles.essential.components | length' "$TEMP_DIR/registry.json")
  442. echo -e " ${GREEN}1) ${essential_name}${NC}"
  443. echo -e " ${essential_desc}"
  444. echo -e " Components: ${essential_count}\n"
  445. # Developer profile
  446. local dev_desc
  447. dev_desc=$(jq_exec '.profiles.developer.description' "$TEMP_DIR/registry.json")
  448. local dev_count
  449. dev_count=$(jq_exec '.profiles.developer.components | length' "$TEMP_DIR/registry.json")
  450. local dev_badge
  451. dev_badge=$(jq_exec '.profiles.developer.badge // ""' "$TEMP_DIR/registry.json")
  452. if [ -n "$dev_badge" ]; then
  453. echo -e " ${BLUE}2) Developer ${GREEN}[${dev_badge}]${NC}"
  454. else
  455. echo -e " ${BLUE}2) Developer${NC}"
  456. fi
  457. echo -e " ${dev_desc}"
  458. echo -e " Components: ${dev_count}\n"
  459. # Business profile
  460. local business_name
  461. business_name=$(jq_exec '.profiles.business.name' "$TEMP_DIR/registry.json")
  462. local business_desc
  463. business_desc=$(jq_exec '.profiles.business.description' "$TEMP_DIR/registry.json")
  464. local business_count
  465. business_count=$(jq_exec '.profiles.business.components | length' "$TEMP_DIR/registry.json")
  466. echo -e " ${CYAN}3) ${business_name}${NC}"
  467. echo -e " ${business_desc}"
  468. echo -e " Components: ${business_count}\n"
  469. # Full profile
  470. local full_name
  471. full_name=$(jq_exec '.profiles.full.name' "$TEMP_DIR/registry.json")
  472. local full_desc
  473. full_desc=$(jq_exec '.profiles.full.description' "$TEMP_DIR/registry.json")
  474. local full_count
  475. full_count=$(jq_exec '.profiles.full.components | length' "$TEMP_DIR/registry.json")
  476. echo -e " ${MAGENTA}4) ${full_name}${NC}"
  477. echo -e " ${full_desc}"
  478. echo -e " Components: ${full_count}\n"
  479. # Advanced profile
  480. local adv_name
  481. adv_name=$(jq_exec '.profiles.advanced.name' "$TEMP_DIR/registry.json")
  482. local adv_desc
  483. adv_desc=$(jq_exec '.profiles.advanced.description' "$TEMP_DIR/registry.json")
  484. local adv_count
  485. adv_count=$(jq_exec '.profiles.advanced.components | length' "$TEMP_DIR/registry.json")
  486. echo -e " ${YELLOW}5) ${adv_name}${NC}"
  487. echo -e " ${adv_desc}"
  488. echo -e " Components: ${adv_count}\n"
  489. echo " 6) Back to main menu"
  490. echo ""
  491. read -p "Enter your choice [1-6]: " choice
  492. case $choice in
  493. 1) PROFILE="essential" ;;
  494. 2) PROFILE="developer" ;;
  495. 3) PROFILE="business" ;;
  496. 4) PROFILE="full" ;;
  497. 5) PROFILE="advanced" ;;
  498. 6) show_main_menu; return ;;
  499. *) print_error "Invalid choice"; sleep 2; show_profile_menu; return ;;
  500. esac
  501. # Load profile components (compatible with bash 3.2+)
  502. SELECTED_COMPONENTS=()
  503. local temp_file="$TEMP_DIR/components.tmp"
  504. get_profile_components "$PROFILE" > "$temp_file"
  505. while IFS= read -r component; do
  506. [ -n "$component" ] && SELECTED_COMPONENTS+=("$component")
  507. done < "$temp_file"
  508. # Resolve dependencies for profile installs
  509. print_step "Resolving dependencies..."
  510. local original_count=${#SELECTED_COMPONENTS[@]}
  511. for comp in "${SELECTED_COMPONENTS[@]}"; do
  512. resolve_dependencies "$comp"
  513. done
  514. local new_count=${#SELECTED_COMPONENTS[@]}
  515. if [ "$new_count" -gt "$original_count" ]; then
  516. local added=$((new_count - original_count))
  517. print_info "Added $added dependencies"
  518. fi
  519. show_installation_preview
  520. }
  521. #############################################################################
  522. # Custom Component Selection
  523. #############################################################################
  524. show_custom_menu() {
  525. clear
  526. print_header
  527. echo -e "${BOLD}Select component categories to install:${NC}\n"
  528. echo "Use space to toggle, Enter to continue"
  529. echo ""
  530. local categories=("agents" "subagents" "commands" "tools" "plugins" "skills" "contexts" "config")
  531. local selected_categories=()
  532. # Simple selection (for now, we'll make it interactive later)
  533. echo "Available categories:"
  534. for i in "${!categories[@]}"; do
  535. local cat="${categories[$i]}"
  536. local count
  537. count=$(jq_exec ".components.${cat} | length" "$TEMP_DIR/registry.json")
  538. local cat_display
  539. cat_display=$(echo "$cat" | awk '{print toupper(substr($0,1,1)) tolower(substr($0,2))}')
  540. echo " $((i+1))) ${cat_display} (${count} available)"
  541. done
  542. echo " $((${#categories[@]}+1))) Select All"
  543. echo " $((${#categories[@]}+2))) Continue to component selection"
  544. echo " $((${#categories[@]}+3))) Back to main menu"
  545. echo ""
  546. read -p "Enter category numbers (space-separated) or option: " -a selections
  547. for sel in "${selections[@]}"; do
  548. if [ "$sel" -eq $((${#categories[@]}+1)) ]; then
  549. selected_categories=("${categories[@]}")
  550. break
  551. elif [ "$sel" -eq $((${#categories[@]}+2)) ]; then
  552. break
  553. elif [ "$sel" -eq $((${#categories[@]}+3)) ]; then
  554. show_main_menu
  555. return
  556. elif [ "$sel" -ge 1 ] && [ "$sel" -le ${#categories[@]} ]; then
  557. selected_categories+=("${categories[$((sel-1))]}")
  558. fi
  559. done
  560. if [ ${#selected_categories[@]} -eq 0 ]; then
  561. print_warning "No categories selected"
  562. sleep 2
  563. show_custom_menu
  564. return
  565. fi
  566. show_component_selection "${selected_categories[@]}"
  567. }
  568. show_component_selection() {
  569. local categories=("$@")
  570. clear
  571. print_header
  572. echo -e "${BOLD}Select components to install:${NC}\n"
  573. local all_components=()
  574. local component_details=()
  575. for category in "${categories[@]}"; do
  576. local cat_display
  577. cat_display=$(echo "$category" | awk '{print toupper(substr($0,1,1)) tolower(substr($0,2))}')
  578. echo -e "${CYAN}${BOLD}${cat_display}:${NC}"
  579. local components
  580. components=$(jq_exec ".components.${category}[]? | .id" "$TEMP_DIR/registry.json")
  581. local idx=1
  582. while IFS= read -r comp_id; do
  583. local comp_name
  584. comp_name=$(jq_exec ".components.${category}[]? | select(.id == \"${comp_id}\") | .name" "$TEMP_DIR/registry.json")
  585. local comp_desc
  586. comp_desc=$(jq_exec ".components.${category}[]? | select(.id == \"${comp_id}\") | .description" "$TEMP_DIR/registry.json")
  587. echo " ${idx}) ${comp_name}"
  588. echo " ${comp_desc}"
  589. all_components+=("${category}:${comp_id}")
  590. component_details+=("${comp_name}|${comp_desc}")
  591. idx=$((idx+1))
  592. done <<< "$components"
  593. echo ""
  594. done
  595. echo "Enter component numbers (space-separated), 'all' for all, or 'done' to continue:"
  596. read -a selections
  597. for sel in "${selections[@]}"; do
  598. if [ "$sel" = "all" ]; then
  599. SELECTED_COMPONENTS=("${all_components[@]}")
  600. break
  601. elif [ "$sel" = "done" ]; then
  602. break
  603. elif [ "$sel" -ge 1 ] && [ "$sel" -le ${#all_components[@]} ]; then
  604. SELECTED_COMPONENTS+=("${all_components[$((sel-1))]}")
  605. fi
  606. done
  607. if [ ${#SELECTED_COMPONENTS[@]} -eq 0 ]; then
  608. print_warning "No components selected"
  609. sleep 2
  610. show_custom_menu
  611. return
  612. fi
  613. # Resolve dependencies
  614. print_step "Resolving dependencies..."
  615. local original_count=${#SELECTED_COMPONENTS[@]}
  616. for comp in "${SELECTED_COMPONENTS[@]}"; do
  617. resolve_dependencies "$comp"
  618. done
  619. if [ ${#SELECTED_COMPONENTS[@]} -gt $original_count ]; then
  620. print_info "Added $((${#SELECTED_COMPONENTS[@]} - original_count)) dependencies"
  621. fi
  622. show_installation_preview
  623. }
  624. #############################################################################
  625. # Installation Preview & Confirmation
  626. #############################################################################
  627. show_installation_preview() {
  628. # Only clear screen in interactive mode
  629. if [ "$NON_INTERACTIVE" != true ]; then
  630. clear
  631. fi
  632. print_header
  633. echo -e "${BOLD}Installation Preview${NC}\n"
  634. if [ -n "$PROFILE" ]; then
  635. echo -e "Profile: ${GREEN}${PROFILE}${NC}"
  636. else
  637. echo -e "Mode: ${GREEN}Custom${NC}"
  638. fi
  639. echo -e "Installation directory: ${CYAN}${INSTALL_DIR}${NC}"
  640. echo -e "\nComponents to install (${#SELECTED_COMPONENTS[@]} total):\n"
  641. # Group by type
  642. local agents=()
  643. local subagents=()
  644. local commands=()
  645. local tools=()
  646. local plugins=()
  647. local skills=()
  648. local contexts=()
  649. local configs=()
  650. for comp in "${SELECTED_COMPONENTS[@]}"; do
  651. local type="${comp%%:*}"
  652. case $type in
  653. agent) agents+=("$comp") ;;
  654. subagent) subagents+=("$comp") ;;
  655. command) commands+=("$comp") ;;
  656. tool) tools+=("$comp") ;;
  657. plugin) plugins+=("$comp") ;;
  658. skill) skills+=("$comp") ;;
  659. context) contexts+=("$comp") ;;
  660. config) configs+=("$comp") ;;
  661. esac
  662. done
  663. [ ${#agents[@]} -gt 0 ] && echo -e "${CYAN}Agents (${#agents[@]}):${NC} ${agents[*]##*:}"
  664. [ ${#subagents[@]} -gt 0 ] && echo -e "${CYAN}Subagents (${#subagents[@]}):${NC} ${subagents[*]##*:}"
  665. [ ${#commands[@]} -gt 0 ] && echo -e "${CYAN}Commands (${#commands[@]}):${NC} ${commands[*]##*:}"
  666. [ ${#tools[@]} -gt 0 ] && echo -e "${CYAN}Tools (${#tools[@]}):${NC} ${tools[*]##*:}"
  667. [ ${#plugins[@]} -gt 0 ] && echo -e "${CYAN}Plugins (${#plugins[@]}):${NC} ${plugins[*]##*:}"
  668. [ ${#skills[@]} -gt 0 ] && echo -e "${CYAN}Skills (${#skills[@]}):${NC} ${skills[*]##*:}"
  669. [ ${#contexts[@]} -gt 0 ] && echo -e "${CYAN}Contexts (${#contexts[@]}):${NC} ${contexts[*]##*:}"
  670. [ ${#configs[@]} -gt 0 ] && echo -e "${CYAN}Config (${#configs[@]}):${NC} ${configs[*]##*:}"
  671. echo ""
  672. # Skip confirmation if profile was provided via command line
  673. if [ "$NON_INTERACTIVE" = true ]; then
  674. print_info "Installing automatically (profile specified)..."
  675. perform_installation
  676. else
  677. read -p "Proceed with installation? [Y/n]: " confirm
  678. if [[ $confirm =~ ^[Nn] ]]; then
  679. print_info "Installation cancelled"
  680. cleanup_and_exit 0
  681. fi
  682. perform_installation
  683. fi
  684. }
  685. #############################################################################
  686. # Collision Detection
  687. #############################################################################
  688. show_collision_report() {
  689. local collision_count=$1
  690. shift
  691. local collisions=("$@")
  692. echo ""
  693. print_warning "Found ${collision_count} file collision(s):"
  694. echo ""
  695. # Group by type
  696. local agents=()
  697. local subagents=()
  698. local commands=()
  699. local tools=()
  700. local plugins=()
  701. local skills=()
  702. local contexts=()
  703. local configs=()
  704. for file in "${collisions[@]}"; do
  705. # Skip empty entries
  706. [ -z "$file" ] && continue
  707. if [[ $file == *"/agent/subagents/"* ]]; then
  708. subagents+=("$file")
  709. elif [[ $file == *"/agent/"* ]]; then
  710. agents+=("$file")
  711. elif [[ $file == *"/command/"* ]]; then
  712. commands+=("$file")
  713. elif [[ $file == *"/tool/"* ]]; then
  714. tools+=("$file")
  715. elif [[ $file == *"/plugin/"* ]]; then
  716. plugins+=("$file")
  717. elif [[ $file == *"/skill/"* ]]; then
  718. skills+=("$file")
  719. elif [[ $file == *"/context/"* ]]; then
  720. contexts+=("$file")
  721. else
  722. configs+=("$file")
  723. fi
  724. done
  725. # Display grouped collisions
  726. [ ${#agents[@]} -gt 0 ] && echo -e "${YELLOW} Agents (${#agents[@]}):${NC}" && printf ' %s\n' "${agents[@]}"
  727. [ ${#subagents[@]} -gt 0 ] && echo -e "${YELLOW} Subagents (${#subagents[@]}):${NC}" && printf ' %s\n' "${subagents[@]}"
  728. [ ${#commands[@]} -gt 0 ] && echo -e "${YELLOW} Commands (${#commands[@]}):${NC}" && printf ' %s\n' "${commands[@]}"
  729. [ ${#tools[@]} -gt 0 ] && echo -e "${YELLOW} Tools (${#tools[@]}):${NC}" && printf ' %s\n' "${tools[@]}"
  730. [ ${#plugins[@]} -gt 0 ] && echo -e "${YELLOW} Plugins (${#plugins[@]}):${NC}" && printf ' %s\n' "${plugins[@]}"
  731. [ ${#skills[@]} -gt 0 ] && echo -e "${YELLOW} Skills (${#skills[@]}):${NC}" && printf ' %s\n' "${skills[@]}"
  732. [ ${#contexts[@]} -gt 0 ] && echo -e "${YELLOW} Context (${#contexts[@]}):${NC}" && printf ' %s\n' "${contexts[@]}"
  733. [ ${#configs[@]} -gt 0 ] && echo -e "${YELLOW} Config (${#configs[@]}):${NC}" && printf ' %s\n' "${configs[@]}"
  734. echo ""
  735. }
  736. get_install_strategy() {
  737. echo -e "${BOLD}How would you like to proceed?${NC}\n" >&2
  738. echo " 1) ${GREEN}Skip existing${NC} - Only install new files, keep all existing files unchanged" >&2
  739. echo " 2) ${YELLOW}Overwrite all${NC} - Replace existing files with new versions (your changes will be lost)" >&2
  740. echo " 3) ${CYAN}Backup & overwrite${NC} - Backup existing files, then install new versions" >&2
  741. echo " 4) ${RED}Cancel${NC} - Exit without making changes" >&2
  742. echo "" >&2
  743. read -p "Enter your choice [1-4]: " strategy_choice
  744. case $strategy_choice in
  745. 1) echo "skip" ;;
  746. 2)
  747. echo "" >&2
  748. print_warning "This will overwrite existing files. Your changes will be lost!"
  749. read -p "Are you sure? Type 'yes' to confirm: " confirm
  750. if [ "$confirm" = "yes" ]; then
  751. echo "overwrite"
  752. else
  753. echo "cancel"
  754. fi
  755. ;;
  756. 3) echo "backup" ;;
  757. 4) echo "cancel" ;;
  758. *) echo "cancel" ;;
  759. esac
  760. }
  761. #############################################################################
  762. # Installation
  763. #############################################################################
  764. perform_installation() {
  765. print_step "Preparing installation..."
  766. # Create base directory only - subdirectories created on-demand when files are installed
  767. mkdir -p "$INSTALL_DIR"
  768. # Check for collisions
  769. local collisions=()
  770. for comp in "${SELECTED_COMPONENTS[@]}"; do
  771. local type="${comp%%:*}"
  772. local id="${comp##*:}"
  773. local registry_key
  774. registry_key=$(get_registry_key "$type")
  775. local path
  776. path=$(jq_exec ".components.${registry_key}[]? | select(.id == \"${id}\") | .path" "$TEMP_DIR/registry.json")
  777. if [ -n "$path" ] && [ "$path" != "null" ]; then
  778. local install_path
  779. install_path=$(get_install_path "$path")
  780. if [ -f "$install_path" ]; then
  781. collisions+=("$install_path")
  782. fi
  783. fi
  784. done
  785. # Determine installation strategy
  786. local install_strategy="fresh"
  787. if [ ${#collisions[@]} -gt 0 ]; then
  788. # In non-interactive mode, use default strategy (skip existing files)
  789. if [ "$NON_INTERACTIVE" = true ]; then
  790. print_info "Found ${#collisions[@]} existing file(s) - using 'skip' strategy (non-interactive mode)"
  791. print_info "To overwrite, download script and run interactively, or delete existing files first"
  792. install_strategy="skip"
  793. else
  794. show_collision_report ${#collisions[@]} "${collisions[@]}"
  795. install_strategy=$(get_install_strategy)
  796. if [ "$install_strategy" = "cancel" ]; then
  797. print_info "Installation cancelled by user"
  798. cleanup_and_exit 0
  799. fi
  800. fi
  801. # Handle backup strategy
  802. if [ "$install_strategy" = "backup" ]; then
  803. local backup_dir
  804. backup_dir="${INSTALL_DIR}.backup.$(date +%Y%m%d-%H%M%S)"
  805. print_step "Creating backup..."
  806. # Only backup files that will be overwritten
  807. local backup_count=0
  808. for file in "${collisions[@]}"; do
  809. if [ -f "$file" ]; then
  810. local backup_file="${backup_dir}/${file}"
  811. mkdir -p "$(dirname "$backup_file")"
  812. if cp "$file" "$backup_file" 2>/dev/null; then
  813. backup_count=$((backup_count + 1))
  814. else
  815. print_warning "Failed to backup: $file"
  816. fi
  817. fi
  818. done
  819. if [ $backup_count -gt 0 ]; then
  820. print_success "Backed up ${backup_count} file(s) to $backup_dir"
  821. install_strategy="overwrite" # Now we can overwrite
  822. else
  823. print_error "Backup failed. Installation cancelled."
  824. cleanup_and_exit 1
  825. fi
  826. fi
  827. fi
  828. # Perform installation
  829. print_step "Installing components..."
  830. local installed=0
  831. local skipped=0
  832. local failed=0
  833. for comp in "${SELECTED_COMPONENTS[@]}"; do
  834. local type="${comp%%:*}"
  835. local id="${comp##*:}"
  836. # Get the correct registry key (handles singular/plural)
  837. local registry_key
  838. registry_key=$(get_registry_key "$type")
  839. # Get component path
  840. local path
  841. path=$(jq_exec ".components.${registry_key}[]? | select(.id == \"${id}\") | .path" "$TEMP_DIR/registry.json")
  842. if [ -z "$path" ] || [ "$path" = "null" ]; then
  843. print_warning "Could not find path for ${comp}"
  844. failed=$((failed + 1))
  845. continue
  846. fi
  847. # Convert registry path to installation path
  848. local dest
  849. dest=$(get_install_path "$path")
  850. # Check if file exists before we install (for proper messaging)
  851. local file_existed=false
  852. if [ -f "$dest" ]; then
  853. file_existed=true
  854. fi
  855. # Check if file exists and we're in skip mode
  856. if [ "$file_existed" = true ] && [ "$install_strategy" = "skip" ]; then
  857. print_info "Skipped existing: ${type}:${id}"
  858. skipped=$((skipped + 1))
  859. continue
  860. fi
  861. # Download component
  862. local url="${RAW_URL}/${path}"
  863. # Create parent directory if needed
  864. mkdir -p "$(dirname "$dest")"
  865. if curl -fsSL "$url" -o "$dest"; then
  866. # Transform paths for global installation (any non-local path)
  867. # Local paths: .opencode or */.opencode
  868. if [[ "$INSTALL_DIR" != ".opencode" ]] && [[ "$INSTALL_DIR" != *"/.opencode" ]]; then
  869. # Expand tilde and get absolute path for transformation
  870. local expanded_path="${INSTALL_DIR/#\~/$HOME}"
  871. # Transform @.opencode/context/ references to actual install path
  872. sed -i.bak -e "s|@\.opencode/context/|@${expanded_path}/context/|g" \
  873. -e "s|\.opencode/context|${expanded_path}/context|g" "$dest" 2>/dev/null || true
  874. rm -f "${dest}.bak" 2>/dev/null || true
  875. fi
  876. # Show appropriate message based on whether file existed before
  877. if [ "$file_existed" = true ]; then
  878. print_success "Updated ${type}: ${id}"
  879. else
  880. print_success "Installed ${type}: ${id}"
  881. fi
  882. installed=$((installed + 1))
  883. else
  884. print_error "Failed to install ${type}: ${id}"
  885. failed=$((failed + 1))
  886. fi
  887. done
  888. # Handle additional paths for advanced profile
  889. if [ "$PROFILE" = "advanced" ]; then
  890. local additional_paths
  891. additional_paths=$(jq_exec '.profiles.advanced.additionalPaths[]?' "$TEMP_DIR/registry.json")
  892. if [ -n "$additional_paths" ]; then
  893. print_step "Installing additional paths..."
  894. while IFS= read -r path; do
  895. # For directories, we'd need to recursively download
  896. # For now, just note them
  897. print_info "Additional path: $path (manual download required)"
  898. done <<< "$additional_paths"
  899. fi
  900. fi
  901. echo ""
  902. print_success "Installation complete!"
  903. echo -e " Installed: ${GREEN}${installed}${NC}"
  904. [ $skipped -gt 0 ] && echo -e " Skipped: ${CYAN}${skipped}${NC}"
  905. [ $failed -gt 0 ] && echo -e " Failed: ${RED}${failed}${NC}"
  906. show_post_install
  907. }
  908. #############################################################################
  909. # Post-Installation
  910. #############################################################################
  911. show_post_install() {
  912. echo ""
  913. print_step "Next Steps"
  914. echo "1. Review the installed components in ${CYAN}${INSTALL_DIR}/${NC}"
  915. # Check if env.example was installed
  916. if [ -f "${INSTALL_DIR}/env.example" ] || [ -f "env.example" ]; then
  917. echo "2. Copy env.example to .env and configure:"
  918. echo " ${CYAN}cp env.example .env${NC}"
  919. echo "3. Start using OpenCode agents:"
  920. else
  921. echo "2. Start using OpenCode agents:"
  922. fi
  923. echo " ${CYAN}opencode${NC}"
  924. echo ""
  925. # Show installation location info
  926. print_info "Installation directory: ${CYAN}${INSTALL_DIR}${NC}"
  927. # Check for backup directories
  928. local has_backup=0
  929. local backup_dir
  930. local backup_dirs=()
  931. shopt -s nullglob
  932. backup_dirs=("${INSTALL_DIR}.backup."*)
  933. shopt -u nullglob
  934. for backup_dir in "${backup_dirs[@]}"; do
  935. if [ -d "$backup_dir" ]; then
  936. has_backup=1
  937. break
  938. fi
  939. done
  940. if [ "$has_backup" -eq 1 ]; then
  941. print_info "Backup created - you can restore files from ${INSTALL_DIR}.backup.* if needed"
  942. fi
  943. print_info "Documentation: ${REPO_URL}"
  944. echo ""
  945. cleanup_and_exit 0
  946. }
  947. #############################################################################
  948. # Component Listing
  949. #############################################################################
  950. list_components() {
  951. clear || true
  952. print_header
  953. echo -e "${BOLD}Available Components${NC}\n"
  954. local categories=("agents" "subagents" "commands" "tools" "plugins" "skills" "contexts")
  955. for category in "${categories[@]}"; do
  956. local cat_display
  957. cat_display=$(echo "$category" | awk '{print toupper(substr($0,1,1)) tolower(substr($0,2))}')
  958. echo -e "${CYAN}${BOLD}${cat_display}:${NC}"
  959. local components
  960. components=$(jq_exec ".components.${category}[]? | \"\(.id)|\(.name)|\(.description)\"" "$TEMP_DIR/registry.json")
  961. while IFS='|' read -r id name desc; do
  962. echo -e " ${GREEN}${name}${NC} (${id})"
  963. echo -e " ${desc}"
  964. done <<< "$components"
  965. echo ""
  966. done
  967. }
  968. #############################################################################
  969. # Cleanup
  970. #############################################################################
  971. cleanup_and_exit() {
  972. rm -rf "$TEMP_DIR"
  973. exit "$1"
  974. }
  975. trap 'cleanup_and_exit 1' INT TERM
  976. #############################################################################
  977. # Main
  978. #############################################################################
  979. main() {
  980. # Parse command line arguments
  981. while [ $# -gt 0 ]; do
  982. case "$1" in
  983. --install-dir=*)
  984. CUSTOM_INSTALL_DIR="${1#*=}"
  985. # Basic validation - check not empty
  986. if [ -z "$CUSTOM_INSTALL_DIR" ]; then
  987. echo "Error: --install-dir requires a non-empty path"
  988. exit 1
  989. fi
  990. shift
  991. ;;
  992. --install-dir)
  993. if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
  994. CUSTOM_INSTALL_DIR="$2"
  995. shift 2
  996. else
  997. echo "Error: --install-dir requires a path argument"
  998. exit 1
  999. fi
  1000. ;;
  1001. essential|--essential)
  1002. INSTALL_MODE="profile"
  1003. PROFILE="essential"
  1004. NON_INTERACTIVE=true
  1005. shift
  1006. ;;
  1007. developer|--developer)
  1008. INSTALL_MODE="profile"
  1009. PROFILE="developer"
  1010. NON_INTERACTIVE=true
  1011. shift
  1012. ;;
  1013. business|--business)
  1014. INSTALL_MODE="profile"
  1015. PROFILE="business"
  1016. NON_INTERACTIVE=true
  1017. shift
  1018. ;;
  1019. full|--full)
  1020. INSTALL_MODE="profile"
  1021. PROFILE="full"
  1022. NON_INTERACTIVE=true
  1023. shift
  1024. ;;
  1025. advanced|--advanced)
  1026. INSTALL_MODE="profile"
  1027. PROFILE="advanced"
  1028. NON_INTERACTIVE=true
  1029. shift
  1030. ;;
  1031. list|--list)
  1032. check_dependencies
  1033. fetch_registry
  1034. list_components
  1035. cleanup_and_exit 0
  1036. ;;
  1037. --help|-h|help)
  1038. print_header
  1039. echo "Usage: $0 [PROFILE] [OPTIONS]"
  1040. echo ""
  1041. echo -e "${BOLD}Profiles:${NC}"
  1042. echo " essential, --essential Minimal setup with core agents"
  1043. echo " developer, --developer Code-focused development tools"
  1044. echo " business, --business Content and business-focused tools"
  1045. echo " full, --full Everything except system-builder"
  1046. echo " advanced, --advanced Complete system with all components"
  1047. echo ""
  1048. echo -e "${BOLD}Options:${NC}"
  1049. echo " --install-dir PATH Custom installation directory"
  1050. echo " (default: .opencode)"
  1051. echo " list, --list List all available components"
  1052. echo " help, --help, -h Show this help message"
  1053. echo ""
  1054. echo -e "${BOLD}Environment Variables:${NC}"
  1055. echo " OPENCODE_INSTALL_DIR Installation directory"
  1056. echo " OPENCODE_BRANCH Git branch to install from (default: main)"
  1057. echo ""
  1058. echo -e "${BOLD}Examples:${NC}"
  1059. echo ""
  1060. echo " ${CYAN}# Interactive mode (choose location and components)${NC}"
  1061. echo " $0"
  1062. echo ""
  1063. echo " ${CYAN}# Quick install with default location (.opencode/)${NC}"
  1064. echo " $0 developer"
  1065. echo ""
  1066. echo " ${CYAN}# Install to global location (Linux/macOS)${NC}"
  1067. echo " $0 developer --install-dir ~/.config/opencode"
  1068. echo ""
  1069. echo " ${CYAN}# Install to global location (Windows Git Bash)${NC}"
  1070. echo " $0 developer --install-dir ~/.config/opencode"
  1071. echo ""
  1072. echo " ${CYAN}# Install to custom location${NC}"
  1073. echo " $0 essential --install-dir ~/my-agents"
  1074. echo ""
  1075. echo " ${CYAN}# Using environment variable${NC}"
  1076. echo " export OPENCODE_INSTALL_DIR=~/.config/opencode"
  1077. echo " $0 developer"
  1078. echo ""
  1079. echo " ${CYAN}# Install from URL (non-interactive)${NC}"
  1080. echo " curl -fsSL https://raw.githubusercontent.com/darrenhinde/OpenAgents/main/install.sh | bash -s developer"
  1081. echo ""
  1082. echo -e "${BOLD}Platform Support:${NC}"
  1083. echo " ✓ Linux (bash 3.2+)"
  1084. echo " ✓ macOS (bash 3.2+)"
  1085. echo " ✓ Windows (Git Bash, WSL)"
  1086. echo ""
  1087. exit 0
  1088. ;;
  1089. *)
  1090. echo "Unknown option: $1"
  1091. echo "Run '$0 --help' for usage information"
  1092. exit 1
  1093. ;;
  1094. esac
  1095. done
  1096. # Apply custom install directory if specified (CLI arg overrides env var)
  1097. if [ -n "$CUSTOM_INSTALL_DIR" ]; then
  1098. local normalized_path
  1099. normalized_path=$(normalize_and_validate_path "$CUSTOM_INSTALL_DIR")
  1100. if [ $? -eq 0 ]; then
  1101. INSTALL_DIR="$normalized_path"
  1102. if ! validate_install_path "$INSTALL_DIR"; then
  1103. print_warning "Installation path may have issues, but continuing..."
  1104. fi
  1105. else
  1106. print_error "Invalid installation directory: $CUSTOM_INSTALL_DIR"
  1107. exit 1
  1108. fi
  1109. fi
  1110. check_bash_version
  1111. check_dependencies
  1112. fetch_registry
  1113. if [ -n "$PROFILE" ]; then
  1114. # Non-interactive mode (compatible with bash 3.2+)
  1115. SELECTED_COMPONENTS=()
  1116. local temp_file="$TEMP_DIR/components.tmp"
  1117. get_profile_components "$PROFILE" > "$temp_file"
  1118. while IFS= read -r component; do
  1119. [ -n "$component" ] && SELECTED_COMPONENTS+=("$component")
  1120. done < "$temp_file"
  1121. # Resolve dependencies for profile installs
  1122. print_step "Resolving dependencies..."
  1123. local original_count=${#SELECTED_COMPONENTS[@]}
  1124. for comp in "${SELECTED_COMPONENTS[@]}"; do
  1125. resolve_dependencies "$comp"
  1126. done
  1127. local new_count=${#SELECTED_COMPONENTS[@]}
  1128. if [ "$new_count" -gt "$original_count" ]; then
  1129. local added=$((new_count - original_count))
  1130. print_info "Added $added dependencies"
  1131. fi
  1132. show_installation_preview
  1133. else
  1134. # Interactive mode - show location menu first
  1135. show_install_location_menu
  1136. show_main_menu
  1137. if [ "$INSTALL_MODE" = "profile" ]; then
  1138. show_profile_menu
  1139. elif [ "$INSTALL_MODE" = "custom" ]; then
  1140. show_custom_menu
  1141. fi
  1142. fi
  1143. }
  1144. main "$@"