BlueGit

ict rusty-teams

Files

rusty-teams / packaging / linux / package.sh

package.sh

package.sh 8.8 KiB Download Raw
1#!/usr/bin/env bash
2# Build and package Rusty Teams for Linux (<arch> is x86_64 or aarch64):
3#
4# $DIST/rusty-teams-<version>-linux-<arch>.AppImage any distro with glibc >= the build host's
5# $DIST/rusty-teams-<version>-linux-<arch>.AppImage.zsync delta updates (needs zsyncmake)
6# $DIST/rusty-teams-<version>-linux-<arch>.deb Debian, Ubuntu, Mint, Pop!_OS, ...
7# $DIST/rusty-teams-<version>-linux-<arch>.rpm Fedora, openSUSE, RHEL, ...
8# $DIST/rusty-teams-<version>-linux-<arch>.pkg.tar.zst Arch Linux
9# $DIST/rusty-teams-<version>-linux-<arch>.tar.gz plain FHS-style tree (bin/, share/)
10#
11# Usage: packaging/linux/package.sh [--skip-build] [--formats "appimage deb rpm archlinux tar"]
12#
13# Needs: cargo and the Linux build setup from the README (clang 21+, mold); nfpm for deb/rpm/Arch
14# (https://nfpm.goreleaser.com); objdump (binutils). AppImage tooling is downloaded at verified
15# pins into $CARGO_TARGET_DIR. Build on an old distro (CI: Ubuntu 22.04, glibc 2.35) so the
16# binary runs on newer ones. Optional: desktop-file-validate, appstreamcli, zsyncmake (the zsync
17# package) for the AppImage's .zsync. --skip-build packages $CARGO_TARGET_DIR/release/teams as is.
18set -euo pipefail
19# Packaged files and directories get 644/755 whatever the caller's umask.
20umask 022
21# shellcheck source=../env.sh
22. "$(dirname "${BASH_SOURCE[0]}")/../env.sh"
23HERE="$ROOT/packaging/linux"
24# shellcheck source=verified-download.sh
25. "$HERE/verified-download.sh"
26# The window's app id, the .desktop file and the icon name (DESKTOP_ID in linux_desktop.rs).
27DESKTOP_ID=rusty-teams
28# The AppStream component id (packaging/linux/rusty-teams.metainfo.xml.in).
29COMPONENT_ID=io.github.danieldaeschle.RustyTeams
30
31SKIP_BUILD=0
32FORMATS="appimage deb rpm archlinux tar"
33while [[ $# -gt 0 ]]; do
34 case "$1" in
35 --skip-build) SKIP_BUILD=1; shift ;;
36 --formats) FORMATS="$2"; shift 2 ;;
37 -h | --help) sed -n '2,17p' "$0"; exit 0 ;;
38 *) echo "unknown argument: $1" >&2; exit 2 ;;
39 esac
40done
41
42ARCH="$(uname -m)"
43case "$ARCH" in
44 x86_64) DEB_ARCH=amd64 ;;
45 aarch64 | arm64) ARCH=aarch64; DEB_ARCH=arm64 ;;
46 *) echo "unsupported architecture $ARCH" >&2; exit 2 ;;
47esac
48export RUSTY_TEAMS_MAINTAINER="${RUSTY_TEAMS_MAINTAINER:-Daniel Däschle <30751516+danieldaeschle@users.noreply.github.com>}"
49BASENAME="rusty-teams-$VERSION-linux-$ARCH"
50
51echo "==> Rusty Teams $VERSION for Linux $ARCH ($FORMATS)"
52
53if [[ "$SKIP_BUILD" = 0 ]]; then
54 (cd "$ROOT" && cargo build --release --locked -p app)
55fi
56BIN="$CARGO_TARGET_DIR/release"
57[[ -x "$BIN/teams" ]] || { echo "error: $BIN/teams not found (build it or drop --skip-build)" >&2; exit 1; }
58WORK="$CARGO_TARGET_DIR/linux-package"
59STAGE="$WORK/root"
60rm -rf "$WORK"
61
62# ---- stage an FHS tree (shared by every format) -------------------------------------------------
63install -Dm755 "$BIN/teams" "$STAGE/usr/bin/teams"
64strip "$STAGE/usr/bin/teams" 2>/dev/null || true
65install -Dm644 "$HERE/$DESKTOP_ID.desktop" "$STAGE/usr/share/applications/$DESKTOP_ID.desktop"
66mkdir -p "$STAGE/usr/share/metainfo"
67sed -e "s/@VERSION@/$VERSION/g" -e "s/@DATE@/$BUILD_DATE/g" \
68 "$HERE/$DESKTOP_ID.metainfo.xml.in" >"$STAGE/usr/share/metainfo/$COMPONENT_ID.metainfo.xml"
69mkdir -p "$STAGE/usr/share/icons"
70cp -R "$HERE/hicolor" "$STAGE/usr/share/icons/"
71mkdir -p "$STAGE/usr/share/doc/rusty-teams"
72copy_docs "$STAGE/usr/share/doc/rusty-teams"
73
74if command -v desktop-file-validate >/dev/null; then
75 desktop-file-validate "$STAGE/usr/share/applications/$DESKTOP_ID.desktop"
76fi
77if command -v appstreamcli >/dev/null; then
78 appstreamcli validate --no-net --explain "$STAGE/usr/share/metainfo/$COMPONENT_ID.metainfo.xml"
79fi
80
81# The newest glibc symbol version the binary needs: the deb/rpm depend on it, and it is the
82# oldest distro the AppImage and tarball run on.
83GLIBC_MIN="$(objdump -T "$STAGE/usr/bin/teams" | grep -o 'GLIBC_[0-9][0-9.]*' | sed 's/^GLIBC_//' | sort -uV | tail -n 1)"
84[[ -n "$GLIBC_MIN" ]] || { echo "error: could not read the glibc version from $STAGE/usr/bin/teams" >&2; exit 1; }
85echo "needs glibc >= $GLIBC_MIN"
86
87has() { case " $FORMATS " in *" $1 "*) return 0 ;; *) return 1 ;; esac; }
88
89# ---- .tar.gz ------------------------------------------------------------------------------------
90if has tar; then
91 mkdir -p "$WORK/tar"
92 cp -R "$STAGE/usr" "$WORK/tar/$BASENAME"
93 tar -C "$WORK/tar" -czf "$DIST/$BASENAME.tar.gz" "$BASENAME"
94 echo "wrote $DIST/$BASENAME.tar.gz"
95fi
96
97# ---- .deb / .rpm / Arch -------------------------------------------------------------------------
98if has deb || has rpm || has archlinux; then
99 command -v nfpm >/dev/null || { echo "error: nfpm not found (https://nfpm.goreleaser.com/install/)" >&2; exit 1; }
100 export VERSION
101 export NFPM_ARCH="$DEB_ARCH"
102 # nfpm expands env vars in fields like `version` and `arch`, but not in `contents[].src` or
103 # the dependency lists.
104 sed -e "s|\${STAGE}|$STAGE|g" -e "s|\${GLIBC_MIN}|$GLIBC_MIN|g" "$HERE/nfpm.yaml" >"$WORK/nfpm.yaml"
105 for fmt in deb rpm; do
106 if has "$fmt"; then (cd "$ROOT" && nfpm package -f "$WORK/nfpm.yaml" -p "$fmt" -t "$DIST/$BASENAME.$fmt"); fi
107 done
108 if has archlinux; then
109 (cd "$ROOT" && nfpm package -f "$WORK/nfpm.yaml" -p archlinux -t "$DIST/$BASENAME.pkg.tar.zst")
110 fi
111fi
112
113# ---- AppImage -----------------------------------------------------------------------------------
114if has appimage; then
115 APPDIR="$WORK/RustyTeams.AppDir"
116 cp -R "$STAGE" "$APPDIR"
117 # AppRun is a script, not a symlink: it installs the .desktop entry and icons into
118 # $XDG_DATA_HOME before launching, so Wayland compositors can resolve the window's
119 # app_id to our icon instead of the generic Wayland logo (opt-out env in the script
120 # header). Logic is covered by packaging/linux/apprun-test.sh.
121 install -Dm755 "$HERE/AppRun" "$APPDIR/AppRun"
122 cp "$HERE/$DESKTOP_ID.desktop" "$APPDIR/$DESKTOP_ID.desktop"
123 cp "$HERE/hicolor/256x256/apps/$DESKTOP_ID.png" "$APPDIR/$DESKTOP_ID.png"
124 ln -s "$DESKTOP_ID.png" "$APPDIR/.DirIcon"
125
126 # Digests from the official GitHub release asset metadata:
127 # https://github.com/AppImage/appimagetool/releases/tag/1.9.1
128 # https://github.com/AppImage/type2-runtime/releases/tag/20251108
129 # Keep both pins together:
130 # appimagetool otherwise downloads the mutable latest type2 runtime itself.
131 TOOL_VERSION=1.9.1
132 RUNTIME_VERSION=20251108
133 case "$ARCH" in
134 x86_64)
135 TOOL_SHA256=ed4ce84f0d9caff66f50bcca6ff6f35aae54ce8135408b3fa33abfc3cb384eb0
136 RUNTIME_SHA256=2fca8b443c92510f1483a883f60061ad09b46b978b2631c807cd873a47ec260d
137 ;;
138 aarch64)
139 TOOL_SHA256=f0837e7448a0c1e4e650a93bb3e85802546e60654ef287576f46c71c126a9158
140 RUNTIME_SHA256=00cbdfcf917cc6c0ff6d3347d59e0ca1f7f45a6df1a428a0d6d8a78664d87444
141 ;;
142 esac
143 mkdir -p "$CARGO_TARGET_DIR"
144 TOOL="${APPIMAGETOOL:-$CARGO_TARGET_DIR/appimagetool-$TOOL_VERSION-$ARCH.AppImage}"
145 if [[ -n "${APPIMAGETOOL:-}" ]]; then
146 verify_appimagetool_override "$TOOL" "$TOOL_SHA256" "$TOOL_VERSION" "$ARCH"
147 else
148 download_verified \
149 "https://github.com/AppImage/appimagetool/releases/download/$TOOL_VERSION/appimagetool-$ARCH.AppImage" \
150 "$TOOL" "$TOOL_SHA256" true
151 fi
152 RUNTIME="$CARGO_TARGET_DIR/type2-runtime-$RUNTIME_VERSION-$ARCH"
153 download_verified \
154 "https://github.com/AppImage/type2-runtime/releases/download/$RUNTIME_VERSION/runtime-$ARCH" \
155 "$RUNTIME" "$RUNTIME_SHA256"
156 # Absolute, because appimagetool runs in $DIST below (CARGO_TARGET_DIR or APPIMAGETOOL may be
157 # relative).
158 OUT="$(cd "$DIST" && pwd)/$BASENAME.AppImage"
159 APPDIR="$(cd "$APPDIR" && pwd)"
160 TOOL="$(cd "$(dirname "$TOOL")" && pwd)/$(basename "$TOOL")"
161 RUNTIME="$(cd "$(dirname "$RUNTIME")" && pwd)/$(basename "$RUNTIME")"
162 # A .zsync left by an earlier run would hide a missing zsyncmake and describe another file.
163 rm -f "$OUT.zsync"
164 # Update information: AppImageUpdate, AppImageLauncher and the like read it from the file and
165 # fetch only the blocks that changed in a newer release, through the .zsync published next to
166 # each AppImage on GitHub Releases. `latest` is the newest published release that is not a
167 # pre-release. A fork's builds point at its own releases through GITHUB_REPOSITORY.
168 REPO="${GITHUB_REPOSITORY:-danieldaeschle/rusty-teams}"
169 UPDATE_INFO="gh-releases-zsync|${REPO%%/*}|${REPO#*/}|latest|rusty-teams-*-linux-$ARCH.AppImage.zsync"
170 # Extract-and-run: works without FUSE (containers, CI). The output embeds the static runtime,
171 # so users don't need libfuse2 either. With zsyncmake on the host appimagetool also writes the
172 # .zsync, into its working directory, hence the cd.
173 (cd "$DIST" && ARCH="$ARCH" APPIMAGE_EXTRACT_AND_RUN=1 "$TOOL" --no-appstream \
174 --runtime-file "$RUNTIME" -u "$UPDATE_INFO" "$APPDIR" "$OUT")
175 echo "wrote $OUT"
176 if [[ -s "$OUT.zsync" ]]; then
177 echo "wrote $OUT.zsync"
178 else
179 warn "zsyncmake not found, so $OUT.zsync was not written; AppImage delta updates need it"
180 fi
181fi
182
183echo "==> done"
184ls -lh "$DIST"