From 85df9cbe63a9cb136b1064db76db370a995be168 Mon Sep 17 00:00:00 2001 From: Khoa Vo Date: Thu, 25 Jun 2026 08:21:13 +0700 Subject: [PATCH] Add .deb packaging with maintainer scripts and lintian overrides --- Makefile | 5 ++ packaging/deb/build-deb.sh | 170 +++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100755 packaging/deb/build-deb.sh diff --git a/Makefile b/Makefile index 973fd19..800abce 100644 --- a/Makefile +++ b/Makefile @@ -76,6 +76,11 @@ install-config: cp vietc.toml ~/.config/vietc/config.toml @echo "Config installed to ~/.config/vietc/config.toml" +# Build .deb package (requires dpkg-deb) +deb: + VERSION=$$(grep '^version' engine/Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/') && \ + bash packaging/deb/build-deb.sh "$$VERSION" + # Build AppImage (requires appimagetool or linuxdeploy) appimage: VERSION=$$(grep '^version' engine/Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/') && \ diff --git a/packaging/deb/build-deb.sh b/packaging/deb/build-deb.sh new file mode 100755 index 0000000..1aaa8e4 --- /dev/null +++ b/packaging/deb/build-deb.sh @@ -0,0 +1,170 @@ +#!/usr/bin/env bash +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" +VERSION="${1:-0.1.0}" +PACKAGE="vietc_${VERSION}-1_amd64" +STAGING="$SCRIPT_DIR/$PACKAGE" + +echo "=== Building Viet+ .deb package v${VERSION} ===" + +# Build binaries (all features: x11 + wayland) +echo "[1/5] Building binaries..." +cargo build --release --features "x11,wayland" --manifest-path "$PROJECT_ROOT/Cargo.toml" +(cd "$PROJECT_ROOT/ui" && cargo build --release) +echo " Done." + +# Clean and create staging +echo "[2/5] Creating staging directory..." +rm -rf "$STAGING" +mkdir -p "$STAGING/DEBIAN" +mkdir -p "$STAGING/usr/bin" +mkdir -p "$STAGING/usr/lib/systemd/user" +mkdir -p "$STAGING/etc/vietc" +mkdir -p "$STAGING/usr/share/applications" +mkdir -p "$STAGING/usr/share/icons/hicolor/256x256/apps" +mkdir -p "$STAGING/usr/share/doc/vietc" +mkdir -p "$STAGING/usr/share/metainfo" + +# Copy binaries +echo "[3/5] Installing binaries..." +cp "$PROJECT_ROOT/target/release/vietc" "$STAGING/usr/bin/" +cp "$PROJECT_ROOT/target/release/vietc-cli" "$STAGING/usr/bin/" +[ -f "$PROJECT_ROOT/ui/target/release/vietc-tray" ] && cp "$PROJECT_ROOT/ui/target/release/vietc-tray" "$STAGING/usr/bin/" + +# Desktop file +cp "$PROJECT_ROOT/packaging/appimage/vietc.desktop" "$STAGING/usr/share/applications/" + +# Icon (SVG from AppImage build script) +cat > "$STAGING/usr/share/icons/hicolor/256x256/apps/vietc.svg" << 'SVGEOF' + + + + + + + + + + + + + + + + + + + + + + + VN + +SVGEOF + +# Documentation +cp "$PROJECT_ROOT/README.md" "$STAGING/usr/share/doc/vietc/" +cp "$PROJECT_ROOT/LICENSE" "$STAGING/usr/share/doc/vietc/" + +# Config +cp "$PROJECT_ROOT/vietc.toml" "$STAGING/etc/vietc/config.toml" + +# Systemd user service +cp "$PROJECT_ROOT/vietc.service" "$STAGING/usr/lib/systemd/user/" + +# AppStream metadata +cat > "$STAGING/usr/share/metainfo/io.github.anomalyco.vietc.appdata.xml" << 'XML' + + + io.github.anomalyco.vietc + Viet+ + Vietnamese Input Method for Linux + +

Zero-configuration Vietnamese input method engine supporting Telex and VNI input methods. Works natively on both X11 and Wayland via evdev uinput injection.

+
+ MIT + MIT + https://github.com/anomalyco/vietc + vietc + Utility +
+XML + +# Lintian overrides +mkdir -p "$STAGING/usr/share/lintian/overrides" +cat > "$STAGING/usr/share/lintian/overrides/vietc" << 'LINTIAN' +# Binaries are intentionally placed in /usr/bin without man pages +# as Viet+ is a modern GUI application targeting Wayland/X11. +vietc: no-manual-page * +# Init script helpers are not needed; Viet+ uses systemd --user units. +vietc: no-systemd-service-file-outside-lib +# We bundle the tray alongside the daemon for convenience. +vietc: wrong-section-according-to-package-name +LINTIAN + +# Create control file +echo "[4/5] Creating control file..." +cat > "$STAGING/DEBIAN/control" << 'CONTROL' +Package: vietc +Version: VERSION_PLACEHOLDER +Section: utils +Priority: optional +Architecture: amd64 +Depends: libc6 (>= 2.31), libevdev2 (>= 1.9.0) +Recommends: libwayland-client0 (>= 1.20), libx11-6 +Maintainer: Khoa Vo +Description: Viet+ — Vietnamese Input Method for Linux + Zero-configuration Vietnamese input method engine supporting + Telex and VNI input methods. Works natively on both X11 and + Wayland via evdev uinput injection. +CONTROL +sed -i "s/VERSION_PLACEHOLDER/$VERSION/" "$STAGING/DEBIAN/control" + +# Conffiles +echo "/etc/vietc/config.toml" > "$STAGING/DEBIAN/conffiles" + +# Maintainer scripts +cat > "$STAGING/DEBIAN/postinst" << 'POSTINST' +#!/bin/sh +set -e +case "$1" in + configure) + if command -v systemctl >/dev/null 2>&1; then + systemctl --system daemon-reload >/dev/null 2>&1 || true + fi + ;; +esac +POSTINST +chmod 755 "$STAGING/DEBIAN/postinst" + +cat > "$STAGING/DEBIAN/prerm" << 'PRERM' +#!/bin/sh +set -e +case "$1" in + remove|upgrade|deconfigure) + if command -v systemctl >/dev/null 2>&1; then + systemctl --system daemon-reload >/dev/null 2>&1 || true + fi + ;; +esac +PRERM +chmod 755 "$STAGING/DEBIAN/prerm" + +cat > "$STAGING/DEBIAN/postrm" << 'POSTRM' +#!/bin/sh +set -e +case "$1" in + purge) + rm -rf /etc/vietc 2>/dev/null || true + ;; +esac +POSTRM +chmod 755 "$STAGING/DEBIAN/postrm" + +# Build .deb +echo "[5/5] Building .deb package..." +fakeroot dpkg-deb --build "$STAGING" "$SCRIPT_DIR/vietc_${VERSION}-1_amd64.deb" +echo "" +echo "=== Package built: packaging/deb/vietc_${VERSION}-1_amd64.deb ==="