#!/usr/bin/env python3

import tarfile
import sys


def main():
    assert len(sys.argv) == 3
    assert sys.argv[1] == "--upstream-version"
    has_elf = False
    with tarfile.open(f"../box64_{sys.argv[2]}.orig.tar.xz") as in_tar:
        for member in in_tar:
            if not member.isfile():
                continue
            with in_tar.extractfile(member) as file:
                magic = file.read(7)
                if magic[:4] == b"\x7fELF" and magic[5:7] == b"\x01\x01":
                    has_elf = True
                    print(f"ELF binary: {member.name}", file=sys.stderr)
    if has_elf:
        exit(1)


if __name__ == "__main__":
    main()
