As a workaround, you could write a script that checks which network you are connected to and changes /etc/apt/sources.list accordingly. Something like the script below, just edit it to suit your needs.
First, make a backup of your
/etc/apt/sources.list. Then, create two sources.list files, one for your home and one for the office. Let's assume they are called
sources.home.list. Save both of them in
Now, edit the following script to suit your needs save it (for this example, I am assuming you will save it as
~/bin/change_sources.sh), and make it executable by running this command :
$ chmod +x ~/bin/change_sources.sh
ip=ifconfig | grep Bcast | cut -d " " -f 12
## Set this for your office IP
if [ $ip == "XXX.XXX.XXX.XXX" ]
cp /etc/apt/sources.office.list /etc/apt/sources.list
cp /etc/apt/sources.home.list /etc/apt/sources.list
Now, edit the file
etc/rc.local and add this line to the end of the file, before
Obviously, change the path above to reflect the path to the script you just created.
The next time you reboot, the script should be run and automatically choose the correct sources.list file.
EDIT: If you want to have both repositories accessible at all times, and download a given package from the fastest, if present, you just need to change the order of the repos in the sources.list. Follow the procedure I suggested above, simply make it so that the relevant lines in /etc/apt/sources.office.list are like this:
and in /etc/apt/sources.home.list like this:
If a package exists with the same version in both repositories, apt will download from the first.
NOTE1: If the versions are different, apt will get the newest irrespective of the order the repositories are in.
NOTE2: This does not check the download speed of the repos. You have to do that yourself. To find the fastest mirror you can try using netselect-apt:
sudo apt-get install netselect-apt
speed tester for choosing a fast Debian mirror
This package provides a utility that can choose the best Debian mirror
by downloading the full mirror list and using netselect to find the