From b81d2ea7cff415778094d21bb1a0ad6cbab0eb8d Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Mon, 9 Nov 2026 05:23:35 -0700 Subject: [PATCH] feat(packaging): Linux AppImage, deb, rpm, tar.gz and Flatpak (M8) Desktop entry, AppStream metainfo, MIME types for .anicraft/.fla/.xfl and hicolor icons in every format; riscv64 cross builds; Flatpak bundle and from-source manifests with display, GPU, sound and document folders only. --- .../linux/ai.storyteller.anicraft.desktop | 16 ++ .../ai.storyteller.anicraft.metainfo.xml.in | 74 ++++++++ .../linux/ai.storyteller.anicraft.mime.xml | 23 +++ packaging/linux/flatpak-bundle.sh | 80 ++++++++ packaging/linux/flatpak-oci.sh | 64 +++++++ .../ai.storyteller.anicraft.bundle.yml | 50 +++++ .../linux/flatpak/ai.storyteller.anicraft.yml | 71 +++++++ packaging/linux/nfpm.yaml | 87 +++++++++ packaging/linux/package.sh | 174 ++++++++++++++++++ packaging/linux/postinst.sh | 13 ++ packaging/linux/verified-download.sh | 39 ++++ 11 files changed, 691 insertions(+) create mode 100644 packaging/linux/ai.storyteller.anicraft.desktop create mode 100644 packaging/linux/ai.storyteller.anicraft.metainfo.xml.in create mode 100644 packaging/linux/ai.storyteller.anicraft.mime.xml create mode 100644 packaging/linux/flatpak-bundle.sh create mode 100644 packaging/linux/flatpak-oci.sh create mode 100644 packaging/linux/flatpak/ai.storyteller.anicraft.bundle.yml create mode 100644 packaging/linux/flatpak/ai.storyteller.anicraft.yml create mode 100644 packaging/linux/nfpm.yaml create mode 100644 packaging/linux/package.sh create mode 100644 packaging/linux/postinst.sh create mode 100644 packaging/linux/verified-download.sh diff --git a/packaging/linux/ai.storyteller.anicraft.desktop b/packaging/linux/ai.storyteller.anicraft.desktop new file mode 100644 index 00000000..677e31c2 --- /dev/null +++ b/packaging/linux/ai.storyteller.anicraft.desktop @@ -0,0 +1,16 @@ +[Desktop Entry] +Type=Application +Name=AniCraft +GenericName=Animation Studio +Comment=Draw and animate 2D vector art on a timeline +Exec=anicraft %f +TryExec=anicraft +Icon=ai.storyteller.anicraft +Terminal=false +# The native runner does not complete desktop startup-notification handshakes. +StartupNotify=false +# The window's Wayland app_id and X11 class (src/platform.rs), so docks match it to this entry. +StartupWMClass=ai.storyteller.anicraft +Categories=Graphics;2DGraphics;VectorGraphics; +Keywords=animation;animator;timeline;keyframe;tween;vector;drawing;cartoon;motion; +MimeType=application/x-anicraft;application/x-fla;application/x-xfl; diff --git a/packaging/linux/ai.storyteller.anicraft.metainfo.xml.in b/packaging/linux/ai.storyteller.anicraft.metainfo.xml.in new file mode 100644 index 00000000..f85fc88c --- /dev/null +++ b/packaging/linux/ai.storyteller.anicraft.metainfo.xml.in @@ -0,0 +1,74 @@ + + + + ai.storyteller.anicraft + CC0-1.0 + MIT OR Apache-2.0 + AniCraft + Draw and animate 2D vector art on a timeline + + ArtCraft Team + + +

+ AniCraft is an open-source, native 2D animation studio. Draw with vector tools, animate on a + layered timeline with keyframes, classic, shape and motion tweens, and export frames, GIFs, + sprite sheets, SVG, Lottie and video. +

+
    +
  • Pen, pencil, shapes, paint bucket, text, width and subselection tools for editable vector art
  • +
  • Timeline with layers, folders, masks, onion skin, easing and a motion editor
  • +
  • Symbols, a library and nested timelines
  • +
  • Opens FLA and XFL documents as untitled copies
  • +
  • Every action is a command, scriptable from a CLI, a JSON control channel and an MCP server
  • +
