X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=filesystem%2Fetc%2Fapt%2Fdetect-http-proxy;h=1cfdaf978b878dd6f76aa2e94c371a8fcfb902db;hb=8c9f3c9c69a1f76d8ffba1343fc0ab308fb4661a;hp=7a97b95c0c11b6781f013d1f3a608b41ce129e46;hpb=6c41878284a2347515e54a61b5aa650f130b0a81;p=distro-setup diff --git a/filesystem/etc/apt/detect-http-proxy b/filesystem/etc/apt/detect-http-proxy index 7a97b95..1cfdaf9 100755 --- a/filesystem/etc/apt/detect-http-proxy +++ b/filesystem/etc/apt/detect-http-proxy @@ -3,17 +3,32 @@ # http://askubuntu.com/questions/53443/how-do-i-ignore-a-proxy-if-not-available # altered because testing a down proxy takes like 2 seconds, # and we would do it like 100 times in a row. so cache a failed result -# locally for 1 hour. Also, using newer option based on man apt.conf. +# locally for 10 minutes. Also, using newer option based on man apt.conf. +# +# Once when I was testing, it seemed I needed to have it output +# DIRECT after toutputing the proxy url proxy_host=faiserver proxy_port=3142 -proxy_url=http://$proxy_host:$proxy_port +proxy_url=http://$proxy_host:$proxy_port/ f=/tmp/apt_proxy_fail -if [[ ! -r $f ]] \ - || (( $(( $(date +%s) - $(stat -c %Y $f ) )) > 60*60 )); then - if host $proxy_host && nc -z $proxy_host $proxy_port; then - echo $proxy_url +if [[ ! -w /tmp ]]; then + echo DIRECT + exit 0 +fi +if [[ -r $f ]]; then + if (( $(( $(date +%s) - $(stat -c %Y $f ) )) < 60*10 )); then + echo DIRECT + exit 0 else + if [[ -w $f ]]; then + rm $f + fi + fi +fi +if getent hosts $proxy_host &>/dev/null && timeout 1 nc -z $proxy_host $proxy_port &>/dev/null; then + echo $proxy_url +else + if [[ ! -e $f || -w $f ]]; then touch $f fi fi -echo DIRECT