web/website/scripts/install-migration-seals.py
2026-11-21 20:22:37 +01:00

46 lines
2.2 KiB
Python

"""Install CI-approved custom integration adapters and merge the seal catalogue."""
from pathlib import Path
import json
import os
import subprocess
import sys
root = Path(__file__).resolve().parents[1]
target = Path('/home/dunerealms/apps/integrations')
names = ('sync-public-profile.php', 'sync-staff-seals.php', 'managed-signatures.php', 'osticket/dune-support-home.php')
for name in names:
subprocess.run(['php', '-l', str(root / 'integrations' / name)], check=True)
catalogue = json.loads((root / 'artwork/seals/great-migration/catalogue.json').read_text())
entries = {}
for key, metadata in catalogue.items():
entries[key] = dict(metadata)
for size, field in ((150, 'footer150'), (300, 'standard300')):
name = f'{key}-{size}.png'
source = root / 'web/assets/seals' / name
if not source.is_file() or source.read_bytes()[:8] != b'\x89PNG\r\n\x1a\n':
raise ValueError(f'Missing PNG: {name}')
entries[key][field] = '/assets/seals/' + name
if '--apply' not in sys.argv:
print(f'Plan: {len(entries)} seals, four custom adapters; no changes applied')
sys.exit(0)
def atomic(path, content):
temporary = path.with_name(path.name + '.migration-new')
temporary.write_bytes(content)
temporary.chmod(0o644)
os.replace(temporary, path)
# Artwork becomes reachable before any adapter starts referring to it.
for folder in ('osticket/assets/seals', 'mybb/assets/seals'):
destination = target / folder
destination.mkdir(parents=True, exist_ok=True)
for key in entries:
for size in (150, 300):
name = f'{key}-{size}.png'
atomic(destination / name, (root / 'web/assets/seals' / name).read_bytes())
manifest = target / 'seal-manifest.json'
existing = json.loads(manifest.read_text())
existing.update(entries) # Keep every historical asset and entitlement.
atomic(manifest, (json.dumps(existing, indent=2)+'\n').encode())
atomic(target / 'organisation-seals.json', (root / 'integrations/organisation-seals.json').read_bytes())
for name in names:
atomic(target / name, (root / 'integrations' / name).read_bytes())
print(f'Installed {len(entries)} seals and four custom adapters; native core unchanged')