fixes and new bashrc func
[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 10 minutes. Also, using newer option based on man apt.conf.
7 #
8 # Once when I was testing, it seemed I needed to have it output
9 # DIRECT after toutputing the proxy url
10 proxy_host=faiserver
11 proxy_port=3142
12 proxy_url=http://$proxy_host:$proxy_port/
13 f=/tmp/apt_proxy_fail
14 if [[ ! -w /tmp ]]; then
15 echo DIRECT
16 exit 0
17 fi
18 if [[ -r $f ]]; then
19 if (( $(( $(date +%s) - $(stat -c %Y $f ) )) < 60*10 )); then
20 echo DIRECT
21 exit 0
22 else
23 if [[ -w $f ]]; then
24 rm $f
25 fi
26 fi
27 fi
28 if getent hosts $proxy_host &>/dev/null && timeout 1 nc -z $proxy_host $proxy_port &>/dev/null; then
29 echo $proxy_url
30 else
31 if [[ ! -e $f || -w $f ]]; then
32 touch $f
33 fi
34 fi