BlueGit

ict rusty-teams

Files

rusty-teams / packaging / linux / flatpak-bundle.sh

flatpak-bundle.sh

feat(packaging): Linux AppImage, deb, rpm and Flatpak
metis Samuel David Merlin Kemper · pushed by metis · 2 weeks ago
228f36c5 History
flatpak-bundle.sh 3.1 KiB Download Raw
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.
17set -euo pipefail
18umask 022
19# shellcheck source=../env.sh
20. "$(dirname "${BASH_SOURCE[0]}")/../env.sh"
21HERE="$ROOT/packaging/linux"
22APP_ID=io.github.danieldaeschle.RustyTeams
23FLATHUB=https://dl.flathub.org/repo/flathub.flatpakrepo
24
25TEST=1
26TARBALL=""
27while [[ $# -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
34done
35
36ARCH="$(uname -m)"
37case "$ARCH" in
38 x86_64) ;;
39 aarch64 | arm64) ARCH=aarch64 ;;
40 *) echo "unsupported architecture $ARCH" >&2; exit 2 ;;
41esac
42BASENAME="rusty-teams-$VERSION-linux-$ARCH"
43TARBALL="${TARBALL:-$DIST/$BASENAME.tar.gz}"
44[[ -f "$TARBALL" ]] || { echo "error: $TARBALL not found (run packaging/linux/package.sh --formats tar first)" >&2; exit 1; }
45for 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; }
47done
48
49warn "the Flatpak is known broken: the app cannot start the host's browser from the sandbox"
50echo "==> Rusty Teams $VERSION Flatpak bundle for $ARCH from $(basename "$TARBALL")"
51
52WORK="$CARGO_TARGET_DIR/flatpak-bundle"
53rm -rf "$WORK"
54mkdir -p "$WORK/stage"
55tar -xzf "$TARBALL" -C "$WORK/stage" --strip-components=1
56[[ -x "$WORK/stage/bin/teams" ]] || { echo "error: $TARBALL has no bin/teams" >&2; exit 1; }
57cp "$HERE/flatpak/$APP_ID.yml" "$WORK/$APP_ID.yml"
58
59flatpak remote-add --user --if-not-exists flathub "$FLATHUB"
60# --disable-rofiles-fuse: no FUSE in containers and CI runners.
61flatpak-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
64OUT="$DIST/$BASENAME.flatpak"
65# --runtime-repo lets `flatpak install` fetch the freedesktop runtime from Flathub if missing.
66flatpak build-bundle --runtime-repo="$FLATHUB" "$WORK/repo" "$OUT" "$APP_ID" stable
67echo "wrote $OUT"
68
69if [[ "$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'
73fi
74echo "==> done"
75ls -lh "$OUT"