Skip to content

Instantly share code, notes, and snippets.

@lmlsna

lmlsna/02proxy

Last active Oct 21, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.