BlueGit

ict rusty-teams

Files

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

flatpak-bundle.sh

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