"""Install the existing canonical chrome publisher after successful promotion.""" from pathlib import Path import argparse import os import subprocess CURRENT = Path('/home/dunerealms/apps/dunerealms/current') RELEASES = Path('/home/dunerealms/apps/dunerealms/releases') DROPIN = Path('/etc/systemd/system/dunerealms-ci-promote.service.d/30-shared-chrome.conf') def main(): parser = argparse.ArgumentParser() parser.add_argument('--apply', action='store_true') args = parser.parse_args() release = CURRENT.resolve(strict=True) if not release.is_relative_to(RELEASES) or not release.name.startswith('ci-'): raise RuntimeError('Unexpected live release directory') publisher = release / 'scripts/publish-shared-chrome.py' if not publisher.is_file(): raise RuntimeError('Canonical publisher missing from live release') if not args.apply: print('Publish canonical navigation and keep native headers current after deployment.') return if os.geteuid() != 0: raise RuntimeError('Deployment operator required') # This is the existing file publisher: no application restart or DB write. subprocess.run(['/usr/bin/python3', str(publisher), '--apply'], check=True) DROPIN.parent.mkdir(parents=True, exist_ok=True) command = '[Service]\nExecStartPost=/usr/bin/python3 ' + str(CURRENT / 'scripts/publish-shared-chrome.py') + ' --apply\n' if DROPIN.exists() and DROPIN.read_text() != command: raise RuntimeError('Existing publication override differs; inspect before replacing') temporary = DROPIN.with_suffix('.new') temporary.write_text(command) temporary.chmod(0o644) os.replace(temporary, DROPIN) subprocess.run(['/usr/bin/systemctl', 'daemon-reload'], check=True) print('Shared forum/support navigation published; future promotions will refresh it.') if __name__ == '__main__': main()