#!/usr/bin/env bash # Vyomi — laptop installer (curl-bash style). # # What it does: # 1. Verifies Docker + Docker Compose v2 are present # 2. Creates ~/.vyomi/{compose,data,deployments} (no sudo) # 3. Downloads docker-compose.yml + host config defaults from GitHub # 4. Runs `docker compose up -d` (4 services: simulator, cloudsim, # postgres, gcs — heavy backends provision lazily on first use) # 5. Polls until /healthz responds, then opens the browser # # Usage: # curl -fsSL https://raw.githubusercontent.com/vyomi-cloud/appliance/main/install.sh | bash # # # With all 10 services eager (instead of lazy): # curl -fsSL ... | bash -s -- --full # # # Pin a specific version: # curl -fsSL ... | bash -s -- --tag v0.1.0 # # # Just print what it would do without doing it: # curl -fsSL ... | bash -s -- --dry-run # # Re-running is safe — idempotent: existing volumes survive, only the # compose file is re-downloaded. set -euo pipefail # ─── colours / formatting ─────────────────────────────────────────────── if [ -t 1 ] && command -v tput >/dev/null 2>&1; then B=$(tput bold) D=$(tput dim) R=$(tput sgr0) G=$(tput setaf 2) Y=$(tput setaf 3) C=$(tput setaf 6) M=$(tput setaf 5) else B="" D="" R="" G="" Y="" C="" M="" fi ok() { printf " ${G}✓${R} %s\n" "$*"; } warn() { printf " ${Y}⚠${R} %s\n" "$*" >&2; } err() { printf " ${R}${B}✗${R} %s\n" "$*" >&2; } step() { printf "\n${B}${M}▶${R} ${B}%s${R}\n" "$*"; } # ─── args ─────────────────────────────────────────────────────────────── PROFILE="" DRY_RUN="0" IMAGE_TAG="" REPO_RAW="https://raw.githubusercontent.com/vyomi-cloud/appliance/main" while [ $# -gt 0 ]; do case "$1" in --full) PROFILE="full" ; shift ;; --dry-run) DRY_RUN="1" ; shift ;; --tag) IMAGE_TAG="$2" ; shift 2 ;; --repo) REPO_RAW="$2" ; shift 2 ;; # for forks / local testing -h|--help) sed -n '1,30p' "$0" | sed 's/^# *//' exit 0 ;; *) err "unknown flag: $1 (try --help)" exit 2 ;; esac done # ─── prereqs ──────────────────────────────────────────────────────────── step "Checking prerequisites" # On macOS, auto-install Docker Desktop via Homebrew if it's missing and brew # is available — avoids a dead-end "go install it yourself, then re-run" for # the common case. Without brew, fall back to the old manual-link behavior # rather than curl|bash-ing an installer with no checksum of our own. if ! command -v docker >/dev/null 2>&1 && [ "$(uname -s)" = "Darwin" ] && [ "$DRY_RUN" != "1" ]; then if command -v brew >/dev/null 2>&1; then warn "docker not found — installing Docker Desktop via Homebrew" echo " ${D}brew install --cask docker${R}" if brew install --cask docker; then ok "Docker Desktop installed" echo " ${D}launching it once to finish setup (creates the docker CLI symlink;" echo " ${D}macOS may prompt for your password to install Docker's network helper)${R}" open -a Docker >/dev/null 2>&1 || true for i in $(seq 1 60); do command -v docker >/dev/null 2>&1 && break sleep 2 done else err "brew install --cask docker failed" fi else warn "docker not found, and Homebrew isn't installed to auto-install it" echo " Install Homebrew (https://brew.sh) and re-run this script for automatic" echo " setup, or install Docker Desktop manually: https://docs.docker.com/get-docker/" fi fi if ! command -v docker >/dev/null 2>&1; then if [ "$DRY_RUN" = "1" ]; then echo " (dry-run) docker not found — would install it (Homebrew cask on macOS) and re-check" else err "docker not found in PATH" echo " Install Docker Desktop: https://docs.docker.com/get-docker/" exit 1 fi else ok "docker: $(docker --version | awk '{print $3}' | tr -d ,)" fi if ! docker compose version >/dev/null 2>&1; then err "Docker Compose v2 not available (need 'docker compose', not 'docker-compose')" echo " Update Docker Desktop to a recent version." exit 1 fi ok "docker compose: $(docker compose version --short)" # On macOS the engine runs inside Docker Desktop's VM (Apple Virtualization # framework) — it's frequently installed but not running. Start it and wait # instead of bailing. Same idea for OrbStack / Colima if that's the provider. # # Prefer `docker desktop start` (the Docker Desktop CLI plugin) over `open -a # Docker`: it manages the whole app/VM lifecycle itself instead of sending an # Apple Events activation at whatever process macOS finds for that bundle id — # which, right after quitting Docker, can be a still-dying instance instead of # a fresh one, leaving the engine's VM networking wedged indefinitely. And if # Desktop already reports itself "running" (true even mid-wedge — that status # reflects the app/VM process existing, not the engine answering), `start` # no-ops; `restart` is what actually recovers that case. start_docker_engine() { case "$(uname -s)" in Darwin) if command -v docker >/dev/null 2>&1 && docker desktop start --help >/dev/null 2>&1; then if docker desktop status 2>/dev/null | grep -qi running; then echo " ${D}Docker Desktop is running but the engine isn't answering, restarting it (docker desktop restart)${R}" docker desktop restart >/dev/null 2>&1 || true else echo " ${D}starting Docker Desktop (docker desktop start)${R}" docker desktop start >/dev/null 2>&1 || true fi elif open -a Docker >/dev/null 2>&1; then echo " ${D}launched Docker Desktop — waiting for the engine (first start can take ~1 min)${R}" elif open -a OrbStack >/dev/null 2>&1; then echo " ${D}launched OrbStack — waiting for the engine${R}" elif command -v colima >/dev/null 2>&1; then echo " ${D}starting Colima${R}" colima start >/dev/null 2>&1 || true else return 1 fi ;; Linux) systemctl --user start docker-desktop >/dev/null 2>&1 \ || sudo -n systemctl start docker >/dev/null 2>&1 \ || return 1 ;; *) return 1 ;; esac } if ! docker info >/dev/null 2>&1; then warn "Docker daemon isn't running — trying to start it" if [ "$DRY_RUN" = "1" ]; then echo " (dry-run) would start the Docker engine and wait up to 150s" elif start_docker_engine; then retried=0 for i in $(seq 1 50); do docker info >/dev/null 2>&1 && break # Halfway through the wait, if the engine is still down, retry the # launch once — covers a launch that raced a half-dead Docker Desktop. if [ "$retried" = "0" ] && [ "$i" -ge 25 ]; then retried=1 echo " ${D}engine still not up halfway through the wait, retrying the launch${R}" start_docker_engine || true fi sleep 3 done fi if [ "$DRY_RUN" != "1" ] && ! docker info >/dev/null 2>&1; then err "Docker daemon still isn't reachable" echo " Start Docker Desktop (or OrbStack/Colima), wait until it shows" echo " \"Engine running\", then re-run this script. Verify with: docker info" exit 1 fi fi ok "docker daemon reachable" # ─── install dir ──────────────────────────────────────────────────────── # ── Path migration (Phase 10 — vyomi rebrand) ────────────────────────── # Canonical compose state dir is now ~/.vyomi/ (was ~/.cloudlearn/). If # the old dir exists and the new one doesn't, rename it once and # symlink the old path for back-compat. if [ -d "$HOME/.cloudlearn" ] && [ ! -L "$HOME/.cloudlearn" ] && [ ! -e "$HOME/.vyomi" ]; then mv "$HOME/.cloudlearn" "$HOME/.vyomi" 2>/dev/null && \ ln -s "$HOME/.vyomi" "$HOME/.cloudlearn" 2>/dev/null || true fi CL_HOME="${VYOMI_HOME:-${CLOUDLEARN_HOME:-$HOME/.vyomi}}" step "Installing to ${B}${CL_HOME}${R}" mkdir -p "$CL_HOME"/{compose,data,deployments,config} ok "created $CL_HOME/{compose,data,deployments,config}" # ─── fetch compose + host config defaults ─────────────────────────────── step "Downloading compose + config from GitHub" DOWNLOAD() { local rel="$1" dest="$2" if [ "$DRY_RUN" = "1" ]; then echo " (dry-run) would download $REPO_RAW/$rel → $dest" return fi if ! curl -fsSL -o "$dest" "$REPO_RAW/$rel"; then err "failed to download $rel" exit 1 fi ok "downloaded $rel" } DOWNLOAD "docker-compose.yml" "$CL_HOME/compose/docker-compose.yml" DOWNLOAD ".cloudlearn-host.json" "$CL_HOME/config/.cloudlearn-host.json" DOWNLOAD ".cloudlearn-appliance/host-sizing-report.json" "$CL_HOME/config/host-sizing-report.json" # ─── .env with the right paths ────────────────────────────────────────── step "Generating .env" ENV_FILE="$CL_HOME/compose/.env" if [ -f "$ENV_FILE" ]; then ok ".env exists — not overwriting" else cat > "$ENV_FILE" <&1 | sed 's/^/ /' echo " ${D}starting containers...${R}" docker compose $COMPOSE_FLAGS up -d 2>&1 | sed 's/^/ /' ok "containers started" # ─── one-time mkcert TLS provisioning (Phase 12 — vyomi rebrand) ────── # Provision a locally-trusted cert so the browser opens # https://vyomi.local:9443 with a green padlock (Caddy sidecar # terminates TLS, reverse-proxies to the simulator). Honors # VYOMI_NO_TLS=1 to skip. TLS_DIR="${VYOMI_TLS_DIR:-$HOME/.vyomi/tls}" if [ "${VYOMI_NO_TLS:-0}" != "1" ] && [ ! -f "$TLS_DIR/cert.pem" ]; then if command -v mkcert >/dev/null 2>&1; then step "Provisioning local TLS cert via mkcert (one-time)" mkdir -p "$TLS_DIR" mkcert -install >/dev/null 2>&1 || true ( cd "$TLS_DIR" && mkcert -cert-file cert.pem -key-file key.pem \ vyomi.local localhost 127.0.0.1 >/dev/null 2>&1 ) \ && ok "TLS cert provisioned at $TLS_DIR" \ || echo " ${D}cert generation failed — Caddy will run cert-less${R}" else echo " ${D}mkcert not installed — skipping HTTPS provisioning${R}" echo " ${D} macOS: brew install mkcert${R}" echo " ${D} Linux: sudo apt install mkcert (or dnf install)${R}" echo " ${D}HTTP on :9000 still works without mkcert.${R}" fi fi # ─── one-time hosts entry so http://vyomi.local:9000 works ───────────── # Multipass-based install paths publish vyomi.local via mDNS. Docker # Desktop on macOS/Windows runs in a Linux VM and can't broadcast mDNS # to the host, so we map the same hostname to 127.0.0.1 with a single # /etc/hosts line. Idempotent — only adds the line if it isn't already # there. Skipped on Windows (PowerShell admin is the cleaner path). HOSTS_FILE="/etc/hosts" PORT="${CLOUDLEARN_SIMULATOR_PORT:-9000}" VYOMI_URL="http://vyomi.local:${PORT}" LOCAL_URL="http://localhost:${PORT}" URL="$LOCAL_URL" if [ -w "$HOSTS_FILE" ] || command -v sudo >/dev/null 2>&1; then if ! grep -qE '^127\.0\.0\.1[[:space:]]+vyomi\.local([[:space:]]|$)' "$HOSTS_FILE" 2>/dev/null; then step "Adding 127.0.0.1 vyomi.local to $HOSTS_FILE (sudo prompt)" if [ -w "$HOSTS_FILE" ]; then printf '\n# Added by cloud-learn install.sh — maps vyomi.local to the host\n127.0.0.1 vyomi.local\n' >> "$HOSTS_FILE" 2>/dev/null && URL="$VYOMI_URL" else printf '\n# Added by cloud-learn install.sh — maps vyomi.local to the host\n127.0.0.1 vyomi.local\n' | sudo tee -a "$HOSTS_FILE" >/dev/null 2>&1 && URL="$VYOMI_URL" fi if [ "$URL" = "$VYOMI_URL" ]; then # Best-effort DNS-cache flush so the browser picks up the new entry. sudo dscacheutil -flushcache >/dev/null 2>&1 \ || sudo systemd-resolve --flush-caches >/dev/null 2>&1 \ || true ok "vyomi.local mapped — simulator reachable as $VYOMI_URL or $LOCAL_URL" else echo " ${D}couldn't update hosts file — falling back to localhost URL${R}" fi else URL="$VYOMI_URL" ok "vyomi.local already in $HOSTS_FILE — reachable as $VYOMI_URL or $LOCAL_URL" fi fi # ─── wait for healthy ────────────────────────────────────────────────── step "Waiting for $URL to respond" for i in $(seq 1 60); do if curl -fsS --max-time 2 "$URL/healthz" >/dev/null 2>&1; then ok "ready after ${i}s" break fi sleep 1 [ "$i" = "60" ] && { err "did not respond within 60s — check 'docker compose logs simulator'"; exit 1; } done # ─── open browser ─────────────────────────────────────────────────────── step "All set" echo echo " ${G}${B}$URL${R}" echo echo " Profile : ${PROFILE:-default (4 services; rest lazy-provisioned)}" echo " Install dir : $CL_HOME" echo " Compose dir : $CL_HOME/compose" echo echo " Useful commands (from $CL_HOME/compose):" echo " ${C}docker compose logs -f simulator${R} tail logs" echo " ${C}docker compose down${R} stop everything" echo " ${C}docker compose pull && docker compose up -d${R} upgrade to latest" echo # 4.0.0: the appliance is headless (API only). The UI is Nano at https://vyomi.cloud/nano — nothing to open locally.