Last active
January 5, 2025 05:54
-
-
Save lmlsna/119e37ada9c225c5f1d9352c1825f961 to your computer and use it in GitHub Desktop.
Using apt-cacher proxies with fallback to direct
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## /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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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-traditional | |
#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