]> code.delx.au - osx-proxyconf/blobdiff - proxyconf.sh
proxyconf.sh can now find sysconfig as long as they are in the same dir (even
[osx-proxyconf] / proxyconf.sh
index 261ffbe3c7fdbc11b618aea084f57c1ed61a0899..a6b7d23ff822b85e9e05794c51499bf0bd3cea0c 100755 (executable)
@@ -1,21 +1,35 @@
 #!/bin/bash
 
-if [ "$(sysconfig -q "HTTPEnable")" = "1" ]; then
-       host="$(sysconfig -q "HTTPProxy")"
-       port="$(sysconfig -q "HTTPPort")"
-       echo "export http_proxy=\"http://${host}:${port}\""
-fi
-if [ "$(sysconfig -q "HTTPSEnable")" = "1" ]; then
-       host="$(sysconfig -q "HTTPSProxy")"
-       port="$(sysconfig -q "HTTPSPort")"
-       echo "export https_proxy=\"http://${host}:${port}\""
-fi
-if [ "$(sysconfig -q "FTPEnable")" = "1" ]; then
-       host="$(sysconfig -q "FTPProxy")"
-       port="$(sysconfig -q "FTPPort")"
-       echo "export ftp_proxy=\"http://${host}:${port}\""
-fi
-if [ -n "${host}" ]; then
-       no_proxy="$(sysconfig ExceptionsList | tr '\n' ',' | sed 's/,$//g')"
+PROXY_FOUND=0
+function printEnvironment() {
+       local proxy_type="$1"
+       local environment_variable="$2"
+       local uri_prefix="${3:-http}"
+       local host port
+
+       if [ "$(sysconfig -q "${proxy_type}Enable")" = "1" ]; then
+               host="$(sysconfig -q "${proxy_type}Proxy")"
+               port="$(sysconfig -q "${proxy_type}Port")"
+               echo "export ${environment_variable}='${uri_prefix}://${host}:${port}'"
+
+               PROXY_FOUND=1
+       else
+               echo "unset ${environment_variable}"
+       fi
+
+}
+
+
+PATH="$(dirname "$0"):${PATH}"
+
+printEnvironment "HTTP" "http_proxy"
+printEnvironment "HTTPS" "https_proxy"
+printEnvironment "FTP" "ftp_proxy"
+printEnvironment "SOCKS" "socks_proxy" "socks"
+
+no_proxy="$(sysconfig -q ExceptionsList)"
+if [ -n "${no_proxy}" -a $PROXY_FOUND -eq 1 ]; then
        echo "export no_proxy=\"${no_proxy}\""
+else
+       echo "unset no_proxy"
 fi