Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm using apt-cacher-ng at my local network with the following configuration on the clients:

Acquire::http { Proxy "http://acng-host:3142"; };

Some of the clients are laptops, so how do I configure them to use the cache only when it's available on this network?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

Something like this should work:

/etc/NetworkManager/dispatcher.d

#!/bin/bash
ip=10.0.1.13
port=3142
nc -w 1 $ip $port
proxy_file="/etc/apt/apt.conf.d/02local_proxy"
if [ $? -eq 0 ]; then
    echo "Acquire::http { Proxy \"http://$ip:$port\"; };" > $proxy_file
    echo 'Acquire::https { Proxy "false"; };' >> $proxy_file
else
    rm -f $proxy_file
fi

Fix permissions

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

Notes:

  • The "nc" command tests that it can connect to the 3142 port on the given IP address.
  • This script is run everytime the networking interfaces are changed by network manager.
  • Feel free to alter the way that you detect for the proxy, this works for me, but it is a security vulnerability if you install packages on a foreign network, for example.
share|improve this answer

Not an exact answer, since you'll have to change your existing cache setup, but squid-deb-proxy is a good solution to providing a cache that will be used transparently if available, and is very easy to set up on both cache server and clients. See the first answer to this question for more details.

share|improve this answer
    
... that was hopefully meant to be "that will be used transparently if available and if avahi is installed on the client side" ;) –  0xC0000022L Feb 28 '13 at 20:34

From the server you can announce to the network there is an apt-cacher-ng instance through avahi

From the client you can check if exist an apt-cacher-ng service and modify apt proxy settings accordly.


Server

Install

$ sudo apt-get install apt-cacher-ng squid-deb-proxy-client

Put the following snippet in /etc/avahi/services/apt-cacher-ng.service

<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
 <name replace-wildcards="yes">apt-cacher-ng proxy on %h</name>
 <service protocol="ipv4">
  <type>_apt_proxy._tcp</type>
  <port>3142</port>
 </service>
</service-group>

Client

Install

$ sudo apt-get install squid-deb-proxy-client

Here is a snippet to install server|client depending if there is already an apt-get proxy or not:

Source: http://blog.surgut.co.uk/2013/03/avahi-apt-cacher-ng-sbuild.html

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.