7a97b95c0c11b6781f013d1f3a608b41ce129e46
[distro-setup] / filesystem / etc / apt / detect-http-proxy
1 #!/bin/bash
2 # based on
3 # http://askubuntu.com/questions/53443/how-do-i-ignore-a-proxy-if-not-available
4 # altered because testing a down proxy takes like 2 seconds,
5 # and we would do it like 100 times in a row. so cache a failed result
6 # locally for 1 hour. Also, using newer option based on man apt.conf.
7 proxy_host=faiserver
8 proxy_port=3142
9 proxy_url=http://$proxy_host:$proxy_port
10 f=/tmp/apt_proxy_fail
11 if [[ ! -r $f ]] \
12 || (( $(( $(date +%s) - $(stat -c %Y $f ) )) > 60*60 )); then
13 if host $proxy_host && nc -z $proxy_host $proxy_port; then
14 echo $proxy_url
15 else
16 touch $f
17 fi
18 fi
19 echo DIRECT