|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# |
| 4 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 5 | +# contributor license agreements. See the NOTICE file distributed with |
| 6 | +# this work for additional information regarding copyright ownership. |
| 7 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 8 | +# (the "License"); you may not use this file except in compliance with |
| 9 | +# the License. You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +# See the License for the specific language governing permissions and |
| 17 | +# limitations under the License. |
| 18 | +# |
| 19 | + |
| 20 | +# Determine the current working directory |
| 21 | +_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 22 | +# Preserve the calling directory |
| 23 | +_CALLING_DIR="$(pwd)" |
| 24 | + |
| 25 | +# Installs any application tarball given a URL, the expected tarball name, |
| 26 | +# and, optionally, a checkable binary path to determine if the binary has |
| 27 | +# already been installed |
| 28 | +## Arg1 - URL |
| 29 | +## Arg2 - Tarball Name |
| 30 | +## Arg3 - Checkable Binary |
| 31 | +install_app() { |
| 32 | + local remote_tarball="$1/$2" |
| 33 | + local local_tarball="${_DIR}/$2" |
| 34 | + local binary="${_DIR}/$3" |
| 35 | + |
| 36 | + # setup `curl` and `wget` silent options if we're running on Jenkins |
| 37 | + local curl_opts="" |
| 38 | + local wget_opts="" |
| 39 | + if [ -n "$AMPLAB_JENKINS" ]; then |
| 40 | + curl_opts="-s" |
| 41 | + wget_opts="--quiet" |
| 42 | + else |
| 43 | + curl_opts="--progress-bar" |
| 44 | + wget_opts="--progress=bar:force" |
| 45 | + fi |
| 46 | + |
| 47 | + if [ -z "$3" -o ! -f "$binary" ]; then |
| 48 | + # check if we already have the tarball |
| 49 | + # check if we have curl installed |
| 50 | + # download application |
| 51 | + [ ! -f "${local_tarball}" ] && [ -n "`which curl 2>/dev/null`" ] && \ |
| 52 | + echo "exec: curl ${curl_opts} ${remote_tarball}" && \ |
| 53 | + curl ${curl_opts} "${remote_tarball}" > "${local_tarball}" |
| 54 | + # if the file still doesn't exist, lets try `wget` and cross our fingers |
| 55 | + [ ! -f "${local_tarball}" ] && [ -n "`which wget 2>/dev/null`" ] && \ |
| 56 | + echo "exec: wget ${wget_opts} ${remote_tarball}" && \ |
| 57 | + wget ${wget_opts} -O "${local_tarball}" "${remote_tarball}" |
| 58 | + # if both were unsuccessful, exit |
| 59 | + [ ! -f "${local_tarball}" ] && \ |
| 60 | + echo -n "ERROR: Cannot download $2 with cURL or wget; " && \ |
| 61 | + echo "please install manually and try again." && \ |
| 62 | + exit 2 |
| 63 | + cd "${_DIR}" && tar -xzf "$2" |
| 64 | + rm -rf "$local_tarball" |
| 65 | + fi |
| 66 | +} |
| 67 | + |
| 68 | +# Install maven under the build/ folder |
| 69 | +install_mvn() { |
| 70 | + install_app \ |
| 71 | + "http://apache.claz.org/maven/maven-3/3.2.3/binaries" \ |
| 72 | + "apache-maven-3.2.3-bin.tar.gz" \ |
| 73 | + "apache-maven-3.2.3/bin/mvn" |
| 74 | + MVN_BIN="${_DIR}/apache-maven-3.2.3/bin/mvn" |
| 75 | +} |
| 76 | + |
| 77 | +# Install zinc under the build/ folder |
| 78 | +install_zinc() { |
| 79 | + local zinc_path="zinc-0.3.5.3/bin/zinc" |
| 80 | + [ ! -f "${zinc_path}" ] && ZINC_INSTALL_FLAG=1 |
| 81 | + install_app \ |
| 82 | + "http://downloads.typesafe.com/zinc/0.3.5.3" \ |
| 83 | + "zinc-0.3.5.3.tgz" \ |
| 84 | + "${zinc_path}" |
| 85 | + ZINC_BIN="${_DIR}/${zinc_path}" |
| 86 | +} |
| 87 | + |
| 88 | +# Determine the Scala version from the root pom.xml file, set the Scala URL, |
| 89 | +# and, with that, download the specific version of Scala necessary under |
| 90 | +# the build/ folder |
| 91 | +install_scala() { |
| 92 | + # determine the Scala version used in Spark |
| 93 | + local scala_version=`grep "scala.version" "${_DIR}/../pom.xml" | \ |
| 94 | + head -1 | cut -f2 -d'>' | cut -f1 -d'<'` |
| 95 | + local scala_bin="${_DIR}/scala-${scala_version}/bin/scala" |
| 96 | + |
| 97 | + install_app \ |
| 98 | + "http://downloads.typesafe.com/scala/${scala_version}" \ |
| 99 | + "scala-${scala_version}.tgz" \ |
| 100 | + "scala-${scala_version}/bin/scala" |
| 101 | + |
| 102 | + SCALA_COMPILER="$(cd "$(dirname ${scala_bin})/../lib" && pwd)/scala-compiler.jar" |
| 103 | + SCALA_LIBRARY="$(cd "$(dirname ${scala_bin})/../lib" && pwd)/scala-library.jar" |
| 104 | +} |
| 105 | + |
| 106 | +# Determines if a given application is already installed. If not, will attempt |
| 107 | +# to install |
| 108 | +## Arg1 - application name |
| 109 | +## Arg2 - Alternate path to local install under build/ dir |
| 110 | +check_and_install_app() { |
| 111 | + # create the local environment variable in uppercase |
| 112 | + local app_bin="`echo $1 | awk '{print toupper(\$0)}'`_BIN" |
| 113 | + # some black magic to set the generated app variable (i.e. MVN_BIN) into the |
| 114 | + # environment |
| 115 | + eval "${app_bin}=`which $1 2>/dev/null`" |
| 116 | + |
| 117 | + if [ -z "`which $1 2>/dev/null`" ]; then |
| 118 | + install_$1 |
| 119 | + fi |
| 120 | +} |
| 121 | + |
| 122 | +# Setup healthy defaults for the Zinc port if none were provided from |
| 123 | +# the environment |
| 124 | +ZINC_PORT=${ZINC_PORT:-"3030"} |
| 125 | + |
| 126 | +# Check and install all applications necessary to build Spark |
| 127 | +check_and_install_app "mvn" |
| 128 | + |
| 129 | +# Install the proper version of Scala and Zinc for the build |
| 130 | +install_zinc |
| 131 | +install_scala |
| 132 | + |
| 133 | +# Reset the current working directory |
| 134 | +cd "${_CALLING_DIR}" |
| 135 | + |
| 136 | +# Now that zinc is ensured to be installed, check its status and, if its |
| 137 | +# not running or just installed, start it |
| 138 | +if [ -n "${ZINC_INSTALL_FLAG}" -o -z "`${ZINC_BIN} -status`" ]; then |
| 139 | + ${ZINC_BIN} -shutdown |
| 140 | + ${ZINC_BIN} -start -port ${ZINC_PORT} \ |
| 141 | + -scala-compiler "${SCALA_COMPILER}" \ |
| 142 | + -scala-library "${SCALA_LIBRARY}" &>/dev/null |
| 143 | +fi |
| 144 | + |
| 145 | +# Set any `mvn` options if not already present |
| 146 | +export MAVEN_OPTS=${MAVEN_OPTS:-"-Xmx2g -XX:MaxPermSize=512M -XX:ReservedCodeCacheSize=512m"} |
| 147 | + |
| 148 | +# Last, call the `mvn` command as usual |
| 149 | +${MVN_BIN} "$@" |
0 commit comments