Skip to content

A bash tool that configures use of a specified apt-cache-ng server. I made this for myself, to manage Proxmox guests, and am sharing it here in hopes it helps others. It should work on any debian based os. It features options to: - Configure the local machine. - Configure target vm's, target lxc, or all lxc on that local machine. - Remove config.

License

Notifications You must be signed in to change notification settings

GrandDay/APT-Cache-Proxy-Configurator

Repository files navigation

APT Cache Proxy Configurator

Automate APT-Cacher-NG proxy configuration across Proxmox hosts, LXC containers, and VMs.

Quick Start

Option 1: Interactive Installation (Recommended)

⚠️ Security Note: Review scripts before piping to bash. Use the 2-step method for production:

Quick (review first):

curl -fsSL https://raw.githubusercontent.com/GrandDay/apt-cache-config/main/install-interactive.sh | bash

Safer 2-step (recommended for production):

# 1. Download and review
curl -fsSL https://raw.githubusercontent.com/GrandDay/apt-cache-config/main/install-interactive.sh -o /tmp/install-apt-cache.sh
less /tmp/install-apt-cache.sh  # Review the script

# 2. Run after review
bash /tmp/install-apt-cache.sh
rm /tmp/install-apt-cache.sh

Alternative methods if CDN cache causes issues:

# Method 1: Process substitution
bash <(curl -fsSL https://raw.githubusercontent.com/GrandDay/apt-cache-config/main/install-interactive.sh)

# Method 2: With cache-busting
curl -fsSL "https://raw.githubusercontent.com/GrandDay/apt-cache-config/main/install-interactive.sh?$(date +%s)" | bash

This will:

  • Prompt for your APT-Cacher-NG server IP and port
  • Ask for SSH configuration preferences
  • Optionally accept an existing SSH public key
  • Download and configure the script automatically

Option 2: Manual Installation

# 1. Download the script
curl -o /usr/local/bin/connect-to-apt-cache.sh https://raw.githubusercontent.com/GrandDay/apt-cache-config/main/src/connect-to-apt-cache.sh
chmod +x /usr/local/bin/connect-to-apt-cache.sh

# 2. Edit configuration (REQUIRED - set your proxy server IP)
nano /usr/local/bin/connect-to-apt-cache.sh
# Change: APT_PROXY_SERVER="http://YOUR_SERVER_IP:3142"

# 3. Configure your system
connect-to-apt-cache.sh local           # Configure current host
connect-to-apt-cache.sh lxc-all         # Configure all LXC containers
connect-to-apt-cache.sh vm 10.1.50.10   # Configure a VM

Overview

The APT Cache Proxy Configurator is a tool designed to simplify the configuration of Debian/Ubuntu systems to use an APT-Cacher-NG proxy server. This tool helps in speeding up package downloads and reducing bandwidth usage by caching packages.

Features

  • SSH Key Management: Automatically checks for existing SSH keys and generates new ones if necessary.
  • Flexible Configuration: Supports configuration for local systems, LXC containers, and virtual machines (VMs).
  • Interactive Prompts: Provides user-friendly prompts for reconfiguration and SSH key generation.
  • Detailed Logging: Outputs color-coded messages for easy identification of operation statuses.

Installation

Quick Install (Interactive - Recommended)

One-liner that prompts for your configuration:

curl -fsSL https://raw.githubusercontent.com/GrandDay/apt-cache-config/main/install-interactive.sh | bash

This interactive installer will ask for your APT-Cacher-NG server details and SSH preferences.

Manual Install

For manual configuration:

curl -o /usr/local/bin/connect-to-apt-cache.sh https://raw.githubusercontent.com/GrandDay/apt-cache-config/main/src/connect-to-apt-cache.sh
chmod +x /usr/local/bin/connect-to-apt-cache.sh
nano /usr/local/bin/connect-to-apt-cache.sh  # Edit configuration

Repository Install

Clone and install from source:

git clone https://github.com/GrandDay/apt-cache-config.git
cd apt-cache-config
./install.sh

Note: Manual and repository installs require editing the configuration. See the Configuration section below.

How It Works

This tool writes a single configuration file on target systems:

/etc/apt/apt.conf.d/00aptproxy

Containing:

Acquire::http::Proxy "http://YOUR_SERVER_IP:3142";

Why this approach:

  • Safe: Doesn't modify sources.list or other user configs
  • Idempotent: Re-running is safe; checks if already configured
  • Reversible: remove command deletes only this file
  • Standard: Follows Debian/Ubuntu APT configuration best practices

Important: Your apt-cacher-ng server must have HTTPS pass-through enabled. Add to /etc/apt-cacher-ng/acng.conf:

PassThroughPattern: .*

Then restart: systemctl restart apt-cacher-ng

Configuration

IMPORTANT: Before using the script, you must edit /usr/local/bin/connect-to-apt-cache.sh and customize the configuration variables at the top:

APT_PROXY_SERVER="http://10.1.50.183:3142"    # Change to your apt-cacher-ng server
SSH_USER="root"                                # Change if using different user
SSH_KEY_PATH="$HOME/.ssh/id_rsa"              # Path to SSH private key
SSH_PUBLIC_KEY_PATH="$HOME/.ssh/id_rsa.pub"   # Path to SSH public key
CUSTOM_SSH_PUBLIC_KEY=""                       # Optional: paste existing SSH public key

Quick Configuration

# Edit the script
nano /usr/local/bin/connect-to-apt-cache.sh

# Or use sed to update the proxy server
sed -i 's|http://10.1.50.183:3142|http://YOUR_SERVER_IP:3142|' /usr/local/bin/connect-to-apt-cache.sh

Usage

After installation, you can use the script to configure your system to use the APT-Cacher-NG proxy. Here are some common commands:

Configure Local System

connect-to-apt-cache.sh local

Configure a Single LXC Container

connect-to-apt-cache.sh lxc-single <CTID>

Configure All LXC Containers

connect-to-apt-cache.sh lxc-all

Configure a VM via SSH

connect-to-apt-cache.sh vm <IP_ADDRESS> [username]

Remove APT Proxy Configuration

connect-to-apt-cache.sh remove <lxc|vm|local> <target>

Documentation

For detailed usage instructions, configuration options, and examples, please refer to the GUIDE.md.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue for any enhancements or bug fixes.

Contact

For questions or feedback, please:

About

A bash tool that configures use of a specified apt-cache-ng server. I made this for myself, to manage Proxmox guests, and am sharing it here in hopes it helps others. It should work on any debian based os. It features options to: - Configure the local machine. - Configure target vm's, target lxc, or all lxc on that local machine. - Remove config.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages