various updates
[distro-setup] / filesystem / etc / apt / detect-http-proxy
index 2e4a962119c8206ff78b9f157bcafe5598dcbee5..56804025e1ff5a4e3d0fc921dfa4e97f389b1dd1 100755 (executable)
@@ -11,16 +11,24 @@ 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
-        rm $f
+        if [[ -w $f ]]; then
+            rm -f $f
+        fi
     fi
 fi
-if host $proxy_host && nc -z $proxy_host $proxy_port; then
+if getent hosts $proxy_host &>/dev/null && timeout 1 nc -z $proxy_host $proxy_port &>/dev/null; then
     echo $proxy_url
 else
-    touch $f
+    if [[ ! -e $f || -w $f ]]; then
+        touch $f
+    fi
 fi