|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Determine the current working directory |
| 4 | +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 5 | + |
| 6 | +# Called before any binaries are installed for any unknown operating system. |
| 7 | +# Current checks are as follows: |
| 8 | +# - NA |
| 9 | +prep_install_for_unknown() { |
| 10 | + echo "ERROR: Forced installation is not available at this time for an" |
| 11 | + echo "Operating System of type $OSTYPE" |
| 12 | + exit 1 |
| 13 | +} |
| 14 | + |
| 15 | +# Called before any binaries are installed for the Solaris operating system. |
| 16 | +# Current checks are as follows: |
| 17 | +# - NA |
| 18 | +prep_install_for_solaris() { |
| 19 | + echo "ERROR: Forced installation is not available at this time for" |
| 20 | + echo "Solaris-based systems." |
| 21 | + exit 1 |
| 22 | +} |
| 23 | + |
| 24 | +# Called before any binaries are installed for the BSD operating system. |
| 25 | +# Current checks are as follows: |
| 26 | +# - NA |
| 27 | +prep_install_for_bsd() { |
| 28 | + echo "ERROR: Forced installation is not available at this time for BSD-based systems." |
| 29 | + exit 1 |
| 30 | +} |
| 31 | + |
| 32 | +# Called before any binaries are installed for the Linux operating system. |
| 33 | +# Current checks are as follows: |
| 34 | +# - NA |
| 35 | +prep_install_for_linux() { |
| 36 | + echo |
| 37 | +} |
| 38 | + |
| 39 | +# Called before any binaries are installed for the OS X operating system. |
| 40 | +# Current checks are as follows: |
| 41 | +# - 'brew' must be installed |
| 42 | +prep_install_for_osx() { |
| 43 | + [ -z "`which brew 2>/dev/null`" ] && \ |
| 44 | + echo "ERROR: Must have 'brew' installed for forced installation on OSX." && \ |
| 45 | + echo " - You can download 'brew' at: http://brew.sh/" && \ |
| 46 | + exit 1 |
| 47 | +} |
| 48 | + |
| 49 | +# Determine if a given application is already installed and, if not, check for |
| 50 | +# forced installation, |
| 51 | +## Arg1 - application name |
| 52 | +check_and_install_app() { |
| 53 | + if [ -z "`which $1 2>/dev/null`" ]; then |
| 54 | + # attempt to force install if flagged |
| 55 | + if [ -n "${FORCE_INSTALL}" ]; then |
| 56 | + local resource="${DIR}/packages/$1.sh" |
| 57 | + if [ -f "$resource" ]; then |
| 58 | + source "${DIR}/packages/$1.sh" |
| 59 | + prep_install_for_${_OSTYPE} |
| 60 | + install_$1_for_${_OSTYPE} |
| 61 | + else |
| 62 | + echo "ERROR: Cannot find the $1.sh build file from within ${DIR}/packages." |
| 63 | + echo " Ensure the file exists and is accesible." |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | + # else exit with error message |
| 67 | + else |
| 68 | + echo "ERROR: $1 isn't installed; please install or automatically force install (-f)." |
| 69 | + exit 2 |
| 70 | + fi |
| 71 | + fi |
| 72 | +} |
| 73 | + |
| 74 | +# Set a cleaned OS type string based on the $OSTYPE bash variable |
| 75 | +case "$OSTYPE" in |
| 76 | + solaris*) |
| 77 | + _OSTYPE="solaris" |
| 78 | + ;; |
| 79 | + darwin*) |
| 80 | + _OSTYPE="osx" |
| 81 | + ;; |
| 82 | + linux*) |
| 83 | + _OSTYPE="linux" |
| 84 | + ;; |
| 85 | + bsd*) |
| 86 | + _OSTYPE="bsd" |
| 87 | + ;; |
| 88 | + *) |
| 89 | + _OSTYPE="unknown" |
| 90 | + ;; |
| 91 | +esac |
| 92 | + |
| 93 | +# Here we build our own CLI event loop with the '--' as the stop |
| 94 | +OPT="$1" |
| 95 | +while [ ! "$OPT" = "--" -a ! $# -eq 0 ]; do |
| 96 | + case $OPT in |
| 97 | + -f) |
| 98 | + FORCE_INSTALL=1 |
| 99 | + shift |
| 100 | + ;; |
| 101 | + -p=*) |
| 102 | + ZINC_PORT=${OPT/-p=/} |
| 103 | + shift |
| 104 | + ;; |
| 105 | + *) |
| 106 | + echo "Unknown option: $OPT" |
| 107 | + shift |
| 108 | + ;; |
| 109 | + esac |
| 110 | + OPT="$1" |
| 111 | +done |
| 112 | +shift |
| 113 | + |
| 114 | +# Setup healthy defaults for the Zinc port if none were provided |
| 115 | +ZINC_PORT=${ZINC_PORT:-"3030"} |
| 116 | + |
| 117 | +# Check and install all applications necessary to fully build Spark |
| 118 | +check_and_install_app "mvn" |
| 119 | +check_and_install_app "zinc" |
| 120 | +check_and_install_app "scala" |
| 121 | + |
| 122 | +# Now that zinc is ensured to be installed, check its status and, if not |
| 123 | +# running, start it |
| 124 | +if [ -z "`zinc -status`" ]; then |
| 125 | + zinc -start -port ${ZINC_PORT} |
| 126 | +fi |
| 127 | + |
| 128 | +# Determine the parameters pushed in from the command line and, if any are |
| 129 | +# present, use those within the maven |
| 130 | +if [ $# -gt 0 ]; then |
| 131 | + mvn "$@" |
| 132 | +else |
| 133 | + mvn clean package -DskipTests |
| 134 | +fi |
0 commit comments