|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import os, json, hashlib, tarfile, sys |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +REPO_DIR = "/var/www/repo/stable" |
| 6 | +INDEX_FILE = os.path.join(REPO_DIR, "index.json") |
| 7 | + |
| 8 | +def sha256sum(filename): |
| 9 | + h = hashlib.sha256() |
| 10 | + with open(filename, "rb") as f: |
| 11 | + while chunk := f.read(8192): |
| 12 | + h.update(chunk) |
| 13 | + return f"sha256:{h.hexdigest()}" |
| 14 | + |
| 15 | +def extract_meta(package_file): |
| 16 | + meta = {} |
| 17 | + try: |
| 18 | + with tarfile.open(package_file, "r:gz") as tar: |
| 19 | + f = tar.extractfile("aura.meta") |
| 20 | + if f: |
| 21 | + meta = json.load(f) |
| 22 | + except Exception as e: |
| 23 | + print(f"Warning: cannot read aura.meta in {package_file}: {e}") |
| 24 | + return meta |
| 25 | + |
| 26 | +def update_index(): |
| 27 | + packages = [] |
| 28 | + for f in Path(REPO_DIR).glob("*.aura"): |
| 29 | + meta = extract_meta(f) |
| 30 | + pkg = { |
| 31 | + "name": meta.get("name", f.stem), |
| 32 | + "version": meta.get("version", "unknown"), |
| 33 | + "description": meta.get("description", ""), |
| 34 | + "url": f"https://repo.auraos.org/stable/{f.name}", |
| 35 | + "checksum": sha256sum(f) |
| 36 | + } |
| 37 | + packages.append(pkg) |
| 38 | + |
| 39 | + index = {"version": "1.0", "packages": packages} |
| 40 | + with open(INDEX_FILE, "w") as out: |
| 41 | + json.dump(index, out, indent=2) |
| 42 | + |
| 43 | + print(f"✅ index.json updated with {len(packages)} packages.") |
| 44 | + |
| 45 | +if __name__ == "__main__": |
| 46 | + update_index() |
0 commit comments