#!/bin/bash # Tunal release packages. Run: tools/package.sh (see the common part below for what it makes) # packaging/arch/ stays the build-from-this-checkout PKGBUILD; packaging/arch-bin/ is the release package (tunal-bin). set -euo pipefail root=$(cd "$(dirname "$0")/.." && pwd) APP=tunal NAME=Tunal DESKTOP=tunal.desktop PKGDIR=packaging/arch-bin BINS=(tunal) ver=$(sed -n 's/^version = "\(.*\)"/\1/p' "$root/Cargo.toml" | head -n 1) build() { nice cargo build --release --locked -q -j 2 -p tunal; } # share/ as it lands under the prefix. The polkit policy only works under /usr (the Arch package). stage() { local s=$1 install -Dm644 assets/tunal.desktop "$s/applications/tunal.desktop" install -Dm644 assets/tunal.svg "$s/icons/hicolor/scalable/apps/tunal.svg" install -Dm644 assets/tunal.png "$s/icons/hicolor/256x256/apps/tunal.png" install -Dm644 assets/polkit/org.tunal.Tunal.elevated-helper.policy "$s/polkit-1/actions/org.tunal.Tunal.elevated-helper.policy" install -Dm644 assets/fonts/LICENSE "$s/licenses/tunal/fonts-LICENSE" } # ---------------------------------------------------------------- common part (same in every project) # Builds into dist/: $NAME--Linux-x86_64.tar.gz (install.sh, uninstall.sh), $NAME--x86_64.AppImage (GUI only), # $NAME--arch-x86_64.pkg.tar.zst (makepkg from that tar.gz, offline) and SHA256SUMS-. # It also writes the tar.gz checksum and version into $PKGDIR/PKGBUILD and .SRCINFO, and the glibc floor read # from the binary into installer.sh and the PKGBUILD. Nothing is downloaded: appimagetool comes from # ~/.local/opt/build-tools and runs extracted (no FUSE, no runtime fetch). Never writes to releases/. # SKIP_BUILD=1 packages the existing build. CARGO_TARGET_DIR is honoured. cd "$root"; PKGDIR=${PKGDIR:-packaging/arch} [ "${SKIP_BUILD:-}" = 1 ] || build rel=${CARGO_TARGET_DIR:-$root/target}/release out=$root/dist work=$(mktemp -d); trap 'rm -rf "$work"' EXIT export SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH:-$(git log -1 --format=%ct 2>/dev/null || date +%s)} # glibc floor: the newest GLIBC_x.y symbol version any shipped binary (or EXTRA_ELF library) needs. glibc=$(for b in "${BINS[@]}" ${EXTRA_ELF[@]+"${EXTRA_ELF[@]}"}; do objdump -T "$rel/$b"; done | grep -o 'GLIBC_[0-9.]*' | sed 's/GLIBC_//' | sort -uV | tail -n 1) [ -n "$glibc" ] || { echo "could not read the glibc version from the binary" >&2; exit 1; } sed -i "s/^app=$APP main=\([^ ]*\) need=.*/app=$APP main=\1 need=$glibc/; s/glibc [0-9.]* or newer\./glibc $glibc or newer./" installer.sh sed -i "s/'glibc>=[0-9.]*'/'glibc>=$glibc'/" $PKGDIR/PKGBUILD # tar.gz: bin/ and share/ laid out like a prefix, so installer.sh and the PKGBUILD just copy them. rm -rf "$out"; mkdir -p "$out" t=$work/$APP-$ver mkdir -p "$t/bin" "$t/share" # stage may add $t/lib too for b in "${BINS[@]}"; do install -m755 "$rel/$b" "$t/bin/$b"; done stage "$t/share" install -m755 installer.sh "$t/install.sh" printf '#!/bin/sh\n# Removes %s installed by install.sh. --purge also deletes settings and data; --system or --prefix DIR as for install.sh.\nexec sh "$(dirname "$0")/install.sh" --uninstall "$@"\n' "$NAME" > "$t/uninstall.sh" chmod 755 "$t/uninstall.sh" cp README.md "$t/" find "$t" -exec touch -h -d "@$SOURCE_DATE_EPOCH" {} + tgz=$NAME-$ver-Linux-x86_64.tar.gz tar -C "$work" --sort=name --owner=0 --group=0 --numeric-owner -cf - "$APP-$ver" | gzip -n -9 > "$out/$tgz" # AppImage (GUI apps): the same tree under usr/, desktop file and icon at the top. if [ -n "${DESKTOP:-}" ]; then a=$work/AppDir mkdir -p "$a/usr" cp -R "$t/bin" "$t/share" "$a/usr/"; [ ! -d "$t/lib" ] || cp -R "$t/lib" "$a/usr/" cp "$a/usr/share/applications/$DESKTOP" "$a/" icon=$(sed -n 's/^Icon=//p' "$a/$DESKTOP" | head -n 1) for ext in svg png; do f=$(find "$a/usr/share/icons" -name "$icon.$ext" | sort -V | tail -n 1) [ -n "$f" ] && { cp "$f" "$a/$icon.$ext"; break; } done cat > "$a/AppRun" </dev/null; then appdir_hook "$a"; fi # project extras (bundled libraries) cp ~/.local/opt/build-tools/appimagetool "$work/appimagetool" (cd "$work" && ./appimagetool --appimage-extract >/dev/null) ARCH=x86_64 "$work/squashfs-root/AppRun" --no-appstream "$a" "$out/$NAME-$ver-x86_64.AppImage" >"$work/ait.log" 2>&1 \ || { tail -20 "$work/ait.log"; exit 1; } fi # Arch package from the local tar.gz; the repo's PKGBUILD gets this version and checksum. sum=$(sha256sum "$out/$tgz" | cut -d' ' -f1) sed -i "s/^pkgver=.*/pkgver=$ver/; s/^sha256sums=.*/sha256sums=('$sum')/" $PKGDIR/PKGBUILD mkdir "$work/arch"; cp $PKGDIR/PKGBUILD "$work/arch/" (cd "$work/arch" && makepkg --printsrcinfo > "$root/$PKGDIR/.SRCINFO") (cd "$work/arch" && TARBALL="file://$out/$tgz" makepkg -f -C --nodeps --noconfirm >"$work/makepkg.log" 2>&1) \ || { tail -20 "$work/makepkg.log"; exit 1; } cp "$work"/arch/"$APP"-bin-"$ver"-*-x86_64.pkg.tar.zst "$out/$NAME-$ver-arch-x86_64.pkg.tar.zst" (cd "$out" && sha256sum "$NAME-$ver"-* > "SHA256SUMS-$ver") echo "glibc floor: $glibc" ls -l "$out"