54 lines
2.3 KiB
Python
54 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Compose a Linux inventory-only release without rotating the installed helper or updater.
|
|
|
|
Use two build directories from tools/build.py, and the helper SHA-256 from
|
|
the currently published release for the target platform. The composition
|
|
receipt identifies the actual source build for every file.
|
|
"""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import tempfile
|
|
|
|
from agent_release import binaries, FILES, LINUX, LINUX_ARM64
|
|
|
|
|
|
def compose(new, previous, helper_sha, destination):
|
|
def receipt(folder):
|
|
r = folder / 'manifest.json'
|
|
target, _ = binaries(folder, r)
|
|
digest = hashlib.sha256(r.read_bytes()).hexdigest()
|
|
if folder.name != digest or target not in (LINUX, LINUX_ARM64):
|
|
raise ValueError('Expected a receipt-addressed Linux build')
|
|
meta = json.loads(r.read_bytes())
|
|
return target, dict(revision=meta['revision'], receipt_sha256=digest,
|
|
builder=meta['builder']), meta['sha256']
|
|
target, fresh, new_hashes = receipt(new)
|
|
old_target, old, old_hashes = receipt(previous)
|
|
if target != old_target or old_hashes['rmm-privileged-helper'] != helper_sha:
|
|
raise ValueError('Prior build does not match selected platform and published helper')
|
|
with tempfile.TemporaryDirectory(dir=destination.parent) as tmp:
|
|
bundle = Path(tmp) / 'bundle'
|
|
bundle.mkdir()
|
|
hashes, origins = {}, {}
|
|
for name in FILES[target]:
|
|
folder, source, digests = (new, fresh, new_hashes) if name == 'rmm-agent' else (previous, old, old_hashes)
|
|
shutil.copy2(folder / name, bundle / name)
|
|
origins[name], hashes[name] = source, digests[name]
|
|
r = bundle / 'manifest.json'
|
|
r.write_text(json.dumps(dict(target=target, sha256=hashes, sources=origins), indent=2) + '\n')
|
|
binaries(bundle, r)
|
|
os.rename(bundle, destination)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
p = argparse.ArgumentParser(description=__doc__)
|
|
for opt in ['new', 'previous', 'destination']:
|
|
p.add_argument('--' + opt, type=Path, required=True)
|
|
p.add_argument('--published-helper-sha256', required=True)
|
|
a = p.parse_args()
|
|
compose(a.new, a.previous, a.published_helper_sha256, a.destination)
|