#!/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}" ARCH="amd64" PKGNAME="vietc" PKGDIR="$SCRIPT_DIR/${PKGNAME}_${VERSION}_${ARCH}" echo "=== Building Viet+ .deb v${VERSION} ===" # Clean rm -rf "$PKGDIR" mkdir -p "$PKGDIR/DEBIAN" chmod 0755 "$PKGDIR/DEBIAN" mkdir -p "$PKGDIR/usr/bin" mkdir -p "$PKGDIR/usr/share/applications" mkdir -p "$PKGDIR/usr/share/icons/hicolor/256x256/apps" mkdir -p "$PKGDIR/usr/share/doc/vietc" mkdir -p "$PKGDIR/etc/vietc" mkdir -p "$PKGDIR/usr/lib/systemd/user" # Build binaries echo "[1/6] Building binaries..." cd "$PROJECT_ROOT" if pkg-config --exists x11 xtst 2>/dev/null; then cargo build --release --features "x11,wayland" echo " Built with x11 + wayland" else cargo build --release --features wayland echo " Built with wayland only (X11 libs not found)" fi # Copy binaries echo "[2/6] Installing binaries..." cp target/release/vietc "$PKGDIR/usr/bin/" cp target/release/vietc-cli "$PKGDIR/usr/bin/" # Try building UI (optional) cd "$PROJECT_ROOT/ui" && cargo build --release 2>/dev/null && cd "$SCRIPT_DIR" && { cp "$PROJECT_ROOT/ui/target/release/vietc-settings" "$PKGDIR/usr/bin/" cp "$PROJECT_ROOT/ui/target/release/vietc-tray" "$PKGDIR/usr/bin/" echo " UI binaries included" } || { echo " UI build skipped (missing GTK4 libs)" cd "$SCRIPT_DIR" } cd "$PROJECT_ROOT" # DEBIAN control files echo "[3/6] Installing control files..." cp "$SCRIPT_DIR/DEBIAN/control" "$PKGDIR/DEBIAN/control" sed -i "s/^Version:.*/Version: ${VERSION}/" "$PKGDIR/DEBIAN/control" cp "$SCRIPT_DIR/DEBIAN/postinst" "$PKGDIR/DEBIAN/" cp "$SCRIPT_DIR/DEBIAN/prerm" "$PKGDIR/DEBIAN/" cp "$SCRIPT_DIR/DEBIAN/postrm" "$PKGDIR/DEBIAN/" chmod 755 "$PKGDIR/DEBIAN/postinst" "$PKGDIR/DEBIAN/prerm" "$PKGDIR/DEBIAN/postrm" # Desktop integration echo "[4/6] Installing desktop integration..." cp "$PROJECT_ROOT/packaging/appimage/vietc.desktop" "$PKGDIR/usr/share/applications/" # SVG icon cat > "$PKGDIR/usr/share/icons/hicolor/256x256/apps/vietc.svg" << 'SVGEOF' VN SVGEOF # Convert SVG to PNG if possible if command -v rsvg-convert &>/dev/null; then rsvg-convert -w 256 -h 256 "$PKGDIR/usr/share/icons/hicolor/256x256/apps/vietc.svg" \ -o "$PKGDIR/usr/share/icons/hicolor/256x256/apps/vietc.png" fi # Config and docs echo "[5/6] Installing config and docs..." cp "$PROJECT_ROOT/vietc.toml" "$PKGDIR/etc/vietc/config.toml" cp "$PROJECT_ROOT/README.md" "$PKGDIR/usr/share/doc/vietc/" cp "$PROJECT_ROOT/LICENSE" "$PKGDIR/usr/share/doc/vietc/" cp "$PROJECT_ROOT/vietc.service" "$PKGDIR/usr/lib/systemd/user/" # Calculate installed size INSTALLED_SIZE=$(du -sk "$PKGDIR" | cut -f1) sed -i "s/^Installed-Size:.*/Installed-Size: ${INSTALLED_SIZE}/" "$PKGDIR/DEBIAN/control" 2>/dev/null || true # Fix permissions for dpkg-deb chmod -R 0755 "$PKGDIR/DEBIAN" find "$PKGDIR" -type d -exec chmod 0755 {} \; # Build .deb echo "[6/6] Building .deb package..." dpkg-deb --root-owner-group --build "$PKGDIR" DEBFILE="${PKGNAME}_${VERSION}_${ARCH}.deb" echo "" echo "=== Built: $SCRIPT_DIR/$DEBFILE ===" echo "" echo "Install with:" echo " sudo dpkg -i $DEBFILE" echo " sudo apt-get install -f # fix dependencies if needed"