| 1 | #!/usr/bin/env bash |
| 2 | # Repackage a Rusty Teams Linux tarball as a single-file Flatpak bundle: |
| 3 | # |
| 4 | # $DIST/rusty-teams-<version>-linux-<arch>.flatpak |
| 5 | # |
| 6 | # BROKEN: the app cannot start the host's browser from inside the sandbox, so it cannot sign |
| 7 | # in (details in packaging/linux/flatpak/io.github.danieldaeschle.RustyTeams.yml). Not part of |
| 8 | # the release; kept to work on the sandbox support. |
| 9 | # |
| 10 | # Usage: packaging/linux/flatpak-bundle.sh [--no-test] [TARBALL] |
| 11 | # |
| 12 | # TARBALL defaults to $DIST/rusty-teams-<version>-linux-<arch>.tar.gz from package.sh. The bundle |
| 13 | # is built for the host architecture (x86_64 or aarch64), which must match the tarball's. |
| 14 | # Needs flatpak and flatpak-builder; the freedesktop runtime and SDK named in the manifest are |
| 15 | # installed per-user from Flathub. Unless --no-test, the bundle is then installed per-user and |
| 16 | # its files are listed inside the sandbox as a smoke test. |
| 17 | set -euo pipefail |
| 18 | umask 022 |
| 19 | # shellcheck source=../env.sh |
| 20 | . "$(dirname "${BASH_SOURCE[0]}")/../env.sh" |
| 21 | HERE="$ROOT/packaging/linux" |
| 22 | APP_ID=io.github.danieldaeschle.RustyTeams |
| 23 | FLATHUB=https://dl.flathub.org/repo/flathub.flatpakrepo |
| 24 | |
| 25 | TEST=1 |
| 26 | TARBALL="" |
| 27 | while [[ $# -gt 0 ]]; do |
| 28 | case "$1" in |
| 29 | --no-test) TEST=0; shift ;; |
| 30 | -h | --help) sed -n '2,17p' "$0"; exit 0 ;; |
| 31 | -*) echo "unknown argument: $1" >&2; exit 2 ;; |
| 32 | *) TARBALL="$1"; shift ;; |
| 33 | esac |
| 34 | done |
| 35 | |
| 36 | ARCH="$(uname -m)" |
| 37 | case "$ARCH" in |
| 38 | x86_64) ;; |
| 39 | aarch64 | arm64) ARCH=aarch64 ;; |
| 40 | *) echo "unsupported architecture $ARCH" >&2; exit 2 ;; |
| 41 | esac |
| 42 | BASENAME="rusty-teams-$VERSION-linux-$ARCH" |
| 43 | TARBALL="${TARBALL:-$DIST/$BASENAME.tar.gz}" |
| 44 | [[ -f "$TARBALL" ]] || { echo "error: $TARBALL not found (run packaging/linux/package.sh --formats tar first)" >&2; exit 1; } |
| 45 | for tool in flatpak flatpak-builder; do |
| 46 | command -v "$tool" >/dev/null || { echo "error: $tool not found (apt install flatpak flatpak-builder)" >&2; exit 1; } |
| 47 | done |
| 48 | |
| 49 | warn "the Flatpak is known broken: the app cannot start the host's browser from the sandbox" |
| 50 | echo "==> Rusty Teams $VERSION Flatpak bundle for $ARCH from $(basename "$TARBALL")" |
| 51 | |
| 52 | WORK="$CARGO_TARGET_DIR/flatpak-bundle" |
| 53 | rm -rf "$WORK" |
| 54 | mkdir -p "$WORK/stage" |
| 55 | tar -xzf "$TARBALL" -C "$WORK/stage" --strip-components=1 |
| 56 | [[ -x "$WORK/stage/bin/teams" ]] || { echo "error: $TARBALL has no bin/teams" >&2; exit 1; } |
| 57 | cp "$HERE/flatpak/$APP_ID.yml" "$WORK/$APP_ID.yml" |
| 58 | |
| 59 | flatpak remote-add --user --if-not-exists flathub "$FLATHUB" |
| 60 | # --disable-rofiles-fuse: no FUSE in containers and CI runners. |
| 61 | flatpak-builder --user --install-deps-from=flathub --disable-rofiles-fuse --force-clean \ |
| 62 | --default-branch=stable --repo="$WORK/repo" --state-dir="$WORK/state" "$WORK/build" "$WORK/$APP_ID.yml" |
| 63 | |
| 64 | OUT="$DIST/$BASENAME.flatpak" |
| 65 | # --runtime-repo lets `flatpak install` fetch the freedesktop runtime from Flathub if missing. |
| 66 | flatpak build-bundle --runtime-repo="$FLATHUB" "$WORK/repo" "$OUT" "$APP_ID" stable |
| 67 | echo "wrote $OUT" |
| 68 | |
| 69 | if [[ "$TEST" = 1 ]]; then |
| 70 | flatpak install --user -y --noninteractive --reinstall "$OUT" |
| 71 | flatpak info --user "$APP_ID" |
| 72 | flatpak run --command=sh "$APP_ID" -c 'test -x /app/bin/teams && ls /app/share/applications /app/share/metainfo /app/share/icons/hicolor/256x256/apps' |
| 73 | fi |
| 74 | echo "==> done" |
| 75 | ls -lh "$OUT" |