Build legacy drivers and publish per-OS packages with web activation and DEB

This commit is contained in:
2026-11-27 20:55:31 +00:00
96 changed files with 3204 additions and 25 deletions

60
packaging/build-deb.py Normal file
View File

@@ -0,0 +1,60 @@
#!/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('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/windows').iterdir():copy(str(f.relative_to(root)),'usr/local/share/mars-vme/driver-packages/'+f.name)
# 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 <root@localhost>\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.8.1-1\nArchitecture: {arch}\nMaintainer: MARS VME <root@localhost>\nDepends: {deps}, python3, jq, iproute2, nftables, libpcap0.8t64\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/'postinst').write_text('''#!/bin/sh
set -e
if [ "$1" = configure ]; then
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\\n5 0\\n200 0\\n' > /usr/local/etc/mars_nwe/nwserv.conf
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 ('postinst','prerm'):(deb/name).chmod(0o755)
for name in ('COPYING','LEGACY-BUILD.md','WINDOWS.md','DRIVER-RELEASE.md'):copy(name,'usr/share/doc/mars-vme/'+name)
package=out/f'mars-vme_0.8.1-1_{arch}.deb';run('dpkg-deb','--root-owner-group','--build',str(stage),str(package))
(out/'SHA256SUMS').write_text(hashlib.sha256(package.read_bytes()).hexdigest()+' '+package.name+'\n')
print(package)

62
packaging/mars-ipxpkt-net Executable file
View File

@@ -0,0 +1,62 @@
#!/bin/sh
# Called only by mars-pcapd. Own TAP, own nft table. Never change host forwarding.
set -eu
PATH=/usr/sbin:/usr/bin:/sbin:/bin
export PATH
[ "$(id -u)" = 0 ] || exit 1
case "$1" in
down) nft delete table inet mars_ipxpkt; exit;;
up) ;;
*) exit 2;;
esac
uplink=$2; gateway=$3; dns=$4; mac=$5; web=$6; ping=$7
# Defense in depth; caller already validates full address ranges and interface names.
case "$uplink" in ''|-*|*[!a-zA-Z0-9_.-]*|lo|marsipx0) exit 2;; esac
case "$gateway:$dns" in *[!0-9.:]*) exit 2;; esac
case "$mac" in *[!0-9a-f:]*) exit 2;; esac
[ "$web" = 0 ] || [ "$web" = 1 ] || exit 2
[ "$ping" = 0 ] || [ "$ping" = 1 ] || exit 2
[ "$(cat /proc/sys/net/ipv4/ip_forward)" = 1 ] || { echo 'IPXPKT: Enable IPv4 forwarding deliberately before use' >&2; exit 1; }
# Refuse existing containing or more-specific routes in any table (except default).
subnet=${gateway%.*}.0/24
cover=$(ip -4 route show table all match "$subnet") || exit 1
inside=$(ip -4 route show table all root "$subnet") || exit 1
if [ -n "$inside" ] || printf '%s\n' "$cover" | grep -Ev '^(default([[:space:]]|$)|[[:space:]]*$)' >/dev/null; then
echo "IPXPKT: virtual network overlaps an existing route: $subnet" >&2; exit 1
fi
# Never replace an existing table (including stale table after a crash).
if nft list table inet mars_ipxpkt >/dev/null 2>&1; then echo 'IPXPKT: nft table mars_ipxpkt already exists; inspect before removing' >&2; exit 1; fi
# Forwards only IPv4 Internet traffic on the selected uplink; no access to local host.
# IPv4 non-public ranges blocked. Sites with internally routed public space must add restrictions.
web_rule=''; ping_rule=''
[ "$web" = 0 ] || web_rule='iifname "marsipx0" tcp dport { 80, 443 } ct state new,established accept'
[ "$ping" = 0 ] || ping_rule='iifname "marsipx0" icmp type echo-request ct state new,established accept'
nft -f - <<RULES
create table inet mars_ipxpkt
add chain inet mars_ipxpkt input { type filter hook input priority -10; policy accept; }
add rule inet mars_ipxpkt input iifname "marsipx0" drop
add chain inet mars_ipxpkt forward { type filter hook forward priority -10; policy accept; }
add rule inet mars_ipxpkt forward iifname "marsipx0" meta nfproto != ipv4 drop
add rule inet mars_ipxpkt forward iifname "marsipx0" oifname != "$uplink" drop
add rule inet mars_ipxpkt forward iifname "marsipx0" ip saddr != $subnet drop
add rule inet mars_ipxpkt forward iifname "marsipx0" ip daddr { 0.0.0.0/8, 10.0.0.0/8, 100.64.0.0/10, 127.0.0.0/8, 169.254.0.0/16, 172.16.0.0/12, 192.0.0.0/24, 192.0.2.0/24, 192.168.0.0/16, 198.18.0.0/15, 198.51.100.0/24, 203.0.113.0/24, 224.0.0.0/3 } drop
add rule inet mars_ipxpkt forward iifname "marsipx0" ct state invalid drop
add rule inet mars_ipxpkt forward iifname "marsipx0" ip daddr $dns udp dport 53 ct state new,established accept
add rule inet mars_ipxpkt forward iifname "marsipx0" ip daddr $dns tcp dport 53 ct state new,established accept
${web_rule:+add rule inet mars_ipxpkt forward $web_rule}
${ping_rule:+add rule inet mars_ipxpkt forward $ping_rule}
add rule inet mars_ipxpkt forward iifname "marsipx0" drop
add rule inet mars_ipxpkt forward oifname "marsipx0" iifname "$uplink" ip daddr $subnet ct state established,related accept
add rule inet mars_ipxpkt forward oifname "marsipx0" drop
add chain inet mars_ipxpkt nat { type nat hook postrouting priority srcnat; policy accept; }
add rule inet mars_ipxpkt nat iifname "marsipx0" oifname "$uplink" ip saddr $subnet masquerade
RULES
# Roll back only our freshly created table on errors, keep TAP down until rules exist.
trap 'nft delete table inet mars_ipxpkt || true' EXIT
# IPv6 traffic is not accepted by the decoder; avoid link-local address creation as well.
ip link set dev marsipx0 address "$mac" mtu 1500
if [ -e /proc/sys/net/ipv6/conf/marsipx0/disable_ipv6 ]; then echo 1 > /proc/sys/net/ipv6/conf/marsipx0/disable_ipv6; fi
ip -4 addr add "$gateway/24" dev marsipx0
ip link set dev marsipx0 up
trap - EXIT