196 lines
8.1 KiB
Shell
Executable file
196 lines
8.1 KiB
Shell
Executable file
#!/usr/bin/env bash
|
|
# Build the .deb, .rpm and Arch .pkg.tar.zst packages inside an ubuntu:24.04 container.
|
|
# The binary links against glibc 2.39, so the packages also run on newer
|
|
# systems (Debian 13, Ubuntu 25.x, Fedora, Arch). All three packages hold the same
|
|
# files; only the metadata and the dependency names differ.
|
|
# Output: dist/korterm_<version>_<arch>.deb, dist/korterm-<version>-1.<arch>.rpm,
|
|
# dist/korterm-<version>-1-<arch>.pkg.tar.zst (a hyphen in <version> becomes ~ in rpm, _ in Arch)
|
|
#
|
|
# Usage: scripts/build-packages.sh (run on the host, needs Docker)
|
|
set -euo pipefail
|
|
|
|
IMAGE="${DEB_IMAGE:-ubuntu:24.04}"
|
|
APP_ID="me.r4ven.KorTerm"
|
|
|
|
if [[ "${1:-}" != "--inside" ]]; then
|
|
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
mkdir -p "$root/dist"
|
|
# Named volumes keep the cargo cache and build output between runs.
|
|
docker run --rm \
|
|
-v "$root:/src:ro" \
|
|
-v "$root/dist:/out" \
|
|
-v korterm-deb-cargo:/root/.cargo \
|
|
-v korterm-deb-target:/build/target \
|
|
-e HOST_UID="$(id -u)" -e HOST_GID="$(id -g)" \
|
|
"$IMAGE" bash /src/scripts/build-packages.sh --inside
|
|
ls -l "$root"/dist/*.deb "$root"/dist/*.rpm "$root"/dist/*.pkg.tar.zst
|
|
exit 0
|
|
fi
|
|
|
|
# ---- inside the container ----
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
apt-get update -qq
|
|
apt-get install -y -qq --no-install-recommends \
|
|
build-essential dpkg-dev ca-certificates curl pkg-config \
|
|
libgtk-4-dev libfontconfig-dev libfreetype-dev libgl-dev \
|
|
rpm libarchive-tools zstd
|
|
|
|
# Keep the toolchain inside the cached cargo volume.
|
|
export RUSTUP_HOME=/root/.cargo/rustup
|
|
if [[ ! -d "$RUSTUP_HOME/toolchains" ]]; then
|
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
|
|
| sh -s -- -y --profile minimal
|
|
fi
|
|
export PATH="/root/.cargo/bin:$PATH"
|
|
|
|
# Copy sources so the read-only mount stays clean and target/ is not used.
|
|
rm -rf /build/src
|
|
mkdir -p /build/src
|
|
(cd /src && tar --exclude=./target --exclude=./dist --exclude=./.git -cf - .) | tar -xf - -C /build/src
|
|
cd /build/src
|
|
export CARGO_TARGET_DIR=/build/target
|
|
cargo build --release --locked
|
|
|
|
# Notices of the Rust dependencies. cargo-about fails on a licence that
|
|
# packaging/about.toml does not accept, so a new one cannot slip in unseen.
|
|
command -v cargo-about >/dev/null || cargo install cargo-about --locked --features cli
|
|
cargo about generate --locked --fail -c packaging/about.toml packaging/about.hbs \
|
|
> /build/THIRD_PARTY_NOTICES.txt
|
|
|
|
version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)"
|
|
arch="$(dpkg --print-architecture)"
|
|
pkg="/build/pkg"
|
|
rm -rf "$pkg"
|
|
|
|
install -Dm755 /build/target/release/korterm "$pkg/usr/bin/korterm"
|
|
install -d "$pkg/usr/share/applications"
|
|
sed '/^#/!s|@BINDIR@|/usr/bin|g' "data/$APP_ID.desktop" > "$pkg/usr/share/applications/$APP_ID.desktop"
|
|
chmod 644 "$pkg/usr/share/applications/$APP_ID.desktop"
|
|
for s in 16 22 24 32 48 64; do
|
|
install -Dm644 "data/icons/${s}x${s}.png" "$pkg/usr/share/icons/hicolor/${s}x${s}/apps/$APP_ID.png"
|
|
install -Dm644 "data/icons/tray-${s}x${s}.png" "$pkg/usr/share/icons/hicolor/${s}x${s}/apps/$APP_ID-tray.png"
|
|
done
|
|
install -Dm644 "data/$APP_ID.png" "$pkg/usr/share/icons/hicolor/512x512/apps/$APP_ID.png"
|
|
install -Dm644 LICENSE "$pkg/usr/share/doc/korterm/copyright"
|
|
install -Dm644 THIRD_PARTY_LICENSES.md "$pkg/usr/share/doc/korterm/THIRD_PARTY_LICENSES.md"
|
|
for f in Regular Bold Italic BoldItalic; do
|
|
install -Dm644 "packaging/fonts/HackNerdFontMono-$f.ttf" \
|
|
"$pkg/usr/share/fonts/truetype/korterm/HackNerdFontMono-$f.ttf"
|
|
done
|
|
install -Dm644 packaging/fonts/LICENSE.md "$pkg/usr/share/doc/korterm/Hack-Nerd-Font-LICENSE.md"
|
|
install -Dm644 /build/THIRD_PARTY_NOTICES.txt "$pkg/usr/share/doc/korterm/THIRD_PARTY_NOTICES.txt"
|
|
install -Dm644 packaging/bundled-c-notices.txt "$pkg/usr/share/doc/korterm/bundled-c-notices.txt"
|
|
install -Dm644 crates/korterm-ui/resources/tabler/LICENSE "$pkg/usr/share/doc/korterm/Tabler-Icons-LICENSE"
|
|
|
|
# Compute runtime dependencies from the real binary.
|
|
mkdir -p /build/shl/debian
|
|
printf 'Source: korterm\n\nPackage: korterm\nArchitecture: any\n' > /build/shl/debian/control
|
|
depends="$(cd /build/shl && dpkg-shlibdeps -O -e"$pkg/usr/bin/korterm" 2>/dev/null | sed 's/^shlibs:Depends=//')"
|
|
|
|
size="$(du -sk "$pkg" | cut -f1)"
|
|
install -d "$pkg/DEBIAN"
|
|
cat > "$pkg/DEBIAN/control" <<EOF
|
|
Package: korterm
|
|
Version: $version
|
|
Section: x11
|
|
Priority: optional
|
|
Architecture: $arch
|
|
Installed-Size: $size
|
|
Depends: $depends, librsvg2-common, fonts-dejavu-core|fonts-dejavu
|
|
Maintainer: Ivan Cherniy <noreply@r4ven.me>
|
|
Homepage: https://git.r4ven.me/ivan/korterm
|
|
Description: KorTerm, a terminal emulator with GPU rendering
|
|
Terminal emulator with OpenGL rendering, tabs, splits, profiles,
|
|
colour themes, SSH host groups and session recording.
|
|
EOF
|
|
|
|
# Refresh the icon and menu caches. Without this, desktops that ship a
|
|
# hicolor icon-theme.cache (Linux Mint) show a generic icon for the new entry.
|
|
for script in postinst postrm; do
|
|
cat > "$pkg/DEBIAN/$script" <<'EOF'
|
|
#!/bin/sh
|
|
set -e
|
|
if [ -f /usr/share/icons/hicolor/index.theme ] && command -v gtk-update-icon-cache >/dev/null 2>&1; then
|
|
gtk-update-icon-cache -q -t -f /usr/share/icons/hicolor || true
|
|
fi
|
|
if command -v fc-cache >/dev/null 2>&1; then
|
|
fc-cache -f /usr/share/fonts/truetype/korterm || true
|
|
fi
|
|
if command -v update-desktop-database >/dev/null 2>&1; then
|
|
update-desktop-database -q /usr/share/applications || true
|
|
fi
|
|
exit 0
|
|
EOF
|
|
chmod 755 "$pkg/DEBIAN/$script"
|
|
done
|
|
|
|
dpkg-deb --root-owner-group --build "$pkg" "/out/korterm_${version}_${arch}.deb"
|
|
chown "$HOST_UID:$HOST_GID" "/out/korterm_${version}_${arch}.deb"
|
|
|
|
# ---- rpm: the same files, dependencies as sonames of the real binary ----
|
|
machine="$(uname -m)"
|
|
# A hyphen splits version and release in rpm and Arch: 0.4.0-rc1 becomes 0.4.0~rc1 (rpm,
|
|
# sorts before 0.4.0) and 0.4.0_rc1 (Arch).
|
|
rpm_version="${version//-/"~"}"
|
|
arch_version="${version//-/_}"
|
|
rpm_root="/build/rpmroot"
|
|
rm -rf "$rpm_root" /build/rpmbuild
|
|
mkdir -p "$rpm_root"
|
|
(cd "$pkg" && tar --exclude=./DEBIAN -cf - .) | tar -xf - -C "$rpm_root"
|
|
needed="$(readelf -d /build/target/release/korterm | sed -n 's/.*Shared library: \[\(.*\)\]/\1/p')"
|
|
spec=/build/korterm.spec
|
|
{
|
|
cat <<EOF
|
|
Name: korterm
|
|
Version: $rpm_version
|
|
Release: 1
|
|
Summary: KorTerm, a terminal emulator with GPU rendering
|
|
License: GPL-3.0-or-later
|
|
URL: https://git.r4ven.me/ivan/korterm
|
|
BuildArch: $machine
|
|
AutoReqProv: no
|
|
Requires: librsvg2
|
|
Requires: dejavu-sans-fonts
|
|
EOF
|
|
for lib in $needed; do echo "Requires: $lib()(64bit)"; done
|
|
cat <<EOF
|
|
%description
|
|
Terminal emulator with OpenGL rendering, tabs, splits, profiles,
|
|
colour themes, SSH host groups and session recording.
|
|
%install
|
|
mkdir -p %{buildroot}
|
|
cp -a $rpm_root/. %{buildroot}/
|
|
%files
|
|
%dir /usr/share/doc/korterm
|
|
%dir /usr/share/fonts/truetype/korterm
|
|
EOF
|
|
(cd "$rpm_root" && find usr -type f | sed 's|^|/|')
|
|
} > "$spec"
|
|
rpmbuild -bb --quiet --define "_topdir /build/rpmbuild" --define "_dbpath /build/rpmdb" \
|
|
--define "_binary_payload w9.gzdio" --define "debug_package %{nil}" \
|
|
--define "__os_install_post %{nil}" --define "_build_id_links none" "$spec"
|
|
rpm_file="korterm-${rpm_version}-1.${machine}.rpm"
|
|
install -m644 "/build/rpmbuild/RPMS/${machine}/${rpm_file}" "/out/${rpm_file}"
|
|
chown "$HOST_UID:$HOST_GID" "/out/${rpm_file}"
|
|
|
|
# ---- Arch: a zstd tar with a .PKGINFO file ----
|
|
arch_root="/build/archroot"
|
|
rm -rf "$arch_root"
|
|
mkdir -p "$arch_root"
|
|
cp -a "$rpm_root/." "$arch_root/"
|
|
{
|
|
echo "pkgname = korterm"
|
|
echo "pkgbase = korterm"
|
|
echo "pkgver = ${arch_version}-1"
|
|
echo "pkgdesc = KorTerm, a terminal emulator with GPU rendering"
|
|
echo "url = https://git.r4ven.me/ivan/korterm"
|
|
echo "builddate = $(date +%s)"
|
|
echo "packager = Ivan Cherniy <noreply@r4ven.me>"
|
|
echo "size = $(du -sb "$arch_root" | cut -f1)"
|
|
echo "arch = $machine"
|
|
echo "license = GPL-3.0-or-later"
|
|
for dep in gtk4 fontconfig freetype2 libglvnd librsvg ttf-dejavu; do echo "depend = $dep"; done
|
|
} > "$arch_root/.PKGINFO"
|
|
arch_file="korterm-${arch_version}-1-${machine}.pkg.tar.zst"
|
|
(cd "$arch_root" && bsdtar --uid 0 --gid 0 --numeric-owner --zstd -cf "/out/${arch_file}" .PKGINFO usr)
|
|
chown "$HOST_UID:$HOST_GID" "/out/${arch_file}"
|