Last active
July 24, 2024 09:06
-
-
Save hardyscc/36a827085bb3a65906b2f173e280c422 to your computer and use it in GitHub Desktop.
get-java-opts-proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Usage: export JAVA_TOOL_OPTIONS=`get-java-opts-proxy` | |
local_http_proxy=${HTTP_PROXY:-$http_proxy} | |
if [ -n "$local_http_proxy" ] ; then | |
if [ $? -eq 0 ]; then # If variable has username and password, its parse method different | |
http_proxy_host=$(echo $local_http_proxy | sed 's/http:\/\/.*@\(.*\):.*/\1/') | |
http_proxy_port=$(echo $local_http_proxy | sed 's/http:\/\/.*@.*:\(.*\)/\1/' | tr -d "/") | |
http_proxy_user=$(echo $local_http_proxy | sed 's/http:\/\/\(.*\)@.*/\1/' | awk -F: '{print $1}') | |
http_proxy_password=$(echo $local_http_proxy | sed 's/http:\/\/\(.*\)@.*/\1/' | awk -F: '{print $2}') | |
else # If it doesn't have username and password, its parse method this | |
http_proxy_host=$(echo $local_http_proxy | sed 's/http:\/\/\(.*\):.*/\1/') | |
http_proxy_port=$(echo $local_http_proxy | sed 's/http:\/\/.*:\(.*\)/\1/' | tr -d "/") | |
fi | |
fi | |
local_https_proxy=${HTTPS_PROXY:-$https_proxy} | |
if [ -n "$local_https_proxy" ] ; then | |
if [ $? -eq 0 ]; then # If variable has username and password, its parse method different | |
https_proxy_host=$(echo $local_https_proxy | sed 's/http:\/\/.*@\(.*\):.*/\1/') | |
https_proxy_port=$(echo $local_https_proxy | sed 's/http:\/\/.*@.*:\(.*\)/\1/' | tr -d "/") | |
https_proxy_user=$(echo $local_https_proxy | sed 's/http:\/\/\(.*\)@.*/\1/' | awk -F: '{print $1}') | |
https_proxy_password=$(echo $local_http_proxy | sed 's/http:\/\/\(.*\)@.*/\1/' | awk -F: '{print $2}') | |
else # If it doesn't have username and password, its parse method this | |
https_proxy_host=$(echo $local_https_proxy | sed 's/http:\/\/\(.*\):.*/\1/') | |
https_proxy_port=$(echo $local_https_proxy | sed 's/http:\/\/.*:\(.*\)/\1/' | tr -d "/") | |
fi | |
fi | |
local_no_proxy=${NO_PROXY:-$no_proxy} | |
if [ -n "$local_no_proxy" ] ; then | |
http_non_proxy_hosts=$(echo $local_no_proxy | sed 's/,/|/g; s/|\./|\*\./g') | |
fi | |
if [ -n "$http_proxy_host" ] ; then | |
java_opts="$java_opts -Dhttp.proxyHost=$http_proxy_host" | |
fi | |
if [ -n "$http_proxy_port" ] ; then | |
java_opts="$java_opts -Dhttp.proxyPort=$http_proxy_port" | |
fi | |
if [ -n "$http_proxy_user" ] ; then | |
java_opts="$java_opts -Dhttp.proxyUser=$http_proxy_user" | |
fi | |
if [ -n "$http_proxy_password" ] ; then | |
java_opts="$java_opts -Dhttp.proxyPassword=$http_proxy_password" | |
fi | |
if [ -n "$https_proxy_host" ] ; then | |
java_opts="$java_opts -Dhttps.proxyHost=$https_proxy_host" | |
fi | |
if [ -n "$https_proxy_port" ] ; then | |
java_opts="$java_opts -Dhttps.proxyPort=$https_proxy_port" | |
fi | |
if [ -n "$https_proxy_user" ] ; then | |
java_opts="$java_opts -Dhttps.proxyUser=$https_proxy_user" | |
fi | |
if [ -n "$https_proxy_password" ] ; then | |
java_opts="$java_opts -Dhttps.proxyPassword=$https_proxy_password" | |
fi | |
if [ -n "$http_non_proxy_hosts" ] ; then | |
java_opts="$java_opts -Dhttp.nonProxyHosts=\"$http_non_proxy_hosts\"" | |
fi | |
echo $java_opts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment