Add a versioned manifest that records actual ROOT/musrfit versions, native ELF architecture, musrfit revision, and SHA-256 fingerprints independently of the GUI version. Source builds also record checkout provenance and CMake options. Require matching metadata during Linux packaging and WSL staging, reject mixed or incorrectly labelled runtimes, and support explicit recording of existing trees without inventing historical build settings. Add regression coverage and document the build-only metadata workflow.
76 lines
3.1 KiB
Bash
Executable File
76 lines
3.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Package the built ROOT + musrfit runtime tree (runtime/) as a portable
|
|
# AppImage. The resulting image is a self-contained runtime launcher:
|
|
#
|
|
# musrflow-runtime-<version>-x86_64.AppImage --install # installs to /opt/musrflow/runtime
|
|
# musrflow-runtime-<version>-x86_64.AppImage musrfit ... # runs a bundled tool
|
|
#
|
|
# The AppImage is assembled from the same tooling electron-builder uses (the
|
|
# FUSE2 runtime and mksquashfs), so run `npm run dist:appimage` (or any
|
|
# AppImage build) at least once to populate the electron-builder cache, or set
|
|
# APPIMAGE_RUNTIME_BIN and MKSQUASHFS_BIN explicitly.
|
|
set -euo pipefail
|
|
|
|
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
root="$(cd "$here/../.." && pwd)"
|
|
|
|
runtime_dir="${RUNTIME_DIR:-$root/runtime}"
|
|
out_dir="${OUT_DIR:-$root/dist}"
|
|
version="$(node -p "require('$root/package.json').version")"
|
|
arch="${ARCH:-x86_64}"
|
|
case "$arch" in
|
|
x86_64|x64) arch=x86_64 ;;
|
|
*) echo "error: runtime AppImage launcher currently supports only x86_64, not $arch" >&2; exit 1 ;;
|
|
esac
|
|
|
|
# Reject an incomplete or unloadable runtime before touching existing artifacts.
|
|
bash "$here/validate-runtime.sh" "$runtime_dir" --arch "$arch"
|
|
|
|
cache="${ELECTRON_BUILDER_CACHE:-${XDG_CACHE_HOME:-$HOME/.cache}/electron-builder}"
|
|
|
|
find_cached() {
|
|
# find_cached <override-env-name> <glob-relative-to-cache> <description>
|
|
local override="$1" pattern="$2" description="$3" value
|
|
value="${!override:-}"
|
|
if [ -n "$value" ]; then
|
|
echo "$value"
|
|
return 0
|
|
fi
|
|
value="$(ls -1d $cache/$pattern 2>/dev/null | head -n1 || true)"
|
|
if [ -z "$value" ]; then
|
|
echo "error: $description not found in $cache; run 'npm run dist:appimage' first or set $override" >&2
|
|
return 1
|
|
fi
|
|
echo "$value"
|
|
}
|
|
|
|
appimage_runtime="$(find_cached APPIMAGE_RUNTIME_BIN 'appimage-*/appimage-*/runtime-x64' 'the AppImage (FUSE2) runtime')"
|
|
mksquashfs="$(find_cached MKSQUASHFS_BIN 'appimage-*/appimage-*/linux-x64/mksquashfs' 'mksquashfs')"
|
|
|
|
stage="$(mktemp -d)"
|
|
trap 'rm -rf "$stage"' EXIT
|
|
|
|
mkdir -p "$stage/usr/lib/musrflow-runtime" "$stage/usr/share/icons/hicolor/256x256/apps"
|
|
cp -a "$runtime_dir/." "$stage/usr/lib/musrflow-runtime/"
|
|
rm -f "$stage/usr/lib/musrflow-runtime/.gitkeep"
|
|
install -m 0755 "$here/runtime-appimage/AppRun" "$stage/AppRun"
|
|
cp "$root/assets/musrflow-icon.png" "$stage/usr/share/icons/hicolor/256x256/apps/musrflow-runtime.png"
|
|
ln -s usr/share/icons/hicolor/256x256/apps/musrflow-runtime.png "$stage/musrflow-runtime.png"
|
|
ln -s musrflow-runtime.png "$stage/.DirIcon"
|
|
install -m 0644 "$here/runtime-appimage/musrflow-runtime.desktop" "$stage/musrflow-runtime.desktop"
|
|
|
|
out="$out_dir/musrflow-runtime-${version}-${arch}.AppImage"
|
|
mkdir -p "$out_dir"
|
|
rm -f "$out"
|
|
|
|
# Build the squashfs with a gap for the runtime, then overwrite that gap with
|
|
# the AppImage runtime exactly as electron-builder does.
|
|
runtime_size="$(stat -c %s "$appimage_runtime")"
|
|
"$mksquashfs" "$stage" "$out" -offset "$runtime_size" -all-root -noappend \
|
|
-no-progress -quiet -no-xattrs -no-fragments -comp gzip
|
|
dd if="$appimage_runtime" of="$out" bs=4096 conv=notrunc status=none
|
|
chmod 0755 "$out"
|
|
|
|
echo "Built $out"
|