mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-12-03 15:31:40 -05:00
155324710e
Dylan's Linux packaging isolates the deb/rpm (config and data), but the installed packages, the AppImage and the plain nightly tar still started the GUI with no profile at all, so an installed or unpacked Nightly wrote the stable profile (settings, recovery, dictionary, logs, clipboard cache and the socket). The app-side flavor refuses that by design, which also meant those wrappers could not start it. - deb/rpm: the GUI binary and its OCR models move to /usr/lib/pdfcraft-nightly, and /usr/bin/pdfcraft-nightly is a launcher that runs it as `--launch-profile nightly-v1 --profile-root <data>/pdfcraft-nightly -- <files>`. A first-argument `--version`/`-V` keeps the Launcher's query form. - AppImage: AppRun and usr/bin/pdfcraft-nightly are launchers (not a symlink to the binary), and the desktop entry's Exec/TryExec name the launcher. - Arch: nightly-arch-launch.sh runs through the profile instead of exporting PDFCRAFT_CONFIG_DIR. - Flatpak: the rendered manifest runs a launcher command (and the desktop entry names it), inside the Nightly app id's own sandbox. - Plain nightly tar: a `pdfcraft-nightly` launcher beside the binary, allowed and required by packaging/nightly-archive.py, so an unpacked tar is isolated too. - The nightly metainfo drops its `<mediatype>` entries in both renders (no PDF handler claim). - nightly-common.sh: the version check is the exact `pdfcraft <version> (nightly-v1)` the flavor prints, instead of a prefix, and the notices are copied flat (the app's copy_docs also carries licenses/, which the flat archive refuses). - profile_root: a Flatpak instance is refused unless it is the Nightly app id itself. - packaging/nightly-archive-tests.py: the archive policy suite (flat members, required set, launcher, refusals), and the Arch tar test now checks the launch arguments.
138 lines
6.6 KiB
Bash
Executable File
138 lines
6.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Repackage a PdfCraft Linux tarball as a single-file Flatpak bundle:
|
|
#
|
|
# $DIST/pdfcraft-<version>-linux-<arch>.flatpak
|
|
#
|
|
# Usage: packaging/linux/flatpak-bundle.sh [--no-test] [TARBALL]
|
|
#
|
|
# TARBALL defaults to $DIST/pdfcraft-<version>-linux-<arch>.tar.gz from package.sh. The bundle
|
|
# is built for the host architecture (x86_64 or aarch64), which must match the tarball's.
|
|
# Needs flatpak, flatpak-builder and the SVG pixbuf loader (librsvg2-common) for the host's
|
|
# `appstreamcli compose`; the freedesktop runtime and SDK named in the manifest are
|
|
# installed per-user from Flathub. Unless --no-test, the bundle is then installed per-user and
|
|
# `pdfcraft-cli --version` is run inside the sandbox as a smoke test.
|
|
# Manifest: packaging/linux/flatpak/ai.storyteller.pdfcraft.bundle.yml.
|
|
set -euo pipefail
|
|
# shellcheck source=../env.sh
|
|
. "$(dirname "${BASH_SOURCE[0]}")/../env.sh"
|
|
HERE="$ROOT/packaging/linux"
|
|
APP_ID=ai.storyteller.pdfcraft
|
|
FLATPAK_ID="$APP_ID"
|
|
# The remote indexes both app IDs on the stable ref branch; IDs isolate installations.
|
|
FLATPAK_BRANCH=stable
|
|
if [[ "${PDFCRAFT_BUILD_CHANNEL:-}" == nightly-v1 || "$VERSION" == *-nightly* ]]; then
|
|
FLATPAK_ID="$APP_ID.nightly"
|
|
fi
|
|
FLATHUB=https://dl.flathub.org/repo/flathub.flatpakrepo
|
|
|
|
TEST=1
|
|
OCI=0
|
|
TARBALL=""
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--no-test) TEST=0; shift ;;
|
|
--oci) OCI=1; shift ;;
|
|
-h | --help) sed -n '2,14p' "$0"; exit 0 ;;
|
|
-*) echo "unknown argument: $1" >&2; exit 2 ;;
|
|
*) TARBALL="$1"; shift ;;
|
|
esac
|
|
done
|
|
|
|
ARCH="$(uname -m)"
|
|
case "$ARCH" in
|
|
x86_64) ;;
|
|
aarch64 | arm64) ARCH=aarch64 ;;
|
|
*) echo "unsupported architecture $ARCH" >&2; exit 2 ;;
|
|
esac
|
|
BASENAME="pdfcraft-$VERSION-linux-$ARCH"
|
|
TARBALL="${TARBALL:-$DIST/$BASENAME.tar.gz}"
|
|
[[ -f "$TARBALL" ]] || { echo "error: $TARBALL not found (run packaging/linux/package.sh --formats tar first)" >&2; exit 1; }
|
|
for tool in flatpak flatpak-builder; do
|
|
command -v "$tool" >/dev/null || { echo "error: $tool not found (apt install flatpak flatpak-builder librsvg2-common)" >&2; exit 1; }
|
|
done
|
|
|
|
echo "==> PdfCraft $VERSION Flatpak bundle for $ARCH from $(basename "$TARBALL")"
|
|
|
|
WORK="$CARGO_TARGET_DIR/flatpak-bundle"
|
|
rm -rf "$WORK"
|
|
mkdir -p "$WORK/stage"
|
|
tar -xzf "$TARBALL" -C "$WORK/stage" --strip-components=1
|
|
[[ -x "$WORK/stage/bin/pdfcraft" ]] || { echo "error: $TARBALL has no bin/pdfcraft" >&2; exit 1; }
|
|
if [[ "$FLATPAK_ID" != "$APP_ID" ]]; then
|
|
# The Nightly GUI starts through its launch profile inside the sandbox, from a wrapper the
|
|
# manifest runs (and the desktop entry names), so the Flatpak never writes the stable profile.
|
|
cat >"$WORK/stage/bin/pdfcraft-nightly-launch" <<'LAUNCHER'
|
|
#!/bin/sh
|
|
# PdfCraft Nightly inside its own Flatpak: the data root is this app's own folder.
|
|
set -eu
|
|
root="${XDG_DATA_HOME:-$HOME/.local/share}/pdfcraft-nightly"
|
|
case "${1:-}" in
|
|
--version | -V) exec /app/bin/pdfcraft --launch-profile nightly-v1 --profile-root "$root" "$1" ;;
|
|
esac
|
|
exec /app/bin/pdfcraft --launch-profile nightly-v1 --profile-root "$root" -- "$@"
|
|
LAUNCHER
|
|
chmod 755 "$WORK/stage/bin/pdfcraft-nightly-launch"
|
|
sed -e "s#^Exec=pdfcraft\([[:space:]]\|$\)#Exec=pdfcraft-nightly-launch\1#" \
|
|
-e "s|^TryExec=pdfcraft$|TryExec=pdfcraft-nightly-launch|" \
|
|
-e "s|^Icon=$APP_ID$|Icon=$FLATPAK_ID|" \
|
|
-e "s|^Name=PdfCraft$|Name=PdfCraft Nightly|" \
|
|
-e 's|^StartupWMClass=.*|StartupWMClass=ai.storyteller.pdfcraft.nightly-v1|' \
|
|
-e '/^MimeType=/d' \
|
|
"$WORK/stage/share/applications/$APP_ID.desktop" >"$WORK/stage/share/applications/$FLATPAK_ID.desktop"
|
|
rm -f "$WORK/stage/share/applications/$APP_ID.desktop"
|
|
sed -e "s|<id>$APP_ID</id>|<id>$FLATPAK_ID</id>|g" \
|
|
-e "s|<name>PdfCraft</name>|<name>PdfCraft Nightly</name>|g" \
|
|
-e "s|<launchable type=\"desktop-id\">$APP_ID.desktop</launchable>|<launchable type=\"desktop-id\">$FLATPAK_ID.desktop</launchable>|g" \
|
|
-e "s|<icon type=\"stock\">$APP_ID</icon>|<icon type=\"stock\">$FLATPAK_ID</icon>|g" \
|
|
-e '/<mediatype>/d' \
|
|
"$WORK/stage/share/metainfo/$APP_ID.metainfo.xml" >"$WORK/stage/share/metainfo/$FLATPAK_ID.metainfo.xml"
|
|
rm -f "$WORK/stage/share/metainfo/$APP_ID.metainfo.xml"
|
|
mv "$WORK/stage/share/mime/packages/$APP_ID.xml" "$WORK/stage/share/mime/packages/$FLATPAK_ID.xml"
|
|
if [[ -f "$ROOT/assets/app-icon/pdfcraft-nightly.png" ]]; then
|
|
rm -rf "$WORK/stage/share/icons/hicolor"
|
|
install -Dm644 "$ROOT/assets/app-icon/pdfcraft-nightly.png" \
|
|
"$WORK/stage/share/icons/hicolor/256x256/apps/$FLATPAK_ID.png"
|
|
else
|
|
for icon in "$WORK/stage/share/icons/hicolor"/*/apps/"$APP_ID".*; do
|
|
[[ -f "$icon" ]] || continue
|
|
ext="${icon##*.}"
|
|
mv "$icon" "$(dirname "$icon")/$FLATPAK_ID.$ext"
|
|
done
|
|
fi
|
|
sed -e "s|ai\.storyteller\.pdfcraft|$FLATPAK_ID|g" \
|
|
-e "s|^command: pdfcraft$|command: pdfcraft-nightly-launch|" \
|
|
-e "s|^ - install -Dm755 bin/pdfcraft-cli /app/bin/pdfcraft-cli$| - install -Dm755 bin/pdfcraft-cli /app/bin/pdfcraft-cli\n - install -Dm755 bin/pdfcraft-nightly-launch /app/bin/pdfcraft-nightly-launch|" \
|
|
"$HERE/flatpak/$APP_ID.bundle.yml" >"$WORK/$FLATPAK_ID.yml"
|
|
else
|
|
cp "$HERE/flatpak/$APP_ID.bundle.yml" "$WORK/$FLATPAK_ID.yml"
|
|
fi
|
|
|
|
flatpak remote-add --user --if-not-exists flathub "$FLATHUB"
|
|
# --disable-rofiles-fuse: no FUSE in containers and CI runners.
|
|
flatpak-builder --user --install-deps-from=flathub --disable-rofiles-fuse --force-clean \
|
|
--default-branch="$FLATPAK_BRANCH" --repo="$WORK/repo" --state-dir="$WORK/state" "$WORK/build" "$WORK/$FLATPAK_ID.yml"
|
|
|
|
OUT="$DIST/$BASENAME.flatpak"
|
|
# --runtime-repo lets `flatpak install` fetch the freedesktop runtime from Flathub if missing.
|
|
flatpak build-bundle --runtime-repo="$FLATHUB" "$WORK/repo" "$OUT" "$FLATPAK_ID" "$FLATPAK_BRANCH"
|
|
echo "wrote $OUT"
|
|
|
|
if [[ "$OCI" = 1 ]]; then
|
|
OUT_OCI="$DIST/$BASENAME-oci"
|
|
rm -rf "$OUT_OCI"
|
|
flatpak build-bundle --oci "$WORK/repo" "$OUT_OCI" "$FLATPAK_ID" "$FLATPAK_BRANCH"
|
|
echo "wrote OCI layout to $OUT_OCI"
|
|
fi
|
|
|
|
if [[ "$TEST" = 1 ]]; then
|
|
flatpak install --user -y --noninteractive --reinstall "$OUT"
|
|
flatpak info --user "$FLATPAK_ID"
|
|
flatpak run --command=pdfcraft-cli "$FLATPAK_ID" --version
|
|
flatpak run --command=sh "$FLATPAK_ID" -c 'ls /app/share/applications /app/share/metainfo /app/share/mime/packages /app/share/icons/hicolor/*/apps /app/share/pdfcraft/models'
|
|
# Informational: printing runs lp/lpstat, which the freedesktop runtime doesn't ship (see the
|
|
# manifest's finish-args). Says so if a runtime update ever adds them.
|
|
flatpak run --command=sh "$FLATPAK_ID" -c 'command -v lp lpstat' || echo "note: no lp/lpstat in the runtime, so printing is unavailable in the Flatpak"
|
|
fi
|
|
echo "==> done"
|
|
ls -lh "$OUT"
|