#!/usr/bin/env python3 import argparse import hashlib import json import os import struct import subprocess import sys import urllib.error import urllib.request from pathlib import Path BINARY_PLATFORMS = ["darwin-amd64", "darwin-arm64", "linux-386", "linux-amd64", "linux-arm", "linux-arm64"] MACHO_MAGIC = b"\xcf\xfa\xed\xfe" ELF_MAGIC = b"\x7fELF" BINARY_REF = { "linux-amd64": (ELF_MAGIC, 64, 0x3e), "linux-arm64": (ELF_MAGIC, 64, 0xb7), "linux-arm": (ELF_MAGIC, 32, 0x28), "linux-386": (ELF_MAGIC, 32, 0x03), "darwin-amd64": (MACHO_MAGIC, 64, 0x01000007), "darwin-arm64": (MACHO_MAGIC, 64, 0x0100000c), } EULA = "End-User-License-Agreement-for-ownCloud-Infinite-Scale.pdf" LICENSES = "third-party-licenses.tar.gz" PROD_TAGS = ("5.0", "7", "8") passed = failed = 0 def ok(msg): global passed; passed += 1; print(f"[PASS] {msg}") def fail(msg): global failed; failed += 1; print(f"[FAIL] {msg}", file=sys.stderr) def expected_files(v): return [f for p in BINARY_PLATFORMS for f in (f"ocis-{v}-{p}", f"ocis-{v}-{p}.sha256")] + [EULA, LICENSES] def is_production(v): return any(v.startswith(t) for t in PROD_TAGS) and "-" not in v def run(cmd): return subprocess.run(cmd, capture_output=True, text=True) def gh_api(path, token): req = urllib.request.Request( f"https://api.github.com{path}", headers={"Authorization": f"Bearer {token}", "Accept": "application/vnd.github+json"}, ) with urllib.request.urlopen(req) as r: return json.load(r) def check_local(directory, version): expected = expected_files(version) present = {f.name for f in directory.iterdir()} missing = [f for f in expected if f not in present] extra = present - set(expected) if missing: fail(f"file set: missing {missing}") else: ok(f"file set: {len(expected)} files present") if extra: fail(f"file set: unexpected {extra}") for platform in BINARY_PLATFORMS: bin_path = directory / f"ocis-{version}-{platform}" sha_path = directory / f"ocis-{version}-{platform}.sha256" if bin_path.exists(): magic, bits, machine = BINARY_REF[platform] if bin_path.stat().st_size == 0: fail(f"{bin_path.name}: empty file") else: h = bin_path.read_bytes()[:20] if not h.startswith(magic): fail(f"{bin_path.name}: wrong magic {h[:4].hex()}") elif magic == ELF_MAGIC: cls, mach = h[4], struct.unpack_from("