forked from nikopueringer/CorridorKey
-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy path1-install.sh
More file actions
412 lines (385 loc) · 15.4 KB
/
Copy path1-install.sh
File metadata and controls
412 lines (385 loc) · 15.4 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
echo ""
echo " ========================================"
echo " EZ-CorridorKey - One-Click Installer"
echo " ========================================"
echo ""
PYTHON_SPEC="${CORRIDORKEY_PYTHON_VERSION:-3.11}"
INSTALL_PYTHON=""
INDEX_URL=""
resolve_system_python() {
local candidate ver major minor
for candidate in python3 python; do
if ! command -v "$candidate" >/dev/null 2>&1; then
continue
fi
ver="$("$candidate" --version 2>&1 | awk '{print $2}')"
major="$(echo "$ver" | cut -d. -f1)"
minor="$(echo "$ver" | cut -d. -f2)"
if [ "$major" -eq 3 ] && [ "$minor" -ge 10 ] && [ "$minor" -lt 14 ]; then
INSTALL_PYTHON="$candidate"
return 0
fi
done
return 1
}
echo "[0/6] Installer runtime target..."
echo " CorridorKey will provision and use Python ${PYTHON_SPEC} for this install."
# ── Step 2: Check for old venv ──
if [ -d "venv" ] && [ ! -d ".venv" ]; then
echo ""
echo " [NOTE] Found old 'venv' directory from previous installer."
echo " The new installer uses '.venv'. You can safely delete 'venv' later."
echo ""
fi
# ── Step 3: Install/locate uv ──
echo "[2/6] Setting up package manager..."
UV_AVAILABLE=0
if command -v uv &>/dev/null; then
UV_AVAILABLE=1
echo " [OK] uv found"
elif [ -f "$HOME/.local/bin/uv" ]; then
export PATH="$HOME/.local/bin:$PATH"
UV_AVAILABLE=1
echo " [OK] uv found at ~/.local/bin"
else
echo " Installing uv (fast Python package manager)..."
if curl -LsSf https://astral.sh/uv/install.sh | sh 2>/dev/null; then
export PATH="$HOME/.local/bin:$PATH"
if command -v uv &>/dev/null; then
UV_AVAILABLE=1
echo " [OK] uv installed"
fi
fi
if [ "$UV_AVAILABLE" -eq 0 ]; then
echo " [WARN] uv install failed."
fi
fi
OS_TYPE="linux"
case "$(uname -s)" in
Darwin*) OS_TYPE="macos" ;;
esac
# ── Step 4: Provision Python ──
echo "[3/6] Provisioning Python..."
if [ "$UV_AVAILABLE" -eq 1 ]; then
if uv python install --managed-python "$PYTHON_SPEC" >/dev/null 2>&1; then
INSTALL_PYTHON="$(uv python find --managed-python "$PYTHON_SPEC")"
else
echo " [WARN] Managed Python download failed, trying a supported system Python..."
fi
fi
if [ -z "$INSTALL_PYTHON" ]; then
if ! resolve_system_python; then
echo " [ERROR] Could not find a supported Python runtime."
echo " CorridorKey needs Python 3.10-3.13, and the one-click installer targets Python ${PYTHON_SPEC}."
case "$OS_TYPE" in
macos) echo " Install via: brew install python@3.11" ;;
*) echo " Install via: your package manager, then rerun this installer." ;;
esac
exit 1
fi
fi
PYVER="$("$INSTALL_PYTHON" --version 2>&1 | awk '{print $2}')"
echo " [OK] Using Python $PYVER ($INSTALL_PYTHON)"
# ── Step 5: Create venv + install dependencies ──
echo "[4/6] Installing dependencies..."
if [ "$UV_AVAILABLE" -eq 1 ]; then
echo " Creating virtual environment..."
uv venv --clear --managed-python --python "$INSTALL_PYTHON" .venv >/dev/null 2>&1
echo " Installing packages (uv + auto CUDA detection)..."
if uv pip install --python .venv/bin/python --torch-backend=auto -e . 2>&1; then
echo " [OK] Dependencies installed via uv"
else
echo " [WARN] uv install failed, trying pip fallback..."
UV_AVAILABLE=0
fi
fi
if [ "$UV_AVAILABLE" -eq 0 ]; then
echo " Creating virtual environment..."
rm -rf .venv
"$INSTALL_PYTHON" -m venv .venv
source .venv/bin/activate
if [ "$OS_TYPE" = "macos" ]; then
# macOS: default PyTorch wheels include MPS support, no special index needed
echo " macOS detected — PyTorch will use MPS (Apple Silicon) or CPU"
elif command -v nvidia-smi &>/dev/null; then
CUDA_VER=$(nvidia-smi 2>/dev/null | grep -oP 'CUDA Version: \K[0-9]+\.[0-9]+' || echo "")
if [ -n "$CUDA_VER" ]; then
CUDA_MAJOR=$(echo "$CUDA_VER" | cut -d. -f1)
CUDA_MINOR=$(echo "$CUDA_VER" | cut -d. -f2)
echo " CUDA $CUDA_VER detected"
# cu128 wheels cover Pascal through Blackwell and run on
# any CUDA 12.6-13.x driver. cu130 was removed here in
# 1.9.2 because it drops Pascal (sm_60/61) kernels and
# crashes GTX 10-series users with "no kernel image".
if [ "$CUDA_MAJOR" -ge 13 ]; then
INDEX_URL="https://download.pytorch.org/whl/cu128"
elif [ "$CUDA_MAJOR" -eq 12 ] && [ "$CUDA_MINOR" -ge 6 ]; then
INDEX_URL="https://download.pytorch.org/whl/cu128"
elif [ "$CUDA_MAJOR" -eq 12 ]; then
INDEX_URL="https://download.pytorch.org/whl/cu126"
fi
fi
fi
if [ -z "$INDEX_URL" ] && [ "$OS_TYPE" != "macos" ]; then
echo " No NVIDIA GPU detected, installing CPU-only PyTorch"
INDEX_URL="https://download.pytorch.org/whl/cpu"
fi
echo " Installing packages via pip (this may take a few minutes)..."
.venv/bin/python -m pip install --upgrade pip >/dev/null 2>&1
if [ -n "$INDEX_URL" ]; then
.venv/bin/python -m pip install --extra-index-url "$INDEX_URL" -e . 2>&1
else
.venv/bin/python -m pip install -e . 2>&1
fi
echo " [OK] Dependencies installed via pip"
fi
echo "[4b/6] Verifying torch runtime..."
DIAGNOSTICS_DIR="logs/diagnostics"
TORCH_RUNTIME_LOG="${DIAGNOSTICS_DIR}/install-torch-runtime.json"
SUPPORT_REPORT_LOG="${DIAGNOSTICS_DIR}/install-support-report.md"
mkdir -p "$DIAGNOSTICS_DIR"
if .venv/bin/python scripts/verify_torch_runtime.py --log "$TORCH_RUNTIME_LOG"; then
echo " [OK] Torch runtime verified"
else
echo " [ERROR] Installed torch runtime did not validate."
echo " Preparing a pre-filled GitHub issue to help you report this."
if ! .venv/bin/python scripts/open_installer_issue.py --json "$TORCH_RUNTIME_LOG" --body-out "$SUPPORT_REPORT_LOG" --stage "${OS_TYPE}-installer-runtime-verification"; then
echo " [WARN] Could not open the GitHub issue helper automatically."
fi
echo " See $TORCH_RUNTIME_LOG and $SUPPORT_REPORT_LOG for details."
exit 1
fi
# ── Step 4c: MLX acceleration for Apple Silicon ──
if [ "$OS_TYPE" = "macos" ] && [ "$(uname -m)" = "arm64" ]; then
echo "[4c/6] Installing MLX acceleration for Apple Silicon..."
MLX_OK=0
if [ "$UV_AVAILABLE" -eq 1 ]; then
if uv pip install --python .venv/bin/python -e ".[mlx]" 2>&1; then
MLX_OK=1
fi
else
if .venv/bin/python -m pip install -e ".[mlx]" 2>&1; then
MLX_OK=1
fi
fi
if [ "$MLX_OK" -eq 1 ]; then
echo " [OK] MLX acceleration installed (1.5-2x faster inference on Apple Silicon)"
echo " Downloading MLX checkpoint..."
.venv/bin/python scripts/setup_models.py --corridorkey-mlx 2>&1 || \
echo " [WARN] MLX checkpoint download failed. You can retry: .venv/bin/python scripts/setup_models.py --corridorkey-mlx"
else
echo " [WARN] MLX install failed. CorridorKey will use PyTorch MPS instead."
echo " You can retry later with: .venv/bin/python -m pip install -e '.[mlx]'"
fi
else
echo "[4c/6] MLX acceleration — skipped (Apple Silicon only)"
fi
echo "[4d/6] Optional SAM2 tracker..."
INSTALL_SAM2="y"
if [ "$OS_TYPE" = "macos" ]; then
echo " [NOTE] SAM2 tracking on macOS is experimental in CorridorKey."
fi
INSTALL_SAM2_INPUT="${CORRIDORKEY_INSTALL_SAM2:-}"
if [ -z "$INSTALL_SAM2_INPUT" ]; then
read -rp " Install SAM2 tracking support? [Y/n]: " INSTALL_SAM2_INPUT
fi
if [[ "$(echo "${INSTALL_SAM2_INPUT:-y}" | tr '[:upper:]' '[:lower:]')" == "n" ]]; then
INSTALL_SAM2="n"
fi
if [ "$INSTALL_SAM2" = "y" ]; then
SAM2_OK=0
echo " Installing SAM2 tracker package..."
if [ "$UV_AVAILABLE" -eq 1 ]; then
if uv pip install --python .venv/bin/python --torch-backend=auto -e ".[tracker]" 2>&1; then
SAM2_OK=1
fi
else
if [ -n "${INDEX_URL:-}" ]; then
if .venv/bin/python -m pip install --extra-index-url "$INDEX_URL" -e ".[tracker]" 2>&1; then
SAM2_OK=1
fi
else
if .venv/bin/python -m pip install -e ".[tracker]" 2>&1; then
SAM2_OK=1
fi
fi
fi
if [ "$SAM2_OK" -eq 1 ]; then
echo " [OK] SAM2 tracker support installed"
DOWNLOAD_SAM2="${CORRIDORKEY_PREDOWNLOAD_SAM2:-}"
if [ -z "$DOWNLOAD_SAM2" ]; then
read -rp " Pre-download default SAM2 Base+ model? (324MB) [Y/n]: " DOWNLOAD_SAM2
fi
if [[ "$(echo "${DOWNLOAD_SAM2:-y}" | tr '[:upper:]' '[:lower:]')" != "n" ]]; then
.venv/bin/python scripts/setup_models.py --sam2
fi
else
echo " [WARN] SAM2 tracker install failed. CorridorKey will still run without Track Mask."
echo " You can retry later with:"
echo " .venv/bin/python -m pip install -e '.[tracker]'"
fi
fi
# ── Step 6: Check FFmpeg ──
echo "[5/6] Checking FFmpeg..."
if .venv/bin/python scripts/check_ffmpeg.py; then
:
else
echo " [WARN] Video import/export requires FFmpeg 7.0+ and FFprobe."
case "$OS_TYPE" in
macos)
if command -v brew &>/dev/null; then
INSTALL_FFMPEG="${CORRIDORKEY_INSTALL_FFMPEG:-}"
if [ -z "$INSTALL_FFMPEG" ]; then
if [ -t 0 ]; then
read -rp " FFmpeg not found. Install via Homebrew? [Y/n]: " INSTALL_FFMPEG
else
INSTALL_FFMPEG="y"
echo " Non-interactive shell detected — defaulting to Homebrew FFmpeg install."
fi
fi
if [[ "$(echo "${INSTALL_FFMPEG:-y}" | tr '[:upper:]' '[:lower:]')" != "n" ]]; then
echo " Installing FFmpeg via Homebrew..."
brew list ffmpeg >/dev/null 2>&1 || brew install ffmpeg
if .venv/bin/python scripts/check_ffmpeg.py; then
echo " [OK] FFmpeg installed successfully"
else
echo " [WARN] FFmpeg installed but validation failed."
echo " Try: brew reinstall ffmpeg"
fi
else
echo " Skipped. Install later via: brew install ffmpeg"
fi
else
echo " Homebrew not found. Install Homebrew first:"
echo " /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\""
echo " Then: brew install ffmpeg"
fi ;;
*)
if [ -f /etc/debian_version ]; then
echo " Install via: sudo apt install ffmpeg"
elif [ -f /etc/fedora-release ]; then
echo " Install via: sudo dnf install ffmpeg"
elif [ -f /etc/arch-release ]; then
echo " Install via: sudo pacman -S ffmpeg"
else
echo " Install via your package manager or https://ffmpeg.org/download.html"
fi ;;
esac
echo " Verify both commands afterward:"
echo " ffmpeg -version"
echo " ffprobe -version"
echo ""
fi
# ── Step 7: Download model weights ──
echo "[6/6] Checking model weights..."
.venv/bin/python scripts/setup_models.py --check
.venv/bin/python scripts/setup_models.py --corridorkey
if [ $? -ne 0 ]; then
echo " [WARN] CorridorKey model download failed. Retry later:"
echo " .venv/bin/python scripts/setup_models.py --corridorkey"
fi
echo ""
echo "[6/6] Optional models (can be downloaded later)"
echo ""
INSTALL_GVM="${CORRIDORKEY_INSTALL_GVM:-}"
if [ -z "$INSTALL_GVM" ]; then
read -rp " Download GVM alpha generator? (~6GB) [y/N]: " INSTALL_GVM
fi
if [[ "$(echo "$INSTALL_GVM" | tr '[:upper:]' '[:lower:]')" == "y" ]]; then
.venv/bin/python scripts/setup_models.py --gvm
fi
if [ "$OS_TYPE" = "macos" ]; then
echo ""
echo " [NOTE] VideoMaMa runs on CPU on macOS (no MPS support yet)."
echo " It works but will be slow. 37GB download — skip if unsure."
fi
INSTALL_VM="${CORRIDORKEY_INSTALL_VIDEOMAMA:-}"
if [ -z "$INSTALL_VM" ]; then
read -rp " Download VideoMaMa alpha generator? (~37GB) [y/N]: " INSTALL_VM
fi
if [[ "$(echo "$INSTALL_VM" | tr '[:upper:]' '[:lower:]')" == "y" ]]; then
.venv/bin/python scripts/setup_models.py --videomama
fi
# ── Create desktop shortcut ──
echo ""
CREATE_SHORTCUT="${CORRIDORKEY_CREATE_SHORTCUT:-}"
if [ -z "$CREATE_SHORTCUT" ]; then
read -rp " Create desktop shortcut? [Y/n]: " CREATE_SHORTCUT
fi
if [[ "$(echo "$CREATE_SHORTCUT" | tr '[:upper:]' '[:lower:]')" != "n" ]]; then
ICON_PATH="$SCRIPT_DIR/ui/theme/corridorkey.png"
if [ "$OS_TYPE" = "macos" ]; then
# macOS: create a minimal .app bundle on Desktop (no Terminal window)
APP_DIR="$HOME/Desktop/EZ-CorridorKey.app/Contents/MacOS"
mkdir -p "$APP_DIR"
mkdir -p "$HOME/Desktop/EZ-CorridorKey.app/Contents/Resources"
# Copy icon if available
if [ -f "$ICON_PATH" ]; then
cp "$ICON_PATH" "$HOME/Desktop/EZ-CorridorKey.app/Contents/Resources/corridorkey.png"
fi
cat > "$HOME/Desktop/EZ-CorridorKey.app/Contents/Info.plist" <<PLISTEOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key><string>EZ-CorridorKey</string>
<key>CFBundleExecutable</key><string>launch</string>
<key>CFBundleIconFile</key><string>corridorkey</string>
<key>LSUIElement</key><false/>
</dict>
</plist>
PLISTEOF
cat > "$APP_DIR/launch" <<LAUNCHEOF
#!/usr/bin/env bash
cd "$SCRIPT_DIR"
.venv/bin/python main.py
LAUNCHEOF
chmod +x "$APP_DIR/launch"
if [ -d "$HOME/Desktop/EZ-CorridorKey.app" ]; then
echo " [OK] Desktop app created (EZ-CorridorKey.app — no Terminal window)"
echo " Tip: drag it to the Dock for quick access"
else
echo " [WARN] App creation failed"
fi
else
# Linux: create a .desktop file
DESKTOP_FILE="$HOME/.local/share/applications/ez-corridorkey.desktop"
mkdir -p "$HOME/.local/share/applications"
cat > "$DESKTOP_FILE" <<DSKEOF
[Desktop Entry]
Name=EZ-CorridorKey
Comment=AI Green Screen Keyer
Exec=$SCRIPT_DIR/2-start.sh
Icon=$ICON_PATH
Terminal=false
Type=Application
Categories=Graphics;Video;
DSKEOF
# Also copy to Desktop if it exists
if [ -d "$HOME/Desktop" ]; then
cp "$DESKTOP_FILE" "$HOME/Desktop/EZ-CorridorKey.desktop"
chmod +x "$HOME/Desktop/EZ-CorridorKey.desktop"
fi
if [ -f "$DESKTOP_FILE" ]; then
echo " [OK] Desktop shortcut created — also added to app menu"
else
echo " [WARN] Shortcut creation failed"
fi
fi
fi
# ── Done ──
echo ""
echo " ========================================"
echo " Installation complete!"
echo " ========================================"
echo ""
echo " To launch: ./2-start.sh (or the desktop shortcut)"
echo ""
echo " To download optional models later:"
echo " .venv/bin/python scripts/setup_models.py --gvm"
echo " .venv/bin/python scripts/setup_models.py --videomama"
echo ""