Skip to content

Instantly share code, notes, and snippets.

@Roadmaster
Last active February 4, 2024 00:20
Show Gist options
  • Save Roadmaster/754110f3f49fef19ec89ae29f29edd11 to your computer and use it in GitHub Desktop.
Save Roadmaster/754110f3f49fef19ec89ae29f29edd11 to your computer and use it in GitHub Desktop.
Create an lxc profile enabling use of an apt cache
#!/bin/bash
# Create lxc profile with apt caching
# Requires installing apt-cacher-ng to 10.0.4.1 (your host)
# Could be improved by making the actual apt cache host tunable
# Then use like:
# lxc launch -p default -p aptcache ubuntu:16.04 my-cached-container
NAME=aptcache
CACHE_IP=$(ip addr list lxdbr0 | grep -Po 'inet \K[\d.]+')
if ! ping -c 1 "$CACHE_IP" -w 1 >/dev/null 2>&1; then
echo "No usable cache_ip?"
exit 1
fi
lxc profile create $NAME &> /dev/null || true
cat << EOF | lxc profile edit $NAME
name: $NAME
description: set up apt caching via $CACHE_IP
config:
user.vendor-data: |
#cloud-config
apt:
proxy: "http://$CACHE_IP:3142"
apt_proxy: "http://$CACHE_IP:3142"
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment