@@ -26,36 +26,67 @@ _COMPILE_JVM_OPTS="-Xmx2g -XX:ReservedCodeCacheSize=1g"
26
26
27
27
# Installs any application tarball given a URL, the expected tarball name,
28
28
# and, optionally, a checkable binary path to determine if the binary has
29
- # already been installed
30
- # # Arg1 - URL
31
- # # Arg2 - Tarball Name
32
- # # Arg3 - Checkable Binary
29
+ # already been installed. Arguments:
30
+ # 1 - Mirror host
31
+ # 2 - URL path on host
32
+ # 3 - URL query string
33
+ # 4 - checksum suffix
34
+ # 5 - Tarball Name
35
+ # 6 - Checkable Binary
33
36
install_app () {
34
- local remote_tarball=" $1 "
35
- local local_tarball=" ${_DIR} /$2 "
36
- local binary=" ${_DIR} /$3 "
37
+ local mirror_host=" $1 "
38
+ local url_path=" $2 "
39
+ local url_query=" $3 "
40
+ local checksum_suffix=" $4 "
41
+ local local_tarball=" ${_DIR} /$5 "
42
+ local binary=" ${_DIR} /$6 "
43
+ local remote_tarball=" ${mirror_host} /${url_path}${url_query} "
44
+ local local_checksum=" ${local_tarball} .${checksum_suffix} "
45
+ local remote_checksum=" https://archive.apache.org/dist/${url_path} .${checksum_suffix} "
37
46
38
47
local curl_opts=" --silent --show-error -L"
39
48
local wget_opts=" --no-verbose"
40
49
41
- if [ -z " $3 " -o ! -f " $binary " ]; then
50
+ if [ ! -f " $binary " ]; then
42
51
# check if we already have the tarball
43
52
# check if we have curl installed
44
53
# download application
45
- [ ! -f " ${local_tarball} " ] && [ $( command -v curl) ] && \
46
- echo " exec: curl ${curl_opts} ${remote_tarball} " 1>&2 && \
54
+ if [ ! -f " ${local_tarball} " -a $( command -v curl) ]; then
55
+ echo " exec: curl ${curl_opts} ${remote_tarball} " 1>&2
47
56
curl ${curl_opts} " ${remote_tarball} " > " ${local_tarball} "
57
+ if [ ! -z " ${checksum_suffix} " ]; then
58
+ echo " exec: curl ${curl_opts} ${remote_checksum} " 1>&2
59
+ curl ${curl_opts} " ${remote_checksum} " > " ${local_checksum} "
60
+ fi
61
+ fi
48
62
# if the file still doesn't exist, lets try `wget` and cross our fingers
49
- [ ! -f " ${local_tarball} " ] && [ $( command -v wget) ] && \
50
- echo " exec: wget ${wget_opts} ${remote_tarball} " 1>&2 && \
63
+ if [ ! -f " ${local_tarball} " -a $( command -v wget) ]; then
64
+ echo " exec: wget ${wget_opts} ${remote_tarball} " 1>&2
51
65
wget ${wget_opts} -O " ${local_tarball} " " ${remote_tarball} "
66
+ if [ ! -z " ${checksum_suffix} " ]; then
67
+ echo " exec: wget ${wget_opts} ${remote_checksum} " 1>&2
68
+ wget ${wget_opts} -O " ${local_checksum} " " ${remote_checksum} "
69
+ fi
70
+ fi
52
71
# if both were unsuccessful, exit
53
- [ ! -f " ${local_tarball} " ] && \
54
- echo -n " ERROR: Cannot download $2 with cURL or wget; " && \
55
- echo " please install manually and try again." && \
72
+ if [ ! -f " ${local_tarball} " ]; then
73
+ echo -n " ERROR: Cannot download ${remote_tarball} with cURL or wget; please install manually and try again."
56
74
exit 2
57
- cd " ${_DIR} " && tar -xzf " $2 "
58
- rm -rf " $local_tarball "
75
+ fi
76
+ # Checksum may not have been specified; don't check if doesn't exist
77
+ if [ -f " ${local_checksum} " ]; then
78
+ echo " ${local_tarball} " >> ${local_checksum} # two spaces + file are important!
79
+ # Assuming SHA512 here for now
80
+ echo " Veryfing checksum from ${local_checksum} " 1>&2
81
+ if ! shasum -a 512 -q -c " ${local_checksum} " ; then
82
+ echo " Bad checksum from ${remote_checksum} "
83
+ exit 2
84
+ fi
85
+ fi
86
+
87
+ cd " ${_DIR} " && tar -xzf " ${local_tarball} "
88
+ rm -rf " ${local_tarball} "
89
+ rm -f " ${local_checksum} "
59
90
fi
60
91
}
61
92
@@ -71,21 +102,26 @@ install_mvn() {
71
102
local MVN_DETECTED_VERSION=" $( mvn --version | head -n1 | awk ' {print $3}' ) "
72
103
fi
73
104
if [ $( version $MVN_DETECTED_VERSION ) -lt $( version $MVN_VERSION ) ]; then
74
- local FILE_PATH=" maven/maven-3/${MVN_VERSION} /binaries/apache-maven-${MVN_VERSION} -bin.tar.gz"
105
+ local MVN_TARBALL=" apache-maven-${MVN_VERSION} -bin.tar.gz"
106
+ local FILE_PATH=" maven/maven-3/${MVN_VERSION} /binaries/${MVN_TARBALL} "
75
107
local APACHE_MIRROR=${APACHE_MIRROR:- ' https://www.apache.org/dyn/closer.lua' }
76
- local MIRROR_URL= " ${APACHE_MIRROR} / ${FILE_PATH} ?action=download"
108
+ local MIRROR_URL_QUERY= " ?action=download"
77
109
78
110
if [ $( command -v curl) ]; then
79
- if ! curl -L --output /dev/null --silent --head --fail " ${MIRROR_URL } " ; then
111
+ if ! curl -L --output /dev/null --silent --head --fail " ${APACHE_MIRROR} / ${FILE_PATH}${MIRROR_URL_QUERY }" ; then
80
112
# Fall back to archive.apache.org for older Maven
81
113
echo " Falling back to archive.apache.org to download Maven"
82
- MIRROR_URL=" https://archive.apache.org/dist/${FILE_PATH} "
114
+ APACHE_MIRROR=" https://archive.apache.org/dist"
115
+ MIRROR_URL_QUERY=" "
83
116
fi
84
117
fi
85
118
86
119
install_app \
87
- " ${MIRROR_URL} " \
88
- " apache-maven-${MVN_VERSION} -bin.tar.gz" \
120
+ " ${APACHE_MIRROR} " \
121
+ " ${FILE_PATH} " \
122
+ " ${MIRROR_URL_QUERY} " \
123
+ " sha512" \
124
+ " ${MVN_TARBALL} " \
89
125
" apache-maven-${MVN_VERSION} /bin/mvn"
90
126
91
127
MVN_BIN=" ${_DIR} /apache-maven-${MVN_VERSION} /bin/mvn"
@@ -101,10 +137,14 @@ install_scala() {
101
137
local scala_version=` grep " scala.version" " ${_DIR} /../pom.xml" | grep ${scala_binary_version} | head -n1 | awk -F ' [<>]' ' {print $3}' `
102
138
local scala_bin=" ${_DIR} /scala-${scala_version} /bin/scala"
103
139
local TYPESAFE_MIRROR=${TYPESAFE_MIRROR:- https:// downloads.lightbend.com}
140
+ local SCALA_TARBALL=" scala-${scala_version} .tgz"
104
141
105
142
install_app \
106
- " ${TYPESAFE_MIRROR} /scala/${scala_version} /scala-${scala_version} .tgz" \
107
- " scala-${scala_version} .tgz" \
143
+ " ${TYPESAFE_MIRROR} " \
144
+ " scala/${scala_version} /${SCALA_TARBALL} " \
145
+ " " \
146
+ " " \
147
+ ${SCALA_TARBALL} \
108
148
" scala-${scala_version} /bin/scala"
109
149
110
150
SCALA_COMPILER=" $( cd " $( dirname " ${scala_bin} " ) /../lib" && pwd) /scala-compiler.jar"
0 commit comments