Files
L4-Patcher-IOS/tools/zsign.py
T
2026-09-22 18:48:00 +08:00

53 lines
1.5 KiB
Python

"""Download and extract zsign for this operating system."""
import os
import platform
from pathlib import Path
from fetch import ensure_archive, extract_archive
ROOT = Path(__file__).resolve().parents[1]
TOOLS = ROOT / "tools" / "zsign"
VERSION = "1.1.2"
RELEASE = f"https://github.com/zhlynn/zsign/releases/tag/v{VERSION}"
ARCH = {
"amd64": "x86_64",
"x86_64": "x86_64",
"arm64": "aarch64",
"aarch64": "aarch64",
}
# Official v1.1.2 assets. There is no Windows arm64 or macOS x64 build.
ASSETS = {
("windows", "x86_64"): ("zsign-windows-x64.zip", "zsign.exe"),
("darwin", "aarch64"): ("zsign-macos-arm64.tar.gz", "zsign"),
("linux", "x86_64"): ("zsign-linux-x86_64.tar.gz", "zsign"),
("linux", "aarch64"): ("zsign-linux-aarch64.tar.gz", "zsign"),
}
def main() -> None:
system = platform.system().lower()
arch = ARCH.get(platform.machine().lower())
asset = ASSETS.get((system, arch))
if not asset:
print(RELEASE)
raise SystemExit(2)
filename, binary = asset
if (TOOLS / binary).is_file():
return
url = f"https://github.com/zhlynn/zsign/releases/download/v{VERSION}/{filename}"
archive = TOOLS.parent / filename
print(url, flush=True)
ensure_archive(url, archive)
extract_archive(archive, TOOLS)
installed = TOOLS / binary
if not installed.is_file():
raise SystemExit(2)
if os.name != "nt":
installed.chmod(0o755)
if __name__ == "__main__":
main()