forked from kontrafiktion/proxy-settings-osx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mvn-proxy-patch
executable file
·57 lines (45 loc) · 1.08 KB
/
mvn-proxy-patch
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
50
51
52
53
54
55
56
57
#!/bin/bash
NEW_STATE=$1
# if [[ "$BASH" = "" ]]; then
# # assume zsh
# SOURCE_DIR="${0%/*}"
# else
# SOURCE_DIR="${BASH_SOURCE[0]}"
# fi
MVN_PROXY=env-proxy
SETTINGS_XML="$HOME/.m2/settings.xml"
STATE=`grep -A 1 $MVN_PROXY "$SETTINGS_XML" | tail -1 | sed -e 's#[ ]*<active>\([a-z]*\)</active>#\1#'`
if [ -z "$NEW_STATE" ]; then
case $STATE in
true)
NEW_STATE="false"
;;
false)
NEW_STATE="true"
;;
*)
echo "unknown state: $STATE"
exit 1
;;
esac
fi
if [ -z "$PROXY_HOST" ]; then
PROXY_HOST=proxy
PROXY_PORT=8080
fi
REPLACEMENT=$(cat <<TEMPLATE
<id>env-proxy</id>
<active>$NEW_STATE</active>
<protocol>http</protocol>
<host>${PROXY_HOST}</host>
<port>${PROXY_PORT}</port>
</proxy>
TEMPLATE)
cp $SETTINGS_XML ${SETTINGS_XML}.org
replace-block.pl "<id>env-proxy</id>" "</proxy>" "$REPLACEMENT" ${SETTINGS_XML}.org > $SETTINGS_XML
if [ "$NEW_STATE" = "false" ]; then
LINES=1
else
LINES=4
fi
grep -A $LINES $MVN_PROXY "$SETTINGS_XML"