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.office.list
and sources.home.list
. Save both of them in /etc/apt/
.
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
The script:
#!/bin/bash
ip=ifconfig | grep Bcast | cut -d " " -f 12
## Set this for your office IP
if [ $ip == "XXX.XXX.XXX.XXX" ]
then
cp /etc/apt/sources.office.list /etc/apt/sources.list
else
cp /etc/apt/sources.home.list /etc/apt/sources.list
fi
Now, edit the file etc/rc.local
and add this line to the end of the file, before exit(0)
:
/home/youruser/bin/change_sources.sh
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:
deb http://fastest.mirror.for.office
deb http://fastest.mirror.for.home
and in /etc/apt/sources.home.list like this:
deb http://fastest.mirror.for.home
deb http://fastest.mirror.for.office
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
Package 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
fastest/closest one.
Thanks very much terdon. I exported http.proxy variable and both internet and intranet mirror accessible in office, I still want keep internet mirror in the source list in case local mirror don't have the package wanted. is there any solution to test connectivity speed and select the fasted just as fastestmirror did. – Ted – 2012-08-20T16:17:17.350
@Ted I updated the answer, this should be what you need. – terdon – 2012-08-20T16:32:28.027