A full-featured download manager.
feat(packaging): add native arch linux release packages (#2099)
Dr_rOotbed104cbe71c
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex f7457ac9..f1552c8e 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -202,6 +202,7 @@ jobs:tests/scripts/stage-server-app.test.tstests/scripts/verify-electron-package.test.tstests/scripts/verify-appimage-artifact.test.ts+ tests/scripts/verify-pacman-artifact.test.tstests/scripts/verify-container-publication.test.tstests/scripts/verify-server-package.test.tstests/scripts/verify-update-artifacts.test.ts@@ -462,6 +463,20 @@ jobs:--dir--publish never+ - name: Install Arch packaging tools+ if: matrix.platform == 'linux'+ run: |+ sudo apt-get update+ sudo apt-get install --yes zstd libarchive-tools++ - name: Build Arch package smoke+ if: matrix.platform == 'linux'+ run: >-+ pnpm exec electron-builder+ --linux pacman --${{ matrix.arch }}+ --prepackaged "${{ matrix.app_path }}"+ --publish never+- name: Verify Electron packagerun: >-node scripts/verify-electron-package.mjs@@ -470,6 +485,18 @@ jobs:--arch ${{ matrix.arch }}--report "release/size-reports/${{ matrix.target }}.json"+ - name: Verify Arch Linux package+ if: matrix.platform == 'linux'+ shell: bash+ run: |+ version="$(node -p "require('./package.json').version")"+ node scripts/verify-pacman-artifact.mjs \+ --dir release --version "$version" --arch ${{ matrix.arch }}++ - name: Smoke test Arch Linux installation+ if: matrix.target == 'linux-x64'+ run: bash scripts/smoke-pacman-package.sh release+- name: Verify Windows native host runtime importsif: matrix.platform == 'win32'shell: pwshdiff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 4b5669ce..a3ad3865 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -142,7 +142,7 @@ jobs:platform: linuxarch: x64rust_target: x86_64-unknown-linux-musl- electron_builder_args: --linux deb rpm AppImage --x64+ electron_builder_args: --linux deb rpm pacman AppImage --x64resources_dir: release/linux-unpacked/resourcesapp_path: release/linux-unpacked- target: linux-arm64@@ -150,7 +150,7 @@ jobs:platform: linuxarch: arm64rust_target: aarch64-unknown-linux-musl- electron_builder_args: --linux deb rpm AppImage --arm64+ electron_builder_args: --linux deb rpm pacman AppImage --arm64resources_dir: release/linux-arm64-unpacked/resourcesapp_path: release/linux-arm64-unpacked- target: win32-x64@@ -193,7 +193,7 @@ jobs:# squashfs-tools provides `unsquashfs`, used by# verify-appimage-artifact.mjs to read the AppImage's embedded# desktop entry. zsync provides the canonical `zsyncmake` generator.- sudo apt-get install --yes rpm squashfs-tools zsync+ sudo apt-get install --yes rpm squashfs-tools zsync zstd libarchive-tools- name: Setup Rustuses: dtolnay/rust-toolchain@4cda84d5c5c54efe2404f9d843567869ab1699d4 # stable@@ -394,14 +394,27 @@ jobs:shopt -s nullglobdebs=(release/*.deb)rpms=(release/*.rpm)+ pacmans=(release/*.pacman)appimages=(release/*.AppImage)- if (( ${#debs[@]} != 1 || ${#rpms[@]} != 1 || ${#appimages[@]} != 1 )); then- echo "Expected one deb, rpm, and AppImage for ${{ matrix.target }}" >&2+ if (( ${#debs[@]} != 1 || ${#rpms[@]} != 1 || ${#pacmans[@]} != 1 || ${#appimages[@]} != 1 )); then+ echo "Expected one deb, rpm, pacman, and AppImage for ${{ matrix.target }}" >&2exit 1fidpkg-deb --info "${debs[0]}"rpm -qip "${rpms[0]}"+ - name: Verify Arch Linux package+ if: matrix.platform == 'linux'+ run: >-+ node scripts/verify-pacman-artifact.mjs+ --dir release+ --version "${{ needs.preflight.outputs.version }}"+ --arch ${{ matrix.arch }}++ - name: Smoke test Arch Linux installation+ if: matrix.target == 'linux-x64'+ run: bash scripts/smoke-pacman-package.sh release+- name: Verify AppImage artifactif: matrix.platform == 'linux'run: >-@@ -531,6 +544,7 @@ jobs:release/*.dmgrelease/*.exerelease/*.rpm+ release/*.pacmanrelease/*.tar.gzrelease/latest*.ymlrelease/size-reports/${{ matrix.target }}.jsondiff --git a/README.md b/README.mdindex d1ed1dc2..279103f7 100644--- a/README.md+++ b/README.md@@ -144,6 +144,7 @@ package that matches your operating system and architecture:| Windows | `x64` | `.exe` (NSIS installer) / `.zip` | Use the `.exe` installer for a normal installation or `.zip` for a manually extracted copy || Linux | `x64`, `arm64` | `.AppImage` / `.deb` / `.rpm` | Use the portable `.AppImage` on any distribution, `.deb` on Debian or Ubuntu, or `.rpm` on Fedora or openSUSE || Linux (Snap Store) | `amd64`, `arm64` | `latest/edge` | Install the strictly confined beta with `sudo snap install motrix --edge` |+| Arch Linux / Omarchy | `x64`, `arm64` | `.pacman` | Install the native Arch package with `sudo pacman -U ./Motrix-<version>-<arch>.pacman`; see the [Arch installation guide](docs/arch-linux.md) |The `.AppImage` asks on first launch whether to register its desktop entry andURL-scheme handlers under your user data directory; declining leaves your systemdiff --git a/README.zh-CN.md b/README.zh-CN.mdindex adde7897..80dd582f 100644--- a/README.zh-CN.md+++ b/README.zh-CN.md@@ -141,6 +141,7 @@ Motrix Extension 已上架官方浏览器扩展商店,配合 Motrix 2 使用| Windows | `x64` | `.exe`(NSIS 安装包)/ `.zip` | 常规安装使用 `.exe`;`.zip` 可解压后手动运行 || Linux | `x64`、`arm64` | `.AppImage` / `.deb` / `.rpm` | 任意发行版可使用便携的 `.AppImage`,Debian 或 Ubuntu 使用 `.deb`,Fedora 或 openSUSE 使用 `.rpm` || Linux(Snap Store) | `amd64`、`arm64` | `latest/edge` | 使用 `sudo snap install motrix --edge` 安装严格限制的 beta |+| Arch Linux / Omarchy | `x64`、`arm64` | `.pacman` | 使用 `sudo pacman -U ./Motrix-<version>-<arch>.pacman` 安装原生 Arch 包,详见 [Arch 安装指南](docs/arch-linux.zh-CN.md) |`.AppImage` 首次启动时会询问是否把桌面入口和 URL scheme 处理程序注册到你的用户数据目录;拒绝则不改动系统。之后随时可以在「设置 → 集成」中启用或移除该桌面集成。Snap Store 安装包使用严格限制。已批准的 `personal-files` interface 允许 Motrixdiff --git a/docs/arch-linux.md b/docs/arch-linux.mdnew file mode 100644index 00000000..744c48da--- /dev/null+++ b/docs/arch-linux.md@@ -0,0 +1,77 @@+# Arch Linux and Omarchy++[简体中文](arch-linux.zh-CN.md)++Omarchy uses Arch Linux packages and `pacman`. Motrix release builds include a+native `.pacman` package for `x64` (`x86_64`) and `arm64` (`aarch64`). Download it+from the assets of a [GitHub release](https://github.com/agalwood/Motrix/releases)+that includes this format. Older releases may only offer AppImage, DEB, and RPM.++The `.pacman` suffix is electron-builder’s name for a native Arch package. The+archive uses Zstandard compression and contains Arch package metadata, just as+a `.pkg.tar.zst` package does. Keep the published filename: Motrix’s application+updater selects the `.pacman` asset from the release manifest.++## Install++Run `uname -m` to check your architecture. Choose `x64` for `x86_64`, or `arm64`+for `aarch64` (the ARM filename uses `aarch64`). Update Omarchy through its Update menu before installing; on+ordinary Arch Linux, run `sudo pacman -Syu`.++In the directory containing the download, replace the placeholders with its+actual filename:++```bash+sudo pacman -U ./Motrix-<version>-<arch>.pacman+motrix+```++Pacman installs the application in `/opt/Motrix`, adds the `motrix` command,+and installs the launcher, icons, and torrent/Magnet/Motrix URL handlers. The+package includes its own Electron runtime, aria2, and native helpers. Pacman+resolves the declared system libraries; a separate system Electron package is+not needed. Run Motrix as your normal user.++For a system tray that requires AppIndicator support, install the optional+`libayatana-appindicator` package. Browser extension pairing is configured in+Motrix’s Integration settings after launch.++## Update and remove++Install a newer downloaded `.pacman` file using the same `pacman -U` command.+The package also carries the metadata for Motrix’s application update flow.+Because a downloaded package is not a configured package repository, `pacman+-Syu` alone does not fetch newer Motrix releases.++```bash+sudo pacman -R motrix+```++Removing the package removes the installed application and desktop entry.+Your downloads and user configuration remain in your user directories.+Existing AUR variants such as `motrix-bin` are declared as conflicts so pacman+can resolve the transition instead of allowing overlapping installations.++## Building and verification++After building and staging the Linux desktop application, package it on the+matching Linux architecture. The release workflow supplies the native build+inputs and packaging tools (`zstd` and `bsdtar`, provided by `libarchive` on+Arch or `libarchive-tools` on Ubuntu):++```bash+pnpm exec electron-builder --linux pacman --x64 --publish never+node scripts/verify-pacman-artifact.mjs --dir release --version <version> --arch x64+bash scripts/smoke-pacman-package.sh release+```++Use `--arm64` and `--arch arm64` for ARM builds. CI and the release workflow+inspect both architectures’ final archives, metadata, desktop handlers, and+Electron/native payloads. The Docker smoke test uses the official x86_64 Arch+image to check installation, shared-library resolution, aria2 execution,+reinstallation, and removal. It does not validate a full Omarchy/Hyprland GUI+session; tray behavior, Wayland rendering, and browser pairing still need+desktop testing. The ARM package does not run through that x86_64 install test.++These artifacts are distributed through Motrix releases. This does not publish+or update an AUR entry or add Motrix to Omarchy’s package repository.diff --git a/docs/arch-linux.zh-CN.md b/docs/arch-linux.zh-CN.mdnew file mode 100644index 00000000..dbb6c193--- /dev/null+++ b/docs/arch-linux.zh-CN.md@@ -0,0 +1,71 @@+# Arch Linux 与 Omarchy++[English](arch-linux.md)++Omarchy 使用 Arch Linux 软件包和 `pacman`。Motrix 发布构建提供 `x64`+(`x86_64`)和 `arm64`(`aarch64`)原生 `.pacman` 包。请从包含此格式的+[GitHub Release](https://github.com/agalwood/Motrix/releases) 附件中下载。+较早的版本可能只提供 AppImage、DEB 和 RPM。++`.pacman` 是 electron-builder 为原生 Arch 包使用的后缀。压缩包使用+Zstandard 压缩,包含 Arch 软件包元数据,与 `.pkg.tar.zst` 包属于同一类+格式。请保留发布时的文件名:Motrix 的应用更新器会从发布清单中选择+`.pacman` 附件。++## 安装++运行 `uname -m` 查看架构。输出 `x86_64` 时选择 `x64`,输出 `aarch64`+时选择 `arm64`(ARM 文件名使用 `aarch64`)。安装前先通过 Omarchy 的 Update 菜单更新系统;普通+Arch Linux 使用 `sudo pacman -Syu`。++在下载文件所在目录执行以下命令,把占位符替换为实际文件名:++```bash+sudo pacman -U ./Motrix-<version>-<arch>.pacman+motrix+```++Pacman 会把应用安装到 `/opt/Motrix`,添加 `motrix` 命令,并安装启动器、+图标以及 Torrent、Magnet、Motrix URL 处理程序。安装包自带 Electron、+aria2 和原生辅助程序。Pacman 会解析声明的系统库依赖,无需单独安装系统+Electron 包。请以普通用户身份运行 Motrix。++如果系统托盘需要 AppIndicator 支持,可安装可选的+`libayatana-appindicator` 包。启动后可在 Motrix 的集成设置中配置浏览器+扩展配对。++## 更新与卸载++下载新版 `.pacman` 文件后,使用相同的 `pacman -U` 命令更新。安装包也+携带 Motrix 应用内更新流程所需的元数据。由于下载的软件包不是已配置的+软件仓库,单独运行 `pacman -Syu` 不会获取 Motrix 新版本。++```bash+sudo pacman -R motrix+```++卸载会移除已安装的应用和桌面入口,下载文件与用户配置仍保留在用户目录+中。安装包声明了与 `motrix-bin` 等现有 AUR 变体的冲突,便于 pacman+处理迁移,避免重叠安装。++## 构建与验证++构建并暂存 Linux 桌面应用后,在对应架构的 Linux 上打包。发布工作流+会提供原生构建输入和打包工具,包括 `zstd` 与 `bsdtar`;后者在 Arch+上由 `libarchive` 提供,在 Ubuntu 上由 `libarchive-tools` 提供:++```bash+pnpm exec electron-builder --linux pacman --x64 --publish never+node scripts/verify-pacman-artifact.mjs --dir release --version <version> --arch x64+bash scripts/smoke-pacman-package.sh release+```++ARM 构建使用 `--arm64` 和 `--arch arm64`。CI 和发布工作流会检查两种+架构的最终压缩包、元数据、桌面处理程序以及 Electron 和原生程序内容。+Docker 冒烟测试使用官方 x86_64 Arch 镜像,检查安装、共享库解析、aria2+执行、重新安装和卸载。它不会验证完整的 Omarchy/Hyprland 图形会话;+托盘、Wayland 渲染和浏览器配对仍需桌面测试。ARM 包不运行这项 x86_64+安装测试。++这些产物通过 Motrix Release 分发,不会自动发布或更新 AUR 条目,也不会+把 Motrix 加入 Omarchy 的软件仓库。diff --git a/electron-builder.json b/electron-builder.jsonindex 9eff1e97..2dfe829c 100644--- a/electron-builder.json+++ b/electron-builder.json@@ -205,7 +205,8 @@"target": [{ "target": "AppImage", "arch": ["x64", "arm64"] },{ "target": "deb", "arch": ["x64", "arm64"] },- { "target": "rpm", "arch": ["x64", "arm64"] }+ { "target": "rpm", "arch": ["x64", "arm64"] },+ { "target": "pacman", "arch": ["x64", "arm64"] }],"extraResources": [{ "from": "./extra/aria2.conf", "to": "./extra/aria2.conf" },@@ -248,6 +249,54 @@"rpm": {"artifactName": "${productName}-${version}.${arch}.${ext}"},+ "pacman": {+ "artifactName": "${productName}-${version}-${arch}.${ext}",+ "packageName": "motrix",+ "compression": "zstd",+ "depends": [+ "alsa-lib",+ "at-spi2-core",+ "cairo",+ "expat",+ "gcc-libs",+ "glib2",+ "glibc",+ "gtk3",+ "libcups",+ "libdrm",+ "libnotify",+ "libsecret",+ "libx11",+ "libxcb",+ "libxcomposite",+ "libxdamage",+ "libxext",+ "libxfixes",+ "libxkbcommon",+ "libxrandr",+ "mesa",+ "nspr",+ "nss",+ "pango",+ "xdg-utils"+ ],+ "fpm": [+ "--description",+ "Full-featured download manager",+ "--iteration",+ "1",+ "--provides",+ "motrix",+ "--conflicts",+ "motrix-bin",+ "--conflicts",+ "motrix-git",+ "--conflicts",+ "motrix-beta-bin",+ "--pacman-optional-depends",+ "libayatana-appindicator: system tray integration"+ ]+ },"beforePack": "./scripts/before-pack-verify.mjs","beforeBuild": "./scripts/before-build-use-staged-dependencies.mjs","artifactBuildCompleted": "./scripts/finalize-appimage-artifact.mjs",diff --git a/scripts/assemble-release-artifacts.mjs b/scripts/assemble-release-artifacts.mjsindex 395a5a0c..2d1d0ddc 100644--- a/scripts/assemble-release-artifacts.mjs+++ b/scripts/assemble-release-artifacts.mjs@@ -53,6 +53,7 @@ export const RELEASE_TARGETS = [assetNames: (version) => [`Motrix_${version}_amd64.deb`,`Motrix-${version}.x86_64.rpm`,+ `Motrix-${version}-x64.pacman`,`Motrix-${version}-x86_64.AppImage`,`Motrix-${version}-x86_64.AppImage.zsync`,flatpakCompanionArchiveName(version, 'x64'),@@ -60,6 +61,7 @@ export const RELEASE_TARGETS = [manifestAssetNames: (version) => [`Motrix_${version}_amd64.deb`,`Motrix-${version}.x86_64.rpm`,+ `Motrix-${version}-x64.pacman`,`Motrix-${version}-x86_64.AppImage`,],legacyAssetName: (version) => `Motrix_${version}_amd64.deb`,@@ -71,6 +73,7 @@ export const RELEASE_TARGETS = [assetNames: (version) => [`Motrix_${version}_arm64.deb`,`Motrix-${version}.aarch64.rpm`,+ `Motrix-${version}-aarch64.pacman`,`Motrix-${version}-arm64.AppImage`,`Motrix-${version}-arm64.AppImage.zsync`,flatpakCompanionArchiveName(version, 'arm64'),@@ -78,6 +81,7 @@ export const RELEASE_TARGETS = [manifestAssetNames: (version) => [`Motrix_${version}_arm64.deb`,`Motrix-${version}.aarch64.rpm`,+ `Motrix-${version}-aarch64.pacman`,`Motrix-${version}-arm64.AppImage`,],legacyAssetName: (version) => `Motrix_${version}_arm64.deb`,@@ -102,6 +106,7 @@ const RELEASE_ASSET_EXTENSIONS = ['.dmg','.exe','.rpm',+ '.pacman','.snap','.tar.gz','.zip',diff --git a/scripts/smoke-pacman-package.sh b/scripts/smoke-pacman-package.shnew file mode 100644index 00000000..8f6255f5--- /dev/null+++ b/scripts/smoke-pacman-package.sh@@ -0,0 +1,39 @@+#!/usr/bin/env bash+set -euo pipefail++# The official Arch Linux image is x86_64. ARM archives are inspected by the+# cross-platform verifier on their native build runner, not run under emulation.+artifact_dir="$(cd "${1:?Expected release directory}" && pwd)"+shopt -s nullglob+packages=("$artifact_dir"/*-x64.pacman)+if (( ${#packages[@]} != 1 )); then+ echo 'Expected exactly one x64 pacman package' >&2+ exit 1+fi++docker run --rm --platform linux/amd64 \+ --mount "type=bind,src=$artifact_dir,dst=/artifacts,readonly" \+ --env "MOTRIX_PACKAGE=/artifacts/$(basename "${packages[0]}")" \+ archlinux:base bash -euo pipefail -c '+ pacman -Syu --noconfirm+ pacman -U --noconfirm "$MOTRIX_PACKAGE"+ pacman -Qk motrix+ test "$(readlink -f /usr/bin/motrix)" = /opt/Motrix/motrix+ test -f /usr/share/applications/motrix.desktop+ test -f /usr/share/icons/hicolor/256x256/apps/motrix.png+ test "$(cat /opt/Motrix/resources/package-type)" = pacman+ ldd /opt/Motrix/motrix > /tmp/motrix-ldd.log+ cat /tmp/motrix-ldd.log+ if grep -q "not found" /tmp/motrix-ldd.log; then+ echo "Packaged Electron has unresolved runtime dependencies" >&2+ exit 1+ fi+ /opt/Motrix/resources/extra/linux/x64/aria2c --version+ # Reinstallation exercises post_upgrade as well as post_install.+ pacman -U --noconfirm "$MOTRIX_PACKAGE"+ test -x /usr/bin/motrix+ pacman -R --noconfirm motrix+ test ! -e /opt/Motrix+ test ! -e /usr/share/applications/motrix.desktop+ test ! -L /usr/bin/motrix+ 'diff --git a/scripts/verify-pacman-artifact.mjs b/scripts/verify-pacman-artifact.mjsnew file mode 100644index 00000000..7118e13b--- /dev/null+++ b/scripts/verify-pacman-artifact.mjs@@ -0,0 +1,174 @@+import { execFile } from 'node:child_process'+import { lstat, mkdtemp, open, readdir, readFile, rm } from 'node:fs/promises'+import { tmpdir } from 'node:os'+import path from 'node:path'+import { fileURLToPath } from 'node:url'+import { promisify } from 'node:util'+import { parseStrictSemVer } from './release-metadata.mjs'+import { verifyElectronPackage } from './verify-electron-package.mjs'++const execFileAsync = promisify(execFile)+const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')+const ARCH_NAMES = { x64: 'x86_64', arm64: 'aarch64' }++export function expectedPacmanName(version, arch) {+ parseStrictSemVer(version, 'release version')+ if (!Object.hasOwn(ARCH_NAMES, arch)) {+ throw new Error(`Unsupported pacman architecture: ${arch}`)+ }+ return `Motrix-${version}-${arch === 'arm64' ? 'aarch64' : 'x64'}.pacman`+}++export function assertPacmanMetadata(source, { version, arch, depends }) {+ expectedPacmanName(version, arch)+ const fields = new Map()+ for (const line of source.split(/\r?\n/)) {+ if (!line.trim() || line.startsWith('#')) continue+ const match = /^([a-z]+) = (.+)$/.exec(line)+ if (!match) throw new Error(`Invalid .PKGINFO line: ${line}`)+ const [, key, value] = match+ fields.set(key, [...(fields.get(key) ?? []), value])+ }+ for (const [key, expected] of Object.entries({+ pkgname: 'motrix',+ pkgver: `${version.replaceAll('-', '_')}-1`,+ arch: ARCH_NAMES[arch],+ url: 'https://motrix.app',+ license: 'MIT',+ })) {+ const values = fields.get(key)+ if (values?.length !== 1 || values[0] !== expected) {+ throw new Error(`.PKGINFO ${key} must be ${expected}`)+ }+ }+ const actualDepends = new Set(fields.get('depend') ?? [])+ for (const dependency of depends) {+ if (!actualDepends.has(dependency)) {+ throw new Error(`.PKGINFO missing dependency: ${dependency}`)+ }+ }+ for (const conflict of ['motrix-bin', 'motrix-git', 'motrix-beta-bin']) {+ if (!fields.get('conflict')?.includes(conflict)) {+ throw new Error(`.PKGINFO missing conflict: ${conflict}`)+ }+ }+}++export async function verifyPacmanArtifact({+ directory,+ version,+ arch,+ verifyPayload = verifyElectronPackage,+ extractArchive = (artifact, destination) =>+ execFileAsync('bsdtar', ['-xf', artifact, '-C', destination]),+}) {+ const expected = expectedPacmanName(version, arch)+ const files = (await readdir(directory)).filter((name) =>+ name.endsWith('.pacman')+ )+ if (files.length !== 1 || files[0] !== expected) {+ throw new Error(`Expected exactly one pacman artifact named ${expected}`)+ }+ const artifact = path.resolve(directory, expected)+ if (!(await lstat(artifact)).isFile()) {+ throw new Error('Pacman artifact must be a regular file')+ }+ const handle = await open(artifact, 'r')+ try {+ const magic = Buffer.alloc(4)+ await handle.read(magic, 0, magic.length, 0)+ if (magic.toString('hex') !== '28b52ffd') {+ throw new Error('Pacman artifact must use Zstandard compression')+ }+ } finally {+ await handle.close()+ }++ // Inspect the final archive, including native binaries and ASAR contents,+ // rather than assuming the unpacked electron-builder input was preserved.+ const temporary = await mkdtemp(path.join(tmpdir(), 'motrix-pacman-'))+ try {+ await extractArchive(artifact, temporary)+ const config = JSON.parse(+ await readFile(path.join(ROOT, 'electron-builder.json'), 'utf8')+ )+ assertPacmanMetadata(+ await readFile(path.join(temporary, '.PKGINFO'), 'utf8'),+ { version, arch, depends: config.pacman.depends }+ )+ if (!(await lstat(path.join(temporary, '.MTREE'))).isFile()) {+ throw new Error('Pacman artifact is missing .MTREE')+ }+ const appDir = path.join(temporary, 'opt/Motrix')+ const packageType = await readFile(+ path.join(appDir, 'resources/package-type'),+ 'utf8'+ )+ if (packageType.trim() !== 'pacman') {+ throw new Error('Pacman package must select the pacman updater')+ }+ const desktop = await readFile(+ path.join(temporary, 'usr/share/applications/motrix.desktop'),+ 'utf8'+ )+ const mime = /^MimeType=(.*)$/m.exec(desktop)?.[1].split(';') ?? []+ for (const type of [+ 'application/x-bittorrent',+ 'x-scheme-handler/magnet',+ 'x-scheme-handler/motrix',+ ]) {+ if (!mime.includes(type)) {+ throw new Error(`Pacman desktop entry is missing ${type}`)+ }+ }+ if (!/^Exec="?\/opt\/Motrix\/motrix"? .*%U.*$/m.test(desktop)) {+ throw new Error(+ 'Pacman desktop entry must launch Motrix with URL arguments'+ )+ }+ const binary = await lstat(path.join(appDir, 'motrix'))+ if (!binary.isFile() || (binary.mode & 0o111) === 0) {+ throw new Error('Packaged Motrix must be executable')+ }+ const report = await verifyPayload({+ appDir,+ platform: 'linux',+ arch,+ reportPath: path.resolve(+ directory,+ 'size-reports',+ `pacman-${arch}.json`+ ),+ })+ if (!report.passed) {+ throw new Error(+ `Pacman payload verification failed: ${report.errors.join('; ')}`+ )+ }+ return { artifact: expected, arch, version }+ } finally {+ await rm(temporary, { recursive: true, force: true })+ }+}++if (+ process.argv[1] &&+ path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)+) {+ const { parseArgs } = await import('node:util')+ const { values } = parseArgs({+ options: {+ dir: { type: 'string' },+ version: { type: 'string' },+ arch: { type: 'string' },+ },+ })+ verifyPacmanArtifact({ directory: values.dir ?? 'release', ...values })+ .then((result) =>+ console.log(`[verify-pacman-artifact] passed ${result.artifact}`)+ )+ .catch((error) => {+ console.error(`[verify-pacman-artifact] ${error.message}`)+ process.exitCode = 1+ })+}diff --git a/scripts/verify-update-artifacts.mjs b/scripts/verify-update-artifacts.mjsindex 742944e7..3551050d 100644--- a/scripts/verify-update-artifacts.mjs+++ b/scripts/verify-update-artifacts.mjs@@ -13,12 +13,12 @@ const MANIFEST_PLATFORMS = [{suffix: '-linux',legacyExtension: '.deb',- requiredExtensions: ['.deb', '.rpm', '.AppImage'],+ requiredExtensions: ['.deb', '.rpm', '.AppImage', '.pacman'],},{suffix: '-linux-arm64',legacyExtension: '.deb',- requiredExtensions: ['.deb', '.rpm', '.AppImage'],+ requiredExtensions: ['.deb', '.rpm', '.AppImage', '.pacman'],},]diff --git a/tests/scripts/assemble-release-artifacts.test.ts b/tests/scripts/assemble-release-artifacts.test.tsindex 51649ecb..071302bb 100644--- a/tests/scripts/assemble-release-artifacts.test.ts+++ b/tests/scripts/assemble-release-artifacts.test.ts@@ -52,6 +52,8 @@ describe('assembleReleaseArtifacts', () => {'Motrix-2.0.0-x86_64.AppImage.zsync','Motrix-2.0.0.aarch64.rpm','Motrix-2.0.0.x86_64.rpm',+ 'Motrix-2.0.0-x64.pacman',+ 'Motrix-2.0.0-aarch64.pacman','Motrix-Native-Host-2.0.0-linux-arm64.tar.gz','Motrix-Native-Host-2.0.0-linux-x64.tar.gz','Motrix_2.0.0_amd64.deb',@@ -94,8 +96,8 @@ describe('assembleReleaseArtifacts', () => {const linuxManifest = load(await readFile(path.join(fixture.output, manifestName), 'utf8')) as { files: Array<{ url: string }> }- expect(linuxManifest.files).toHaveLength(3)- expect(new Set(linuxManifest.files.map((file) => file.url)).size).toBe(3)+ expect(linuxManifest.files).toHaveLength(4)+ expect(new Set(linuxManifest.files.map((file) => file.url)).size).toBe(4)expect(linuxManifest.files.some((file) => file.url.endsWith('.AppImage'))).toBe(true)@@ -526,6 +528,20 @@ describe('assembleReleaseArtifacts', () => {}})+ it('rejects a missing Arch package before assembling a release', async () => {+ const fixture = await createFixture()+ await unlink(fixture.paths.linuxX64Pacman)+ await expect(+ assembleReleaseArtifacts({+ inputDirectory: fixture.input,+ outputDirectory: fixture.output,+ version: VERSION,+ })+ ).rejects.toThrow(+ 'required release asset Motrix-2.0.0-x64.pacman is missing'+ )+ })+it('requires a zsync sidecar for every Linux AppImage', async () => {const fixture = await createFixture()await unlink(fixture.paths.linuxX64Zsync)@@ -606,11 +622,13 @@ async function createFixture(version = VERSION) {await mkdir(input)const names = {+ linuxArm64Pacman: `Motrix-${version}-aarch64.pacman`,linuxArm64Deb: `Motrix_${version}_arm64.deb`,linuxArm64Companion: `Motrix-Native-Host-${version}-linux-arm64.tar.gz`,linuxArm64Rpm: `Motrix-${version}.aarch64.rpm`,linuxArm64AppImage: `Motrix-${version}-arm64.AppImage`,linuxArm64Zsync: `Motrix-${version}-arm64.AppImage.zsync`,+ linuxX64Pacman: `Motrix-${version}-x64.pacman`,linuxX64Deb: `Motrix_${version}_amd64.deb`,linuxX64Companion: `Motrix-Native-Host-${version}-linux-x64.tar.gz`,linuxX64Rpm: `Motrix-${version}.x86_64.rpm`,@@ -625,6 +643,7 @@ async function createFixture(version = VERSION) {const linuxArm64AppImageContent = Buffer.from('Linux arm64 AppImage')const linuxX64AppImageContent = Buffer.from('Linux x64 AppImage')const contents = {+ linuxArm64Pacman: Buffer.from('Linux arm64 pacman'),linuxArm64Deb: Buffer.from('Linux arm64 deb'),linuxArm64Companion: Buffer.from('Linux arm64 Flatpak companion'),linuxArm64Rpm: Buffer.from('Linux arm64 rpm'),@@ -633,6 +652,7 @@ async function createFixture(version = VERSION) {names.linuxArm64AppImage,linuxArm64AppImageContent),+ linuxX64Pacman: Buffer.from('Linux x64 pacman'),linuxX64Deb: Buffer.from('Linux x64 deb'),linuxX64Companion: Buffer.from('Linux x64 Flatpak companion'),linuxX64Rpm: Buffer.from('Linux x64 rpm'),@@ -699,6 +719,11 @@ async function createFixture(version = VERSION) {)const linuxX64 = await makeTarget(input, 'linux-x64')+ const linuxX64Pacman = await writeAsset(+ linuxX64,+ names.linuxX64Pacman,+ contents.linuxX64Pacman+ )const linuxX64Deb = await writeAsset(linuxX64,names.linuxX64Deb,@@ -729,6 +754,7 @@ async function createFixture(version = VERSION) {{ name: names.linuxX64Deb, content: contents.linuxX64Deb },{ name: names.linuxX64Rpm, content: contents.linuxX64Rpm },{ name: names.linuxX64AppImage, content: contents.linuxX64AppImage },+ { name: names.linuxX64Pacman, content: contents.linuxX64Pacman },{ name: names.linuxX64Rpm, content: contents.linuxX64Rpm },],names.linuxX64AppImage@@ -740,12 +766,18 @@ async function createFixture(version = VERSION) {{ name: names.linuxX64Deb, content: contents.linuxX64Deb },{ name: names.linuxX64Rpm, content: contents.linuxX64Rpm },{ name: names.linuxX64AppImage, content: contents.linuxX64AppImage },+ { name: names.linuxX64Pacman, content: contents.linuxX64Pacman },{ name: names.linuxX64Rpm, content: contents.linuxX64Rpm },],names.linuxX64AppImage)const linuxArm64 = await makeTarget(input, 'linux-arm64')+ const linuxArm64Pacman = await writeAsset(+ linuxArm64,+ names.linuxArm64Pacman,+ contents.linuxArm64Pacman+ )const linuxArm64Deb = await writeAsset(linuxArm64,names.linuxArm64Deb,@@ -779,6 +811,7 @@ async function createFixture(version = VERSION) {{ name: names.linuxArm64Deb, content: contents.linuxArm64Deb },{ name: names.linuxArm64Rpm, content: contents.linuxArm64Rpm },{ name: names.linuxArm64AppImage, content: contents.linuxArm64AppImage },+ { name: names.linuxArm64Pacman, content: contents.linuxArm64Pacman },{ name: names.linuxArm64Rpm, content: contents.linuxArm64Rpm },],names.linuxArm64AppImage@@ -790,6 +823,7 @@ async function createFixture(version = VERSION) {{ name: names.linuxArm64Deb, content: contents.linuxArm64Deb },{ name: names.linuxArm64Rpm, content: contents.linuxArm64Rpm },{ name: names.linuxArm64AppImage, content: contents.linuxArm64AppImage },+ { name: names.linuxArm64Pacman, content: contents.linuxArm64Pacman },{ name: names.linuxArm64Rpm, content: contents.linuxArm64Rpm },],names.linuxArm64AppImage@@ -818,12 +852,14 @@ async function createFixture(version = VERSION) {names,output,paths: {+ linuxArm64Pacman: linuxArm64Pacman.path,linuxArm64Deb: linuxArm64Deb.path,linuxArm64Companion: linuxArm64Companion.path,linuxArm64Manifest,linuxArm64Rpm: linuxArm64Rpm.path,linuxArm64AppImage: linuxArm64AppImage.path,linuxArm64Zsync: linuxArm64Zsync.path,+ linuxX64Pacman: linuxX64Pacman.path,linuxX64Deb: linuxX64Deb.path,linuxX64Companion: linuxX64Companion.path,linuxX64AppImage: linuxX64AppImage.path,diff --git a/tests/scripts/verify-pacman-artifact.test.ts b/tests/scripts/verify-pacman-artifact.test.tsnew file mode 100644index 00000000..3dfec902--- /dev/null+++ b/tests/scripts/verify-pacman-artifact.test.ts@@ -0,0 +1,204 @@+import {+ chmod,+ mkdir,+ mkdtemp,+ readFile,+ rm,+ writeFile,+} from 'node:fs/promises'+import { tmpdir } from 'node:os'+import path from 'node:path'+import { afterEach, describe, expect, it, vi } from 'vitest'+import {+ assertPacmanMetadata,+ expectedPacmanName,+ verifyPacmanArtifact,+} from '../../scripts/verify-pacman-artifact.mjs'++const directories: string[] = []+const config = JSON.parse(await readFile('electron-builder.json', 'utf8'))+const version = '2.0.0-beta.34'+const depends: string[] = config.pacman.depends++afterEach(async () => {+ await Promise.all(+ directories+ .splice(0)+ .map((dir) => rm(dir, { recursive: true, force: true }))+ )+})++function metadata(arch = 'x86_64', pkgver = '2.0.0_beta.34-1') {+ return [+ '# Generated by fpm',+ 'pkgname = motrix',+ `pkgver = ${pkgver}`,+ `arch = ${arch}`,+ 'url = https://motrix.app',+ 'license = MIT',+ ...depends.map((dependency) => `depend = ${dependency}`),+ 'conflict = motrix-bin',+ 'conflict = motrix-git',+ 'conflict = motrix-beta-bin',+ ].join('\n')+}++describe('Arch package metadata', () => {+ it.each([+ ['x64', 'x86_64'],+ ['arm64', 'aarch64'],+ ])(+ 'maps %s to pacman architecture %s and normalizes prereleases',+ (arch, nativeArch) => {+ expect(expectedPacmanName(version, arch)).toBe(+ `Motrix-${version}-${arch === 'arm64' ? 'aarch64' : 'x64'}.pacman`+ )+ expect(() =>+ assertPacmanMetadata(metadata(nativeArch), { version, arch, depends })+ ).not.toThrow()+ }+ )++ it('accepts stable versions with the fixed package release', () => {+ expect(() =>+ assertPacmanMetadata(metadata('x86_64', '2.0.0-1'), {+ version: '2.0.0',+ arch: 'x64',+ depends,+ })+ ).not.toThrow()+ })++ it.each([+ ['arch = x86_64', 'arch = aarch64', 'arch must be x86_64'],+ ['pkgver = 2.0.0_beta.34-1', 'pkgver = 2.0.0-beta.34-1', 'pkgver must be'],+ ['pkgname = motrix', 'pkgname = motrix-turbo', 'pkgname must be motrix'],+ [+ 'depend = libsecret',+ 'optdepend = libsecret',+ 'missing dependency: libsecret',+ ],+ ['conflict = motrix-bin', '# omitted', 'missing conflict: motrix-bin'],+ [+ 'license = MIT',+ 'pkgdesc = Summary\n Long description\nlicense = MIT',+ 'Invalid .PKGINFO line',+ ],+ ['arch = x86_64', 'arch = x86_64\narch = aarch64', 'arch must be x86_64'],+ ])('rejects invalid metadata: %s', (before, after, message) => {+ expect(() =>+ assertPacmanMetadata(metadata().replace(before, after), {+ version,+ arch: 'x64',+ depends,+ })+ ).toThrow(message)+ })++ it('rejects unsupported architectures and malformed versions', () => {+ expect(() => expectedPacmanName(version, 'ia32')).toThrow(+ 'Unsupported pacman architecture'+ )+ expect(() => expectedPacmanName('../2.0.0', 'x64')).toThrow('strict SemVer')+ })+})++async function fixture() {+ const directory = await mkdtemp(path.join(tmpdir(), 'motrix-pacman-test-'))+ directories.push(directory)+ await writeFile(+ path.join(directory, expectedPacmanName(version, 'x64')),+ Buffer.from('28b52ffd', 'hex')+ )+ const extractArchive = async (_file: string, destination: string) => {+ const files = {+ '.PKGINFO': metadata(),+ '.MTREE': 'mtree',+ 'opt/Motrix/resources/package-type': 'pacman',+ 'opt/Motrix/motrix': 'executable payload',+ 'usr/share/applications/motrix.desktop': [+ '[Desktop Entry]',+ 'Exec="/opt/Motrix/motrix" %U',+ 'MimeType=application/x-bittorrent;x-scheme-handler/magnet;x-scheme-handler/motrix;',+ ].join('\n'),+ }+ for (const [name, content] of Object.entries(files)) {+ const file = path.join(destination, name)+ await mkdir(path.dirname(file), { recursive: true })+ await writeFile(file, content)+ }+ await chmod(path.join(destination, 'opt/Motrix/motrix'), 0o755)+ }+ return {+ directory,+ version,+ arch: 'x64',+ extractArchive,+ verifyPayload: vi.fn(async () => ({+ passed: true,+ errors: [] as string[],+ })),+ }+}++describe('pacman final archive verification', () => {+ it('verifies the extracted Electron payload with the target architecture', async () => {+ const input = await fixture()+ await expect(verifyPacmanArtifact(input)).resolves.toEqual({+ artifact: expectedPacmanName(version, 'x64'),+ version,+ arch: 'x64',+ })+ expect(input.verifyPayload).toHaveBeenCalledWith(+ expect.objectContaining({+ platform: 'linux',+ arch: 'x64',+ appDir: expect.stringContaining('/opt/Motrix'),+ })+ )+ })++ it('rejects archives with the wrong compression or architecture filename', async () => {+ const input = await fixture()+ await writeFile(+ path.join(input.directory, expectedPacmanName(version, 'x64')),+ 'not zstd'+ )+ await expect(verifyPacmanArtifact(input)).rejects.toThrow(+ 'Zstandard compression'+ )+ await expect(+ verifyPacmanArtifact({ ...input, arch: 'arm64' })+ ).rejects.toThrow('Expected exactly one')+ expect(input.verifyPayload).not.toHaveBeenCalled()+ })++ it.each([+ ['opt/Motrix/resources/package-type', 'rpm', 'pacman updater'],+ [+ 'usr/share/applications/motrix.desktop',+ '[Desktop Entry]\nExec=/opt/Motrix/motrix %U',+ 'missing application/x-bittorrent',+ ],+ ])('rejects broken integration in %s', async (name, content, error) => {+ const input = await fixture()+ const extract = input.extractArchive+ input.extractArchive = async (file, destination) => {+ await extract(file, destination)+ await writeFile(path.join(destination, name), content)+ }+ await expect(verifyPacmanArtifact(input)).rejects.toThrow(error)+ expect(input.verifyPayload).not.toHaveBeenCalled()+ })++ it('propagates native payload failures instead of accepting correct metadata alone', async () => {+ const input = await fixture()+ input.verifyPayload.mockResolvedValue({+ passed: false,+ errors: ['wrong native architecture'],+ })+ await expect(verifyPacmanArtifact(input)).rejects.toThrow(+ 'wrong native architecture'+ )+ })+})diff --git a/tests/scripts/verify-update-artifacts.test.ts b/tests/scripts/verify-update-artifacts.test.tsindex 7d075006..ac92dbf8 100644--- a/tests/scripts/verify-update-artifacts.test.ts+++ b/tests/scripts/verify-update-artifacts.test.ts@@ -31,6 +31,9 @@ describe('verifyUpdateArtifacts', () => {const deb = Buffer.from('signed Linux arm64 deb')const rpm = Buffer.from('signed Linux arm64 rpm')const appImage = Buffer.from('signed Linux arm64 AppImage')+ const pacman = Buffer.from('Linux arm64 pacman')+ const pacmanName = 'Motrix-2.0.0-aarch64.pacman'+ await writeFile(path.join(fixture, pacmanName), pacman)const debName = 'Motrix_2.0.0_arm64.deb'const rpmName = 'Motrix-2.0.0.aarch64.rpm'const appImageName = 'Motrix-2.0.0-arm64.AppImage'@@ -48,6 +51,7 @@ describe('verifyUpdateArtifacts', () => {{ name: debName, content: deb },{ name: rpmName, content: rpm },{ name: appImageName, content: appImage },+ { name: pacmanName, content: pacman },],debName)@@ -57,7 +61,13 @@ describe('verifyUpdateArtifacts', () => {verifyUpdateArtifacts({ directory: fixture, version: '2.0.0' })).resolves.toEqual({manifests: ['latest-linux-arm64.yml'],- assets: [debName, rpmName, appImageName, `${appImageName}.zsync`],+ assets: [+ debName,+ rpmName,+ appImageName,+ pacmanName,+ `${appImageName}.zsync`,+ ],})})diff --git a/tests/scripts/workflow-release-matrix.test.ts b/tests/scripts/workflow-release-matrix.test.tsindex 9ee5fdd2..b24d7adb 100644--- a/tests/scripts/workflow-release-matrix.test.ts+++ b/tests/scripts/workflow-release-matrix.test.ts@@ -1331,7 +1331,7 @@ describe('release workflow publication contract', () => {expect(paths).not.toContain('alpha')})- it('builds AppImage, deb, and rpm Linux release assets', () => {+ it('builds AppImage, deb, rpm, and pacman Linux release assets', () => {const linuxTargets = targetMatrix(releaseWorkflow).entries.filter((entry) => entry.platform === 'linux')@@ -1342,6 +1342,7 @@ describe('release workflow publication contract', () => {expect(args).toMatch(/\bAppImage\b/)expect(args).toMatch(/\bdeb\b/)expect(args).toMatch(/\brpm\b/)+ expect(args).toMatch(/\bpacman\b/)expect(args).not.toMatch(/\bsnap\b/i)}expect(releaseSource).toContain(`\${{ matrix.electron_builder_args }}`)@@ -1398,8 +1399,42 @@ describe('release workflow publication contract', () => {'path')expect(uploadPaths).toContain('release/*.AppImage.zsync')+ expect(uploadPaths).toContain('release/*.pacman')})+ it.each([+ ['CI', ciWorkflow],+ ['release', releaseWorkflow],+ ] as const)(+ '%s verifies Arch archives and tests installation before upload',+ (_, workflow) => {+ const steps = jobSteps(targetMatrix(workflow).job)+ const verifyIndex = steps.findIndex(+ (step) => step.name === 'Verify Arch Linux package'+ )+ const smokeIndex = steps.findIndex(+ (step) => step.name === 'Smoke test Arch Linux installation'+ )+ expect(verifyIndex).toBeGreaterThan(0)+ expect(smokeIndex).toBeGreaterThan(verifyIndex)+ expect(stringField(steps[verifyIndex] as LooseRecord, 'run')).toContain(+ 'scripts/verify-pacman-artifact.mjs'+ )+ expect(stringField(steps[smokeIndex] as LooseRecord, 'if')).toBe(+ "matrix.target == 'linux-x64'"+ )+ expect(stringField(steps[smokeIndex] as LooseRecord, 'run')).toBe(+ 'bash scripts/smoke-pacman-package.sh release'+ )+ const uploadIndex = steps.findIndex((step) =>+ workflow === releaseWorkflow+ ? step.name === 'Upload target release input'+ : String(step.uses ?? '').startsWith('actions/upload-artifact')+ )+ expect(uploadIndex).toBeGreaterThan(smokeIndex)+ }+ )+it('pins the modern AppImage toolset and finalization hook', () => {const builderConfig = asRecord(JSON.parse(