build-linux-appimage.sh
scripts/build-linux-appimage.sh
1#!/usr/bin/env bash2# Wraps the jpackage app image (":composeApp:createReleaseDistributable") into a3# standalone AppImage. The app image already carries its own jlink runtime, so the4# AppDir only needs the AppImage entry points: AppRun, a .desktop file and an icon.5set -euo pipefail67if [[ $# != 1 ]]; then8 echo "Usage: bash scripts/build-linux-appimage.sh out.AppImage" >&29 exit 210fi1112out=$113repo_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)14app_image="$repo_root/composeApp/build/compose/binaries/main-release/app/Yokan"15icon="$repo_root/composeApp/src/androidMain/res/mipmap-anydpi/ic_launcher.png"1617[[ -x "$app_image/bin/Yokan" ]] || {18 echo "Run ./gradlew :composeApp:createReleaseDistributable first; missing $app_image/bin/Yokan" >&219 exit 120}21[[ -f "$icon" ]] || { echo "Icon does not exist: $icon" >&2; exit 1; }2223arch=$(uname -m)24case "$arch" in25 x86_64 | aarch64) ;;26 *) echo "Unsupported AppImage architecture: $arch" >&2; exit 1 ;;27esac2829work=$(mktemp -d)30trap 'rm -rf "$work"' EXIT31appdir="$work/Yokan.AppDir"3233mkdir -p "$appdir/usr"34cp -a "$app_image/." "$appdir/usr/"35cp "$icon" "$appdir/yokan.png"3637# appimagetool requires exactly one .desktop entry in the AppDir root, and its Icon38# key must name an image file sitting next to it (extension omitted).39cat > "$appdir/yokan.desktop" <<'DESKTOP'40[Desktop Entry]41Type=Application42Name=Yokan43Comment=Manga, anime and novel library44Exec=Yokan45Icon=yokan46Terminal=false47Categories=AudioVideo;Graphics;48DESKTOP4950cat > "$appdir/AppRun" <<'APPRUN'51#!/bin/sh52here=$(dirname "$(readlink -f "$0")")53exec "$here/usr/bin/Yokan" "$@"54APPRUN55chmod +x "$appdir/AppRun"5657appimagetool=${APPIMAGETOOL:-}58if [[ -z "$appimagetool" ]]; then59 appimagetool="$work/appimagetool"60 url="https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-$arch.AppImage"61 curl -fsSL "$url" -o "$appimagetool"62 chmod +x "$appimagetool"63fi6465mkdir -p "$(dirname "$out")"66# --appimage-extract-and-run: GitHub runners have no FUSE, so the tool cannot mount itself.67ARCH="$arch" "$appimagetool" --appimage-extract-and-run "$appdir" "$out"68