Publish recorded menu pack through existing download host

This commit is contained in:
unimatrixgit 2026-11-28 22:59:31 +01:00
commit 94419ab22b
2 changed files with 61 additions and 0 deletions

View file

@ -23,6 +23,8 @@ with zipfile.ZipFile(pack,'w',zipfile.ZIP_DEFLATED,compresslevel=9) as z:
for module,name in [('DuneMenus','DuneMenus.jar'),('DuneEss','DuneRealms-Essentials.jar'),('DuneLobby','DuneRealms-Lobby.jar'),('DuneRealms-minecraft-only','DuneRealms-Core.jar'),('JarvisConnector','jarvistranslator.jar')]:
shutil.copy2(root/module/'build/libs'/name,out/name)
shutil.copy2(root/'tools/install-dunemenus-release.py',out/'install-dunemenus-release.py')
shutil.copy2(root/'network/resource-pack/dunemenus-v7.nginx.conf',out/'dunemenus-v7.nginx.conf')
shutil.copy2(root/'tools/publish-dunemenus-pack.py',out/'publish-dunemenus-pack.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,59 @@
"""Publish the recorded v7 pack at its exact existing DuneRealms download host."""
from pathlib import Path
import datetime
import hashlib
import json
import os
import shutil
import subprocess
bundle = Path(__file__).resolve().parent
manifest = json.loads((bundle / 'release.json').read_text())
names = ['DuneRealms-Network-Artwork-v7.zip', 'dunemenus-v7.nginx.conf']
for name in names:
if hashlib.sha256((bundle / name).read_bytes()).hexdigest() != manifest['files'][name]['sha256']:
raise ValueError('Publication checksum differs: ' + name)
downloads = Path('/var/lib/dunerealms-public-downloads')
parent = Path('/etc/nginx/snippets/dunerealms-gui-download-v3.conf')
route = Path('/etc/nginx/snippets/dunemenus-v7.nginx.conf')
pack = downloads / names[0]
if not downloads.is_dir() or not parent.is_file() or any(p.is_symlink() for p in [parent, route, pack]):
raise ValueError('Unexpected publication paths')
include = 'include /etc/nginx/snippets/dunemenus-v7.nginx.conf;'
old_parent = parent.read_bytes()
if include not in old_parent.decode() and names[0] in old_parent.decode():
raise ValueError('An unmanaged v7 route already exists')
for path, source in [(pack, bundle / names[0]), (route, bundle / names[1])]:
if path.exists() and path.read_bytes() != source.read_bytes():
raise ValueError('Refusing to overwrite different versioned content: ' + str(path))
stamp = datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%S%fZ')
backup = Path('/root/dunemenus-pack-before-' + stamp)
backup.mkdir(mode=0o700)
originals = {p: p.read_bytes() if p.exists() else None for p in [pack, route, parent]}
for path, content in originals.items():
if content is not None:
shutil.copy2(path, backup / path.name)
try:
for destination, source in [(pack, bundle / names[0]), (route, bundle / names[1])]:
staged = destination.with_name(destination.name + '.build-staged')
if staged.exists() or staged.is_symlink():
raise ValueError('Staging path exists')
shutil.copyfile(source, staged)
os.chmod(staged, 0o644)
os.replace(staged, destination)
if include not in old_parent.decode():
parent.write_bytes(old_parent.rstrip() + b'\n' + include.encode() + b'\n')
subprocess.run(['nginx', '-t'], check=True, timeout=30)
subprocess.run(['systemctl', 'reload', 'nginx'], check=True, timeout=30)
except Exception:
for path, content in originals.items():
if content is None:
if path.exists():
path.unlink()
else:
path.write_bytes(content)
subprocess.run(['nginx', '-t'], check=True, timeout=30)
subprocess.run(['systemctl', 'reload', 'nginx'], check=True, timeout=30)
raise
print(json.dumps({'source': manifest['source'], 'backup': str(backup), 'url': manifest['pack_url'],
'sha256': manifest['files'][names[0]]['sha256']}))