apt caches on notebooks

Using a apt caching daemon on a notebook is usually pain. Most require to alter the /etc/apt/sources.list which is quite annoying as you have to maintain the different lists for different locations. If the daemon requires you to add repositories, third party repositories are usually not added anyways.

But there is a good solution which works great here, thanks to apt-cacher-ng. Apt-cacher-ng does not require you to alter the sources.list as it can work as a http proxy. It also does not require any configuration for repositories.

On your server simply do sudo aptitude install apt-cacher-ng

On a permanent client add a file /etc/apt/apt.conf.d/02proxy with:

Acquire::http { Proxy "http://SERVERIP:3142"; Timeout "10"; };
Acquire::HTTP::Proxy::bugs.debian.org "DIRECT";

Now to laptops. switchconf is a useful tool for this, as it can change config files depending on locations.

sudo aptitude install switchconf
sudo mkdir -p /etc/switchconf/other/etc/apt/apt.conf.d
sudo touch /etc/switchconf/other/etc/apt/apt.conf.d/02proxy
sudo mkdir -p /etc/switchconf/home/etc/apt/apt.conf.d
sudo vi /etc/switchconf/home/etc/apt/apt.conf.d/02proxy

And paste the client config there.

This adds two locations, home and other. other will not use any proxy and should therefor work everywhere and home will use your home proxy. You can of course add more locations as you have more places with proxies found.

But as you don’t want to type “sudo switchconf LOCATION” whenever you change places, some auto-detection is required. I use Network-Manager and use the dispatcher for this.

sudo vi /etc/NetworkManager/dispatcher.d/99switchconf

And this is my detection script. I use arp to test if a certain IP has a specific MAC address which is a very precise test. arp -a SERVERIP will show you the MAC address of your server.

#!/bin/bash

if [[ `arp -a 192.168.22.1` =~ 54:52:00:31:fe:a9 ]]; then
  switchconf home;
else
  switchconf other;
fi

Don’t forget to make it executeable

sudo chmod +x /etc/NetworkManager/dispatcher.d/99switchconf

Now i got cache at home and no cache on the road.

Next entry

Previous entry

Similar entries

Pingbacks

Pingbacks are closed.

Comments

Comments are closed.