]> code.delx.au - osx-proxyconf/commitdiff
Moved code to parse/print the environment variables, added support for socks
authorGreg Darke <greg+laptop@tsukasa.net.au>
Mon, 4 Feb 2008 10:47:08 +0000 (21:47 +1100)
committerGreg Darke <greg+laptop@tsukasa.net.au>
Mon, 4 Feb 2008 10:47:08 +0000 (21:47 +1100)
proxies.

proxyconf.sh

index 5c49ada1e56f8c7e63e17ef7aa5ff3900e0c67dd..be37736bc227248052028a595f427346baaa53f6 100755 (executable)
@@ -1,28 +1,27 @@
 #!/bin/bash
 
 #!/bin/bash
 
-if [ "$(sysconfig -q "HTTPEnable")" = "1" ]; then
-       host="$(sysconfig -q "HTTPProxy")"
-       port="$(sysconfig -q "HTTPPort")"
-       echo "export http_proxy=\"http://${host}:${port}\""
-else
-       echo "unset http_proxy"
-fi
-if [ "$(sysconfig -q "HTTPSEnable")" = "1" ]; then
-       host="$(sysconfig -q "HTTPSProxy")"
-       port="$(sysconfig -q "HTTPSPort")"
-       echo "export https_proxy=\"http://${host}:${port}\""
-else
-       echo "unset https_proxy"
-fi
-if [ "$(sysconfig -q "FTPEnable")" = "1" ]; then
-       host="$(sysconfig -q "FTPProxy")"
-       port="$(sysconfig -q "FTPPort")"
-       echo "export ftp_proxy=\"http://${host}:${port}\""
-else
-       echo "unset ftp_proxy"
-fi
-if [ -n "${host}" ]; then
-       no_proxy="$(sysconfig ExceptionsList | tr '\n' ',' | sed 's/,$//g')"
+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}'"
+       else
+               echo "unset ${environment_variable}"
+       fi
+
+}
+printEnvironment "HTTP" "http_proxy"
+printEnvironment "HTTPS" "https_proxy"
+printEnvironment "FTP" "ftp_proxy"
+printEnvironment "SOCKS" "socks_proxy" "socks"
+
+no_proxy="$(sysconfig -q ExceptionsList | tr '\n' ',' | sed 's/,$//g')"
+if [ ! -z "${no_proxy}" ]; then
        echo "export no_proxy=\"${no_proxy}\""
 else
        echo "unset no_proxy"
        echo "export no_proxy=\"${no_proxy}\""
 else
        echo "unset no_proxy"