#!/bin/bash # Build apt-ostree for Debian Trixie/Forky # This script ensures compatibility with libapt-pkg7.0 # Usage: ./build-debian-trixie.sh [install|remove] # - No arguments: Build only # - "install" argument: Build, remove existing installation, then install new # - "remove" argument: Remove existing apt-ostree installation from system set -e # Parse command line arguments INSTALL_AFTER_BUILD=false REMOVE_ONLY=false if [[ "$1" == "install" ]]; then INSTALL_AFTER_BUILD=true print_status "Install mode enabled - will remove existing installation, build, then install new" elif [[ "$1" == "remove" ]]; then REMOVE_ONLY=true print_status "Remove mode enabled - will only remove existing apt-ostree installation" elif [[ "$1" != "" ]]; then print_error "Invalid argument: $1" print_error "Usage: $0 [install|remove]" print_error " - No arguments: Build only" print_error " - 'install': Build, remove existing installation, then install new" print_error " - 'remove': Remove existing apt-ostree installation from system" exit 1 fi # Colors for output GREEN='\033[0;32m' BLUE='\033[0;34m' RED='\033[0;31m' YELLOW='\033[1;33m' NC='\033[0m' print_status() { echo -e "${BLUE}[INFO]${NC} $1" } print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } print_error() { echo -e "${RED}[ERROR]${NC} $1" } print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } print_header() { echo "" echo -e "${BLUE}================================${NC}" echo -e "${BLUE}$1${NC}" echo -e "${BLUE}================================${NC}" } print_header "Building apt-ostree for Debian Trixie/Forky" # Show usage information if [[ "$REMOVE_ONLY" == "true" ]]; then print_status "Mode: REMOVE ONLY (will not build or install)" elif [[ "$INSTALL_AFTER_BUILD" == "true" ]]; then print_status "Mode: BUILD + REMOVE + INSTALL (will replace system installation)" else print_status "Mode: BUILD ONLY (package will not be installed)" fi # Check if we're in the right directory if [ ! -f "Cargo.toml" ]; then print_error "Cargo.toml not found. Please run this script from the project root." exit 1 fi # Remove mode: Only remove existing installation if [[ "$REMOVE_ONLY" == "true" ]]; then print_header "Removing existing apt-ostree installation" # Check if apt-ostree is currently installed if command -v apt-ostree >/dev/null 2>&1; then print_status "Found existing apt-ostree installation, removing..." # Remove existing binaries if [ -f "/usr/local/bin/apt-ostree" ]; then sudo rm -f /usr/local/bin/apt-ostree print_status "Removed /usr/local/bin/apt-ostree" fi if [ -f "/usr/local/bin/apt-ostreed" ]; then sudo rm -f /usr/local/bin/apt-ostreed print_status "Removed /usr/local/bin/apt-ostreed" fi # Remove existing configuration if [ -d "/etc/apt-ostreed" ]; then sudo rm -rf /etc/apt-ostreed print_status "Removed /etc/apt-ostreed configuration" fi # Remove existing systemd service if [ -f "/etc/systemd/system/apt-ostreed.service" ]; then sudo systemctl stop apt-ostreed.service 2>/dev/null || true sudo systemctl disable apt-ostreed.service 2>/dev/null || true sudo rm -f /etc/systemd/system/apt-ostreed.service print_status "Removed apt-ostreed systemd service" fi # Remove symlinks if [ -L "/etc/systemd/system/multi-user.target.wants/apt-ostreed.service" ]; then sudo rm -f /etc/systemd/system/multi-user.target.wants/apt-ostreed.service print_status "Removed systemd symlink" fi print_success "Existing apt-ostree installation removed successfully!" else print_status "No existing apt-ostree installation found" fi # Exit after removal exit 0 fi # Check if debian directory exists if [ ! -d "debian" ]; then print_error "debian/ directory not found. Please ensure Debian packaging files are present." exit 1 fi # Check system compatibility print_status "Checking system compatibility..." # Check if we're on Debian Trixie or newer if [ -f /etc/os-release ]; then source /etc/os-release if [[ "$ID" == "debian" && "$VERSION_ID" == "13" ]] || [[ "$ID" == "debian" && "$VERSION_ID" == "14" ]]; then print_success "Detected Debian $VERSION_ID (Trixie/Forky)" else print_error "This script is designed for Debian Trixie (13) or Forky (14)" print_error "Current system: $ID $VERSION_ID" exit 1 fi else print_error "Cannot determine OS version" exit 1 fi # Check for required dependencies print_status "Checking build dependencies..." # Check for apt-pkg if ! pkg-config --exists apt-pkg; then print_error "apt-pkg development files not found" print_error "Install with: sudo apt install libapt-pkg-dev" exit 1 fi APT_PKG_VERSION=$(pkg-config --modversion apt-pkg) print_status "Found libapt-pkg version: $APT_PKG_VERSION" # Check if it's version 7.0 or newer if [[ "$APT_PKG_VERSION" < "3.0.0" ]]; then print_error "libapt-pkg version $APT_PKG_VERSION is too old" print_error "Need version 3.0.0 or newer for Debian Trixie/Forky" exit 1 fi print_success "System compatibility verified" # Clean previous builds print_status "Cleaning previous builds..." rm -rf target/ rm -f ../apt-ostree_*.deb rm -f ../apt-ostree-dbgsym_*.deb # Update Cargo.lock if needed print_status "Updating Cargo.lock..." cargo update # Test build first print_status "Testing Rust build..." cargo build --release if [ $? -eq 0 ]; then print_success "Rust build successful" else print_error "Rust build failed" exit 1 fi # Test development features print_status "Testing development features..." cargo build --features development --release if [ $? -eq 0 ]; then print_success "Development features build successful" else print_error "Development features build failed" exit 1 fi # Test development commands print_status "Testing development commands..." if cargo run --features development -- testutils --help >/dev/null 2>&1; then print_success "Development commands working correctly" else print_error "Development commands failed" exit 1 fi # Build the Debian package print_status "Building Debian package..." dpkg-buildpackage -us -uc -b # Check if build was successful if [ $? -eq 0 ]; then print_success "Package built successfully!" # List built packages print_status "Built packages:" ls -la ../apt-ostree_*.deb 2>/dev/null || echo "No apt-ostree .deb files found" ls -la ../apt-ostree-dbgsym_*.deb 2>/dev/null || echo "No debug symbol files found" # Test package installation print_status "Testing package installation..." if sudo dpkg -i ../apt-ostree_*.deb; then print_success "Package installation test successful!" # Test if apt-ostree works if apt-ostree --help >/dev/null 2>&1; then print_success "apt-ostree command working correctly!" else print_error "apt-ostree command failed after installation" fi # Uninstall test package sudo dpkg -r apt-ostree print_status "Test package uninstalled" else print_error "Package installation test failed!" exit 1 fi else print_error "Package build failed!" exit 1 fi print_success "Build and test completed successfully!" print_status "Package ready for Debian Trixie/Forky:" ls -la ../apt-ostree_*.deb # Install mode: Replace system installation if [[ "$INSTALL_AFTER_BUILD" == "true" ]]; then print_header "Installing new build to system" # First remove existing installation print_status "Removing existing apt-ostree installation..." # Remove existing binaries if [ -f "/usr/local/bin/apt-ostree" ]; then sudo rm -f /usr/local/bin/apt-ostree print_status "Removed /usr/local/bin/apt-ostree" fi if [ -f "/usr/local/bin/apt-ostreed" ]; then sudo rm -f /usr/local/bin/apt-ostreed print_status "Removed /usr/local/bin/apt-ostreed" fi # Remove existing configuration if [ -d "/etc/apt-ostreed" ]; then sudo rm -rf /etc/apt-ostreed print_status "Removed /etc/apt-ostreed configuration" fi # Remove existing systemd service if [ -f "/etc/systemd/system/apt-ostreed.service" ]; then sudo systemctl stop apt-ostreed.service 2>/dev/null || true sudo systemctl disable apt-ostreed.service 2>/dev/null || true sudo rm -f /etc/systemd/system/apt-ostreed.service print_status "Removed apt-ostreed systemd service" fi # Remove symlinks if [ -L "/etc/systemd/system/multi-user.target.wants/apt-ostreed.service" ]; then sudo rm -f /etc/systemd/system/multi-user.target.wants/apt-ostreed.service print_status "Removed systemd symlink" fi print_status "Existing installation removed, proceeding with new installation..." # Install the new package print_status "Installing new package..." if sudo dpkg -i ../apt-ostree_*.deb; then print_success "Package installed successfully!" # Verify installation print_status "Verifying installation..." if command -v apt-ostree >/dev/null 2>&1; then print_success "apt-ostree command available" apt-ostree --version else print_error "apt-ostree command not found after installation" exit 1 fi # Check if daemon is available if command -v apt-ostreed >/dev/null 2>&1; then print_success "apt-ostreed daemon available" else print_warning "apt-ostreed daemon not found (may be normal for some builds)" fi # Reload systemd and enable service if daemon exists if command -v apt-ostreed >/dev/null 2>&1; then print_status "Setting up systemd service..." sudo systemctl daemon-reload # Check if service file was created by the package if [ -f "/etc/systemd/system/apt-ostreed.service" ]; then sudo systemctl enable apt-ostreed.service print_success "apt-ostreed service enabled" else print_warning "No systemd service file found - manual setup may be required" fi fi print_success "System installation completed successfully!" print_status "New apt-ostree is now active on the system" else print_error "Package installation failed!" exit 1 fi else print_status "Install mode not enabled - package built but not installed" print_status "To install, run: $0 install" print_status "To remove existing installation only, run: $0 remove" print_status "To test existing .deb file: $0 remove && sudo dpkg -i ../apt-ostree_*.deb" fi