diff --git a/packaging/check-app-specific.sh b/packaging/check-app-specific.sh index b8673c394..f2a1c912a 100644 --- a/packaging/check-app-specific.sh +++ b/packaging/check-app-specific.sh @@ -19,6 +19,7 @@ bash packaging/linux/nightly-arch-tar-test.sh # Every Nightly shell script must parse: a quoting slip breaks bash -n, and nothing else would # catch it until a runner started the script for real. for script in packaging/nightly-common.sh packaging/linux/nightly.sh packaging/linux/nightly-launch.sh \ + packaging/linux/nightly-package-launch.sh \ packaging/linux/nightly-launch-test.sh \ packaging/linux/nightly-arch-tar.sh packaging/macos/nightly-lib.sh packaging/macos/nightly.sh \ packaging/macos/nightly-sign.sh packaging/macos/nightly-verify.sh; do diff --git a/packaging/linux/nightly-arch-tar.sh b/packaging/linux/nightly-arch-tar.sh index eb9074b0a..695eb19fd 100755 --- a/packaging/linux/nightly-arch-tar.sh +++ b/packaging/linux/nightly-arch-tar.sh @@ -14,7 +14,7 @@ cp -R "$source_tree" "$stage" mkdir "$stage/bin/.figcraft-nightly" mv "$stage/bin/figcraft" "$stage/bin/.figcraft-nightly/figcraft" awk -v real='"$(dirname "$0")/.figcraft-nightly/figcraft"' '{ gsub(/@REAL_BIN@/, real); print }' \ - "$here/nightly-launch.sh" >"$stage/bin/figcraft" + "$here/nightly-package-launch.sh" >"$stage/bin/figcraft" chmod 755 "$stage/bin/figcraft" tar -C "$work" -czf "$destination/$basename.tar.gz" "$basename" echo "wrote $destination/$basename.tar.gz" diff --git a/packaging/linux/nightly-launch-test.sh b/packaging/linux/nightly-launch-test.sh index c7c127a3c..1bff40844 100755 --- a/packaging/linux/nightly-launch-test.sh +++ b/packaging/linux/nightly-launch-test.sh @@ -1,8 +1,15 @@ #!/usr/bin/env bash -# The nightly launcher (packaging/linux/nightly-launch.sh) in each form the formats install it: -# beside the GUI as figcraft-bin in a tarball, at /usr/lib in a package, inside an AppImage, and the -# Launcher's own protocol passed through. Runs in a second with a recording stub; it builds nothing -# and opens no window. +# Both nightly launchers, in each form the formats install them. +# +# The plain nightly tar's `figcraft` is the canonical shared template +# (packaging/linux/nightly-launch.sh, rendered from craft-common-actions's +# scripts/nightly-launcher.sh.in): it starts `figcraft-bin` beside itself on the nightly-v1 profile +# under the Nightly package identity and answers a version query with one plain `--version`. +# +# The distro launchers (`packaging/linux/nightly-package-launch.sh`, with @REAL_BIN@ substituted per +# format) keep their own profile folder and the stable-XDG export the GUI's fence reads: beside the +# GUI in a distro tree, at /usr/lib in a package, and inside an AppImage. Runs in a second with a +# recording stub; it builds nothing and opens no window. set -euo pipefail HERE="$(cd "$(dirname "$0")" && pwd)" @@ -18,27 +25,15 @@ printf '<%s>\n' "$@" RECORDER chmod 755 "$1" } -install_launcher() { - awk -v real="$2" '{ gsub(/@REAL_BIN@/, real); print }' "$HERE/nightly-launch.sh" >"$1" +install_package_launcher() { + awk -v real="$2" '{ gsub(/@REAL_BIN@/, real); print }' "$HERE/nightly-package-launch.sh" >"$1" chmod 755 "$1" } -# The tarball's standard layout: `figcraft` is the launcher and the GUI beside it is `figcraft-bin`. -recorder "$work/bin/figcraft-bin" -# shellcheck disable=SC2016 # $(dirname "$0") stays literal in the launcher: it resolves at run time -install_launcher "$work/bin/figcraft" '"$(dirname "$0")/figcraft-bin"' -# deb/rpm: the wrapper at /usr/bin, the GUI under /usr/lib. The absolute path cannot resolve in a -# test, so this form is checked by its text (and by the packaging tests that stage a package). -install_launcher "$work/deb/figcraft-nightly" '/usr/lib/figcraft-nightly/figcraft' -grep -Fxq 'real_bin=/usr/lib/figcraft-nightly/figcraft' "$work/deb/figcraft-nightly" \ - || { echo "the package wrapper does not start the packaged GUI" >&2; exit 1; } -# AppImage: AppRun runs the launcher, which starts the GUI in the AppDir's usr/bin. -mkdir -p "$work/app/usr/bin" -recorder "$work/app/usr/bin/figcraft" -install_launcher "$work/app/figcraft-nightly" "\"$work/app/usr/bin/figcraft\"" - export HOME="$work/home with space" unset XDG_CONFIG_HOME XDG_DATA_HOME +identity=ai.storyteller.figcraft.nightly +tar_profile="$HOME/.local/share/$identity" profile="$HOME/.local/share/figcraft-nightly/profile" check() { @@ -49,7 +44,54 @@ check() { [[ "$actual" == "$want" ]] || { printf '%s %s: unexpected launch\nwant:\n%s\ngot:\n%s\n' "${launcher#"$work"/}" "$*" "$want" "$actual" >&2; exit 1; } } -for launcher in "$work/bin/figcraft" "$work/app/figcraft-nightly"; do +# ---- the plain nightly tar: the canonical template, the GUI beside it ---- +recorder "$work/bin/figcraft-bin" +install -m755 "$HERE/nightly-launch.sh" "$work/bin/figcraft" +tar="$work/bin/figcraft" +check "$tar" "$(printf 'CONFIG=\nDATA=\n<--launch-profile>\n\n<--profile-root>\n<%s>\n<-->\n\n<--other-name.figcraft>\n' \ + "$tar_profile")" 'design with spaces.figcraft' '--other-name.figcraft' +check "$tar" "$(printf 'CONFIG=\nDATA=\n<--launch-profile>\n\n<--profile-root>\n<%s>\n<-->\n' "$tar_profile")" +# Both version spellings reach the GUI as one plain `--version`, and no launch creates the profile. +for flag in --version -V; do + check "$tar" "$(printf 'CONFIG=\nDATA=\n<--launch-profile>\n\n<--profile-root>\n<%s>\n<--version>\n' "$tar_profile")" "$flag" +done +# The ArtCraft Launcher starts the entry point with its own profile pair; the template hands that +# line to the GUI unchanged and keeps no second pair of its own. +check "$tar" "$(printf 'CONFIG=\nDATA=\n<--launch-profile>\n\n<--profile-root>\n<%s>\n<-->\n\n' \ + "$work/launcher profile")" --launch-profile nightly-v1 --profile-root "$work/launcher profile" -- chosen.figcraft +# Anything else is wrapped in the template's own root, including a profile line that does not open +# the arguments. +check "$tar" "$(printf 'CONFIG=\nDATA=\n<--launch-profile>\n\n<--profile-root>\n<%s>\n<-->\n<--profile-root>\n<%s>\n<-->\n' \ + "$tar_profile" "$work/launcher profile")" --profile-root "$work/launcher profile" -- +[[ ! -e "$tar_profile" ]] || { echo "a version or launch created the tar profile" >&2; exit 1; } +# XDG_DATA_HOME decides the root when it is set. +XDG_DATA_HOME="$work/xdg data" check "$tar" "$(printf 'CONFIG=\nDATA=%s\n<--launch-profile>\n\n<--profile-root>\n<%s>\n<-->\n<%s>\n' \ + "$work/xdg data" "$work/xdg data/$identity" 'a.figcraft')" 'a.figcraft' +# The template starts the GUI beside itself or nothing. +mv "$work/bin/figcraft-bin" "$work/moved-aside" +if "$tar" 'a.figcraft' >/dev/null 2>&1; then + echo "the tar launcher started without its GUI beside it" >&2 + exit 1 +fi +mv "$work/moved-aside" "$work/bin/figcraft-bin" + +# ---- the distro formats: the package launcher, their own profile folder ---- +# deb/rpm: the wrapper at /usr/bin, the GUI under /usr/lib. The absolute path cannot resolve in a +# test, so this form is checked by its text (and by the packaging tests that stage a package). +install_package_launcher "$work/deb/figcraft-nightly" '/usr/lib/figcraft-nightly/figcraft' +grep -Fxq 'real_bin=/usr/lib/figcraft-nightly/figcraft' "$work/deb/figcraft-nightly" \ + || { echo "the package wrapper does not start the packaged GUI" >&2; exit 1; } +# AppImage: the nightly entry runs the launcher, which starts the GUI in the AppDir's usr/bin. +mkdir -p "$work/app/usr/bin" +recorder "$work/app/usr/bin/figcraft" +install_package_launcher "$work/app/figcraft-nightly" "\"$work/app/usr/bin/figcraft\"" +# A distro tree: bin/figcraft-nightly beside bin/figcraft-bin. +mkdir -p "$work/tree/bin" +recorder "$work/tree/bin/figcraft-bin" +# shellcheck disable=SC2016 # $(dirname "$0") stays literal in the launcher: it resolves at run time +install_package_launcher "$work/tree/bin/figcraft-nightly" '"$(dirname "$0")/figcraft-bin"' + +for launcher in "$work/tree/bin/figcraft-nightly" "$work/app/figcraft-nightly"; do # A plain launch starts the nightly profile and passes the files after the delimiter. check "$launcher" "$(printf 'CONFIG=%s\nDATA=%s\n<--launch-profile>\n\n<--profile-root>\n<%s>\n<-->\n\n<--other-name.figcraft>\n' \ "$HOME/.config/figcraft-nightly" "$HOME/.local/share/figcraft-nightly" "$profile")" \ @@ -72,16 +114,17 @@ for launcher in "$work/bin/figcraft" "$work/app/figcraft-nightly"; do [[ ! -e "$profile" ]] || { echo "${launcher#"$work"/}: a version or Launcher launch created the profile" >&2; exit 1; } done -# The wrapper hands the GUI the XDG bases it overrode, so the stable folders under them stay fenced. +# The distro wrapper hands the GUI the XDG bases it overrode, so the stable folders under them stay +# fenced. The tar's canonical template cannot: it exports nothing (see the nightly release notes). stable_recorder="$work/bin/stable-bases" cat >"$stable_recorder" <<'RECORDER' #!/bin/sh printf 'STABLE_CONFIG=%s\nSTABLE_DATA=%s\n' "${FIGCRAFT_STABLE_XDG_CONFIG_HOME:-}" "${FIGCRAFT_STABLE_XDG_DATA_HOME:-}" RECORDER chmod 755 "$stable_recorder" -install_launcher "$work/bin/stable-launch" "\"$stable_recorder\"" +install_package_launcher "$work/bin/stable-launch" "\"$stable_recorder\"" check "$work/bin/stable-launch" "$(printf 'STABLE_CONFIG=%s\nSTABLE_DATA=%s\n' "$HOME/.config" "$HOME/.local/share")" XDG_CONFIG_HOME="$work/xdg config" XDG_DATA_HOME="$work/xdg data" \ check "$work/bin/stable-launch" "$(printf 'STABLE_CONFIG=%s\nSTABLE_DATA=%s\n' "$work/xdg config" "$work/xdg data")" -echo "PASS: the nightly launcher starts the nightly-v1 profile in every form and passes a supplied one through" +echo "PASS: the tar's template launcher and the distro launcher start the nightly profile in every form" diff --git a/packaging/linux/nightly-launch.sh b/packaging/linux/nightly-launch.sh index 0008494c2..686d23a99 100755 --- a/packaging/linux/nightly-launch.sh +++ b/packaging/linux/nightly-launch.sh @@ -1,35 +1,16 @@ #!/bin/sh -# FigCraft Nightly launch wrapper, shared by every nightly Linux format (the flat .tar.gz, the Arch -# handoff, the deb/rpm and the AppImage entry). It starts the GUI on the Launcher's nightly-v1 -# profile under a per-channel directory, so a nightly install never reads or writes the stable -# app's settings, recovery copies, plugins, font store or session state. -# -# The GUI binary this starts is substituted where the script is installed: beside the script as -# figcraft-bin in a tarball, $APPDIR/usr/bin/figcraft in an AppImage, /usr/lib/figcraft-nightly/… in -# a deb/rpm, and bin/.figcraft-nightly/figcraft in the Arch handoff. -# -# The Launcher speaks this same protocol (`--launch-profile nightly-v1 --profile-root --`), -# so its command line passes straight through rather than being wrapped in a second pair. A bare -# `--version` or `-V` goes straight to the binary too: the answer must be the plain version line, -# and a version query never creates the profile. Everything else starts the nightly profile. +# Nightly launcher generated by craft-common-actions scripts/nightly-launcher.sh.in. Do not edit: +# the shared nightly producer accepts this file only byte for byte as rendered for the app. set -eu -real_bin=@REAL_BIN@ -case "${1:-}" in - --launch-profile | --profile-root | --version | -V) exec "$real_bin" "$@" ;; +dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P) +readonly dir +target="$dir/figcraft-bin" +readonly target +profile_root="${XDG_DATA_HOME:-$HOME/.local/share}/ai.storyteller.figcraft.nightly" +readonly profile_root +case "${1-}" in + # The ArtCraft Launcher passes its own profile and per-install root; the app validates the pair. + --launch-profile) exec "$target" "$@" ;; + --version | -V) exec "$target" --launch-profile nightly-v1 --profile-root "$profile_root" --version ;; esac -config_base="${XDG_CONFIG_HOME:-${HOME:?HOME is required}/.config}" -data_base="${XDG_DATA_HOME:-${HOME:?HOME is required}/.local/share}" -# The bases in effect before the override below: the GUI's profile fence still refuses the stable -# FigCraft folders under them (profile_root.rs reads FIGCRAFT_STABLE_). -export FIGCRAFT_STABLE_XDG_CONFIG_HOME="$config_base" -export FIGCRAFT_STABLE_XDG_DATA_HOME="$data_base" -# Belt and braces for anything that still asks the process environment for a folder. -export XDG_CONFIG_HOME="$config_base/figcraft-nightly" -export XDG_DATA_HOME="$data_base/figcraft-nightly" -# One profile per channel, chosen here only: a caller cannot point the Nightly at another folder, -# so the fence the GUI applies can never be handed the stable app's config or data directory. -profile="$XDG_DATA_HOME/profile" -# A `--` the caller wrote already separates the files from the options: drop it, so the app is -# handed exactly one and no file name arrives as `--`. -if [ "${1:-}" = "--" ]; then shift; fi -exec "$real_bin" --launch-profile nightly-v1 --profile-root "$profile" -- "$@" +exec "$target" --launch-profile nightly-v1 --profile-root "$profile_root" -- "$@" diff --git a/packaging/linux/nightly-package-launch.sh b/packaging/linux/nightly-package-launch.sh new file mode 100644 index 000000000..de8539bef --- /dev/null +++ b/packaging/linux/nightly-package-launch.sh @@ -0,0 +1,40 @@ +#!/bin/sh +# The FigCraft Nightly launcher for the distro formats this app builds itself: the deb/rpm's +# `usr/bin/figcraft-nightly`, the AppImage's, and the Arch handoff's `bin/figcraft`. @REAL_BIN@ is +# substituted where each format installs the file, so those packages keep their own profile folder +# (`XDG_DATA_HOME/figcraft-nightly/profile`) and the stable-XDG fence they export. The plain nightly +# tar the Launcher installs uses the canonical shared template in nightly-launch.sh instead. +# FigCraft Nightly launch wrapper, shared by every nightly Linux format (the flat .tar.gz, the Arch +# handoff, the deb/rpm and the AppImage entry). It starts the GUI on the Launcher's nightly-v1 +# profile under a per-channel directory, so a nightly install never reads or writes the stable +# app's settings, recovery copies, plugins, font store or session state. +# +# The GUI binary this starts is substituted where the script is installed: beside the script as +# figcraft-bin in a tarball, $APPDIR/usr/bin/figcraft in an AppImage, /usr/lib/figcraft-nightly/… in +# a deb/rpm, and bin/.figcraft-nightly/figcraft in the Arch handoff. +# +# The Launcher speaks this same protocol (`--launch-profile nightly-v1 --profile-root --`), +# so its command line passes straight through rather than being wrapped in a second pair. A bare +# `--version` or `-V` goes straight to the binary too: the answer must be the plain version line, +# and a version query never creates the profile. Everything else starts the nightly profile. +set -eu +real_bin=@REAL_BIN@ +case "${1:-}" in + --launch-profile | --profile-root | --version | -V) exec "$real_bin" "$@" ;; +esac +config_base="${XDG_CONFIG_HOME:-${HOME:?HOME is required}/.config}" +data_base="${XDG_DATA_HOME:-${HOME:?HOME is required}/.local/share}" +# The bases in effect before the override below: the GUI's profile fence still refuses the stable +# FigCraft folders under them (profile_root.rs reads FIGCRAFT_STABLE_). +export FIGCRAFT_STABLE_XDG_CONFIG_HOME="$config_base" +export FIGCRAFT_STABLE_XDG_DATA_HOME="$data_base" +# Belt and braces for anything that still asks the process environment for a folder. +export XDG_CONFIG_HOME="$config_base/figcraft-nightly" +export XDG_DATA_HOME="$data_base/figcraft-nightly" +# One profile per channel, chosen here only: a caller cannot point the Nightly at another folder, +# so the fence the GUI applies can never be handed the stable app's config or data directory. +profile="$XDG_DATA_HOME/profile" +# A `--` the caller wrote already separates the files from the options: drop it, so the app is +# handed exactly one and no file name arrives as `--`. +if [ "${1:-}" = "--" ]; then shift; fi +exec "$real_bin" --launch-profile nightly-v1 --profile-root "$profile" -- "$@" diff --git a/packaging/linux/nightly.sh b/packaging/linux/nightly.sh index 6fa656a07..508236be5 100755 --- a/packaging/linux/nightly.sh +++ b/packaging/linux/nightly.sh @@ -19,13 +19,13 @@ OUTPUT="$DIST/figcraft-$VERSION-linux-x86_64-nightly.tar.gz" nightly_build_gui STAGE="$NIGHTLY_WORK/stage" mkdir -p "$STAGE" -# The standard nightly layout: the archive's entry point `figcraft` is the shared launcher, which -# starts the GUI on the Launcher's nightly-v1 profile, and the GUI itself sits beside it as -# `figcraft-bin`. An unpacked tar is isolated too, even when started straight from its folder. +# The standard nightly layout: the archive's entry point `figcraft` is the canonical shared +# launcher template, which starts the GUI on the Launcher's nightly-v1 profile, and the GUI itself +# sits beside it as `figcraft-bin`. An unpacked tar is isolated too, even when started straight from +# its folder. cp "$NIGHTLY_GUI" "$STAGE/figcraft-bin" chmod 755 "$STAGE/figcraft-bin" -awk -v real='"$(dirname "$0")/figcraft-bin"' '{ gsub(/@REAL_BIN@/, real); print }' \ - "$HERE/nightly-launch.sh" >"$STAGE/figcraft" +install -m755 "$HERE/nightly-launch.sh" "$STAGE/figcraft" chmod 755 "$STAGE/figcraft" cp "$ROOT/assets/app-icon/figcraft-nightly.png" "$STAGE/figcraft-nightly.png" nightly_copy_notices "$STAGE" diff --git a/packaging/linux/package.sh b/packaging/linux/package.sh index 061dac999..d95a0f386 100755 --- a/packaging/linux/package.sh +++ b/packaging/linux/package.sh @@ -86,11 +86,11 @@ for bin in "${BINS[@]}"; do done install -Dm644 "$HERE/$APP_ID.desktop" "$STAGE/usr/share/applications/$APP_ID.desktop" if [[ "$IS_NIGHTLY" = 1 ]]; then - # The nightly entry point is the shared launcher (packaging/linux/nightly-launch.sh): every - # format starts the GUI on the Launcher's nightly-v1 profile, so nothing reads or writes the + # The nightly entry point is the distro launcher (packaging/linux/nightly-package-launch.sh): + # every format starts the GUI on the Launcher's nightly-v1 profile, so nothing reads or writes the # stable app's user state. The deb/rpm wrapper and the AppImage entry below specialise its path. awk -v real='"$(dirname "$0")/figcraft"' '{ gsub(/@REAL_BIN@/, real); print }' \ - "$HERE/nightly-launch.sh" >"$STAGE/usr/bin/figcraft-nightly" + "$HERE/nightly-package-launch.sh" >"$STAGE/usr/bin/figcraft-nightly" chmod 755 "$STAGE/usr/bin/figcraft-nightly" # The entry starts the launcher, names the Nightly and registers no file types (a Nightly never # takes a document association from the stable app). `#` delimits, so \(...\|...\) is alternation. @@ -174,10 +174,10 @@ if has deb || has rpm; then rm -rf "$NFPM_STAGE" cp -R "$STAGE" "$NFPM_STAGE" install -Dm755 "$NFPM_STAGE/usr/bin/figcraft" "$NFPM_STAGE/usr/lib/figcraft-nightly/figcraft" - # The shared launcher (packaging/linux/nightly-launch.sh) starts the GUI on the Launcher's - # nightly-v1 profile, so the package never reads or writes the stable app's user state. + # The distro launcher (packaging/linux/nightly-package-launch.sh) starts the GUI on the + # Launcher's nightly-v1 profile, so the package never reads or writes the stable app's user state. awk -v real='/usr/lib/figcraft-nightly/figcraft' '{ gsub(/@REAL_BIN@/, real); print }' \ - "$HERE/nightly-launch.sh" >"$NFPM_STAGE/usr/bin/$NFPM_BIN" + "$HERE/nightly-package-launch.sh" >"$NFPM_STAGE/usr/bin/$NFPM_BIN" chmod 755 "$NFPM_STAGE/usr/bin/$NFPM_BIN" rm -f "$NFPM_STAGE/usr/bin/figcraft" if [[ "$HAS_CLI" = 1 ]]; then