#!/usr/bin/env bash set -euo pipefail # --------------------------------------------------------------------------- # Interactive docker compose launcher for Open WebUI. # Supports GPU auto-detection, configurable ports, data mounts, and Playwright. # --------------------------------------------------------------------------- readonly BOLD='\033[1m' readonly GREEN='\033[1;32m' readonly WHITE='\033[1;37m' readonly RED='\033[0;31m' readonly RESET='\033[0m' readonly CHECK_MARK='\xE2\x9C\x93' # ── GPU detection ───────────────────────────────────────────────────────────── detect_gpu_driver() { if command -v nvidia-smi &>/dev/null && nvidia-smi &>/dev/null; then echo "nvidia" elif lspci 2>/dev/null | grep -qi 'vga.*amd\|display.*amd'; then if lspci | grep -qiE 'Radeon (RX|R[579]|HD [78])'; then echo "amdgpu" else echo "radeon" fi elif lspci 2>/dev/null | grep -qi 'vga.*intel\|display.*intel'; then echo "i915" else echo >&2 "Error: No supported GPU detected." return 1 fi } # ── Argument helpers ────────────────────────────────────────────────────────── extract_bracket_value() { local input="$1" fallback="${2:-}" if [[ "$input" =~ \[.*=(.*)\] ]]; then echo "${BASH_REMATCH[1]}" else echo "$fallback" fi } usage() { cat <&2 "Error: Invalid GPU count '${gpu_count}'. Must be a number or 'all'." exit 1 fi export OLLAMA_GPU_DRIVER OLLAMA_GPU_DRIVER=$(detect_gpu_driver) export OLLAMA_GPU_COUNT="$gpu_count" compose_files+=("-f" "docker-compose.gpu.yaml") fi if [[ "$enable_api" == true ]]; then export OLLAMA_WEBAPI_PORT="$api_port" compose_files+=("-f" "docker-compose.api.yaml") fi if [[ -n "$data_dir" ]]; then export OLLAMA_DATA_DIR="$data_dir" compose_files+=("-f" "docker-compose.data.yaml") fi if [[ "$enable_playwright" == true ]]; then compose_files+=("-f" "docker-compose.playwright.yaml") fi export OPEN_WEBUI_PORT="$webui_port" up_args=("up" "-d" "--remove-orphans" "--force-recreate") if [[ "$build_image" == true ]]; then up_args+=("--build") fi # ── Confirmation ────────────────────────────────────────────────────────────── echo echo -e "${WHITE}${BOLD}Current Setup:${RESET}" echo -e " ${GREEN}${BOLD}GPU Driver:${RESET} ${OLLAMA_GPU_DRIVER:-Disabled}" echo -e " ${GREEN}${BOLD}GPU Count:${RESET} ${OLLAMA_GPU_COUNT:-Disabled}" echo -e " ${GREEN}${BOLD}API Port:${RESET} ${OLLAMA_WEBAPI_PORT:-Disabled}" echo -e " ${GREEN}${BOLD}Data Dir:${RESET} ${data_dir:-Docker volume}" echo -e " ${GREEN}${BOLD}WebUI Port:${RESET} ${webui_port}" echo -e " ${GREEN}${BOLD}Playwright:${RESET} ${enable_playwright}" echo if [[ "$headless" != true ]]; then read -rp "$(echo -e "${WHITE}${BOLD}Proceed with this setup? [Y/n]: ${RESET}")" confirm if [[ "${confirm,,}" == "n" ]]; then echo "Aborted." exit 0 fi fi # ── Launch ──────────────────────────────────────────────────────────────────── if docker compose "${compose_files[@]}" "${up_args[@]}"; then echo echo -e "${GREEN}${BOLD}${CHECK_MARK} Compose project started successfully.${RESET}" else echo echo -e "${RED}${BOLD}Failed to start compose project.${RESET}" exit 1 fi echo