#!/bin/bash # based on # 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 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/ f=/tmp/apt_proxy_fail 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 $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