Following the instructions in Best way to cache apt downloads on a LAN?, I've set up a caching proxy in my local network. Since that machine is not always up, I'd like to be able to refresh the sources list and install packages without using that proxy if unavailable.
I've already read the Acquire group section in the manual page of apt.conf(5)
, but I couldn't find an option like "Silent-Fail".
At the moment, sudo apt-get update
and related commands fail because no connection could be established. So how do I configure the client so that the proxy is ignored if it's not available?
Best Answer
There is an undocumented setting,
Acquire::http::ProxyAutoDetect
. This setting should contains the full path to the binary and cannot have arguments. The command should output the proxy to be used (example:http://10.0.0.1:8000
).Given the above information, a script could be created that tries a proxy before setting it. If no proxy is available, a direct connection should be used.
Below is such a proxy detection script which tries the
http://10.0.0.1:8000/
andhttp://10.0.0.2:8000
proxies.Put the code in
/etc/apt/detect-http-proxy
:Now, APT must be configured to use the above proxy detection script, so put the following code in
/etc/apt/apt.conf.d/30detectproxy
:I've also put the next code to the file to prevent some host from being proxified.
By default, the script outputs whether a proxy is used or not. To disable that, edit
/etc/apt/detect-http-proxy
and changeshow_proxy_messages=1
toshow_proxy_messages=0
.