X-Git-Url: https://code.delx.au/osx-proxyconf/blobdiff_plain/00753391a2870d115009501ce763a6cf5b75341e..455327818f1ab19e2310c39c383db3d5be369841:/proxyconf.sh diff --git a/proxyconf.sh b/proxyconf.sh index 78b537c..262dfc8 100755 --- a/proxyconf.sh +++ b/proxyconf.sh @@ -1,17 +1,31 @@ #!/bin/bash -if [ "$(sysconfig "HTTPEnable")" -eq 1 ]; then - host="$(sysconfig "HTTPProxy")" - port="$(sysconfig "HTTPPort")" - echo "export http_proxy=\"http://${host}:${port}\"" -fi -if [ "$(sysconfig "HTTPSEnable")" -eq 1 ]; then - host="$(sysconfig "HTTPSProxy")" - port="$(sysconfig "HTTPSPort")" - echo "export https_proxy=\"http://${host}:${port}\"" -fi -if [ "$(sysconfig "FTPEnable")" -eq 1 ]; then - host="$(sysconfig "FTPProxy")" - port="$(sysconfig "FTPPort")" - echo "export ftp_proxy=\"http://${host}:${port}\"" +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 + +} +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}" ] && [ $PROXY_FOUND -ne 0 ]; then + echo "export no_proxy=\"${no_proxy}\"" +else + echo "unset no_proxy" fi