#!/usr/bin/env python3 """Real installed D09 owner postboot operation after private bootstrap/OS apply. Fresh root fixture observer supplies retained-code reactivation from an external preboot ledger, never renewed package execution or a database restore. """ import importlib.util import atexit import json from pathlib import Path import platform import secrets import socket import struct import subprocess import sys import time assert 'QEMU' in Path('/sys/class/dmi/id/sys_vendor').read_text() assert subprocess.check_output(['findmnt','-n','-o','SOURCE','/'],text=True).strip()=='/dev/vda' sys.path.insert(0,'/usr/libexec') import os_update_executor as executor import d09_wire as wire # Installed executable has no .py suffix; use its explicit source loader. from importlib.machinery import SourceFileLoader loader=SourceFileLoader('installed_provision','/usr/libexec/archipelago-d09-provision') spec=importlib.util.spec_from_loader(loader.name,loader) provision=importlib.util.module_from_spec(spec) loader.exec_module(provision) owner=provision.owner evidence=Path('/var/log/os-ota-stage') def retain_diagnostics(): try: raw=(owner.ROOT/'ledger.json').read_bytes() (evidence/'postboot-retained-ledger.json').write_bytes(raw) value=json.loads(raw) units=['archipelago.service','archipelago-d09-lifecycle.service'] if value.get('execution'):units.append(value['execution']['unit']) command=['journalctl','--no-pager','-b'] for unit in units:command+=['-u',unit] r=subprocess.run(command,capture_output=True,text=True,timeout=30) (evidence/'postboot-d09-journal.log').write_text(r.stdout+r.stderr) except Exception as error: print('POSTBOOT_DIAGNOSTIC_ERROR',repr(error),flush=True) atexit.register(retain_diagnostics) bootstrap=json.loads((evidence/'bootstrap-result.json').read_text()) assert bootstrap['passed'] crypto=json.loads((evidence/'crypto-result.json').read_text()) if (evidence/'crypto-result.json').exists() else None preserved=crypto['forward_preserved'] if crypto else dict(bootstrap['preserved']) if not crypto and bootstrap.get('forward_wallet_sha256'): preserved['/var/lib/archipelago/ota-synthetic-canaries/wallet.db']=bootstrap['forward_wallet_sha256'] binding=json.loads(owner.BINDING.read_text()) instance=executor.Executor(binding['os_update']) assert instance.status['phase']=='REBOOT_REQUIRED' assert platform.release()==instance.plan['boot']['expected_release'] for path,sha in preserved.items(): assert executor.file_hash(path)==sha,path subprocess.run(['systemctl','start','archipelago-d09-lifecycle.service'],check=True) deadline=time.monotonic()+30 while not owner.PRIVATE.exists() and time.monotonic()