#!/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 1 hour. Also, using newer option based on man apt.conf. proxy_host=faiserver proxy_port=3142 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 else touch $f fi fi echo DIRECT