BlueGit

ict rusty-teams

Files

rusty-teams / packaging / linux / package.sh

package.sh

package.sh 8.9 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 # pacman names the architecture x86_64/aarch64, not the Debian amd64/arm64.
103 export NFPM_PACMAN_ARCH="$ARCH"
104 # nfpm expands env vars in fields like `version` and `arch`, but not in `contents[].src` or
105 # the dependency lists.
106 sed -e "s|\${STAGE}|$STAGE|g" -e "s|\${GLIBC_MIN}|$GLIBC_MIN|g" "$HERE/nfpm.yaml" >"$WORK/nfpm.yaml"
107 for fmt in deb rpm; do
108 if has "$fmt"; then (cd "$ROOT" && nfpm package -f "$WORK/nfpm.yaml" -p "$fmt" -t "$DIST/$BASENAME.$fmt"); fi
109 done
110 if has archlinux; then
111 (cd "$ROOT" && nfpm package -f "$WORK/nfpm.yaml" -p archlinux -t "$DIST/$BASENAME.pkg.tar.zst")
112 fi
113fi
114
115# ---- AppImage -----------------------------------------------------------------------------------
116if has appimage; then
117 APPDIR="$WORK/RustyTeams.AppDir"
118 cp -R "$STAGE" "$APPDIR"
119 # AppRun is a script, not a symlink: it installs the .desktop entry and icons into
120 # $XDG_DATA_HOME before launching, so Wayland compositors can resolve the window's
121 # app_id to our icon instead of the generic Wayland logo (opt-out env in the script
122 # header). Logic is covered by packaging/linux/apprun-test.sh.
123 install -Dm755 "$HERE/AppRun" "$APPDIR/AppRun"
124 cp "$HERE/$DESKTOP_ID.desktop" "$APPDIR/$DESKTOP_ID.desktop"
125 cp "$HERE/hicolor/256x256/apps/$DESKTOP_ID.png" "$APPDIR/$DESKTOP_ID.png"
126 ln -s "$DESKTOP_ID.png" "$APPDIR/.DirIcon"
127
128 # Digests from the official GitHub release asset metadata:
129 # https://github.com/AppImage/appimagetool/releases/tag/1.9.1
130 # https://github.com/AppImage/type2-runtime/releases/tag/20251108
131 # Keep both pins together:
132 # appimagetool otherwise downloads the mutable latest type2 runtime itself.
133 TOOL_VERSION=1.9.1
134 RUNTIME_VERSION=20251108
135 case "$ARCH" in
136 x86_64)
137 TOOL_SHA256=ed4ce84f0d9caff66f50bcca6ff6f35aae54ce8135408b3fa33abfc3cb384eb0
138 RUNTIME_SHA256=2fca8b443c92510f1483a883f60061ad09b46b978b2631c807cd873a47ec260d
139 ;;
140 aarch64)
141 TOOL_SHA256=f0837e7448a0c1e4e650a93bb3e85802546e60654ef287576f46c71c126a9158
142 RUNTIME_SHA256=00cbdfcf917cc6c0ff6d3347d59e0ca1f7f45a6df1a428a0d6d8a78664d87444
143 ;;
144 esac
145 mkdir -p "$CARGO_TARGET_DIR"
146 TOOL="${APPIMAGETOOL:-$CARGO_TARGET_DIR/appimagetool-$TOOL_VERSION-$ARCH.AppImage}"
147 if [[ -n "${APPIMAGETOOL:-}" ]]; then
148 verify_appimagetool_override "$TOOL" "$TOOL_SHA256" "$TOOL_VERSION" "$ARCH"
149 else
150 download_verified \
151 "https://github.com/AppImage/appimagetool/releases/download/$TOOL_VERSION/appimagetool-$ARCH.AppImage" \
152 "$TOOL" "$TOOL_SHA256" true
153 fi
154 RUNTIME="$CARGO_TARGET_DIR/type2-runtime-$RUNTIME_VERSION-$ARCH"
155 download_verified \
156 "https://github.com/AppImage/type2-runtime/releases/download/$RUNTIME_VERSION/runtime-$ARCH" \
157 "$RUNTIME" "$RUNTIME_SHA256"
158 # Absolute, because appimagetool runs in $DIST below (CARGO_TARGET_DIR or APPIMAGETOOL may be
159 # relative).
160 OUT="$(cd "$DIST" && pwd)/$BASENAME.AppImage"
161 APPDIR="$(cd "$APPDIR" && pwd)"
162 TOOL="$(cd "$(dirname "$TOOL")" && pwd)/$(basename "$TOOL")"
163 RUNTIME="$(cd "$(dirname "$RUNTIME")" && pwd)/$(basename "$RUNTIME")"
164 # A .zsync left by an earlier run would hide a missing zsyncmake and describe another file.
165 rm -f "$OUT.zsync"
166 # Update information: AppImageUpdate, AppImageLauncher and the like read it from the file and
167 # fetch only the blocks that changed in a newer release, through the .zsync published next to
168 # each AppImage on GitHub Releases. `latest` is the newest published release that is not a
169 # pre-release. A fork's builds point at its own releases through GITHUB_REPOSITORY.
170 REPO="${GITHUB_REPOSITORY:-danieldaeschle/rusty-teams}"
171 UPDATE_INFO="gh-releases-zsync|${REPO%%/*}|${REPO#*/}|latest|rusty-teams-*-linux-$ARCH.AppImage.zsync"
172 # Extract-and-run: works without FUSE (containers, CI). The output embeds the static runtime,
173 # so users don't need libfuse2 either. With zsyncmake on the host appimagetool also writes the
174 # .zsync, into its working directory, hence the cd.
175 (cd "$DIST" && ARCH="$ARCH" APPIMAGE_EXTRACT_AND_RUN=1 "$TOOL" --no-appstream \
176 --runtime-file "$RUNTIME" -u "$UPDATE_INFO" "$APPDIR" "$OUT")
177 echo "wrote $OUT"
178 if [[ -s "$OUT.zsync" ]]; then
179 echo "wrote $OUT.zsync"
180 else
181 warn "zsyncmake not found, so $OUT.zsync was not written; AppImage delta updates need it"
182 fi
183fi
184
185echo "==> done"
186ls -lh "$DIST"