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