Created
March 25, 2016 15:58
-
-
Save benoitf/de6e9bd44e7eead0ff59 to your computer and use it in GitHub Desktop.
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 | |
extractProxySettings() { | |
local proxyUrl=$1 | |
local proxyType=$2 | |
local PROXY_WITH_USER_AUTH_REGEXP="https?://([^:]*):?(.*)@([^:]*):?(.*)" | |
local PROXY_WITH_USER_AUTH_REGEXP_FOR_SED="https\?://\([^:]*\):\?\(.*\)@\([^:]*\):\?\(.*\)" | |
local PROXY_WITHOUT_USER_AUTH_REGEXP="https?://([^:]*):?(.*)" | |
local PROXY_WITHOUT_USER_AUTH_REGEXP_FOR_SED="https\?://\([^:]*\):\?\(.*\)" | |
if [ -n "$proxyUrl" ]; then | |
local proxyUserName | |
local proxyPassword | |
local proxyHost | |
local proxyPort | |
if [[ $proxyUrl =~ $PROXY_WITH_USER_AUTH_REGEXP ]]; then | |
proxyUser=$(echo $proxyUrl | sed "s|$PROXY_WITH_USER_AUTH_REGEXP_FOR_SED|\1|") | |
proxyPassword=$(echo $proxyUrl | sed "s|$PROXY_WITH_USER_AUTH_REGEXP_FOR_SED|\2|") | |
proxyHost=$(echo $proxyUrl | sed "s|$PROXY_WITH_USER_AUTH_REGEXP_FOR_SED|\3|") | |
proxyPort=$(echo $proxyUrl | sed "s|$PROXY_WITH_USER_AUTH_REGEXP_FOR_SED|\4|") | |
elif [[ $proxyUrl =~ $PROXY_WITHOUT_USER_AUTH_REGEXP ]]; then | |
proxyHost=$(echo $proxyUrl | sed "s|$PROXY_WITHOUT_USER_AUTH_REGEXP_FOR_SED|\1|") | |
proxyPort=$(echo $proxyUrl | sed "s|$PROXY_WITHOUT_USER_AUTH_REGEXP_FOR_SED|\2|") | |
fi | |
if [[ $proxyUser != "" ]]; then | |
PROXY_OPTS="$PROXY_OPTS -D$proxyType.proxyUser=$proxyUser" | |
fi | |
if [[ $proxyPassword != "" ]]; then | |
PROXY_OPTS="$PROXY_OPTS -D$proxyType.proxyPassword=$proxyPassword" | |
fi | |
if [[ $proxyHost != "" ]]; then | |
PROXY_OPTS="$PROXY_OPTS -D$proxyType.proxyHost=$proxyHost" | |
fi | |
if [[ $proxyPort != "" ]]; then | |
PROXY_OPTS="$PROXY_OPTS -D$proxyType.proxyPort=$proxyPort" | |
fi | |
fi | |
} | |
extractProxySettings $1 $2 | |
echo $PROXY_OPTS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment