Release LanUps 0.1.2 with native installers and monitoring updates

This commit is contained in:
tongtong committed 2026-11-28 21:18:14 +08:00
1 parent 90c57f020f
commit 5bdc79d8e4
30 files changed
+751 -270

No files matched your search

+71 -32
View File
@@ -1,6 +1,6 @@
"""Build native system installers from the LanUps publish payloads."""
import hashlib
import argparse
import io
import os
from pathlib import Path
@@ -14,10 +14,10 @@ import tarfile
import tempfile
sys.dont_write_bytecode = True
from package import DEPLOY, ICON, ROOT, binaries, tar_bytes, windows_package
from package import DEPLOY, DIST, ICON, PAYLOAD, ROOT, VERSION, binaries, tar_bytes, write_checksums
NATIVE = DEPLOY / 'native'
OUTPUT = Path(os.environ.get('LANUPS_INSTALLER_OUTPUT', ROOT / 'artifacts' / 'native-installers-optimized')).resolve()
OUTPUT = DIST
def script(path):
@@ -41,7 +41,10 @@ def router_package():
control, data = io.BytesIO(), io.BytesIO()
with tarfile.open(fileobj=control, mode='w:gz') as archive:
for name in ('control', 'postinst', 'prerm'):
tar_bytes(archive, './' + name, script(source / name), 0o644 if name == 'control' else 0o755)
content = script(source / name)
if name == 'control':
content += f'Version: {VERSION}-1\n'.encode('ascii')
tar_bytes(archive, './' + name, content, 0o644 if name == 'control' else 0o755)
with tarfile.open(fileobj=data, mode='w:gz') as archive:
directories = set()
for source_name, name in {
@@ -53,7 +56,7 @@ def router_package():
}.items():
tar_parents(archive, name, directories)
tar_bytes(archive, name, script(source / source_name), 0o755)
path = OUTPUT / 'lanups-router_0.1.0-1_all.ipk'
path = OUTPUT / f'lanups-router_{VERSION}-1_all.ipk'
with tarfile.open(path, 'w:gz') as archive:
for name, value in (('debian-binary', b'2.0\n'), ('control.tar.gz', control.getvalue()), ('data.tar.gz', data.getvalue())):
tar_bytes(archive, './' + name, value, 0o644)
@@ -72,10 +75,8 @@ def write_ar_member(output, name, data):
output.write(b'\n')
def linux_package(rid, stage):
def linux_payload(rid, data):
source = DEPLOY / 'linux'
architecture = {'linux-x64': 'amd64', 'linux-arm64': 'arm64'}[rid]
control, data = stage / 'control.tar.gz', stage / 'data.tar.gz'
libc_version = (0, 0, 0)
with tarfile.open(data, 'w:gz', compresslevel=5) as archive:
directories = set()
@@ -97,17 +98,25 @@ def linux_package(rid, stage):
('./lib/systemd/system/lanups-agent.service', script(source / 'lanups-agent.service'), 0o644),
('./etc/xdg/autostart/lanups-desktop.desktop', launcher.replace(b'/opt/lanups/desktop/LanUps.Desktop --tray', b'/usr/lib/lanups/start-desktop'), 0o644),
('./usr/lib/lanups/start-desktop', script(source/'start-desktop'), 0o755),
('./usr/lib/lanups/configure-agent', script(source/'configure-agent'), 0o755),
('./usr/share/applications/lanups-desktop.desktop', launcher.replace(b' --tray', b''), 0o644),
('./usr/share/icons/hicolor/256x256/apps/lanups.png', ICON.read_bytes(), 0o644),
):
tar_parents(archive, name, directories)
tar_bytes(archive, name, content, mode)
return libc_version
def linux_deb(rid, stage, data, libc_version):
source = DEPLOY / 'linux'
architecture = {'linux-x64': 'amd64', 'linux-arm64': 'arm64'}[rid]
control = stage / 'control.tar.gz'
libc = 'libc6'
if libc_version[0]:
version = '.'.join(str(part) for part in (libc_version if libc_version[2] else libc_version[:2]))
libc = f'libc6 (>= {version})'
metadata = (
'Package: lanups\nVersion: 0.1.0-1\n' f'Architecture: {architecture}\n'
f'Package: lanups\nVersion: {VERSION}-1\nArchitecture: {architecture}\n'
'Maintainer: LanUps Project\nSection: utils\nPriority: optional\n'
f'Depends: adduser, passwd, init-system-helpers, {libc}, libgcc-s1, libstdc++6, libssl3 | libssl3t64, libx11-6, libx11-xcb1, libxcb1, libxext6, libxi6, libxrandr2, libice6, libsm6, libfontconfig1, libgl1, libicu72 | libicu74 | libicu76 | libicu77 | libicu78\n'
'Description: LAN UPS Agent and desktop monitor\n'
@@ -116,16 +125,32 @@ def linux_package(rid, stage):
tar_bytes(archive, './control', metadata.encode(), 0o644)
for name in ('postinst', 'prerm', 'postrm'):
tar_bytes(archive, './'+name, script(source / name), 0o755)
path = OUTPUT / f'lanups_0.1.0-1_{architecture}.deb'
path = OUTPUT / f'lanups_{VERSION}-1_{architecture}.deb'
with path.open('wb') as output:
output.write(b'!<arch>\n')
for name, payload in (('debian-binary', b'2.0\n'), ('control.tar.gz', control), ('data.tar.gz', data)):
write_ar_member(output, name, payload)
control.unlink()
data.unlink()
return path
def linux_rpm(rid, data):
compiler = shutil.which('rpmbuild')
if not compiler:
raise RuntimeError('Install rpmbuild on the Linux packaging host to build RPM packages.')
architecture = {'linux-x64': 'x86_64', 'linux-arm64': 'aarch64'}[rid]
with tempfile.TemporaryDirectory(prefix='lanups-rpm-') as root:
top = Path(root)
sources = top / 'SOURCES'
sources.mkdir()
shutil.copyfile(data, sources / 'lanups-payload.tar.gz')
subprocess.run([compiler, '-bb', '--target', architecture,
'--define', f'_topdir {top}', '--define', f'lanups_version {VERSION}',
str(DEPLOY / 'linux' / 'lanups.spec')], check=True)
name = f'lanups-{VERSION}-1.{architecture}.rpm'
return Path(shutil.copyfile(top / 'RPMS' / architecture / name, OUTPUT / name))
def mac_package(rid, stage, builder):
source = DEPLOY / 'macos'
payload = stage / rid
@@ -139,7 +164,7 @@ def mac_package(rid, stage, builder):
(bundle / 'Resources').mkdir()
plist = dict(CFBundleExecutable='LanUps.Desktop', CFBundleIdentifier='local.lanups.desktop',
CFBundleName='LanUps', CFBundleDisplayName='局域网 UPS', CFBundlePackageType='APPL',
CFBundleIconFile='ups.icns', CFBundleVersion='1', CFBundleShortVersionString='0.1.0')
CFBundleIconFile='ups.icns', CFBundleVersion=VERSION, CFBundleShortVersionString=VERSION)
(bundle / 'Info.plist').write_bytes(plistlib.dumps(plist))
icon = ICON.read_bytes()
(bundle / 'Resources/ups.icns').write_bytes(b'icns' + struct.pack('>I', len(icon)+16) + b'ic08' + struct.pack('>I', len(icon)+8) + icon)
@@ -151,11 +176,31 @@ def mac_package(rid, stage, builder):
(stage / name).write_bytes(script(source / name))
output = OUTPUT / f'LanUps-{rid}.pkg'
subprocess.run([str(builder), str(payload), str(stage/'preinstall'), str(stage/'postinstall'),
'arm64' if rid == 'osx-arm64' else 'x86_64', str(output)], check=True)
'arm64' if rid == 'osx-arm64' else 'x86_64', str(output), VERSION], check=True)
return output
def main(targets):
def windows_package(rid):
compiler = os.environ.get('LANUPS_ISCC') or shutil.which('ISCC.exe')
if not compiler:
for env in ('ProgramFiles(x86)', 'ProgramFiles', 'LOCALAPPDATA'):
if root := os.environ.get(env):
candidate = Path(root) / 'Inno Setup 6' / 'ISCC.exe'
if candidate.is_file():
compiler = str(candidate)
break
if not compiler:
raise RuntimeError('Install Inno Setup 6 on the Windows build host or set LANUPS_ISCC to ISCC.exe.')
for kind in ('Agent', 'Desktop'):
next(binaries(rid, kind))
languages = Path(compiler).parent / 'Languages'
options = ['/DChineseMessages=1'] if (languages / 'ChineseSimplified.isl').is_file() else []
subprocess.run([compiler, *options, f'/DAppVersion={VERSION}', f'/DPayloadDir={PAYLOAD / rid}', f'/O{OUTPUT}',
f'/FLanUps-Setup-{rid}', str(DEPLOY / 'windows' / 'LanUps.iss')], check=True)
return OUTPUT / f'LanUps-Setup-{rid}.exe'
def main(targets, rpm=False):
OUTPUT.mkdir(parents=True, exist_ok=True)
packages = [router_package()]
with tempfile.TemporaryDirectory(dir=OUTPUT.parent) as temp:
@@ -166,32 +211,26 @@ def main(targets):
subprocess.run(['go','build','-mod=readonly','-trimpath','-o',str(builder),'.'],cwd=NATIVE/'macos',check=True)
for rid in targets:
if rid.startswith('linux-'):
output = linux_package(rid, stage)
data = stage / f'{rid}.tar.gz'
libc_version = linux_payload(rid, data)
output = linux_deb(rid, stage, data, libc_version)
if rpm:
print(linux_rpm(rid, data).name, flush=True)
elif rid.startswith('osx-'):
output = mac_package(rid, stage, builder)
elif rid == 'win-x64':
stub = stage / 'setup.exe'
env = dict(os.environ, GOOS='windows', GOARCH='amd64', CGO_ENABLED='0')
subprocess.run(['go','build','-trimpath','-ldflags=-s -w','-o',str(stub),str(NATIVE/'windows/main.go')],cwd=ROOT,env=env,check=True)
payload = windows_package(rid, stage / 'windows-payload.zip')
output = OUTPUT / 'LanUps-Setup-win-x64.exe'
with output.open('wb') as stream:
for part in (stub,payload):
with part.open('rb') as file:
shutil.copyfileobj(file, stream)
if os.name == 'nt':
subprocess.run([str(output),'--verify'],check=True)
output = windows_package(rid)
else:
raise ValueError(f'Unsupported target: {rid}')
packages.append(output)
print(output.name, flush=True)
archives = [path for path in OUTPUT.iterdir() if path.suffix in {'.exe', '.deb', '.pkg', '.ipk'}]
with (OUTPUT / 'SHA256SUMS').open('w', encoding='ascii', newline='\n') as sums:
for path in sorted(archives):
with path.open('rb') as stream:
sums.write(f"{hashlib.file_digest(stream, 'sha256').hexdigest()} {path.name}\n")
write_checksums()
print(packages[0].name, flush=True)
if __name__ == '__main__':
main(sys.argv[1:])
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--rpm', action='store_true', help='Also build RPM installers for Linux targets')
parser.add_argument('targets', nargs='*', help='Desktop targets. Omit to build only the router package.')
args = parser.parse_args()
main(args.targets, args.rpm)