+
+ ai.storyteller.anicraft.desktop + ai.storyteller.anicraft + + https://getartcraft.com/apps/anicraft + https://github.com/storytold/AniCraft/issues + https://github.com/storytold/AniCraft + + Graphics + 2DGraphics + VectorGraphics + + + animation + timeline + keyframe + tween + vector + + + + The sample animation on the stage, with tweens on the timeline and the easing curve in Properties + https://raw.githubusercontent.com/storytold/AniCraft/main/docs/images/shot-1-stage.png + + + + #f2e66a + #6b6102 + + + 760 + + + keyboard + pointing + tablet + + + anicraft + anicraft-cli + application/x-anicraft + application/x-fla + application/x-xfl + + + + + +
diff --git a/packaging/linux/ai.storyteller.anicraft.mime.xml b/packaging/linux/ai.storyteller.anicraft.mime.xml new file mode 100644 index 00000000..9e626330 --- /dev/null +++ b/packaging/linux/ai.storyteller.anicraft.mime.xml @@ -0,0 +1,23 @@ + + + + + AniCraft document + + + + + + + FLA document + + + + + XFL document + + + + diff --git a/packaging/linux/flatpak-bundle.sh b/packaging/linux/flatpak-bundle.sh new file mode 100644 index 00000000..2c762bfb --- /dev/null +++ b/packaging/linux/flatpak-bundle.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash +# Repackage a AniCraft Linux tarball as a single-file Flatpak bundle: +# +# $DIST/anicraft--linux-.flatpak +# +# Usage: packaging/linux/flatpak-bundle.sh [--no-test] [TARBALL] +# +# TARBALL defaults to $DIST/anicraft--linux-.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 +# `anicraft-cli --version` is run inside the sandbox as a smoke test. +# Manifest: packaging/linux/flatpak/ai.storyteller.anicraft.bundle.yml. +set -euo pipefail +# shellcheck source=../env.sh +. "$(dirname "${BASH_SOURCE[0]}")/../env.sh" +HERE="$ROOT/packaging/linux" +APP_ID=ai.storyteller.anicraft +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="anicraft-$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 "==> AniCraft $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/anicraft" ]] || { echo "error: $TARBALL has no bin/anicraft" >&2; exit 1; } +cp "$HERE/flatpak/$APP_ID.bundle.yml" "$WORK/$APP_ID.yml" + +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=stable --repo="$WORK/repo" --state-dir="$WORK/state" "$WORK/build" "$WORK/$APP_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" "$APP_ID" stable +echo "wrote $OUT" +if [[ "$OCI" = 1 ]]; then + OUT_OCI="$DIST/$BASENAME-oci" + rm -rf "$OUT_OCI" + flatpak build-bundle --oci "$WORK/repo" "$OUT_OCI" "$APP_ID" stable + echo "wrote OCI layout to $OUT_OCI" +fi + +if [[ "$TEST" = 1 ]]; then + flatpak install --user -y --noninteractive --reinstall "$OUT" + flatpak info --user "$APP_ID" + flatpak run --command=anicraft-cli "$APP_ID" --version + flatpak run --command=sh "$APP_ID" -c 'ls /app/share/applications /app/share/metainfo /app/share/mime/packages /app/share/icons/hicolor/scalable/apps' +fi +echo "==> done" +ls -lh "$OUT" diff --git a/packaging/linux/flatpak-oci.sh b/packaging/linux/flatpak-oci.sh new file mode 100644 index 00000000..5b85fb11 --- /dev/null +++ b/packaging/linux/flatpak-oci.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash +# Build anicraft as an OCI container layout and push it to GitHub Container Registry (GHCR) +# for consumption by Flatpak OCI clients (flatpak-oci-specs). +# +# Usage: +# packaging/linux/flatpak-oci.sh [--push] [TARBALL] +# +# Environment variables: +# REGISTRY Target registry image (default: ghcr.io/storytold/anicraft) +# TAG Target image tag (default: $VERSION-$ARCH, also tags stable-$ARCH) +# GITHUB_TOKEN Token for GHCR authentication when --push is used +set -euo pipefail +# shellcheck source=../env.sh +. "$(dirname "${BASH_SOURCE[0]}")/../env.sh" +HERE="$ROOT/packaging/linux" + +PUSH=0 +TARBALL="" +while [[ $# -gt 0 ]]; do + case "$1" in + --push) PUSH=1; shift ;; + -h | --help) sed -n '2,12p' "$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="anicraft-$VERSION-linux-$ARCH" +OUT_OCI="$DIST/$BASENAME-oci" + +echo "==> Building Flatpak OCI layout for $BASENAME" +"$HERE/flatpak-bundle.sh" --oci --no-test "${TARBALL:-}" + +[[ -d "$OUT_OCI" ]] || { echo "error: $OUT_OCI layout not generated" >&2; exit 1; } + +REGISTRY="${REGISTRY:-ghcr.io/storytold/anicraft}" +TAG="${TAG:-$VERSION-$ARCH}" + +echo "==> OCI layout ready at $OUT_OCI (Target: $REGISTRY:$TAG)" + +if [[ "$PUSH" = 1 ]]; then + command -v skopeo >/dev/null || { echo "error: skopeo is required to push OCI images (apt install skopeo)" >&2; exit 1; } + + AUTH_ARGS=() + if [[ -n "${GITHUB_TOKEN:-}" ]]; then + AUTH_ARGS=(--dest-creds "${GITHUB_ACTOR:-storytold}:$GITHUB_TOKEN") + fi + + echo "==> Pushing to $REGISTRY:$TAG" + skopeo copy --format oci "${AUTH_ARGS[@]}" "oci:$OUT_OCI" "docker://$REGISTRY:$TAG" + + # Also update architecture-specific stable tag + echo "==> Pushing to $REGISTRY:stable-$ARCH" + skopeo copy --format oci "${AUTH_ARGS[@]}" "oci:$OUT_OCI" "docker://$REGISTRY:stable-$ARCH" + + echo "==> Push complete" +fi diff --git a/packaging/linux/flatpak/ai.storyteller.anicraft.bundle.yml b/packaging/linux/flatpak/ai.storyteller.anicraft.bundle.yml new file mode 100644 index 00000000..eed68ae1 --- /dev/null +++ b/packaging/linux/flatpak/ai.storyteller.anicraft.bundle.yml @@ -0,0 +1,50 @@ +# Flatpak manifest for the single-file bundle attached to every GitHub release +# (anicraft--linux-.flatpak). Build it with packaging/linux/flatpak-bundle.sh. +# +# It repackages the release's own Linux tarball (anicraft--linux-.tar.gz, built on +# Ubuntu 22.04 by package.sh) instead of compiling Rust inside flatpak-builder: no network and no +# vendored crate sources during the build, a few seconds instead of many minutes, and the same +# binaries as the AppImage/deb/rpm. The script unpacks the tarball into `stage/` next to a copy of +# this file. The binaries need glibc >= 2.35, ALSA, and load X11, Wayland, xkbcommon and Vulkan at +# runtime; the freedesktop runtime has all of them, and the GPU driver comes from its +# org.freedesktop.Platform.GL extension. +# +# ai.storyteller.anicraft.yml (same directory) is the from-source manifest for Flathub. Keep +# runtime, runtime-version, sdk and finish-args identical in both (packaging-lint checks this). +id: ai.storyteller.anicraft +runtime: org.freedesktop.Platform +runtime-version: '26.08' +sdk: org.freedesktop.Sdk +command: anicraft +finish-args: + # Display: Wayland first; X11 only when no Wayland compositor is running. + - --socket=wayland + - --socket=fallback-x11 + # X11 shared memory (MIT-SHM). Without it the X11 fallback is slow or fails. + - --share=ipc + # GPU access for wgpu (Vulkan, or GL as a fallback). + - --device=dri + # Sound during playback (cpal over ALSA, which the runtime routes to PulseAudio or PipeWire). + - --socket=pulseaudio + # Open/Save dialogs go through the file-chooser portal (rfd's xdg-portal backend) and + # drag-and-drop through the document portal, so picked files work anywhere without broad + # filesystem access. Documents, Pictures and Videos are granted so files passed by path (the + # command line, Open Recent, exports next to the document) work in the usual places. + - --filesystem=xdg-documents + - --filesystem=xdg-pictures + - --filesystem=xdg-videos + # Deliberately not granted: network (AniCraft never uses it) and home/host filesystem access. +modules: + - name: anicraft + buildsystem: simple + build-commands: + - install -Dm755 bin/anicraft /app/bin/anicraft + - install -Dm755 bin/anicraft-cli /app/bin/anicraft-cli + - install -Dm644 share/applications/ai.storyteller.anicraft.desktop /app/share/applications/ai.storyteller.anicraft.desktop + - install -Dm644 share/mime/packages/ai.storyteller.anicraft.xml /app/share/mime/packages/ai.storyteller.anicraft.xml + # Already has the release's version and date substituted by package.sh. + - install -Dm644 share/metainfo/ai.storyteller.anicraft.metainfo.xml /app/share/metainfo/ai.storyteller.anicraft.metainfo.xml + - mkdir -p /app/share/icons /app/share/doc && cp -R share/icons/hicolor /app/share/icons/ && cp -R share/doc/anicraft /app/share/doc/ + sources: + - type: dir + path: stage diff --git a/packaging/linux/flatpak/ai.storyteller.anicraft.yml b/packaging/linux/flatpak/ai.storyteller.anicraft.yml new file mode 100644 index 00000000..d99fa96a --- /dev/null +++ b/packaging/linux/flatpak/ai.storyteller.anicraft.yml @@ -0,0 +1,71 @@ +# Flatpak manifest for AniCraft, ready for a Flathub submission. +# +# Flatpak builds run offline, so the crate sources must be vendored first. From the repo root: +# +# curl -fsSLO https://raw.githubusercontent.com/flatpak/flatpak-builder-tools/master/cargo/flatpak-cargo-generator.py +# python3 flatpak-cargo-generator.py Cargo.lock -o packaging/linux/flatpak/cargo-sources.json +# flatpak-builder --user --install --force-clean build-flatpak packaging/linux/flatpak/ai.storyteller.anicraft.yml +# flatpak run ai.storyteller.anicraft +# +# For Flathub, replace the `dir` source with a `git` source pinned to a release tag and commit. +# The single-file .flatpak attached to each release comes from ai.storyteller.anicraft.bundle.yml, +# which repackages the prebuilt release binaries. Keep runtime, runtime-version, sdk and +# finish-args identical in both (packaging-lint checks this). +id: ai.storyteller.anicraft +runtime: org.freedesktop.Platform +runtime-version: '26.08' +sdk: org.freedesktop.Sdk +sdk-extensions: + - org.freedesktop.Sdk.Extension.rust-stable +command: anicraft +finish-args: + # Display: Wayland first; X11 only when no Wayland compositor is running. + - --socket=wayland + - --socket=fallback-x11 + # X11 shared memory (MIT-SHM). Without it the X11 fallback is slow or fails. + - --share=ipc + # GPU access for wgpu (Vulkan, or GL as a fallback). + - --device=dri + # Sound during playback (cpal over ALSA, which the runtime routes to PulseAudio or PipeWire). + - --socket=pulseaudio + # Open/Save dialogs go through the file-chooser portal (rfd's xdg-portal backend) and + # drag-and-drop through the document portal, so picked files work anywhere without broad + # filesystem access. Documents, Pictures and Videos are granted so files passed by path (the + # command line, Open Recent, exports next to the document) work in the usual places. + - --filesystem=xdg-documents + - --filesystem=xdg-pictures + - --filesystem=xdg-videos + # Deliberately not granted: network (AniCraft never uses it) and home/host filesystem access. +build-options: + append-path: /usr/lib/sdk/rust-stable/bin +modules: + - name: anicraft + buildsystem: simple + build-options: + env: + CARGO_HOME: /run/build/anicraft/cargo + CARGO_NET_OFFLINE: 'true' + build-commands: + - cargo --offline build --release --locked -p anicraft -p anicraft-cli + - install -Dm755 target/release/anicraft /app/bin/anicraft + - install -Dm755 target/release/anicraft-cli /app/bin/anicraft-cli + - install -Dm644 -t /app/share/doc/anicraft NOTICE ATTRIBUTION.md LICENSE-MIT LICENSE-APACHE + - install -Dm644 packaging/linux/ai.storyteller.anicraft.desktop /app/share/applications/ai.storyteller.anicraft.desktop + - install -Dm644 packaging/linux/ai.storyteller.anicraft.mime.xml /app/share/mime/packages/ai.storyteller.anicraft.xml + - mkdir -p /app/share/icons && cp -R assets/app-icon/hicolor /app/share/icons/ + - >- + version=$(awk '/^\[/{p=($0=="[workspace.package]");next} p&&$1=="version"{gsub(/[" ]/,"",$3);print $3;exit}' Cargo.toml); + install -d /app/share/metainfo; + sed -e "s/@VERSION@/$version/" -e "s/@DATE@/$(date -u +%Y-%m-%d)/" + packaging/linux/ai.storyteller.anicraft.metainfo.xml.in > /app/share/metainfo/ai.storyteller.anicraft.metainfo.xml + sources: + - type: dir + path: ../../.. + skip: + - target + - dist + - shots + - build-flatpak + - .flatpak-builder + - .worktrees + - cargo-sources.json diff --git a/packaging/linux/nfpm.yaml b/packaging/linux/nfpm.yaml new file mode 100644 index 00000000..27afa595 --- /dev/null +++ b/packaging/linux/nfpm.yaml @@ -0,0 +1,87 @@ +# .deb and .rpm packages (nfpm: https://nfpm.goreleaser.com). Run by package.sh, which stages +# the file tree, substitutes its path for ${STAGE} (nfpm doesn't expand env vars in `src`) and the +# glibc the binaries need for @GLIBC_FLOOR@, and exports VERSION and NFPM_ARCH. +# +# nfpm package -f packaging/linux/nfpm.yaml -p deb -t dist/release/ +name: anicraft +arch: ${NFPM_ARCH} +platform: linux +version: ${VERSION} +# semver: 0.2.0-rc.1 becomes 0.2.0~rc.1 in deb/rpm, so pre-releases sort before the release. +version_schema: semver +release: 1 +section: graphics +priority: optional +maintainer: ${ANICRAFT_MAINTAINER} +vendor: ArtCraft Team +homepage: https://getartcraft.com/apps/anicraft +license: MIT OR Apache-2.0 +description: |- + Open-source, native 2D animation studio. + Vector drawing tools, a layered timeline with keyframes and classic, shape + and motion tweens, symbols and a library; opens FLA and XFL documents; + exports PNG, GIF, SVG, sprite sheets, Lottie and (with ffmpeg) video. + Includes anicraft-cli, a headless renderer, command runner and MCP server. + +# The binaries link glibc, libgcc_s and ALSA (libasound, for sound through cpal; PulseAudio and +# PipeWire are reached through their ALSA plugins). Windowing (X11/Wayland, xkbcommon) and the +# GPU (Vulkan, EGL/GL) are loaded at runtime with dlopen, so they aren't ELF NEEDED entries and +# the package tools can't find them: they are listed here. winit 0.30 loads, for X11: libX11, +# libX11-xcb, libxcb, libXcursor, libXi, libxkbcommon and libxkbcommon-x11; for Wayland: +# libwayland-client and libxkbcommon. wgpu needs libvulkan, and the OpenGL fallback libEGL. +overrides: + deb: + depends: + - libc6 (>= @GLIBC_FLOOR@) + - libgcc-s1 + - libasound2 | libasound2t64 + - libxkbcommon0 + - libxkbcommon-x11-0 + - libwayland-client0 + - libx11-6 + - libx11-xcb1 + - libxcb1 + - libxcursor1 + - libxi6 + - libvulkan1 | libegl1 + recommends: + - mesa-vulkan-drivers + - libegl-mesa0 + - xdg-desktop-portal + - pipewire-alsa | pulseaudio + suggests: + # Video export streams frames to the user's own ffmpeg (no encoder is bundled). + - ffmpeg + rpm: + # Soname provides rather than package names, so the same requirements resolve on Fedora/RHEL + # (libxkbcommon-x11, libX11-xcb, ...) and openSUSE (libxkbcommon-x11-0, libX11-xcb1, ...). + depends: + - libasound.so.2()(64bit) + - libxkbcommon.so.0()(64bit) + - libxkbcommon-x11.so.0()(64bit) + - libwayland-client.so.0()(64bit) + - libX11.so.6()(64bit) + - libX11-xcb.so.1()(64bit) + - libxcb.so.1()(64bit) + - libXcursor.so.1()(64bit) + - libXi.so.6()(64bit) + - (libvulkan.so.1()(64bit) or libEGL.so.1()(64bit)) + recommends: + - mesa-vulkan-drivers + - xdg-desktop-portal + - (pipewire-alsa or alsa-plugins-pulseaudio) + +contents: + - src: ${STAGE}/usr/bin/anicraft + dst: /usr/bin/anicraft + file_info: { mode: 0755 } + - src: ${STAGE}/usr/bin/anicraft-cli + dst: /usr/bin/anicraft-cli + file_info: { mode: 0755 } + - src: ${STAGE}/usr/share/ + dst: /usr/share/ + type: tree + +scripts: + postinstall: packaging/linux/postinst.sh + postremove: packaging/linux/postinst.sh diff --git a/packaging/linux/package.sh b/packaging/linux/package.sh new file mode 100644 index 00000000..7505a952 --- /dev/null +++ b/packaging/linux/package.sh @@ -0,0 +1,174 @@ +#!/usr/bin/env bash +# Build and package AniCraft for Linux ( is x86_64, aarch64 or riscv64): +# +# $DIST/anicraft--linux-.AppImage any distro with glibc >= the build host's +# $DIST/anicraft--linux-.AppImage.zsync delta updates (needs zsyncmake) +# $DIST/anicraft--linux-.deb Debian, Ubuntu, Mint, Pop!_OS, ... +# $DIST/anicraft--linux-.rpm Fedora, openSUSE, RHEL, ... +# $DIST/anicraft--linux-.tar.gz plain FHS-style tree (bin/, share/) +# +# Every format installs the desktop entry, the AppStream metainfo, the hicolor icons and the +# MIME types (.anicraft is AniCraft's; .fla and .xfl open as an untitled import). +# +# Usage: packaging/linux/package.sh [--skip-build] [--formats "appimage deb rpm tar"] +# +# Needs: cargo; nfpm for deb/rpm (https://nfpm.goreleaser.com). AppImage tooling is downloaded +# at verified pins into $CARGO_TARGET_DIR. Build on an old distro (CI: Ubuntu 22.04, glibc 2.35) +# so the binaries run on newer ones. Optional: desktop-file-validate, appstreamcli, zsyncmake. +# +# Cross builds (CI: riscv64, deb/rpm/tar only): set CROSS_ARCH (riscv64), CROSS_TARGET (the Rust +# triple), CROSS_COMPILE (binutils prefix, for strip) and optionally EMULATOR (e.g. qemu-riscv64) +# to smoke-test the CLI. GLIBC_FLOOR (default 2.35) is the glibc the deb declares. +set -euo pipefail +# shellcheck source=../env.sh +. "$(dirname "${BASH_SOURCE[0]}")/../env.sh" +HERE="$ROOT/packaging/linux" +# shellcheck source=verified-download.sh +. "$HERE/verified-download.sh" + +SKIP_BUILD=0 +FORMATS="appimage deb rpm tar" +while [[ $# -gt 0 ]]; do + case "$1" in + --skip-build) SKIP_BUILD=1; shift ;; + --formats) FORMATS="$2"; shift 2 ;; + -h | --help) sed -n '2,21p' "$0"; exit 0 ;; + *) echo "unknown argument: $1" >&2; exit 2 ;; + esac +done + +ARCH="${CROSS_ARCH:-$(uname -m)}" +case "$ARCH" in + riscv64) DEB_ARCH=riscv64 ;; + x86_64) DEB_ARCH=amd64 ;; + aarch64 | arm64) ARCH=aarch64; DEB_ARCH=arm64 ;; + *) echo "unsupported architecture $ARCH" >&2; exit 2 ;; +esac +export ANICRAFT_MAINTAINER="${ANICRAFT_MAINTAINER:-AniCraft maintainers }" +BASENAME="anicraft-$VERSION-linux-$ARCH" + +echo "==> AniCraft $VERSION for Linux $ARCH ($FORMATS)" + +if [[ "$SKIP_BUILD" = 0 ]]; then + (cd "$ROOT" && cargo build --release --locked -p anicraft -p anicraft-cli --bins ${CROSS_TARGET:+--target "$CROSS_TARGET"}) +fi +BIN="$CARGO_TARGET_DIR/${CROSS_TARGET:+$CROSS_TARGET/}release" +WORK="$CARGO_TARGET_DIR/linux-package" +STAGE="$WORK/root" +rm -rf "$WORK" + +# ---- stage an FHS tree (shared by every format) ------------------------------------------------- +install -Dm755 "$BIN/anicraft" "$STAGE/usr/bin/anicraft" +install -Dm755 "$BIN/anicraft-cli" "$STAGE/usr/bin/anicraft-cli" +"${CROSS_COMPILE:-}strip" "$STAGE/usr/bin/anicraft" "$STAGE/usr/bin/anicraft-cli" 2>/dev/null || true +install -Dm644 "$HERE/$APP_ID.desktop" "$STAGE/usr/share/applications/$APP_ID.desktop" +install -Dm644 "$HERE/$APP_ID.mime.xml" "$STAGE/usr/share/mime/packages/$APP_ID.xml" +mkdir -p "$STAGE/usr/share/metainfo" +sed -e "s/@VERSION@/$VERSION/g" -e "s/@DATE@/$ANICRAFT_BUILD_DATE/g" \ + "$HERE/$APP_ID.metainfo.xml.in" >"$STAGE/usr/share/metainfo/$APP_ID.metainfo.xml" +mkdir -p "$STAGE/usr/share/icons" +cp -R "$ROOT/assets/app-icon/hicolor" "$STAGE/usr/share/icons/" +mkdir -p "$STAGE/usr/share/doc/anicraft" +copy_docs "$STAGE/usr/share/doc/anicraft" + +if command -v desktop-file-validate >/dev/null; then + desktop-file-validate "$STAGE/usr/share/applications/$APP_ID.desktop" +fi +if command -v appstreamcli >/dev/null; then + appstreamcli validate --no-net --explain "$STAGE/usr/share/metainfo/$APP_ID.metainfo.xml" +fi + +has() { case " $FORMATS " in *" $1 "*) return 0 ;; *) return 1 ;; esac; } + +# ---- .tar.gz ------------------------------------------------------------------------------------ +# Unpacks to anicraft--linux-/{bin,share}; the Flatpak and Arch packages are made +# from this tarball by the shared release workflow. +if has tar; then + mkdir -p "$WORK/tar" + cp -R "$STAGE/usr" "$WORK/tar/$BASENAME" + tar -C "$WORK/tar" -czf "$DIST/$BASENAME.tar.gz" "$BASENAME" + echo "wrote $DIST/$BASENAME.tar.gz" +fi + +# ---- .deb / .rpm -------------------------------------------------------------------------------- +if has deb || has rpm; then + command -v nfpm >/dev/null || { echo "error: nfpm not found (https://nfpm.goreleaser.com/install/)" >&2; exit 1; } + export VERSION + export NFPM_ARCH="$DEB_ARCH" + # nfpm expands env vars in fields like `version` and `arch`, but not in `contents[].src`. + sed -e "s|\${STAGE}|$STAGE|g" -e "s|@GLIBC_FLOOR@|${GLIBC_FLOOR:-2.35}|g" "$HERE/nfpm.yaml" >"$WORK/nfpm.yaml" + for fmt in deb rpm; do + if has "$fmt"; then (cd "$ROOT" && nfpm package -f "$WORK/nfpm.yaml" -p "$fmt" -t "$DIST/$BASENAME.$fmt"); fi + done +fi + +# ---- AppImage ----------------------------------------------------------------------------------- +if has appimage; then + APPDIR="$WORK/AniCraft.AppDir" + cp -R "$STAGE" "$APPDIR" + ln -s usr/bin/anicraft "$APPDIR/AppRun" + cp "$HERE/$APP_ID.desktop" "$APPDIR/$APP_ID.desktop" + cp "$ROOT/assets/app-icon/hicolor/256x256/apps/$APP_ID.png" "$APPDIR/$APP_ID.png" + ln -s "$APP_ID.png" "$APPDIR/.DirIcon" + + # Digests from the official GitHub release asset metadata (the same pins as the other Craft apps): + # https://github.com/AppImage/appimagetool/releases/tag/1.9.1 + # https://github.com/AppImage/type2-runtime/releases/tag/20251108 + # Keep both pins together: appimagetool otherwise downloads the mutable latest type2 runtime. + TOOL_VERSION=1.9.1 + RUNTIME_VERSION=20251108 + case "$ARCH" in + x86_64) + TOOL_SHA256=ed4ce84f0d9caff66f50bcca6ff6f35aae54ce8135408b3fa33abfc3cb384eb0 + RUNTIME_SHA256=2fca8b443c92510f1483a883f60061ad09b46b978b2631c807cd873a47ec260d + ;; + aarch64) + TOOL_SHA256=f0837e7448a0c1e4e650a93bb3e85802546e60654ef287576f46c71c126a9158 + RUNTIME_SHA256=00cbdfcf917cc6c0ff6d3347d59e0ca1f7f45a6df1a428a0d6d8a78664d87444 + ;; + *) echo "no pinned AppImage tooling for $ARCH; leave appimage out of --formats" >&2; exit 2 ;; + esac + mkdir -p "$CARGO_TARGET_DIR" + TOOL="${APPIMAGETOOL:-$CARGO_TARGET_DIR/appimagetool-$TOOL_VERSION-$ARCH.AppImage}" + if [[ -n "${APPIMAGETOOL:-}" ]]; then + verify_appimagetool_override "$TOOL" "$TOOL_SHA256" "$TOOL_VERSION" "$ARCH" + else + download_verified \ + "https://github.com/AppImage/appimagetool/releases/download/$TOOL_VERSION/appimagetool-$ARCH.AppImage" \ + "$TOOL" "$TOOL_SHA256" true + fi + RUNTIME="$CARGO_TARGET_DIR/type2-runtime-$RUNTIME_VERSION-$ARCH" + download_verified \ + "https://github.com/AppImage/type2-runtime/releases/download/$RUNTIME_VERSION/runtime-$ARCH" \ + "$RUNTIME" "$RUNTIME_SHA256" + # Absolute, because appimagetool runs in $DIST below. + OUT="$(cd "$DIST" && pwd)/$BASENAME.AppImage" + APPDIR="$(cd "$APPDIR" && pwd)" + TOOL="$(cd "$(dirname "$TOOL")" && pwd)/$(basename "$TOOL")" + RUNTIME="$(cd "$(dirname "$RUNTIME")" && pwd)/$(basename "$RUNTIME")" + # A .zsync left by an earlier run would hide a missing zsyncmake and describe another file. + rm -f "$OUT.zsync" + # Update information: AppImageUpdate and the like read it from the file and fetch only the + # blocks that changed in a newer release, through the .zsync published next to each AppImage. + # A fork's builds point at its own releases through GITHUB_REPOSITORY. + REPO="${GITHUB_REPOSITORY:-storytold/AniCraft}" + UPDATE_INFO="gh-releases-zsync|${REPO%%/*}|${REPO#*/}|latest|anicraft-*-linux-$ARCH.AppImage.zsync" + # Extract-and-run: works without FUSE (containers, CI). The output embeds the static runtime, + # so users don't need libfuse2 either. + (cd "$DIST" && ARCH="$ARCH" APPIMAGE_EXTRACT_AND_RUN=1 "$TOOL" --no-appstream \ + --runtime-file "$RUNTIME" -u "$UPDATE_INFO" "$APPDIR" "$OUT") + echo "wrote $OUT" + if [[ -s "$OUT.zsync" ]]; then + echo "wrote $OUT.zsync" + else + warn "zsyncmake not found, so $OUT.zsync was not written; AppImage delta updates need it" + fi +fi + +if [[ -z "${CROSS_TARGET:-}" ]]; then + "$STAGE/usr/bin/anicraft-cli" --version +elif [[ -n "${EMULATOR:-}" ]]; then + "$EMULATOR" "$STAGE/usr/bin/anicraft-cli" --version +fi +echo "==> done" +ls -lh "$DIST" diff --git a/packaging/linux/postinst.sh b/packaging/linux/postinst.sh new file mode 100644 index 00000000..775e4df9 --- /dev/null +++ b/packaging/linux/postinst.sh @@ -0,0 +1,13 @@ +#!/bin/sh +# deb/rpm post-install and post-remove: refresh the desktop, MIME and icon caches. +# Every tool is optional; missing ones are skipped. +if command -v update-desktop-database >/dev/null 2>&1; then + update-desktop-database -q /usr/share/applications || true +fi +if command -v update-mime-database >/dev/null 2>&1; then + update-mime-database /usr/share/mime || true +fi +if command -v gtk-update-icon-cache >/dev/null 2>&1; then + gtk-update-icon-cache -q -t -f /usr/share/icons/hicolor || true +fi +exit 0 diff --git a/packaging/linux/verified-download.sh b/packaging/linux/verified-download.sh new file mode 100644 index 00000000..ce6eb1cd --- /dev/null +++ b/packaging/linux/verified-download.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# Source after packaging/env.sh, which supplies sha256(). Keep the verified cache usable when +# an official asset was pre-seeded by a tool that created it without an execute bit. + +download_verified() { + local url="$1" dest="$2" expected="$3" executable="${4:-false}" tmp + if [[ -f "$dest" ]] && [[ "$(sha256 "$dest")" = "$expected" ]]; then + if [[ "$executable" = true ]] && [[ ! -x "$dest" ]] && ! chmod 755 "$dest"; then + echo "error: verified asset is not executable and cannot be chmod'd: $dest" >&2 + return 1 + fi + return 0 + fi + tmp="$(mktemp "$dest.XXXXXX")" + if ! curl -fsSL -o "$tmp" "$url"; then rm -f "$tmp"; return 1; fi + if [[ "$(sha256 "$tmp")" != "$expected" ]]; then + echo "error: SHA-256 mismatch for $url" >&2 + rm -f "$tmp" + return 1 + fi + if [[ "$executable" = true ]]; then + if ! chmod 755 "$tmp"; then rm -f "$tmp"; return 1; fi + else + if ! chmod 644 "$tmp"; then rm -f "$tmp"; return 1; fi + fi + if ! mv -f "$tmp" "$dest"; then rm -f "$tmp"; return 1; fi +} + +verify_appimagetool_override() { + local tool="$1" expected="$2" version="$3" arch="$4" + if [[ ! -f "$tool" ]] || [[ "$(sha256 "$tool")" != "$expected" ]]; then + echo "error: APPIMAGETOOL must be the verified $version $arch release asset" >&2 + return 1 + fi + if [[ ! -x "$tool" ]]; then + echo "error: APPIMAGETOOL must be executable (chmod +x $tool)" >&2 + return 1 + fi +}