#!/usr/bin/env python3 """Build a host-native Ubuntu/Debian DEB without installing or starting services.""" import os,pathlib,subprocess,shutil,tempfile,hashlib root=pathlib.Path(__file__).resolve().parents[1];out=root/'releases/deb';out.mkdir(parents=True,exist_ok=True) def run(*cmd,**kw):return subprocess.check_output(cmd,text=True,**kw) arch=run('dpkg','--print-architecture').strip() with tempfile.TemporaryDirectory(prefix='mars-deb-') as tmp: stage=pathlib.Path(tmp)/'pkg';stage.mkdir() run('cmake','--install',str(root/'upstream/build'),env={**os.environ,'DESTDIR':str(stage)}) def copy(src,dst,mode=0o644): target=stage/dst;target.parent.mkdir(parents=True,exist_ok=True);shutil.copy2(root/src,target);target.chmod(mode) for name in ('mars_vme','mars-pcapd','mars-print'):copy('build/'+name,'usr/local/sbin/'+name,0o755) copy('packaging/mars-ipxpkt-net','usr/local/libexec/mars-ipxpkt-net',0o755) copy('dos-compat-export.py','usr/local/sbin/mars-dos-export',0o755) copy('install-driver-packages.py','usr/local/libexec/mars-install-drivers',0o755) for name in ('publish-mtcp.sh','publish-winclient.sh'):copy(name,'usr/local/sbin/mars-'+name.removesuffix('.sh'),0o755) for f in (root/'websetup').iterdir(): if f.is_file():copy(str(f.relative_to(root)),'usr/local/share/mars-vme/www/'+f.name) for f in (root/'releases/dos').iterdir():copy(str(f.relative_to(root)),'usr/local/share/mars-vme/www/dos/'+f.name) for f in (root/'releases/windows').iterdir():copy(str(f.relative_to(root)),'usr/local/share/mars-vme/driver-packages/'+f.name) for f in (root/'browser').iterdir(): if f.suffix in ('.mjs','.pa','.sh'):copy(str(f.relative_to(root)),'usr/local/libexec/mars-browser/'+f.name,0o755 if f.suffix=='.sh' else 0o644) elif f.suffix in ('.service','.timer'):copy(str(f.relative_to(root)),'lib/systemd/system/'+f.name) for f in (root/'releases/browser').iterdir():copy(str(f.relative_to(root)),'usr/local/share/mars-vme/browser/'+f.name) copy('releases/browser/browser-client-source.zip','usr/local/share/mars-vme/browser-client-source.zip') copy('clients/retro-browser/mars-retrobrowser-x11','usr/local/bin/mars-retrobrowser-x11',0o755) # Runtime state/config is created only if absent by postinst, never shipped over existing configuration. conf=stage/'usr/local/etc/mars_nwe/nwserv.conf' if conf.exists():conf.unlink() service=(root/'mars_vme.service').read_text().replace('--port 8787','--port 8787 --no-autostart') target=stage/'lib/systemd/system/mars_vme.service';target.parent.mkdir(parents=True,exist_ok=True);target.write_text(service) deb=stage/'DEBIAN';deb.mkdir() # Derive exact ELF runtime dependencies from the host shlibs database. control=pathlib.Path(tmp)/'debian';control.mkdir();(control/'control').write_text('Source: mars-vme\nMaintainer: MARS VME \n\nPackage: mars-vme\nArchitecture: any\nDescription: MARS VME\n') elfs=[p for p in stage.rglob('*') if p.is_file() and p.read_bytes()[:4]==b'\x7fELF'] deps=run('dpkg-shlibdeps','-O',*[str(p) for p in elfs],cwd=tmp).strip().split('shlibs:Depends=',1)[1] (deb/'control').write_text(f'Package: mars-vme\nVersion: 0.9.1-3\nArchitecture: {arch}\nMaintainer: MARS VME \nDepends: {deps}, python3, jq, iproute2, nftables, libpcap0.8t64, nodejs (>= 20), ffmpeg, pulseaudio, pulseaudio-utils, util-linux, zip, passwd\nRecommends: chromium | google-chrome-stable\nSection: net\nPriority: optional\nDescription: MARS VME server with web administration and Windows driver packages\n Host-native Ubuntu 26.04 build. Windows drivers are experimental.\n') (deb/'preinst').write_text('#!/bin/sh\nset -e\nbase=/var/lib/mars_nwe/bindery\nif [ -s "$base/nwobj.pag" ] && [ ! -f "$base/.mars-fixed-width-v1" ]; then\n echo \'Upgrade blocked: existing Bindery may use the incompatible old LP64 layout.\' >&2\n echo \'Back up configuration, Bindery and trustees; migrate/recreate and verify it before this upgrade.\' >&2\n echo \'Do not simply create the marker on an old database. See SERVER-64BIT-REPAIR.md.\' >&2\n exit 1\nfi\n') (deb/'postinst').write_text('''#!/bin/sh set -e if [ "$1" = configure ]; then getent passwd mars-browser >/dev/null || useradd --system --home-dir /var/lib/mars-browser --shell /usr/sbin/nologin mars-browser install -d -o mars-browser -g mars-browser -m 0700 /var/lib/mars-browser install -d -m 0755 /usr/local/etc/mars_nwe /var/mars_nwe/SYS/public install -d -m 0700 /var/lib/mars-vme if [ ! -f /usr/local/etc/mars_nwe/nwserv.conf ]; then umask 077 printf '2 MARS\\n3 0x12345678 1\\n1 SYS /var/mars_nwe/SYS ikO\\n6 2\\n5 0\\n200 0\\n' > /usr/local/etc/mars_nwe/nwserv.conf fi if [ ! -s /var/lib/mars_nwe/bindery/nwobj.pag ]; then install -d -m 0700 /var/lib/mars_nwe/bindery touch /var/lib/mars_nwe/bindery/.mars-fixed-width-v1 chmod 0600 /var/lib/mars_nwe/bindery/.mars-fixed-width-v1 fi if [ -d /run/systemd/system ]; then systemctl daemon-reload systemctl enable mars_vme.service systemctl start mars_vme.service fi echo 'Web setup: http://SERVER:8787 — initial admin/admin, change password first.' echo 'Configure IPX/network and SYS volume in the web UI before starting NetWare.' fi ''') (deb/'prerm').write_text('''#!/bin/sh set -e if [ "$1" = remove ] && [ -d /run/systemd/system ]; then systemctl stop mars_vme.service systemctl disable mars_vme.service fi ''') (deb/'conffiles').write_text(''.join('/'+str(f.relative_to(stage))+'\n' for f in (stage/'usr/local/etc').rglob('*') if f.is_file())) for name in ('preinst','postinst','prerm'):(deb/name).chmod(0o755) for name in ('COPYING','LEGACY-BUILD.md','WINDOWS.md','DRIVER-RELEASE.md','LONG-NAMES.md','BROWSER.md','BUILD-RETROBROWSER.md','MARS-BROWSER-LIFECYCLE.md','SERVER-64BIT-REPAIR.md'):copy(name,'usr/share/doc/mars-vme/'+name) package=out/f'mars-vme_0.9.1-3_{arch}.deb';run('dpkg-deb','--root-owner-group','--build',str(stage),str(package)) (out/'SHA256SUMS').write_text(''.join(hashlib.sha256(f.read_bytes()).hexdigest()+' '+f.name+'\n' for f in sorted(out.glob('*.deb')))) print(package)