Files
betterbird-packaging/build-betterbird-deb.sh
T
2026-11-12 09:17:31 +00:00

237 lines
9.3 KiB
Bash

#!/usr/bin/env bash
#
# build-betterbird-deb.sh
#
# Downloads the latest official Betterbird Linux release (.tar.gz, .tar.bz2, or .tar.xz)
# and repackages it UNMODIFIED into a single .deb for Ubuntu 22.04 to 26.10+.
#
# Run it on Ubuntu 22.04 (the oldest supported release) to ensure compatibility:
# docker run --rm -v "$PWD":/work -w /work ubuntu:22.04 ./build-betterbird-deb.sh
#
# The script uses the official .desktop file from the Betterbird repository.
set -euo pipefail
MAINTAINER="${MAINTAINER:-New Life Linux <[email protected]>}"
BB_LANG="${BB_LANG:-en-US}"
DEB_REVISION_SUFFIX="${DEB_REVISION_SUFFIX:-}"
TEST_RELEASES="${TEST_RELEASES:-22.04 24.04 26.04 26.10}"
FORCE="${FORCE:-0}"
WORK="${WORK:-$PWD/work}"
OUT="${OUT:-$PWD/out}"
BASELINE_GLIBC="2.35" # glibc of Ubuntu 22.04; the .deb must not require more
RUN_TEST=0
[[ "${1:-}" == "--test" ]] && RUN_TEST=1
die() { echo "ERROR: $*" >&2; exit 1; }
log() { echo "==> $*"; }
# ---------------------------------------------------------------- preflight
. /etc/os-release
if [[ "${ID:-}" != "ubuntu" || "${VERSION_ID:-}" != "22.04" ]] && [[ "$FORCE" != "1" ]]; then
die "Build on Ubuntu 22.04 so the dependencies stay compatible with every release (this is ${PRETTY_NAME:-unknown}). Use a container, or set FORCE=1."
fi
# Build tools (installed automatically if missing, see below)
TOOL_PKGS=(ca-certificates wget xz-utils file dpkg-dev binutils coreutils diffutils)
# Libraries the Betterbird binaries link against. dpkg-shlibdeps can only turn a
# library into a Depends entry if the providing package is installed here.
BUILD_LIBS=(
libgtk-3-0 libglib2.0-0 libdbus-glib-1-2 libdbus-1-3 libasound2
libx11-xcb1 libxcb1 libxtst6 libxt6 libxcomposite1 libxdamage1 libxrandr2
libxcursor1 libxi6 libxfixes3 libxext6 libxrender1
libpango-1.0-0 libcairo2 libgdk-pixbuf-2.0-0 libfontconfig1 libfreetype6
libatk1.0-0 libatk-bridge2.0-0
)
missing=()
for p in "${TOOL_PKGS[@]}" "${BUILD_LIBS[@]}"; do
dpkg -s "$p" >/dev/null 2>&1 || missing+=("$p")
done
if ((${#missing[@]})); then
log "Installing missing packages: ${missing[*]}"
SUDO=""
if [[ $EUID -ne 0 ]]; then
command -v sudo >/dev/null || die "run as root or install sudo (needed to install: ${missing[*]})"
SUDO="sudo"
fi
$SUDO apt-get update
$SUDO apt-get install -y "${missing[@]}" || die "could not install: ${missing[*]}"
fi
for cmd in wget tar xz file dpkg-shlibdeps dpkg-deb objdump sha256sum diff md5sum; do
command -v "$cmd" >/dev/null || die "missing tool '$cmd'"
done
# ----------------------------------------------------------------- download
rm -rf "$WORK"
mkdir -p "$WORK/dl" "$OUT"
# the build needs roughly 1.2 GB
avail_kb="$(df -Pk "$WORK" | awk 'NR==2 {print $4}')"
if (( avail_kb < 1200000 )); then
die "only $((avail_kb / 1024)) MB free in $WORK, at least 1200 MB are needed."
fi
log "Downloading the latest Betterbird (${BB_LANG}) release"
URL="https://www.betterbird.eu/downloads/get.php?os=linux&lang=${BB_LANG}&version=release"
( cd "$WORK/dl" && wget --trust-server-names "$URL" )
# Accept tar.gz, tar.bz2, or tar.xz
TARBALL="$(cd "$WORK/dl" && ls betterbird-*.linux-x86_64.tar.* 2>/dev/null | head -n1 || true)"
[[ -n "$TARBALL" ]] || die "download did not produce a betterbird-*.linux-x86_64.tar.* file"
log "Got $TARBALL"
# betterbird-140.11.0esr-bb23.en-US.linux-x86_64.tar.xz -> 140.11.0esr-bb23
base="${TARBALL#betterbird-}"
UPVER="${base%%.${BB_LANG}.linux-x86_64*}"
[[ "$UPVER" =~ ^[0-9][0-9A-Za-z.+~-]*$ ]] || die "cannot derive a version from '$TARBALL'"
VERSION="${UPVER}${DEB_REVISION_SUFFIX}"
log "Package version: $VERSION"
# verify the download against the official checksum list
MAJOR="${UPVER%%.*}"
if wget -q -O "$WORK/dl/sha256-${MAJOR}.txt" "https://www.betterbird.eu/downloads/sha256-${MAJOR}.txt"; then
expected="$(grep -F "$TARBALL" "$WORK/dl/sha256-${MAJOR}.txt" | grep -oE '[0-9a-f]{64}' | head -n1 || true)"
actual="$(sha256sum "$WORK/dl/$TARBALL" | cut -d' ' -f1)"
if [[ -z "$expected" ]]; then
echo "WARNING: $TARBALL is not listed in sha256-${MAJOR}.txt, checksum NOT verified" >&2
elif [[ "$expected" == "$actual" ]]; then
log "sha256 matches the official list"
else
die "sha256 mismatch for $TARBALL (expected $expected, got $actual)"
fi
else
echo "WARNING: could not download the official checksum list, compare the sha256 manually" >&2
fi
# ------------------------------------------------------------ package tree
PKG="$WORK/pkg/betterbird_${VERSION}_amd64"
mkdir -p "$PKG"/{DEBIAN,opt,usr/bin,usr/share/applications}
tar -xf "$WORK/dl/$TARBALL" -C "$PKG/opt"
APPDIR="$PKG/opt/betterbird"
[[ -d "$APPDIR" ]] || die "tarball does not contain a 'betterbird' directory"
[[ -f "$APPDIR/betterbird-bin" ]] || die "betterbird-bin not found in the tarball"
if [[ -f "$APPDIR/betterbird" ]]; then LAUNCHER="betterbird"; else LAUNCHER="betterbird-bin"; fi
ln -s "/opt/betterbird/$LAUNCHER" "$PKG/usr/bin/betterbird"
# icons (copied and renamed to match the official .desktop file)
for s in 16 32 48 64 128 256; do
src="$APPDIR/chrome/icons/default/default${s}.png"
if [[ -f "$src" ]]; then
install -Dm644 "$src" "$PKG/usr/share/icons/hicolor/${s}x${s}/apps/eu.betterbird.Betterbird.png"
fi
done
# Download the official .desktop file directly from the Betterbird repository for proper integration
log "Downloading official .desktop file from Betterbird repo"
DESKTOP_URL="https://raw.githubusercontent.com/Betterbird/thunderbird-patches/main/metadata/eu.betterbird.Betterbird.desktop"
if wget -q -O "$PKG/usr/share/applications/eu.betterbird.Betterbird.desktop" "$DESKTOP_URL"; then
log "Got official .desktop file"
else
die "Failed to download the official .desktop file from $DESKTOP_URL"
fi
# ------------------------------------------------- dependencies from binaries
log "Deriving dependencies with dpkg-shlibdeps"
SD="$WORK/shlibdeps"
mkdir -p "$SD/debian"
cat > "$SD/debian/control" <<EOF
Source: betterbird
Maintainer: $MAINTAINER
Package: betterbird
Architecture: amd64
EOF
ARGS=()
while IFS= read -r -d '' f; do
if [[ "$(file -b -- "$f")" == ELF* ]]; then ARGS+=("-e$f"); fi
done < <(find "$APPDIR" -type f -print0)
((${#ARGS[@]})) || die "no ELF files found"
( cd "$SD" && dpkg-shlibdeps -O --ignore-missing-info -l"$APPDIR" "${ARGS[@]}" ) \
> "$SD/out" 2> "$SD/err" || { cat "$SD/err" >&2; die "dpkg-shlibdeps failed"; }
if grep -q . "$SD/err"; then
echo "--- dpkg-shlibdeps warnings (review them) ---" >&2
sort -u "$SD/err" | head -n 30 >&2
echo "---------------------------------------------" >&2
fi
DEPS="$(sed -n 's/^shlibs:Depends=//p' "$SD/out")"
[[ -n "$DEPS" ]] || die "dpkg-shlibdeps produced no dependencies"
log "Depends: $DEPS"
# sanity checks
[[ "$DEPS" == *libc6* && "$DEPS" == *libgtk-3-0* ]] || die "Depends misses libc6 or libgtk-3-0"
if [[ "$DEPS" =~ libc6\ \(\>=\ ([0-9.]+) ]]; then
if dpkg --compare-versions "${BASH_REMATCH[1]}" gt "$BASELINE_GLIBC"; then
die "package would require libc6 >= ${BASH_REMATCH[1]}, which Ubuntu 22.04 does not have; build on 22.04"
fi
fi
# ----------------------------------------------------------- control + build
INSTALLED_SIZE="$(du -sk --exclude=DEBIAN "$PKG" | cut -f1)"
cat > "$PKG/DEBIAN/control" <<EOF
Package: betterbird
Version: ${VERSION}
Architecture: amd64
Maintainer: ${MAINTAINER}
Installed-Size: ${INSTALLED_SIZE}
Depends: ${DEPS}
Section: mail
Priority: optional
Homepage: https://www.betterbird.eu
Description: Betterbird - unofficial repackage of the upstream release
Betterbird is a fine-tuned version of Mozilla Thunderbird.
.
This package repackages the upstream ${TARBALL} release unchanged
under /opt/betterbird. It is not an official Betterbird package.
EOF
( cd "$PKG" && find . -path ./DEBIAN -prune -o -type f -print0 \
| xargs -0 md5sum | sed 's| \./| |' ) > "$PKG/DEBIAN/md5sums"
find "$PKG" -type d -exec chmod 755 {} +
DEB="$OUT/betterbird_${VERSION}_amd64.deb"
log "Building $DEB"
dpkg-deb --root-owner-group -Zxz --build "$PKG" "$DEB" >/dev/null
# ----------------------------------------------------------- verification
log "Verifying that /opt/betterbird is identical to the upstream tarball"
rm -rf "$WORK/verify" && mkdir -p "$WORK/verify"
dpkg-deb -x "$DEB" "$WORK/verify"
diff -r "$APPDIR" "$WORK/verify/opt/betterbird" >/dev/null \
|| die "package content differs from the upstream tarball"
echo " identical"
# Generate a single, unified SHA256SUMS file for easier verification
( cd "$WORK/dl" && sha256sum "$TARBALL" ) > "$OUT/SHA256SUMS"
( cd "$OUT" && sha256sum "$(basename "$DEB")" ) >> "$OUT/SHA256SUMS"
log "Unified SHA256 Checksums generated:"
cat "$OUT/SHA256SUMS"
# -------------------------------------------------------------- docker test
if ((RUN_TEST)); then
command -v docker >/dev/null || die "--test needs docker"
fail=0
for rel in $TEST_RELEASES; do
log "Test install on Ubuntu $rel"
if docker run --rm -v "$OUT":/pkg:ro -e DEBNAME="$(basename "$DEB")" "ubuntu:$rel" bash -euc '
export DEBIAN_FRONTEND=noninteractive
apt-get update -qq >/dev/null
apt-get install -y -qq "/pkg/$DEBNAME" >/dev/null
miss="$(LD_LIBRARY_PATH=/opt/betterbird ldd /opt/betterbird/betterbird-bin | grep "not found" || true)"
if [ -n "$miss" ]; then echo "unresolved libraries:"; echo "$miss"; exit 1; fi
echo " OK"
'; then :; else echo " FAILED on $rel" >&2; fail=1; fi
done
((fail == 0)) || die "install test failed on at least one release"
fi
log "Done: $DEB"