- Root setup.sh orchestrator with per-phase dispatch (./setup.sh p1..p8 | all | status) - Makefile convenience targets (make infra, make llm, make status, etc.) - scripts/common.sh: shared bash library for OS detection, Docker helpers, service management (launchd/systemd), package install, env management - .env.example + .gitignore: shared config template and secret exclusions P1 (homeai-infra): full implementation - docker-compose.yml: Uptime Kuma, code-server, n8n - Note: Home Assistant, Portainer, Gitea are pre-existing instances - setup.sh: Docker install, homeai network, container health checks P2 (homeai-llm): full implementation - Ollama native install with CUDA/ROCm/Metal auto-detection - launchd plist (macOS) + systemd service (Linux) for auto-start - scripts/pull-models.sh: idempotent model puller from manifest - scripts/benchmark.sh: tokens/sec measurement per model - Open WebUI on port 3030 (avoids Gitea :3000 conflict) P3-P8: working stubs with prerequisite checks and TODO sections Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
136 lines
5.1 KiB
Bash
136 lines
5.1 KiB
Bash
#!/usr/bin/env bash
|
|
# homeai-infra/setup.sh — P1: Infrastructure stack
|
|
#
|
|
# Installs Docker (if needed), creates the homeai network,
|
|
# and starts new infrastructure services.
|
|
#
|
|
# Services started:
|
|
# Uptime Kuma :3001
|
|
# code-server :8090
|
|
# n8n :5678
|
|
#
|
|
# NOTE: Home Assistant, Portainer, and Gitea are pre-existing instances.
|
|
# Set their URLs in ~/.env.services manually.
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
REPO_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
|
# shellcheck source=../scripts/common.sh
|
|
source "${REPO_DIR}/scripts/common.sh"
|
|
|
|
COMPOSE_FILE="${SCRIPT_DIR}/docker/docker-compose.yml"
|
|
ENV_FILE="${SCRIPT_DIR}/docker/.env"
|
|
ENV_EXAMPLE="${SCRIPT_DIR}/docker/.env.example"
|
|
|
|
# ─── Pre-flight ────────────────────────────────────────────────────────────────
|
|
preflight() {
|
|
log_section "P1 Preflight"
|
|
detect_platform
|
|
|
|
# Ensure .env exists
|
|
if [[ ! -f "$ENV_FILE" ]]; then
|
|
if [[ -f "$ENV_EXAMPLE" ]]; then
|
|
cp "$ENV_EXAMPLE" "$ENV_FILE"
|
|
log_warn "Created ${ENV_FILE} from .env.example"
|
|
log_warn "Edit it now with real secrets, then re-run this script."
|
|
echo ""
|
|
echo " Secrets to set in ${ENV_FILE}:"
|
|
echo " CODE_SERVER_PASSWORD — your password"
|
|
echo " N8N_BASIC_AUTH_PASSWORD — your password"
|
|
echo " N8N_ENCRYPTION_KEY — 32-char random string (run: openssl rand -hex 16)"
|
|
echo ""
|
|
if ! confirm "Secrets are still at defaults. Continue anyway? (not safe for production)"; then
|
|
log_info "Aborting. Fill in ${ENV_FILE} and re-run."
|
|
exit 0
|
|
fi
|
|
else
|
|
die "No .env or .env.example found at ${SCRIPT_DIR}/docker/"
|
|
fi
|
|
fi
|
|
|
|
# Create data directory
|
|
local data_dir
|
|
load_env "$ENV_FILE"
|
|
data_dir="${DATA_DIR:-${HOME}/homeai-data}"
|
|
log_step "Data directory: ${data_dir}"
|
|
mkdir -p \
|
|
"${data_dir}/uptime-kuma" \
|
|
"${data_dir}/code-server" \
|
|
"${data_dir}/n8n"
|
|
log_success "Data directories ready."
|
|
}
|
|
|
|
# ─── Docker ────────────────────────────────────────────────────────────────────
|
|
setup_docker() {
|
|
log_section "Docker"
|
|
install_docker
|
|
ensure_docker_running
|
|
ensure_docker_network homeai
|
|
}
|
|
|
|
# ─── Services ──────────────────────────────────────────────────────────────────
|
|
start_services() {
|
|
log_section "Starting infra services"
|
|
|
|
log_step "Pulling latest images..."
|
|
docker_compose -f "$COMPOSE_FILE" --env-file "$ENV_FILE" pull
|
|
|
|
log_step "Starting containers..."
|
|
docker_compose -f "$COMPOSE_FILE" --env-file "$ENV_FILE" up -d
|
|
|
|
log_success "Containers started."
|
|
}
|
|
|
|
# ─── Health checks ─────────────────────────────────────────────────────────────
|
|
health_check() {
|
|
log_section "Health checks"
|
|
|
|
wait_for_http "http://localhost:3001" "Uptime Kuma" 60
|
|
wait_for_http "http://localhost:5678" "n8n" 90
|
|
wait_for_http "http://localhost:8090" "code-server" 60
|
|
}
|
|
|
|
# ─── Register services ─────────────────────────────────────────────────────────
|
|
register_services() {
|
|
log_section "Writing service URLs"
|
|
|
|
write_env_service "UPTIME_KUMA_URL" "http://localhost:3001"
|
|
write_env_service "CODE_SERVER_URL" "http://localhost:8090"
|
|
write_env_service "N8N_URL" "http://localhost:5678"
|
|
|
|
log_warn "Set these in ~/.env.services manually (pre-existing instances):"
|
|
log_warn " HA_URL, HA_TOKEN, PORTAINER_URL, GITEA_URL"
|
|
|
|
log_success "Service URLs written to ~/.env.services"
|
|
}
|
|
|
|
# ─── Summary ───────────────────────────────────────────────────────────────────
|
|
print_infra_summary() {
|
|
print_summary "P1 Infrastructure — Ready" \
|
|
"Uptime Kuma" "http://localhost:3001" \
|
|
"code-server" "http://localhost:8090" \
|
|
"n8n" "http://localhost:5678"
|
|
|
|
echo " Pre-existing services (not managed here):"
|
|
echo " Home Assistant, Portainer, Gitea"
|
|
echo ""
|
|
echo " Next steps:"
|
|
echo " 1. Add HA_URL, HA_TOKEN, PORTAINER_URL, GITEA_URL to ~/.env.services"
|
|
echo " 2. Add Uptime Kuma monitors for all HomeAI services"
|
|
echo " 3. Run: ./setup.sh p2 (Ollama + LLM)"
|
|
echo ""
|
|
}
|
|
|
|
# ─── Main ──────────────────────────────────────────────────────────────────────
|
|
main() {
|
|
preflight
|
|
setup_docker
|
|
start_services
|
|
health_check
|
|
register_services
|
|
print_infra_summary
|
|
}
|
|
|
|
main "$@"
|