From 44e142fdf091717ee38811908a942218b6bcb8f7 Mon Sep 17 00:00:00 2001 From: shoemoney Date: Tue, 23 Jun 2026 13:05:16 -0500 Subject: [PATCH] =?UTF-8?q?feat:=20cross-platform=20install=20scripts=20+?= =?UTF-8?q?=20hub=20Docker=20+=20macOS=20Full=20Disk=20Access=20?= =?UTF-8?q?=F0=9F=93=A6=F0=9F=90=B3=F0=9F=94=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Maximum-easy adoption: - install.sh (macOS+Linux): curl|sh friendly. Detects OS/arch, resolves the binary (env → local dist/ → download → go-build fallback), lets you pick the install dir (smart default + prompt on a TTY), and optionally sets up a KEEP-ALIVE auto-restart service — launchd KeepAlive (mac) / systemd Restart=always user unit (linux). Flags + env for non-interactive use. - install.ps1 (Windows): copy exe + user PATH + optional restart-on-failure Scheduled Task at logon. - Hub Docker: Dockerfile (multi-stage, static CGO-free, alpine, healthcheck- ready) + docker-compose.yml (restart: unless-stopped = self-heal, named volume, dashboard-ready, optional autoheal profile for unhealthy-restart) + .dockerignore — drop-in for TrueNAS/Synology/unRAID. - macOS Full Disk Access: 'devbox doctor' now tests the ACTUAL protected mount paths (~/Desktop, ~/Documents, ~/Downloads, iCloud) and flags any it can't read, with the exact System Settings fix + a deep link; install.sh points to it on mac. Windows install.ps1 notes Controlled Folder Access (off by default). (TCC.db probe was unreliable across macOS versions — testing the real mounts is honest + version-proof.) shellcheck-clean; 18 pkgs -race green; win+mac build. --- .dockerignore | 14 +++ Dockerfile | 28 +++++ cmd/devbox/fda_darwin.go | 56 ++++++++++ cmd/devbox/fda_other.go | 11 ++ cmd/devbox/fda_test.go | 32 ++++++ cmd/devbox/main.go | 16 +++ docker-compose.yml | 44 ++++++++ install.ps1 | 122 ++++++++++++++++++++++ install.sh | 213 +++++++++++++++++++++++++++++++++++++++ 9 files changed, 536 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 cmd/devbox/fda_darwin.go create mode 100644 cmd/devbox/fda_other.go create mode 100644 cmd/devbox/fda_test.go create mode 100644 docker-compose.yml create mode 100644 install.ps1 create mode 100755 install.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c910a59 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,14 @@ +# keep the build context small + reproducible. NB: do NOT exclude .go sources or +# internal/hub/dashboard/index.html (it's go:embed'd into the hub binary). +.git +.gitignore +.claude +.playwright-mcp +dist +bin +docs/images +*.png +*.pre-v2.bak +README.md +install.ps1 +deploy diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cde5512 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +# devbox hub — multi-stage, static (CGO-free, pure-Go sqlite), tiny final image. +# Build: docker build -t devbox-hub . +# Run: docker run -d --restart unless-stopped -p 8088:8088 -v devbox:/data devbox-hub +# (or just `docker compose up -d` — see docker-compose.yml) + +FROM golang:1.26-alpine AS build +WORKDIR /src +# cache deps separately from source for faster rebuilds +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +ARG VERSION=docker +# CGO off -> a fully static binary that runs on scratch/alpine without libc. +RUN CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X main.version=${VERSION}" \ + -o /out/devbox-hub ./cmd/devbox-hub + +FROM alpine:3.20 +# ca-certificates + tzdata for correct TLS/timestamps; wget (busybox) backs the healthcheck. +RUN apk add --no-cache ca-certificates tzdata && adduser -D -u 10001 devbox +COPY --from=build /out/devbox-hub /usr/local/bin/devbox-hub +USER devbox +VOLUME /data +# 8088 = hub API · 8099 = live dashboard (only reachable if you enable --dashboard) +EXPOSE 8088 8099 +# ENTRYPOINT is just the binary so `command:` / `docker run … ` can tweak flags +# (e.g. add --dashboard). Default CMD serves the hub on all interfaces. +ENTRYPOINT ["devbox-hub"] +CMD ["serve", "--data", "/data", "--listen", "0.0.0.0:8088"] diff --git a/cmd/devbox/fda_darwin.go b/cmd/devbox/fda_darwin.go new file mode 100644 index 0000000..87be3b8 --- /dev/null +++ b/cmd/devbox/fda_darwin.go @@ -0,0 +1,56 @@ +//go:build darwin + +package main + +import ( + "os" + "path/filepath" + "strings" + + "git.shoemoney.ai/shoemoney/devbox/internal/config" +) + +// protectedMounts returns the local mount paths that live under a macOS TCC- +// protected directory (Desktop/Documents/Downloads/iCloud). A daemon can't sync +// these without Full Disk Access — and being a background agent, it can't even +// show the per-folder prompt, so it just silently fails until FDA is granted. +func protectedMounts(mounts []config.Mount) []string { + home, err := os.UserHomeDir() + if err != nil { + return nil + } + guarded := []string{ + filepath.Join(home, "Desktop"), + filepath.Join(home, "Documents"), + filepath.Join(home, "Downloads"), + filepath.Join(home, "Library", "Mobile Documents"), // iCloud Drive + } + var out []string + for _, m := range mounts { + abs, err := filepath.Abs(m.Local) + if err != nil { + continue + } + for _, g := range guarded { + if abs == g || strings.HasPrefix(abs, g+string(os.PathSeparator)) { + out = append(out, m.Local) + break + } + } + } + return out +} + +// blockedByTCC returns the protected paths this process currently CANNOT read +// (permission denied) — the honest signal that Full Disk Access is missing, since +// it tests the exact dirs we sync rather than a TCC.db probe that varies by macOS +// version. A path that reads fine, or doesn't exist yet, is not reported. +func blockedByTCC(paths []string) []string { + var blocked []string + for _, p := range paths { + if _, err := os.ReadDir(p); err != nil && os.IsPermission(err) { + blocked = append(blocked, p) + } + } + return blocked +} diff --git a/cmd/devbox/fda_other.go b/cmd/devbox/fda_other.go new file mode 100644 index 0000000..cdecc44 --- /dev/null +++ b/cmd/devbox/fda_other.go @@ -0,0 +1,11 @@ +//go:build !darwin + +package main + +import "git.shoemoney.ai/shoemoney/devbox/internal/config" + +// Full Disk Access is a macOS concept; elsewhere these are no-ops. (Windows has a +// loose analog — Controlled Folder Access — but it's off by default; install.ps1 +// notes how to allowlist devbox if a user has it on.) +func protectedMounts([]config.Mount) []string { return nil } +func blockedByTCC([]string) []string { return nil } diff --git a/cmd/devbox/fda_test.go b/cmd/devbox/fda_test.go new file mode 100644 index 0000000..db607ef --- /dev/null +++ b/cmd/devbox/fda_test.go @@ -0,0 +1,32 @@ +//go:build darwin + +package main + +import ( + "os" + "path/filepath" + "testing" + + "git.shoemoney.ai/shoemoney/devbox/internal/config" +) + +func TestProtectedMounts(t *testing.T) { + home, err := os.UserHomeDir() + if err != nil { + t.Skip("no home dir") + } + mounts := []config.Mount{ + {Local: filepath.Join(home, "Documents", "work")}, + {Local: filepath.Join(home, "Desktop")}, + {Local: "/tmp/devbox-not-protected"}, + {Local: filepath.Join(home, "Library", "Mobile Documents", "iCloud~x")}, + } + got := protectedMounts(mounts) + if len(got) != 3 { + t.Fatalf("protectedMounts = %v, want 3 (Documents, Desktop, iCloud — not /tmp)", got) + } + // A readable dir is never reported as TCC-blocked. + if b := blockedByTCC([]string{t.TempDir()}); len(b) != 0 { + t.Fatalf("a readable dir was reported blocked: %v", b) + } +} diff --git a/cmd/devbox/main.go b/cmd/devbox/main.go index 8c56134..9ef948a 100644 --- a/cmd/devbox/main.go +++ b/cmd/devbox/main.go @@ -887,6 +887,22 @@ func doctorCmd() *cobra.Command { } _ = os.RemoveAll(probe) + // macOS Full Disk Access — needed to sync TCC-protected folders + // (~/Desktop, ~/Documents, ~/Downloads, iCloud). A background daemon + // can't show the per-folder prompt, so without FDA those mounts fail + // silently. We test the actual protected mounts (honest, version-proof): + // only the ones we'd really sync, and only flag the ones truly blocked. + if prot := protectedMounts(d.Mounts); len(prot) > 0 { + if blocked := blockedByTCC(prot); len(blocked) == 0 { + check(true, false, "full disk access", "protected mounts readable ("+strings.Join(prot, ", ")+")") + } else { + exe, _ := os.Executable() + check(false, false, "full disk access", "NOT granted — can't read "+strings.Join(blocked, ", ")+ + "\n fix: System Settings → Privacy & Security → Full Disk Access → + add "+exe+ + "\n open it: open \"x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles\"") + } + } + // Mounts: dir exists + writable. check(len(d.Mounts) > 0, len(d.Mounts) == 0, "mounts", fmt.Sprintf("%d configured", len(d.Mounts))) for _, m := range d.Mounts { diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8e305b4 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,44 @@ +# devbox hub — drop-in for a NAS (TrueNAS SCALE, Synology, unRAID, any Docker host). +# +# docker compose up -d --build # hub on :8088, data persisted, self-healing +# docker compose exec hub devbox-hub token --data /data # mint a join token +# docker compose logs -f hub +# +# Devices then: devbox setup (point them at http://:8088) + +services: + hub: + build: . + # Prefer a published image once you have one: + # image: git.shoemoney.ai/shoemoney/devbox-hub:latest + container_name: devbox-hub + restart: unless-stopped # keep-alive + auto-restart + recover (crash & reboot) + ports: + - "8088:8088" # hub API + # - "8099:8099" # live dashboard — uncomment AND enable it in `command:` below + volumes: + - devbox-data:/data # snapshots, blobs, token DB — survives upgrades + # Default serves the hub. To enable the live dashboard, swap in this command: + # command: ["serve","--data","/data","--listen","0.0.0.0:8088","--dashboard","--dashboard-addr","0.0.0.0:8099"] + healthcheck: + test: ["CMD", "wget", "-qO-", "http://127.0.0.1:8088/metrics"] + interval: 30s + timeout: 5s + retries: 3 + start_period: 10s + + # Optional self-heal: restarts the hub if its healthcheck goes unhealthy (Docker's + # restart policy only catches crashes, not a wedged-but-running process). Enable with: + # docker compose --profile selfheal up -d + autoheal: + image: willfarrell/autoheal:latest + container_name: devbox-autoheal + restart: unless-stopped + profiles: ["selfheal"] + environment: + AUTOHEAL_CONTAINER_LABEL: all + volumes: + - /var/run/docker.sock:/var/run/docker.sock + +volumes: + devbox-data: diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 0000000..3395ca8 --- /dev/null +++ b/install.ps1 @@ -0,0 +1,122 @@ +#Requires -Version 5 +<# +.SYNOPSIS + devbox installer for Windows. Installs devbox.exe to a location you choose and + (optionally) registers a keep-alive Scheduled Task that runs the sync daemon at + logon and restarts it on failure. + +.EXAMPLE + irm https://git.shoemoney.ai/shoemoney/devbox/raw/branch/main/install.ps1 | iex + .\install.ps1 -BinDir "$env:LOCALAPPDATA\Programs\devbox" -Service + .\install.ps1 -Hub # also install devbox-hub.exe +#> +param( + [string]$BinDir = $env:DEVBOX_BIN_DIR, + [switch]$Hub, + [switch]$Service, + [switch]$NoService, + [string]$ReleaseUrl = $(if ($env:DEVBOX_RELEASE_URL) { $env:DEVBOX_RELEASE_URL } else { "https://git.shoemoney.ai/shoemoney/devbox/releases/download/latest" }) +) +$ErrorActionPreference = "Stop" + +function Say($m) { Write-Host $m } +function Die($m) { Write-Error $m; exit 1 } + +$arch = if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64") { "arm64" } else { "amd64" } +Say "📦 devbox installer — detected windows/$arch" + +$scriptDir = if ($PSScriptRoot) { $PSScriptRoot } else { (Get-Location).Path } +$tmp = Join-Path $env:TEMP ("devbox-install-" + [System.IO.Path]::GetRandomFileName()) +New-Item -ItemType Directory -Path $tmp -Force | Out-Null +$haveGo = [bool](Get-Command go -ErrorAction SilentlyContinue) + +# Resolve a binary: explicit env, local dist\, download, or `go build`. +function Resolve-Bin($name) { + $envVar = ($name.ToUpper().Replace("-", "_")) + "_BIN" # devbox -> DEVBOX_BIN + $explicit = [Environment]::GetEnvironmentVariable($envVar) + if ($explicit -and (Test-Path $explicit)) { return $explicit } + + foreach ($d in @("$scriptDir\dist", "$scriptDir\..\dist", ".\dist")) { + $cand = Get-ChildItem -Path $d -Filter "${name}_*_windows_${arch}.exe" -ErrorAction SilentlyContinue | Select-Object -First 1 + if ($cand) { return $cand.FullName } + } + $dest = Join-Path $tmp "$name.exe" + try { + Invoke-WebRequest -Uri "$ReleaseUrl/${name}_windows_${arch}.exe" -OutFile $dest -UseBasicParsing + if ((Get-Item $dest).Length -gt 0) { return $dest } + } catch { } + if ($haveGo -and (Test-Path "$scriptDir\go.mod")) { + Say " building $name from source (go)..." + $env:CGO_ENABLED = "0" + Push-Location $scriptDir + try { & go build -o $dest "./cmd/$name"; if ($LASTEXITCODE -ne 0) { throw } } finally { Pop-Location } + return $dest + } + Die "could not find or fetch '$name' — set $envVar, run scripts/build-release.sh, or pass -ReleaseUrl" +} + +# Choose install dir. +if (-not $BinDir) { + $def = "$env:LOCALAPPDATA\Programs\devbox" + if ([Environment]::UserInteractive) { + $ans = Read-Host "Where should the binaries live? [$def]" + $BinDir = if ($ans) { $ans } else { $def } + } else { $BinDir = $def } +} +New-Item -ItemType Directory -Path $BinDir -Force | Out-Null +Say "🚚 installing to $BinDir" + +function Install-One($name) { + $src = Resolve-Bin $name + Copy-Item -Path $src -Destination (Join-Path $BinDir "$name.exe") -Force + Say " ✅ $name -> $BinDir\$name.exe" +} +Install-One "devbox" +if ($Hub) { Install-One "devbox-hub" } + +# Add to the user PATH (persisted) if missing. +$userPath = [Environment]::GetEnvironmentVariable("Path", "User") +if ($userPath -notlike "*$BinDir*") { + [Environment]::SetEnvironmentVariable("Path", "$userPath;$BinDir", "User") + Say " ➕ added $BinDir to your user PATH (open a new terminal to pick it up)" +} + +# Optional keep-alive Scheduled Task: runs `devbox start` at logon, restarts on +# failure — the Windows equivalent of launchd KeepAlive / systemd Restart=always. +function Install-Service { + $exe = Join-Path $BinDir "devbox.exe" + $action = New-ScheduledTaskAction -Execute $exe -Argument "start" + $trigger = New-ScheduledTaskTrigger -AtLogOn + $settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -RestartCount 999 -RestartInterval (New-TimeSpan -Minutes 1) -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries + Register-ScheduledTask -TaskName "devbox" -Action $action -Trigger $trigger -Settings $settings -Force | Out-Null + Start-ScheduledTask -TaskName "devbox" + Say " ✅ scheduled task 'devbox' registered (runs at logon, restarts on failure)" + Say " stop: Unregister-ScheduledTask -TaskName devbox -Confirm:`$false" +} + +$doService = $false +if ($Service) { $doService = $true } +elseif ($NoService) { $doService = $false } +elseif ([Environment]::UserInteractive) { + $ans = Read-Host "Set up a keep-alive auto-restart service for the sync daemon? [Y/n]" + $doService = ($ans -notmatch '^[Nn]') +} +if ($doService) { Say "🔁 setting up keep-alive service"; Install-Service } + +# Windows' loose analog to macOS Full Disk Access is Controlled Folder Access +# (Defender ransomware protection) — OFF by default. If a user has it ON, a +# background sync of Documents/Desktop will be blocked until devbox is allowlisted. +try { + $cfa = (Get-MpPreference -ErrorAction SilentlyContinue).EnableControlledFolderAccess + if ($cfa -and $cfa -ne 0) { + Say "" + Say "🔐 Controlled Folder Access is ON — allow devbox to write protected folders:" + Say " Windows Security → Virus & threat protection → Ransomware protection →" + Say " Allow an app through Controlled folder access → add $BinDir\devbox.exe" + } +} catch { } + +Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue +Say "" +Say "🎉 done. Next: run 'devbox setup' to join a hub and start syncing." +if ($Hub) { Say " hub: 'devbox-hub serve --dashboard' — or use the Dockerfile for a NAS (see README)." } diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..72474f4 --- /dev/null +++ b/install.sh @@ -0,0 +1,213 @@ +#!/bin/sh +# devbox installer — macOS + Linux. Detects your platform, installs the binary to +# a location you choose, and (optionally) sets up a keep-alive auto-restart service +# so the sync daemon survives crashes and reboots. +# +# curl -fsSL https://git.shoemoney.ai/shoemoney/devbox/raw/branch/main/install.sh | sh +# sh install.sh # interactive: pick dir, offer service +# sh install.sh --hub --service # also install the hub + enable the service +# DEVBOX_BIN_DIR=~/.local/bin DEVBOX_SERVICE=1 sh install.sh # non-interactive +# +# Knobs (flags or env): --bin-dir DIR (DEVBOX_BIN_DIR) · --hub (DEVBOX_INSTALL_HUB=1) +# · --service / --no-service (DEVBOX_SERVICE=1/0) · --release-url URL (DEVBOX_RELEASE_URL). +set -eu + +INSTALL_HUB="${DEVBOX_INSTALL_HUB:-0}" +BIN_DIR="${DEVBOX_BIN_DIR:-}" +WANT_SERVICE="${DEVBOX_SERVICE:-ask}" +RELEASE_URL="${DEVBOX_RELEASE_URL:-https://git.shoemoney.ai/shoemoney/devbox/releases/download/latest}" + +while [ $# -gt 0 ]; do + case "$1" in + --hub) INSTALL_HUB=1 ;; + --bin-dir) BIN_DIR="$2"; shift ;; + --service) WANT_SERVICE=1 ;; + --no-service) WANT_SERVICE=0 ;; + --release-url) RELEASE_URL="$2"; shift ;; + -h|--help) sed -n '2,14p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;; + *) echo "unknown option: $1" >&2; exit 2 ;; + esac + shift +done + +say() { printf '%s\n' "$*"; } +die() { printf '🛑 %s\n' "$*" >&2; exit 1; } +is_tty(){ [ -t 0 ] && [ -t 1 ]; } + +# --- detect platform ------------------------------------------------------- +OS=$(uname -s | tr '[:upper:]' '[:lower:]') +case "$OS" in darwin|linux) ;; *) die "unsupported OS '$OS' (this installer is macOS/Linux; use install.ps1 on Windows)";; esac +ARCH=$(uname -m) +case "$ARCH" in + x86_64|amd64) ARCH=amd64 ;; + arm64|aarch64) ARCH=arm64 ;; + *) die "unsupported arch '$ARCH'";; +esac +# windows-only target aside, we ship linux/amd64, linux/arm64*, darwin/arm64, darwin/amd64. +say "📦 devbox installer — detected ${OS}/${ARCH}" + +SCRIPT_DIR=$(cd -- "$(dirname -- "$0")" 2>/dev/null && pwd || echo .) +TMP=$(mktemp -d) +trap 'rm -rf "$TMP"' EXIT +HAVE_GO=0; command -v go >/dev/null 2>&1 && HAVE_GO=1 + +# resolve_bin -> prints an executable path for that binary, building or +# downloading as needed. Order: explicit env, local dist/, beside-script, download, +# go build (if a checkout + toolchain are present). Keeps working before any +# published release exists. +resolve_bin() { + name=$1 + envvar=$(printf '%s_BIN' "$(echo "$name" | tr 'a-z-' 'A-Z_')") # devbox->DEVBOX_BIN, devbox-hub->DEVBOX_HUB_BIN + eval explicit="\${$envvar:-}" + if [ -n "${explicit:-}" ] && [ -x "$explicit" ]; then echo "$explicit"; return; fi + + for d in "$SCRIPT_DIR/dist" "$SCRIPT_DIR/../dist" "./dist"; do + for cand in "$d/${name}"_*_"${OS}"_"${ARCH}"; do + [ -x "$cand" ] && { echo "$cand"; return; } + done + done + [ -x "$SCRIPT_DIR/$name" ] && { echo "$SCRIPT_DIR/$name"; return; } + + asset="${name}_${OS}_${ARCH}" + if curl -fsSL "$RELEASE_URL/$asset" -o "$TMP/$name" 2>/dev/null && [ -s "$TMP/$name" ]; then + chmod +x "$TMP/$name"; echo "$TMP/$name"; return + fi + + if [ "$HAVE_GO" = 1 ] && [ -f "$SCRIPT_DIR/go.mod" ]; then + say " building $name from source (go)…" >&2 + ( cd "$SCRIPT_DIR" && CGO_ENABLED=0 go build -o "$TMP/$name" "./cmd/$name" ) || die "go build $name failed" + echo "$TMP/$name"; return + fi + die "could not find or fetch '$name' — set ${envvar}=/path, run scripts/build-release.sh first, or set --release-url" +} + +# --- choose install dir ---------------------------------------------------- +default_bin_dir() { + if [ -w /usr/local/bin ] 2>/dev/null; then echo /usr/local/bin; return; fi + if command -v sudo >/dev/null 2>&1 && [ "$OS" = linux ]; then echo /usr/local/bin; return; fi + echo "$HOME/.local/bin" +} +if [ -z "$BIN_DIR" ]; then + def=$(default_bin_dir) + if is_tty; then + printf 'Where should the binaries live? [%s] ' "$def" + read -r ans /dev/null || ! [ -w "$BIN_DIR" ]; then + if command -v sudo >/dev/null 2>&1; then + SUDO="sudo"; $SUDO mkdir -p "$BIN_DIR" || die "cannot create $BIN_DIR" + else + die "$BIN_DIR is not writable and sudo is unavailable — pick another with --bin-dir" + fi +fi + +install_one() { + src=$(resolve_bin "$1") + $SUDO install -m 0755 "$src" "$BIN_DIR/$1" + say " ✅ $1 → $BIN_DIR/$1" +} + +say "🚚 installing to $BIN_DIR" +install_one devbox +[ "$INSTALL_HUB" = 1 ] && install_one devbox-hub + +case ":$PATH:" in *":$BIN_DIR:"*) ;; *) + say "⚠️ $BIN_DIR is not on your PATH. Add to your shell rc:" + say " export PATH=\"$BIN_DIR:\$PATH\"" ;; +esac + +# --- keep-alive service (optional) ---------------------------------------- +DEVBOX="$BIN_DIR/devbox" + +install_service_macos() { + label="ai.shoemoney.devbox" + plist="$HOME/Library/LaunchAgents/$label.plist" + mkdir -p "$HOME/Library/LaunchAgents" "$HOME/Library/Logs" + cat > "$plist" < + + + Label$label + ProgramArguments$DEVBOXstart + RunAtLoad + KeepAlive + ThrottleInterval5 + StandardOutPath$HOME/Library/Logs/devbox.log + StandardErrorPath$HOME/Library/Logs/devbox.log + +PLIST + launchctl unload "$plist" 2>/dev/null || true + launchctl load "$plist" + say " ✅ launchd agent loaded (KeepAlive). logs: ~/Library/Logs/devbox.log" + say " stop: launchctl unload $plist" +} + +install_service_linux() { + unit="$HOME/.config/systemd/user/devbox.service" + mkdir -p "$HOME/.config/systemd/user" + cat > "$unit" </dev/null 2>&1; then + systemctl --user daemon-reload + systemctl --user enable --now devbox.service + loginctl enable-linger "$USER" 2>/dev/null || say " (run 'sudo loginctl enable-linger $USER' so it starts before login)" + say " ✅ systemd user service enabled (Restart=always). logs: journalctl --user -u devbox -f" + say " stop: systemctl --user disable --now devbox" + else + say " wrote $unit — no systemd here; start manually with: $DEVBOX start" + fi +} + +if [ "$WANT_SERVICE" = ask ]; then + if is_tty; then + printf 'Set up a keep-alive auto-restart service for the sync daemon? [Y/n] ' + read -r ans /dev/null || true ;; esac + fi +fi + +say "" +say "🎉 done. Next: run 'devbox setup' to join a hub and start syncing." +[ "$INSTALL_HUB" = 1 ] && say " hub: 'devbox-hub serve --dashboard' — or use the Dockerfile for a NAS (see README)."