#!/bin/bash # setup-apt-cacher-ng.sh - Quick setup for apt-cacher-ng set -euo pipefail log_info() { echo -e "\033[0;32m[INFO]\033[0m $1" } log_warn() { echo -e "\033[1;33m[WARN]\033[0m $1" } log_error() { echo -e "\033[0;31m[ERROR]\033[0m $1" } # Check if apt-cacher-ng is already running check_existing() { if curl -s --connect-timeout 5 "http://localhost:3142/acng-report.html" > /dev/null 2>&1; then log_info "apt-cacher-ng is already running at http://localhost:3142" return 0 fi return 1 } # Install apt-cacher-ng install_apt_cacher_ng() { log_info "Installing apt-cacher-ng..." sudo apt update sudo apt install -y apt-cacher-ng # Configure to allow all clients sudo sed -i 's/^#BindAddress: 127.0.0.1/BindAddress: 0.0.0.0/' /etc/apt-cacher-ng/acng.conf # Start and enable service sudo systemctl enable apt-cacher-ng sudo systemctl start apt-cacher-ng log_info "apt-cacher-ng installed and started" } # Test the setup test_setup() { log_info "Testing apt-cacher-ng..." if curl -s --connect-timeout 5 "http://localhost:3142/acng-report.html" > /dev/null 2>&1; then log_info "✅ apt-cacher-ng is working!" log_info "Cache URL: http://localhost:3142" log_info "Status page: http://localhost:3142/acng-report.html" return 0 else log_error "❌ apt-cacher-ng is not responding" return 1 fi } # Main execution main() { log_info "Setting up apt-cacher-ng for faster bootc builds..." if check_existing; then log_info "apt-cacher-ng is already available" exit 0 fi install_apt_cacher_ng test_setup log_info "Setup complete! You can now use:" log_info " export APT_CACHER_NG_URL=http://localhost:3142" log_info " ./build-with-cache.sh" } main "$@"