This repository has been archived by the owner on Dec 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbefore-start.sh
executable file
·44 lines (40 loc) · 1.86 KB
/
before-start.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
#!/bin/sh
#
# Copyright (c) 2019 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
#
set_maven_mirror() {
local m2="$HOME"/.m2
local settingsXML="$m2"/settings.xml
[ ! -d "$m2" ] && mkdir -p "$m2"
if [ ! -f "$settingsXML" ]; then
echo "<settings xmlns=\"http://maven.apache.org/SETTINGS/1.0.0\"" >> "$settingsXML"
echo " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" >> "$settingsXML"
echo " xsi:schemaLocation=\"http://maven.apache.org/SETTINGS/1.0.0" >> "$settingsXML"
echo " https://maven.apache.org/xsd/settings-1.0.0.xsd\">" >> "$settingsXML"
echo " <mirrors>" >> "$settingsXML"
echo " <mirror>" >> "$settingsXML"
echo " <url>\${env.MAVEN_MIRROR_URL}</url>" >> "$settingsXML"
echo " <mirrorOf>external:*</mirrorOf>" >> "$settingsXML"
echo " </mirror>" >> "$settingsXML"
echo " </mirrors>" >> "$settingsXML"
echo "</settings>" >> "$settingsXML"
else
if ! grep -q "<url>\${env.MAVEN_MIRROR_URL}</url>" "$settingsXML"; then
if grep -q "<mirrors>" "$settingsXML"; then
sed -i 's/<mirrors>/<mirrors>\n <mirror>\n <url>${env.MAVEN_MIRROR_URL}<\/url>\n <mirrorOf>external:\*<\/mirrorOf>\n <\/mirror>/' "$settingsXML"
else
sed -i 's/<\/settings>/ <mirrors>\n <mirror>\n <url>${env.MAVEN_MIRROR_URL}<\/url>\n <mirrorOf>external:*<\/mirrorOf>\n <\/mirror>\n <\/mirrors>\n<\/settings>/' "$settingsXML"
fi
fi
fi
}
[ ! -z "$MAVEN_MIRROR_URL" ] && set_maven_mirror
return 0