diff --git a/README.md b/README.md index 1265e5924..a05dcc7fe 100644 --- a/README.md +++ b/README.md @@ -183,10 +183,13 @@ dictionary or single window state. The Nightly app is started only by ArtCraft L fenced against every stable data and install folder, so a Nightly window cannot fall back to stable state. Nightly is managed by the Launcher and does not self-update. -On Linux, every Nightly format starts through the same launcher -(`packaging/linux/nightly-launch.sh`): the `.tar.gz` and AppImage, the deb/rpm package, the Flatpak -and the Arch handoff all pass `--launch-profile nightly-v1 --profile-root -- ` to the -GUI, so an unpacked or distro-installed copy is isolated without the Launcher. +On Linux, the plain nightly `.tar.gz` starts through the canonical shared launcher template +(`packaging/linux/nightly-launch.sh`, rendered from `craft-common-actions`'s +`scripts/nightly-launcher.sh.in`): `deckcraft` starts `deckcraft-bin` beside it on the nightly-v1 +profile under the Nightly package identity. The distro formats keep their own launcher +(`packaging/linux/nightly-package-launch.sh`) and their own profile folder; the AppImage, the deb/rpm +package, the Flatpak and the Arch handoff all pass `--launch-profile nightly-v1 --profile-root +-- ` to the GUI, so an unpacked or distro-installed copy is isolated without the Launcher. The channel's packaging lives in `packaging/nightly-common.sh`, `packaging/{linux,macos,windows}/nightly*` and `.github/workflows/nightly*.yml`. The producer and signer workflows are registered and can be diff --git a/packaging/linux/nightly-arch-tar.sh b/packaging/linux/nightly-arch-tar.sh index 1fd33084a..1754d9d2b 100755 --- a/packaging/linux/nightly-arch-tar.sh +++ b/packaging/linux/nightly-arch-tar.sh @@ -13,7 +13,7 @@ mkdir -p "$work" cp -R "$source_tree" "$stage" mkdir "$stage/bin/.deckcraft-nightly" mv "$stage/bin/deckcraft" "$stage/bin/.deckcraft-nightly/deckcraft-bin" -cp "$here/nightly-launch.sh" "$stage/bin/deckcraft" +cp "$here/nightly-package-launch.sh" "$stage/bin/deckcraft" chmod 755 "$stage/bin/deckcraft" 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 1be5d3ff5..9eb9b27f1 100755 --- a/packaging/linux/nightly-launch-test.sh +++ b/packaging/linux/nightly-launch-test.sh @@ -1,17 +1,27 @@ #!/usr/bin/env bash -# Validate the nightly launcher in every Linux placement without building or opening DeckCraft: -# the flat nightly tar (`deckcraft` + `deckcraft-bin`), the AppImage (`AppRun` + `usr/bin/deckcraft`), -# the distro tree (`bin/deckcraft-nightly` + `bin/deckcraft-bin`) and the /usr/bin rule that reaches -# the fixed /usr/lib copy. A recorder binary stands in for the GUI and prints its argv. +# Validate both Nightly Linux launchers without building or opening DeckCraft. +# +# The flat nightly tar's `deckcraft` is the canonical shared template +# (`packaging/linux/nightly-launch.sh`, rendered from craft-common-actions's +# `scripts/nightly-launcher.sh.in`), which the nightly producer accepts byte for byte: it starts +# `deckcraft-bin` beside itself on the nightly-v1 profile under the Nightly package identity. +# +# The distro formats keep `packaging/linux/nightly-package-launch.sh` and their own profile folder: +# the AppImage (`AppRun` + `usr/bin/deckcraft-bin`), the distro tree (`bin/deckcraft-nightly` + +# `bin/deckcraft-bin`) and the /usr/bin rule that reaches the fixed /usr/lib copy. A recorder binary +# stands in for the GUI and prints its argv. set -euo pipefail HERE="$(cd "$(dirname "$0")" && pwd)" work="$(mktemp -d)" trap 'rm -rf "$work"' EXIT launcher="$HERE/nightly-launch.sh" +package_launcher="$HERE/nightly-package-launch.sh" export HOME="$work/home" mkdir -p "$HOME" export XDG_CONFIG_HOME="$HOME/.config" XDG_DATA_HOME="$HOME/.local/share" +identity=ai.storyteller.deckcraft.nightly +tar_profile="$XDG_DATA_HOME/$identity" profile="$XDG_DATA_HOME/deckcraft-nightly/launcher/profiles/deckcraft" recorder() { @@ -36,30 +46,52 @@ expect() { nightly_argv() { printf '<%s>\n' --launch-profile nightly-v1 --profile-root "$profile" -- } +tar_argv() { + printf '<%s>\n' --launch-profile nightly-v1 --profile-root "$tar_profile" -- +} -# ---- the flat nightly tar: `deckcraft` launcher, `deckcraft-bin` GUI ---- +# ---- the flat nightly tar: the canonical template `deckcraft`, `deckcraft-bin` GUI ---- flat="$work/flat" recorder "$flat/deckcraft-bin" cp "$launcher" "$flat/deckcraft" chmod 755 "$flat/deckcraft" -expect "$flat/deckcraft" "$(nightly_argv)" -expect "$flat/deckcraft" "$(nightly_argv; printf '<%s>\n' 'deck with spaces.pptx' '--other-name.pptx')" \ +expect "$flat/deckcraft" "$(tar_argv)" +expect "$flat/deckcraft" "$(tar_argv; printf '<%s>\n' 'deck with spaces.pptx' '--other-name.pptx')" \ 'deck with spaces.pptx' '--other-name.pptx' -expect "$flat/deckcraft" "$(nightly_argv; printf '<%s>\n' 'deck.pptx')" -- deck.pptx -expect "$flat/deckcraft" '<--version>' --version -expect "$flat/deckcraft" '<-V>' -V -expect "$flat/deckcraft" '<--help>' --help -expect "$flat/deckcraft" "$(printf '<%s>\n' --launch-profile nightly-v1 --profile-root "$work/launcher" -- 'deck.pptx')" \ - --launch-profile nightly-v1 --profile-root "$work/launcher" -- 'deck.pptx' -test ! -e "$profile" +# Both version spellings reach the GUI as one plain `--version`. +expect "$flat/deckcraft" "$(printf '<%s>\n' --launch-profile nightly-v1 --profile-root "$tar_profile" --version)" --version +expect "$flat/deckcraft" "$(printf '<%s>\n' --launch-profile nightly-v1 --profile-root "$tar_profile" --version)" -V +# The ArtCraft Launcher starts the entry point with its own profile pair; the template hands that +# line to the GUI unchanged. +launcher_line=(--launch-profile nightly-v1 --profile-root "$work/launcher root" -- deck.pptx) +expect "$flat/deckcraft" "$(printf '<%s>\n' "${launcher_line[@]}")" "${launcher_line[@]}" +# Anything else is a file argument with the template's own profile, including a query the template +# does not answer (`--help`) and a profile line that does not open the arguments. +expect "$flat/deckcraft" "$(tar_argv; printf '<%s>\n' --help)" --help +expect "$flat/deckcraft" "$(tar_argv; printf '<%s>\n' --profile-root "$work/launcher" --)" --profile-root "$work/launcher" -- +test ! -e "$tar_profile" +# The launcher resolves its own folder physically and starts only the GUI beside it. +linked="$work/linked/bin" +mkdir -p "$(dirname "$linked")" +ln -s "$flat" "$linked" +expect "$linked/deckcraft" "$(tar_argv; printf '<%s>\n' book.pptx)" book.pptx +mkdir -p "$work/flat-empty" +cp "$launcher" "$work/flat-empty/deckcraft" +chmod 755 "$work/flat-empty/deckcraft" +status=0 +"$work/flat-empty/deckcraft" book.pptx >/dev/null 2>&1 || status=$? +[[ "$status" -ne 0 ]] || { echo 'the tar launcher started without its GUI beside it' >&2; exit 1; } +status=0 +env -u XDG_DATA_HOME -u HOME "$flat/deckcraft" book.pptx >/dev/null 2>&1 || status=$? +[[ "$status" -ne 0 ]] || { echo 'the tar launcher started without a data folder' >&2; exit 1; } # ---- the AppImage: AppRun at the mount root, the GUI and the entry's copy in usr/bin ---- appdir="$work/DeckCraft.AppDir" recorder "$appdir/usr/bin/deckcraft-bin" -cp "$launcher" "$appdir/AppRun" +cp "$package_launcher" "$appdir/AppRun" chmod 755 "$appdir/AppRun" expect "$appdir/AppRun" "$(nightly_argv; printf '<%s>\n' book.pptx)" book.pptx -cp "$launcher" "$appdir/usr/bin/deckcraft-nightly" +cp "$package_launcher" "$appdir/usr/bin/deckcraft-nightly" chmod 755 "$appdir/usr/bin/deckcraft-nightly" expect "$appdir/usr/bin/deckcraft-nightly" "$(nightly_argv; printf '<%s>\n' book.pptx)" book.pptx test ! -e "$profile" @@ -67,7 +99,7 @@ test ! -e "$profile" # ---- the distro tree tarball: bin/deckcraft-nightly beside bin/deckcraft-bin ---- tree="$work/tree/bin" recorder "$tree/deckcraft-bin" -cp "$launcher" "$tree/deckcraft-nightly" +cp "$package_launcher" "$tree/deckcraft-nightly" chmod 755 "$tree/deckcraft-nightly" actual=$(PATH="$tree:$PATH" deckcraft-nightly book.pptx) [[ "$actual" == "$(nightly_argv; printf '<%s>\n' book.pptx)" ]] || { printf 'a PATH invocation printed:\n%s\n' "$actual" >&2; exit 1; } @@ -76,13 +108,13 @@ test ! -e "$profile" # ---- a missing GUI fails closed, and so does a tree with no data folder ---- empty="$work/empty" mkdir -p "$empty" -cp "$launcher" "$empty/deckcraft" +cp "$package_launcher" "$empty/deckcraft" chmod 755 "$empty/deckcraft" status=0 "$empty/deckcraft" book.pptx >/dev/null 2>&1 || status=$? [[ "$status" -eq 2 ]] || { printf 'a launcher with no GUI must exit 2, got %s\n' "$status" >&2; exit 1; } recorder "$work/nodata/deckcraft-bin" -cp "$launcher" "$work/nodata/deckcraft" +cp "$package_launcher" "$work/nodata/deckcraft" chmod 755 "$work/nodata/deckcraft" status=0 env -u XDG_DATA_HOME -u HOME "$work/nodata/deckcraft" book.pptx >/dev/null 2>&1 || status=$? @@ -92,14 +124,21 @@ actual=$(env -u XDG_DATA_HOME -u HOME "$work/nodata/deckcraft" --version) \ || { printf 'a no-data-folder --version must still answer\n' >&2; exit 1; } [[ "$actual" == '<--version>' ]] || { printf 'a no-data-folder --version printed:\n%s\n' "$actual" >&2; exit 1; } -# ---- the /usr/bin rule: the fixed /usr/lib copy is named, and no parent path is ever used ---- +# ---- the /usr/bin rule stays with the distro launcher: the fixed /usr/lib copy, never a parent path ---- # The launcher's text is searched literally, so `$here` must not expand here. # shellcheck disable=SC2016 -grep -Fq '[ "$here" = /usr/bin ]' "$launcher" -grep -Fq '/usr/lib/deckcraft-nightly/deckcraft' "$launcher" -if grep -q '\.\.' "$launcher"; then - echo "the launcher must not reach outside its own folder or the fixed /usr/lib path" >&2 +grep -Fq '[ "$here" = /usr/bin ]' "$package_launcher" +grep -Fq '/usr/lib/deckcraft-nightly/deckcraft' "$package_launcher" +if grep -q '\.\.' "$package_launcher"; then + echo "the distro launcher must not reach outside its own folder or the fixed /usr/lib path" >&2 exit 1 fi +# ---- the tar launcher is the shared template, unedited ---- +grep -Fq '# Nightly launcher generated by craft-common-actions scripts/nightly-launcher.sh.in.' "$launcher" +# shellcheck disable=SC2016 +grep -Fq 'target="$dir/deckcraft-bin"' "$launcher" +# shellcheck disable=SC2016 +grep -Fq ' --launch-profile) exec "$target" "$@" ;;' "$launcher" +grep -Fq "}/$identity\"" "$launcher" -echo "PASS: nightly launcher starts the GUI with the profile in every layout and refuses the rest" +echo "PASS: the nightly tar's template launcher and the distro launcher start the GUI with their profile" diff --git a/packaging/linux/nightly-launch.sh b/packaging/linux/nightly-launch.sh index 52b03904f..c3ad31046 100755 --- a/packaging/linux/nightly-launch.sh +++ b/packaging/linux/nightly-launch.sh @@ -1,63 +1,16 @@ #!/bin/sh -# The DeckCraft Nightly launcher every Linux format ships: the plain nightly tar's `deckcraft`, the -# distro tree's `bin/deckcraft-nightly`, the AppImage's `AppRun`, the Arch handoff's `bin/deckcraft` -# and the Flatpak's `/app/bin/deckcraft-nightly`. A nightly build refuses to start without -# `--launch-profile nightly-v1 --profile-root `, and the profile is its only data root, so -# this is what keeps a Nightly run out of the stable app's settings, prefs, logs and recovery. +# 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 - -# Resolve this script's own folder from `$0`. A shell that finds it through PATH passes a bare -# name, so ask the shell where that is instead of using the working directory. -case "$0" in - */*) self="$0" ;; - *) self="$(command -v "$0" || printf '%s' "$0")" ;; -esac -case "$self" in - /*) ;; - *) self="$PWD/$self" ;; -esac -here="$(CDPATH='' cd "$(dirname "$self")" && pwd -P)" -self="$here/$(basename "$self")" - -# The GUI each placement keeps inside its own tree, never from a parent folder: `deckcraft-bin` -# beside the launcher (the flat nightly tar, the distro tree, the Flatpak sandbox), the same name -# in an AppImage's `usr/bin`, and the hidden copy the Arch handoff keeps. A candidate that is this -# same file is never started, so a launcher cannot recurse into itself. -real= -for candidate in "$here/deckcraft-bin" "$here/usr/bin/deckcraft-bin" "$here/.deckcraft-nightly/deckcraft-bin"; do - if [ -f "$candidate" ] && [ -x "$candidate" ] && [ ! "$candidate" -ef "$self" ]; then - real="$candidate" - break - fi -done -# A distro package keeps the GUI in /usr/lib. Reach that fixed path only from /usr/bin, so a -# writable parent folder can never plant a program for this launcher to run. -if [ -z "$real" ] && [ "$here" = /usr/bin ] && [ -f /usr/lib/deckcraft-nightly/deckcraft ] && [ -x /usr/lib/deckcraft-nightly/deckcraft ]; then - real=/usr/lib/deckcraft-nightly/deckcraft -fi -if [ -z "$real" ]; then - echo "deckcraft-nightly: no DeckCraft binary beside $self" >&2 - exit 2 -fi - -# A bare version/help query and the Launcher's own protocol pass straight through: they are not -# file names, need no data folder, and a profile the caller already supplied is never wrapped -# twice. This runs before the data-folder check, so `deckcraft-nightly --version` still answers -# where HOME and XDG_DATA_HOME are both unset. +dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P) +readonly dir +target="$dir/deckcraft-bin" +readonly target +profile_root="${XDG_DATA_HOME:-$HOME/.local/share}/ai.storyteller.deckcraft.nightly" +readonly profile_root case "${1-}" in - --launch-profile | --profile-root | --version | -V | --help | -h) exec "$real" "$@" ;; + # 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 - -if [ -z "${XDG_DATA_HOME:-}" ] && [ -z "${HOME:-}" ]; then - echo "deckcraft-nightly: XDG_DATA_HOME and HOME are both unset, so there is no Nightly data folder" >&2 - exit 2 -fi -# The same root as every other format's launcher: beside the fenced stable `deckcraft` folder, -# never inside it. -profile="${XDG_DATA_HOME:-$HOME/.local/share}/deckcraft-nightly/launcher/profiles/deckcraft" -# A caller-written `--` is the separator this launcher adds below. Drop it, so it can never reach -# the app as a file name. -if [ "${1-}" = "--" ]; then - shift -fi -exec "$real" --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..3652c531e --- /dev/null +++ b/packaging/linux/nightly-package-launch.sh @@ -0,0 +1,68 @@ +#!/bin/sh +# The DeckCraft Nightly launcher for the distro formats this app builds itself: the deb/rpm's +# `bin/deckcraft-nightly`, the AppImage's `AppRun` and `usr/bin/deckcraft-nightly`, the Arch handoff's +# `bin/deckcraft`, and the flat distro tree. Those packages keep their own profile folder +# (`XDG_DATA_HOME/deckcraft-nightly/…`), and this file is unchanged by the shared template: the +# plain nightly tar is the only artifact the canonical file below applies to. +# The DeckCraft Nightly launcher every Linux format ships: the plain nightly tar's `deckcraft`, the +# distro tree's `bin/deckcraft-nightly`, the AppImage's `AppRun`, the Arch handoff's `bin/deckcraft` +# and the Flatpak's `/app/bin/deckcraft-nightly`. A nightly build refuses to start without +# `--launch-profile nightly-v1 --profile-root `, and the profile is its only data root, so +# this is what keeps a Nightly run out of the stable app's settings, prefs, logs and recovery. +set -eu + +# Resolve this script's own folder from `$0`. A shell that finds it through PATH passes a bare +# name, so ask the shell where that is instead of using the working directory. +case "$0" in + */*) self="$0" ;; + *) self="$(command -v "$0" || printf '%s' "$0")" ;; +esac +case "$self" in + /*) ;; + *) self="$PWD/$self" ;; +esac +here="$(CDPATH='' cd "$(dirname "$self")" && pwd -P)" +self="$here/$(basename "$self")" + +# The GUI each placement keeps inside its own tree, never from a parent folder: `deckcraft-bin` +# beside the launcher (the flat nightly tar, the distro tree, the Flatpak sandbox), the same name +# in an AppImage's `usr/bin`, and the hidden copy the Arch handoff keeps. A candidate that is this +# same file is never started, so a launcher cannot recurse into itself. +real= +for candidate in "$here/deckcraft-bin" "$here/usr/bin/deckcraft-bin" "$here/.deckcraft-nightly/deckcraft-bin"; do + if [ -f "$candidate" ] && [ -x "$candidate" ] && [ ! "$candidate" -ef "$self" ]; then + real="$candidate" + break + fi +done +# A distro package keeps the GUI in /usr/lib. Reach that fixed path only from /usr/bin, so a +# writable parent folder can never plant a program for this launcher to run. +if [ -z "$real" ] && [ "$here" = /usr/bin ] && [ -f /usr/lib/deckcraft-nightly/deckcraft ] && [ -x /usr/lib/deckcraft-nightly/deckcraft ]; then + real=/usr/lib/deckcraft-nightly/deckcraft +fi +if [ -z "$real" ]; then + echo "deckcraft-nightly: no DeckCraft binary beside $self" >&2 + exit 2 +fi + +# A bare version/help query and the Launcher's own protocol pass straight through: they are not +# file names, need no data folder, and a profile the caller already supplied is never wrapped +# twice. This runs before the data-folder check, so `deckcraft-nightly --version` still answers +# where HOME and XDG_DATA_HOME are both unset. +case "${1-}" in + --launch-profile | --profile-root | --version | -V | --help | -h) exec "$real" "$@" ;; +esac + +if [ -z "${XDG_DATA_HOME:-}" ] && [ -z "${HOME:-}" ]; then + echo "deckcraft-nightly: XDG_DATA_HOME and HOME are both unset, so there is no Nightly data folder" >&2 + exit 2 +fi +# The same root as every other format's launcher: beside the fenced stable `deckcraft` folder, +# never inside it. +profile="${XDG_DATA_HOME:-$HOME/.local/share}/deckcraft-nightly/launcher/profiles/deckcraft" +# A caller-written `--` is the separator this launcher adds below. Drop it, so it can never reach +# the app as a file name. +if [ "${1-}" = "--" ]; then + shift +fi +exec "$real" --launch-profile nightly-v1 --profile-root "$profile" -- "$@" diff --git a/packaging/linux/package.sh b/packaging/linux/package.sh index 85f18c497..3b02b4edf 100755 --- a/packaging/linux/package.sh +++ b/packaging/linux/package.sh @@ -117,7 +117,7 @@ if has tar; then # bin/deckcraft-bin), because the binary alone refuses to run without a launch profile. install -Dm755 "$WORK/tar/$BASENAME/bin/deckcraft" "$WORK/tar/$BASENAME/bin/deckcraft-bin" rm -f "$WORK/tar/$BASENAME/bin/deckcraft" - install -Dm755 "$HERE/nightly-launch.sh" "$WORK/tar/$BASENAME/bin/deckcraft-nightly" + install -Dm755 "$HERE/nightly-package-launch.sh" "$WORK/tar/$BASENAME/bin/deckcraft-nightly" TAR_DESK="$WORK/tar/$BASENAME/share/applications/$APP_ID.desktop" sed -e "s#^Exec=deckcraft\([[:space:]]\|$\)#Exec=deckcraft-nightly\1#" \ -e "s|^TryExec=deckcraft$|TryExec=deckcraft-nightly|" \ @@ -164,7 +164,7 @@ if has deb || has rpm; then # The GUI keeps its name under /usr/lib; /usr/bin/deckcraft-nightly is the launcher, whose # /usr/bin gate is what reaches that fixed path (the same file as the tar and AppImage use). install -Dm755 "$NFPM_STAGE/usr/bin/deckcraft" "$NFPM_STAGE/usr/lib/deckcraft-nightly/deckcraft" - install -Dm755 "$HERE/nightly-launch.sh" "$NFPM_STAGE/usr/bin/$NFPM_BIN" + install -Dm755 "$HERE/nightly-package-launch.sh" "$NFPM_STAGE/usr/bin/$NFPM_BIN" rm -f "$NFPM_STAGE/usr/bin/deckcraft" mv "$NFPM_STAGE/usr/bin/deckcraft-cli" "$NFPM_STAGE/usr/bin/$NFPM_CLI" mv "$NFPM_STAGE/usr/share/doc/deckcraft" "$NFPM_STAGE/usr/share/doc/$NFPM_NAME" @@ -227,8 +227,8 @@ if has appimage; then # read it. install -Dm755 "$APPDIR/usr/bin/deckcraft" "$APPDIR/usr/bin/deckcraft-bin" rm -f "$APPDIR/usr/bin/deckcraft" - install -Dm755 "$HERE/nightly-launch.sh" "$APPDIR/AppRun" - install -Dm755 "$HERE/nightly-launch.sh" "$APPDIR/usr/bin/deckcraft-nightly" + install -Dm755 "$HERE/nightly-package-launch.sh" "$APPDIR/AppRun" + install -Dm755 "$HERE/nightly-package-launch.sh" "$APPDIR/usr/bin/deckcraft-nightly" else ln -s usr/bin/deckcraft "$APPDIR/AppRun" fi