VibeGame-8B / code /scripts /install_godot.py
khursheed's picture
Release pipeline source, tests, notebook, and licenses
ae36cfb verified
Raw History Blame Contribute Delete
2.55 kB
#!/usr/bin/env python3
"""Install a checksum-pinned official Godot 4 editor (includes headless mode)."""
import argparse
import hashlib
import json
import os
from pathlib import Path
import platform
import stat
import urllib.request
import zipfile
VERSION = "4.5.1-stable"
ASSETS = {
"Darwin": ("Godot_v4.5.1-stable_macos.universal.zip", "65c27959d02aaacfc131ec7ecb90179ba8045200cb02982bf2be96d117010b8a", "Godot.app/Contents/MacOS/Godot"),
"Linux": ("Godot_v4.5.1-stable_linux.x86_64.zip", "02ec53d1cc7dbb9cc6355393c61b9ab43d1244751a124f10248a4802830788cd", "Godot_v4.5.1-stable_linux.x86_64"),
}
def install(destination: Path) -> Path:
system = platform.system()
if system not in ASSETS or (system == "Linux" and platform.machine() not in ("x86_64", "AMD64")):
raise RuntimeError("Only macOS universal and Linux x86_64 are supported")
filename, expected, relative = ASSETS[system]
destination = destination.expanduser().resolve()
destination.mkdir(parents=True, exist_ok=True)
archive = destination / filename
url = f"https://github.com/godotengine/godot-builds/releases/download/{VERSION}/{filename}"
if not archive.exists():
temporary = archive.with_suffix(".download")
urllib.request.urlretrieve(url, temporary)
temporary.replace(archive)
actual = hashlib.sha256(archive.read_bytes()).hexdigest()
if actual != expected:
raise RuntimeError(f"Godot archive checksum mismatch: {archive}; remove and retry")
binary = destination / relative
if not binary.exists():
with zipfile.ZipFile(archive) as zf:
for member in zf.infolist():
candidate = (destination / member.filename).resolve()
if not candidate.is_relative_to(destination):
raise RuntimeError("Unsafe archive path")
mode = member.external_attr >> 16
if stat.S_ISLNK(mode):
raise RuntimeError("Unexpected archive symlink")
zf.extractall(destination)
binary.chmod(0o755)
(destination / "installation.json").write_text(json.dumps({"version": VERSION, "url": url, "archive_sha256": actual, "binary_sha256": hashlib.sha256(binary.read_bytes()).hexdigest(), "binary": str(binary)}, indent=2) + "\n")
return binary
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--destination", type=Path, default=Path(".tools/godot"))
args = parser.parse_args()
print(install(args.destination))