#!/usr/bin/env python3 import argparse import re import sys import urllib.request from pathlib import Path DOWNLOADS_URL = "https://busybox.net/downloads/" VERSION_RE = re.compile(r"busybox-([0-9]+(?:\.[0-9]+)+)\.tar\.bz2") def version_key(version: str): return tuple(int(part) for part in version.split(".")) def fetch_latest_version() -> str: req = urllib.request.Request( DOWNLOADS_URL, headers={"User-Agent": "static-musl-builds-updater"}, ) with urllib.request.urlopen(req, timeout=30) as resp: html = resp.read().decode("utf-8", "replace") versions = sorted(set(VERSION_RE.findall(html)), key=version_key) if not versions: raise RuntimeError("No BusyBox versions found on downloads page") return versions[-1] def main() -> int: parser = argparse.ArgumentParser() parser.add_argument("--version-file", required=True, type=Path) parser.add_argument("--update-file", action="store_true") args = parser.parse_args() latest = fetch_latest_version() current = args.version_file.read_text(encoding="utf-8").strip() if args.version_file.exists() else "" print(f"current={current or ''}") print(f"latest={latest}") if current == latest: print("status=up-to-date") return 0 print("status=update-available") if args.update_file: args.version_file.parent.mkdir(parents=True, exist_ok=True) args.version_file.write_text(latest + "\n", encoding="utf-8") print(f"updated_file={args.version_file}") return 0 if __name__ == "__main__": sys.exit(main())