#!/usr/bin/env bash # Package Getǣl as a Debian/Ubuntu .deb package using cargo-deb. # # On Linux, builds natively by default (pass --docker to build in a Debian container). # On macOS, automatically builds inside a Debian container via Docker/Colima. # # Usage: # ./scripts/package-linux-deb.sh [--arch amd64|arm64] [--out-dir ./dist] [--docker] set -euo pipefail ARCH="" OUT_DIR="./dist" USE_DOCKER=false while [[ $# -gt 0 ]]; do case "$1" in --arch) ARCH="${2:-}" shift 2 ;; --out-dir) OUT_DIR="${2:-}" shift 2 ;; --docker) USE_DOCKER=true shift ;; -h|--help) sed -n '2,8p' "$0" exit 0 ;; *) echo "error: unknown argument '$1'" >&2 exit 1 ;; esac done if [[ "$(uname -s)" == "Darwin" ]]; then USE_DOCKER=true fi if [[ -z "$ARCH" ]]; then case "$(uname -m)" in x86_64|amd64) ARCH="amd64" ;; aarch64|arm64) ARCH="arm64" ;; *) echo "error: unsupported host architecture '$(uname -m)'; specify --arch amd64 or --arch arm64" >&2 exit 1 ;; esac fi case "$ARCH" in amd64) TARGET="x86_64-unknown-linux-gnu" DOCKER_PLATFORM="linux/amd64" ;; arm64) TARGET="aarch64-unknown-linux-gnu" DOCKER_PLATFORM="linux/arm64" ;; *) echo "error: unsupported --arch '$ARCH' (expected amd64 or arm64)" >&2 exit 1 ;; esac REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$REPO_ROOT" VERSION="$(awk -F'"' '/^version = / { print $2; exit }' Cargo.toml)" if [[ -z "$VERSION" ]]; then echo "error: unable to read version from Cargo.toml" >&2 exit 1 fi if [[ ! -f "icons/icon.png" ]]; then python3 scripts/make_icons.py fi if [[ ! -f "web/dist/index.html" ]]; then (cd web && npm ci && npm run build) fi export GETAEL_SKIP_WEB_BUILD=1 mkdir -p "$OUT_DIR" OUT_DIR="$(cd "$OUT_DIR" && pwd)" DEB_NAME="GetAel-v${VERSION}-linux-${ARCH}.deb" DEB_PATH="$OUT_DIR/$DEB_NAME" if [[ "$USE_DOCKER" == "true" ]]; then if ! command -v docker >/dev/null 2>&1; then echo "error: docker is required to build Linux .deb packages from $(uname -s)" >&2 exit 1 fi if ! docker info >/dev/null 2>&1; then echo "error: docker daemon is not running (run 'colima start' or start Docker Desktop)" >&2 exit 1 fi docker run --rm \ --platform "$DOCKER_PLATFORM" \ -v "$REPO_ROOT:/work" \ -v "$OUT_DIR:/out" \ -v "getael-deb-cargo-cache-${ARCH}:/usr/local/cargo/registry" \ -v "getael-deb-cargo-bin-${ARCH}:/opt/cargo-bin" \ -v "getael-deb-target-${ARCH}:/work/target" \ -w /work \ -e GETAEL_SKIP_WEB_BUILD=1 \ -e DEB_NAME="$DEB_NAME" \ rust:1-bookworm \ bash -euo pipefail -c ' export PATH="/opt/cargo-bin/bin:$PATH" apt-get update DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ pkg-config libgtk-3-dev libayatana-appindicator3-dev libxdo-dev if ! command -v cargo-deb >/dev/null 2>&1; then cargo install cargo-deb --locked --root /opt/cargo-bin fi cargo build --release --bin getael --bin getael-tray cargo deb --no-build --output "/out/$DEB_NAME" dpkg-deb --info "/out/$DEB_NAME" dpkg-deb --contents "/out/$DEB_NAME" ' else if ! command -v cargo-deb >/dev/null 2>&1; then echo "error: cargo-deb is not installed. Install via 'cargo install cargo-deb'." >&2 exit 1 fi cargo build --release --target "$TARGET" --bin getael --bin getael-tray cargo deb --no-build --target "$TARGET" --output "$DEB_PATH" if command -v dpkg-deb >/dev/null 2>&1; then dpkg-deb --info "$DEB_PATH" dpkg-deb --contents "$DEB_PATH" fi fi if command -v sha256sum >/dev/null 2>&1; then (cd "$OUT_DIR" && sha256sum "$DEB_NAME" > "${DEB_NAME}.sha256") elif command -v shasum >/dev/null 2>&1; then (cd "$OUT_DIR" && shasum -a 256 "$DEB_NAME" > "${DEB_NAME}.sha256") fi echo "Created $DEB_PATH" cat "$OUT_DIR/${DEB_NAME}.sha256"