Skip to content

Instantly share code, notes, and snippets.

@lmlsna
Last active August 29, 2021 04:44
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lmlsna/119e37ada9c225c5f1d9352c1825f961 to your computer and use it in GitHub Desktop.
Save lmlsna/119e37ada9c225c5f1d9352c1825f961 to your computer and use it in GitHub Desktop.
Using apt-cacher proxies with fallback to direct
## /etc/apt/apt.conf.d/02proxy
# You can add this line for faster failover
Acquire::Retries 0;
# Make sure you use the full path
Acquire::http::Proxy-Auto-Detect "/usr/bin/apt-proxy-detect.sh";
#!/bin/bash
## Tells Proxy-Auto-Config if a specified proxy is reachable or if
## it should just fallback to a direct connection.
##
## This file should be executable and referenced by its full path
## in the /etc/apt/apt.conf.d/02proxy file we create too.
ip="192.168.88.1"
port=3142
## This will install netcat automatically if it's missing if uncommented
#if [[ $(which nc >/dev/null; echo $?) -ne 0 ]]; then
# apt install -y netcat
#fi
if [[ $(nc -w1 -z $ip $port &>/dev/null; echo $?) -eq 0 ]]; then
echo -n "http://${ip}:${port}/"
else
echo -n "DIRECT"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment