Files

60 lines
3.5 KiB
Python
Executable File

#!/usr/bin/env python3
"""Signed full-client file list for fresh installs and repairs (OctoUpdater install mode, octo-install.sh).
install_list.py --repo R --channel octo --release 20261124 --files <manifest.json> [--check-against <client dir>]
<manifest.json>: [{"path": "OctoWoW/<client path>", "size": n, "sha256": hex}, ...] describing the unpacked tree the
server publishes at <channel>/install/<release>/OctoWoW/. Writes <repo>/<channel>/install.txt + install.txt.sig:
OCTO-INSTALL 1 / RELEASE <id> / BASE install/<id>/OctoWoW/ / F <sha256> <size> <path> ... / END
--check-against compares every listed hash with a local client copy (files changed since are reported, not fatal),
so a list computed on the server is only signed after it agrees with the release source.
"""
import argparse, fcntl, hashlib, json, os, subprocess, sys
from pathlib import Path
from publish import load_state, retired_target, retirement_rules
KEY = Path('/mnt/Games/@project/gateway/runtime/continuation-20261113/claude-linux-build-20261121/signing-key-PRIVATE/patch-manifest-key.pem')
PUB = Path(__file__).with_name('patch-manifest-public.pem')
def sha(p):
h = hashlib.sha256()
with open(p, 'rb') as f:
for b in iter(lambda: f.read(1 << 24), b''): h.update(b)
return h.hexdigest()
def main():
a = argparse.ArgumentParser(); a.add_argument('--repo', required=True); a.add_argument('--channel', default='octo')
a.add_argument('--release', required=True); a.add_argument('--files', required=True); a.add_argument('--check-against')
x = a.parse_args()
rows = json.load(open(x.files)); out = ['OCTO-INSTALL 1', f'RELEASE {x.release}', f'BASE install/{x.release}/OctoWoW/']
agree = differ = missing = 0
for r in sorted(rows, key=lambda r: r['path']):
p = r['path']; assert p.startswith('OctoWoW/') and '..' not in p and '\n' not in p, p
rel = p[len('OctoWoW/'):]
if x.check_against:
q = Path(x.check_against) / rel
if not q.exists(): missing += 1
elif q.stat().st_size == r['size'] and sha(q) == r['sha256']: agree += 1
else: differ += 1; print(' differs locally (changed since release?):', rel, file=sys.stderr)
out.append(f"F {r['sha256']} {r['size']} {rel}")
out.append('END')
if x.check_against: print(f'check: {agree} agree, {differ} differ, {missing} missing locally', file=sys.stderr)
chan = Path(x.repo) / x.channel; m = chan / 'install.txt'; tmp = chan / 'install.txt.new'
directory = os.open(chan, os.O_RDONLY | os.O_DIRECTORY)
try:
# A concurrent retirement may have landed during --check-against.
fcntl.flock(directory, fcntl.LOCK_EX)
rules = retirement_rules(load_state(chan).get('retired_paths', []))
for row in rows:
relative = row['path'].removeprefix('OctoWoW/')
if retired_target(relative, rules):
sys.exit(f'remove retired file from the release tree before signing: {relative}')
tmp.write_text('\n'.join(out) + '\n')
subprocess.run(['openssl', 'dgst', '-sha256', '-sign', str(KEY), '-out', str(chan / 'install.txt.sig.new'), str(tmp)], check=True)
subprocess.run(['openssl', 'dgst', '-sha256', '-verify', str(PUB), '-signature', str(chan / 'install.txt.sig.new'), str(tmp)], check=True, capture_output=True)
os.replace(tmp, m); os.replace(chan / 'install.txt.sig.new', chan / 'install.txt.sig')
finally:
os.close(directory)
print('signed', m, len(rows), 'files', sum(r['size'] for r in rows), 'bytes')
if __name__ == '__main__': main()