|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# runs command from parameters and exits with the eoror code of the command |
| 4 | +# if it fails |
| 5 | +function successOrExit { |
| 6 | + "$@" |
| 7 | + local status=$? |
| 8 | + if [ $status -ne 0 ]; then |
| 9 | + echo "$1 exited with error: $status" |
| 10 | + exit $status |
| 11 | + fi |
| 12 | +} |
| 13 | + |
| 14 | +test $1 && MLBUILD_USER=$1 |
| 15 | +test $2 && MLBUILD_PASSWORD=$2 |
| 16 | +test $3 && ML_VERSION=$3 |
| 17 | + |
| 18 | +suffix=$(sed -e 's#.*\.\(\)#\1#' <<< $ML_VERSION) |
| 19 | +if [[ $suffix = 'nightly' ]]; then |
| 20 | + # find today |
| 21 | + day=$(date +"%Y%m%d") |
| 22 | + |
| 23 | + # if the user passed a day string as a param then use it instead |
| 24 | + test $4 && day=$4 |
| 25 | + # make a version number out of the date |
| 26 | + ver="8.0-$day" |
| 27 | + |
| 28 | + echo "********* Downloading MarkLogic nightly $ver" |
| 29 | + |
| 30 | + # fetch/install ML nightly |
| 31 | + fname="MarkLogic-RHEL7-$ver.x86_64.rpm" |
| 32 | + |
| 33 | + url="https://root.marklogic.com/nightly/builds/linux64-rh7/rh7-intel64-80-test-1.marklogic.com/b8_0/pkgs.$day/$fname" |
| 34 | + |
| 35 | + status=$(curl -k --anyauth -u $MLBUILD_USER:$MLBUILD_PASSWORD --head --write-out %{http_code} --silent --output /dev/null $url) |
| 36 | + if [[ $status = 200 ]]; then |
| 37 | + successOrExit curl -k --anyauth -u $MLBUILD_USER:$MLBUILD_PASSWORD -o ./$fname $url |
| 38 | + |
| 39 | + fname=$(pwd)/$fname |
| 40 | + |
| 41 | + yum -y install $fname --skip-broken |
| 42 | + |
| 43 | + echo "********* MarkLogic nightly $ver installed" |
| 44 | + else |
| 45 | + echo "CANNOT DOWNLOAD: status = $status for date $day (URL=\"$url\")" |
| 46 | + exit 1 |
| 47 | + fi |
| 48 | +else |
| 49 | + ver=${ML_VERSION} |
| 50 | + fname=MarkLogic-RHEL7-${ver}.x86_64.rpm |
| 51 | + |
| 52 | + curl -c cookies.txt --data "email=${MLBUILD_USER}&password=${MLBUILD_PASSWORD}" https://developer.marklogic.com/login |
| 53 | + dl_link=$(curl -b cookies.txt --data "download=/download/binaries/8.0/${fname}" https://developer.marklogic.com/get-download-url | perl -pe 's/.*"path":"([^"]+).*/\1/') |
| 54 | + url="https://developer.marklogic.com${dl_link}" |
| 55 | + |
| 56 | + echo "********* Downloading MarkLogic $ver" |
| 57 | + echo "Download URL: $url" |
| 58 | + |
| 59 | + successOrExit curl -k -o ./$fname $url |
| 60 | + |
| 61 | + fname=$(pwd)/$fname |
| 62 | + |
| 63 | + yum -y install $fname --skip-broken |
| 64 | + |
| 65 | + echo "********* MarkLogic $ver installed" |
| 66 | +fi |
0 commit comments