Files
CosmicClash/training/setup_linux.sh
T

61 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Idempotent setup for a Linux training box — safe to re-run at any time;
# every step checks before it acts. See TRAINING_LINUX.md.
set -euo pipefail
cd "$(dirname "$0")"
GODOT_VERSION="4.7.1"
GODOT_BIN="${GODOT_BIN:-$HOME/ai-training/godot/Godot_v${GODOT_VERSION}-stable_linux.x86_64}"
# Godot binary
if [ ! -x "$GODOT_BIN" ]; then
echo "Downloading Godot $GODOT_VERSION to $(dirname "$GODOT_BIN")"
mkdir -p "$(dirname "$GODOT_BIN")"
wget -q "https://github.com/godotengine/godot/releases/download/${GODOT_VERSION}-stable/Godot_v${GODOT_VERSION}-stable_linux.x86_64.zip" \
-O /tmp/godot_dl.zip
unzip -o -q /tmp/godot_dl.zip -d "$(dirname "$GODOT_BIN")"
rm /tmp/godot_dl.zip
chmod +x "$GODOT_BIN"
fi
echo "Godot: $GODOT_BIN"
# Export templates — needed to build the exported training binary
# (export_linux.sh); the editor binary alone can't produce release exports.
TEMPLATES_DIR="$HOME/.local/share/godot/export_templates/${GODOT_VERSION}.stable"
if [ ! -d "$TEMPLATES_DIR" ]; then
echo "Downloading Godot $GODOT_VERSION export templates to $TEMPLATES_DIR"
TMP_DL="$(mktemp -d)"
wget -q "https://github.com/godotengine/godot/releases/download/${GODOT_VERSION}-stable/Godot_v${GODOT_VERSION}-stable_export_templates.tpz" \
-O "$TMP_DL/templates.tpz"
unzip -o -q "$TMP_DL/templates.tpz" -d "$TMP_DL"
mkdir -p "$(dirname "$TEMPLATES_DIR")"
# Single mv creates $TEMPLATES_DIR only on full success — if this script is
# interrupted any earlier, the guard above correctly sees "not installed"
# and retries, instead of finding a half-populated dir and skipping.
mv "$TMP_DL/templates" "$TEMPLATES_DIR"
rm -rf "$TMP_DL"
fi
echo "Export templates: $TEMPLATES_DIR"
# Python env
[ -d .venv ] || python3 -m venv .venv
.venv/bin/pip install -q -r requirements.txt
# CUDA check; pip's default torch is CUDA-enabled on Linux, but fall back to
# the explicit CUDA index if this box ended up with a CPU-only build
if [ "$(.venv/bin/python -c 'import torch; print(torch.cuda.is_available())')" != "True" ]; then
echo "CUDA not available — reinstalling torch from the CUDA wheel index"
.venv/bin/pip install -q torch --index-url https://download.pytorch.org/whl/cu121
fi
# Import pass — a fresh clone has no .godot/ cache, so class_name scripts
# (GameMode, Goal, …) aren't registered and scenes fail to load until the
# project is imported once. Cheap when the cache already exists.
"$GODOT_BIN" --headless --path ../Game --import
# Headless smoke test — the game must boot without rendering
"$GODOT_BIN" --headless --path ../Game res://scenes/free_play.tscn --quit-after 300
echo "Setup OK — train with: ./run_training.sh <experiment> [train.py args...]"