Package guarded backend installer in the recorded GUI build

This commit is contained in:
unimatrixgit 2026-11-28 22:06:58 +01:00
commit d4480cad6f
2 changed files with 51 additions and 0 deletions

View file

@ -22,6 +22,7 @@ with zipfile.ZipFile(pack,'w',zipfile.ZIP_DEFLATED,compresslevel=9) as z:
for name,data in sorted(entries.items()):
zi=zipfile.ZipInfo(name,(2026,11,28,0,0,0));zi.compress_type=zipfile.ZIP_DEFLATED;z.writestr(zi,data)
shutil.copy2(root/'DuneMenus/build/libs/DuneMenus.jar',out/'DuneMenus.jar')
shutil.copy2(root/'tools/install-dunemenus-release.py',out/'install-dunemenus-release.py')
manifest={'source':subprocess.check_output(['git','rev-parse','HEAD'],cwd=root,text=True).strip(),'input_zip_sha256':'6d3cde343ba09fb7088a3a07b0c54c96eeb629c82c527993a76000013c305b60','pack_url':'https://www.dunerealms.com/downloads/'+pack.name,'files':{}}
for p in sorted(out.iterdir()):
if p.is_file() and p.name!='release.json':

View file

@ -0,0 +1,50 @@
"""Install one verified build into one explicitly named backend. Called from the build artifact."""
from pathlib import Path
import datetime,hashlib,json,os,shutil,subprocess,sys,yaml
bundle=Path(__file__).resolve().parent
manifest=json.loads((bundle/'release.json').read_text())
root=Path(sys.argv[1]).resolve();unit=sys.argv[2]
allowed={
'/opt/dunerealms/lobby':'dune-lobby.service',
**{f'/opt/dunerealms/servers/{x}':f'dune-{x}.service' for x in ['arrakis','caladan','giedi_prime','kaitain','sigma_draconis_iv']}}
assert allowed.get(str(root))==unit,'Unexpected backend/unit'
for name,record in manifest['files'].items():
assert '/' not in name and hashlib.sha256((bundle/name).read_bytes()).hexdigest()==record['sha256'],name
plugins=root/'plugins';target=plugins/'DuneMenus.jar';data=plugins/'DuneMenus'
assert target.is_file() and (data/'config.yml').is_file()
stamp=datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%SZ')
backup=Path('/root/dunemenus-before-'+stamp+'-'+root.name);backup.mkdir(mode=0o700)
for p in [target,data/'config.yml',data/'gui-pack.yml']:
if p.exists():shutil.copy2(p,backup/p.name)
others={p.name:hashlib.sha256(p.read_bytes()).hexdigest() for p in plugins.glob('*.jar') if p.name not in ['DuneMenus.jar','DunerealmsGUI.jar','DuneFullscreenPaper.jar','MCGUI.jar']}
(backup/'other-jars.json').write_text(json.dumps(others,indent=2))
config=yaml.safe_load((data/'config.yml').read_text()) or {}
config.setdefault('fullscreen',{})['enabled']=True
config.pop('mcgui',None)
pack=yaml.safe_load((data/'gui-pack.yml').read_text()) or {}
pin={'url':manifest['pack_url'],'sha1':manifest['files']['DuneRealms-Network-Artwork-v7.zip']['sha1']}
pack.update({'world':pin,'lobby':pin})
subprocess.run(['systemctl','stop',unit],check=True,timeout=120)
owner=target.stat();removed=[]
for name in ['DunerealmsGUI.jar','DuneFullscreenPaper.jar','MCGUI.jar','DunerealmsGUI','DuneFullscreenPaper','MCGUI']:
p=plugins/name
if not p.exists():continue
assert p.resolve().is_relative_to(plugins.resolve())
shutil.move(str(p),str(backup/name));removed.append(name)
for name in ['mcgui']:
p=data/name
if p.is_dir():shutil.move(str(p),str(backup/('DuneMenus-'+name)));removed.append('DuneMenus/'+name)
tmp=target.with_suffix('.jar.build-staged');shutil.copy2(bundle/'DuneMenus.jar',tmp);os.chown(tmp,owner.st_uid,owner.st_gid);os.replace(tmp,target)
for name,content in [('config.yml',config),('gui-pack.yml',pack)]:
p=data/name;p.write_text(yaml.safe_dump(content,sort_keys=False,allow_unicode=True));os.chown(p,owner.st_uid,owner.st_gid)
cache=plugins/'.paper-remapped'
if cache.is_dir():
for p in cache.glob('*.jar'):
if any(x in p.name.lower() for x in ['dunemenus','dunerealmsgui','dunefullscreen','mcgui']):
shutil.move(str(p),str(backup/('remapped-'+p.name)))
after={p.name:hashlib.sha256(p.read_bytes()).hexdigest() for p in plugins.glob('*.jar') if p.name not in ['DuneMenus.jar','DunerealmsGUI.jar','DuneFullscreenPaper.jar','MCGUI.jar']}
assert others==after,'Unrelated plugins changed'
assert hashlib.sha256(target.read_bytes()).hexdigest()==manifest['files']['DuneMenus.jar']['sha256']
subprocess.run(['systemctl','start',unit],check=True,timeout=120)
report={'source':manifest['source'],'server':str(root),'unit':unit,'backup':str(backup),'removed':removed,'jar_sha256':manifest['files']['DuneMenus.jar']['sha256'],'pack':pin,'other_plugins_unchanged':True,'runtime_verified':False}
(backup/'deployment.json').write_text(json.dumps(report,indent=2));print(json.dumps(report))