-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathstart_linux.sh
More file actions
173 lines (146 loc) · 4.38 KB
/
Copy pathstart_linux.sh
File metadata and controls
173 lines (146 loc) · 4.38 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
STATE_FILE="$ROOT_DIR/.installer_state.env"
DOCKER_DIR="$ROOT_DIR/docker"
MODE="install" # install | doctor
FIX_MODE="0" # 0 | 1
BACKEND_OVERRIDE="" # cpu | cuda13 | rocm | slim
COMPOSE_MODE="ghcr" # ghcr | local
HEALTH_URL="http://localhost:5107/"
usage() {
cat <<'EOF'
Usage: ./start_linux.sh [options]
Options:
--doctor Run checks only, do not change anything.
--fix Attempt limited auto-remediation where possible.
--backend cpu|cuda13|rocm|slim Force backend selection. slim is explicit only and is not auto-detected.
--compose ghcr|local Use GHCR compose files (default) or local build files.
--help Show this help.
EOF
}
log() { printf '[guideants-installer] %s\n' "$*"; }
warn() { printf '[guideants-installer][warn] %s\n' "$*" >&2; }
fail() { printf '[guideants-installer][error] %s\n' "$*" >&2; exit 1; }
save_state() {
cat >"$STATE_FILE" <<EOF
BACKEND=${SELECTED_BACKEND:-}
COMPOSE_MODE=${COMPOSE_MODE}
LAST_RUN_EPOCH=$(date +%s)
EOF
}
detect_backend() {
if [[ -n "$BACKEND_OVERRIDE" ]]; then
SELECTED_BACKEND="$BACKEND_OVERRIDE"
return
fi
if command -v nvidia-smi >/dev/null 2>&1; then
if nvidia-smi >/dev/null 2>&1; then
SELECTED_BACKEND="cuda13"
return
fi
fi
if [[ -e "/dev/kfd" ]]; then
SELECTED_BACKEND="rocm"
return
fi
if command -v rocminfo >/dev/null 2>&1; then
if rocminfo >/dev/null 2>&1; then
SELECTED_BACKEND="rocm"
return
fi
fi
SELECTED_BACKEND="cpu"
}
ensure_cmd() {
local cmd="$1"
command -v "$cmd" >/dev/null 2>&1 || return 1
}
check_prereqs() {
log "Running preflight checks..."
if ! ensure_cmd docker; then
if [[ "$FIX_MODE" == "1" ]]; then
warn "Docker is missing. Auto-install is distro-specific; install Docker Engine + Compose plugin, then rerun."
fi
fail "Docker CLI not found."
fi
if ! docker compose version >/dev/null 2>&1; then
fail "Docker Compose plugin not found (docker compose)."
fi
if ! docker info >/dev/null 2>&1; then
fail "Docker daemon is not reachable. Start Docker and rerun."
fi
}
select_compose_file() {
if [[ "$COMPOSE_MODE" == "local" ]]; then
case "$SELECTED_BACKEND" in
slim) COMPOSE_FILE="docker-compose.slim.yml" ;;
cuda13) COMPOSE_FILE="docker-compose.cuda.yml" ;;
rocm) COMPOSE_FILE="docker-compose.rocm.yml" ;;
*) COMPOSE_FILE="docker-compose.cpu.yml" ;;
esac
else
case "$SELECTED_BACKEND" in
slim) COMPOSE_FILE="docker-compose.ghcr-slim.yml" ;;
cuda13) COMPOSE_FILE="docker-compose.ghcr-cuda13.yml" ;;
rocm) COMPOSE_FILE="docker-compose.ghcr-rocm.yml" ;;
*) COMPOSE_FILE="docker-compose.ghcr-cpu.yml" ;;
esac
fi
}
wait_for_health() {
log "Waiting for GuideAnts UI to become reachable at $HEALTH_URL"
for _ in $(seq 1 120); do
if curl -fsS "$HEALTH_URL" >/dev/null 2>&1; then
return 0
fi
sleep 2
done
return 1
}
open_browser() {
if ensure_cmd xdg-open; then
xdg-open "$HEALTH_URL" >/dev/null 2>&1 || true
fi
}
while [[ $# -gt 0 ]]; do
case "$1" in
--doctor) MODE="doctor" ;;
--fix) FIX_MODE="1" ;;
--backend)
[[ $# -ge 2 ]] || fail "Missing value for --backend"
BACKEND_OVERRIDE="$2"
shift
;;
--compose)
[[ $# -ge 2 ]] || fail "Missing value for --compose"
COMPOSE_MODE="$2"
shift
;;
--help|-h) usage; exit 0 ;;
*) fail "Unknown option: $1" ;;
esac
shift
done
[[ "$COMPOSE_MODE" == "ghcr" || "$COMPOSE_MODE" == "local" ]] || fail "--compose must be ghcr or local"
[[ -z "$BACKEND_OVERRIDE" || "$BACKEND_OVERRIDE" == "cpu" || "$BACKEND_OVERRIDE" == "cuda13" || "$BACKEND_OVERRIDE" == "rocm" || "$BACKEND_OVERRIDE" == "slim" ]] || fail "--backend must be cpu, cuda13, rocm, or slim"
check_prereqs
detect_backend
select_compose_file
log "Selected backend: $SELECTED_BACKEND"
log "Compose file: docker/$COMPOSE_FILE"
if [[ "$MODE" == "doctor" ]]; then
log "Doctor mode complete. No changes were made."
save_state
exit 0
fi
pushd "$DOCKER_DIR" >/dev/null
docker compose -f "$COMPOSE_FILE" up -d
popd >/dev/null
if wait_for_health; then
log "GuideAnts is up: $HEALTH_URL"
open_browser
else
warn "GuideAnts did not pass health check in time. Check: docker compose -f docker/$COMPOSE_FILE ps"
fi
save_state