-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathincus.macos.setup
More file actions
executable file
·82 lines (71 loc) · 3.01 KB
/
incus.macos.setup
File metadata and controls
executable file
·82 lines (71 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# incus.macos.setup
# macOS pre-flight: ensures Colima + Incus are installed and running.
# Sourced by incus.init — inherits colors, log/warn/error, and set -euo pipefail.
# ---------------------------------------------------------------------------
# Skip on Linux
# ---------------------------------------------------------------------------
if [[ "$(uname -s)" != "Darwin" ]]; then
return 0 2>/dev/null || true
fi
# ---------------------------------------------------------------------------
# Defaults (override by setting these vars before sourcing)
# ---------------------------------------------------------------------------
COLIMA_CPUS="${COLIMA_CPUS:-4}"
COLIMA_MEMORY="${COLIMA_MEMORY:-8}"
COLIMA_DISK="${COLIMA_DISK:-100}"
COLIMA_PROFILE="${COLIMA_PROFILE:-agent-incus}"
# ---------------------------------------------------------------------------
# Check Colima
# ---------------------------------------------------------------------------
if ! command -v colima >/dev/null 2>&1; then
echo ""
warn "Colima is required to run Incus on macOS."
read -rp "Install Colima via brew? [Y/n] " reply
if [[ "${reply:-Y}" =~ ^[Nn]$ ]]; then
error "Colima is required on macOS. Install it with: brew install colima"
fi
log "Installing Colima..."
brew install colima
fi
# ---------------------------------------------------------------------------
# Check Incus CLI
# ---------------------------------------------------------------------------
if ! command -v incus >/dev/null 2>&1; then
echo ""
warn "Incus CLI is required."
read -rp "Install Incus via brew? [Y/n] " reply
if [[ "${reply:-Y}" =~ ^[Nn]$ ]]; then
error "Incus CLI is required. Install it with: brew install incus"
fi
log "Installing Incus CLI..."
brew install incus
fi
# ---------------------------------------------------------------------------
# Check Colima profile
# ---------------------------------------------------------------------------
PROFILE_EXISTS=0
PROFILE_RUNNING=0
if colima list 2>/dev/null | grep -q "$COLIMA_PROFILE"; then
PROFILE_EXISTS=1
if colima list 2>/dev/null | grep "$COLIMA_PROFILE" | grep -q "Running"; then
PROFILE_RUNNING=1
fi
fi
if [[ "$PROFILE_EXISTS" == "0" ]]; then
log "Creating Colima profile '${COLIMA_PROFILE}' with Incus runtime..."
log "Resources: ${COLIMA_CPUS} CPUs, ${COLIMA_MEMORY}GB memory, ${COLIMA_DISK}GB disk"
colima start --runtime incus --profile "$COLIMA_PROFILE" \
--cpu "$COLIMA_CPUS" --memory "$COLIMA_MEMORY" --disk "$COLIMA_DISK"
elif [[ "$PROFILE_RUNNING" == "0" ]]; then
log "Starting Colima profile '${COLIMA_PROFILE}'..."
colima start --profile "$COLIMA_PROFILE"
else
log "Colima profile '${COLIMA_PROFILE}' is running."
fi
# ---------------------------------------------------------------------------
# Verify Incus connectivity
# ---------------------------------------------------------------------------
if ! incus list >/dev/null 2>&1; then
error "Incus CLI cannot connect. Check 'incus remote list' and ensure a local remote is configured."
fi
log "Incus is ready."