-
Notifications
You must be signed in to change notification settings - Fork 57
/
set-proxy-env.sh
49 lines (46 loc) · 1.76 KB
/
set-proxy-env.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function end {
[ "${BASH_SOURCE[0]}" == "$0" ] && exit $1 || return $1
}
if [ "x$http_proxy" == "x" ] || [ "x$https_proxy" == "x" ]; then
echo 'System proxies ($http_proxy and $https_proxy) must first be set'
end -1
fi
HTTP_PROXY_HOST=`echo $http_proxy | awk -F/ '{print $3}' | awk -F: '{print $1}'`
HTTP_PROXY_PORT=`echo $http_proxy | awk -F/ '{print $3}' | awk -F: '{print $2}'`
HTTPS_PROXY_HOST=`echo $https_proxy | awk -F/ '{print $3}' | awk -F: '{print $1}'`
HTTPS_PROXY_PORT=`echo $https_proxy | awk -F/ '{print $3}' | awk -F: '{print $2}'`
cat > ~/.setproxy.sh << EOF
export http_proxy=http://$HTTP_PROXY_HOST:$HTTP_PROXY_PORT
export https_proxy=http://$HTTPS_PROXY_HOST:$HTTPS_PROXY_PORT
export JAVA_FLAGS="-Dhttp.proxyHost=$HTTP_PROXY_HOST -Dhttp.proxyPort=$HTTP_PROXY_PORT -Dhttps.proxyHost=$HTTPS_PROXY_HOST -Dhttps.proxyPort=$HTTPS_PROXY_PORT -Dhttp.nonProxyHosts=localhost,127.0.0.1,$HTTP_PROXY_HOST"
export JAVA_OPTS="\$JAVA_FLAGS"
export MAVEN_OPTS="\$JAVA_FLAGS -Dmaven.javadoc.skip=true"
export JRUBY_OPTS="-J-Dhttp.proxyHost=$HTTP_PROXY_HOST -J-Dhttp.proxyPort=$HTTP_PROXY_PORT -J-Dhttps.proxyHost=$HTTPS_PROXY_HOST -J-Dhttps.proxyPort=$HTTPS_PROXY_PORT"
EOF
if ! fgrep -q 'source ~/.setproxy.sh' ~/.bashrc; then
cat >> ~/.bashrc <<'EOF'
source ~/.setproxy.sh
EOF
source ~/.setproxy.sh
fi
if ! [ -d ~/.m2 ]; then mkdir ~/.m2; fi
cat > ~/.m2/settings.xml <<EOF
<settings>
<proxies>
<proxy>
<id>default</id>
<active>true</active>
<protocol>http</protocol>
<host>$HTTP_PROXY_HOST</host>
<port>$HTTP_PROXY_PORT</port>
</proxy>
<proxy>
<id>default</id>
<active>true</active>
<protocol>https</protocol>
<host>$HTTPS_PROXY_HOST</host>
<port>$HTTPS_PROXY_PORT</port>
</proxy>
</proxies>
</settings>
EOF