|
| 1 | +#!/usr/bin/env sh |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +# or more contributor license agreements. See the NOTICE file |
| 4 | +# distributed with this work for additional information |
| 5 | +# regarding copyright ownership. The ASF licenses this file |
| 6 | +# to you under the Apache License, Version 2.0 (the |
| 7 | +# "License"); you may not use this file except in compliance |
| 8 | +# with the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, |
| 13 | +# software distributed under the License is distributed on an |
| 14 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +# KIND, either express or implied. See the License for the |
| 16 | +# specific language governing permissions and limitations |
| 17 | +# under the License. |
| 18 | + |
| 19 | +# Variable for location |
| 20 | +OFBIZ_HOME="$(pwd)" |
| 21 | +GRADLE_OFBIZ_PATH="$OFBIZ_HOME/gradle" |
| 22 | +GRADLE_WRAPPER_OFBIZ_PATH="$GRADLE_OFBIZ_PATH/wrapper" |
| 23 | + |
| 24 | +# version and uri to download the wrapper |
| 25 | +RELEASE="5.0.0" |
| 26 | +GRADLE_WRAPPER_URI="https://dl.bintray.com/apacheofbiz/GradleWrapper/v$RELEASE/" |
| 27 | +GRADLE_WRAPPER_URI_BACKUP="https://github.com/gradle/gradle/raw/v$RELEASE/gradle/wrapper/" |
| 28 | + |
| 29 | +# Embded checksum shasum to control the download |
| 30 | +SHASUM_GRADLE_WRAPPER_FILES="1d23286bcb9e7d3debff18c1b892b9dbb9a4ec6c gradle/wrapper/gradle-wrapper.jar |
| 31 | +f9c2ad227ef1fe774cb0e141abfc431b05fc9fd4 gradle/wrapper/gradle-wrapper.properties" |
| 32 | + |
| 33 | +GRADLE_WRAPPER_JAR="gradle-wrapper.jar" |
| 34 | +GRADLE_WRAPPER_PROPERTIES="gradle-wrapper.properties" |
| 35 | +GRADLE_WRAPPER_FILES="$GRADLE_WRAPPER_JAR $GRADLE_WRAPPER_PROPERTIES" |
| 36 | + |
| 37 | +whereIsBinary() { |
| 38 | + whereis $1 | grep / |
| 39 | +} |
| 40 | + |
| 41 | +# Resolve the command to use for calling and realize the download |
| 42 | +downloadFile() { |
| 43 | + if [ -n "$(whereIsBinary curl)" ]; then |
| 44 | + GET_CMD="curl -L -o $GRADLE_WRAPPER_OFBIZ_PATH/$1 -s -w %{http_code} $2/$1"; |
| 45 | + if [ "$($GET_CMD)" = "200" ]; then |
| 46 | + return 0; |
| 47 | + fi |
| 48 | + elif [ -n "$(whereIsBinary wget)" ]; then |
| 49 | + GET_CMD="wget -q -O $GRADLE_WRAPPER_OFBIZ_PATH/$1 --server-response $2/$1"; |
| 50 | + GET_CMD="$GET_CMD"' 2>&1 > /dev/null | grep "HTTP/.* 200"'; |
| 51 | + if [ -n "$($GET_CMD)" ]; then |
| 52 | + return 0; |
| 53 | + fi |
| 54 | + fi |
| 55 | + return 1 |
| 56 | +} |
| 57 | + |
| 58 | +# Call and if not succes try to use backup |
| 59 | +resolveFile() { |
| 60 | + downloadFile $1 $GRADLE_WRAPPER_URI; |
| 61 | + if [ $? -eq 1 ]; then |
| 62 | + downloadFile $1 $GRADLE_WRAPPER_URI_BACKUP; |
| 63 | + fi |
| 64 | +} |
| 65 | + |
| 66 | +echo " === Prepare operation ==="; |
| 67 | +# Control that we work the script on a good directory |
| 68 | +if [ ! -d "$GRADLE_OFBIZ_PATH" ]; then |
| 69 | + echo "Location seems to be uncorrected, please take care to run 'sh gradle/init-gradle-wrapper.sh' at the Apache OFBiz home"; |
| 70 | + exit 1; |
| 71 | +fi |
| 72 | + |
| 73 | +# check if we have on binary to download missing wrapper |
| 74 | +if [ -z "$(whereIsBinary curl)" ] && [ -z "$(whereIsBinary wget)" ]; then |
| 75 | + echo "No command curl or wget found, please install one or install yourself gradle (more information see README.adoc or https://gradle.org/install)"; |
| 76 | + exit 1 |
| 77 | +fi |
| 78 | + |
| 79 | +if [ ! -r "$GRADLE_WRAPPER_OFBIZ_PATH/$GRADLE_WRAPPER_JAR" ]; then |
| 80 | + echo "$GRADLE_WRAPPER_OFBIZ_PATH/$GRADLE_WRAPPER_JAR not found, we download it" |
| 81 | + |
| 82 | + for fileToDownload in $GRADLE_WRAPPER_FILES; do |
| 83 | + echo " === Download $fileToDownload ==="; |
| 84 | + resolveFile $fileToDownload |
| 85 | + done |
| 86 | + if [ ! $? -eq 0 ]; then |
| 87 | + rm -f $GRADLE_WRAPPER_OFBIZ_PATH/* |
| 88 | + echo "\nDownload files $GRADLE_WRAPPER_FILES from $GRADLE_WRAPPER_URI failed.\nPlease check the log to found the reason and run the script again." |
| 89 | + fi |
| 90 | + echo " === Control downloaded files ===" |
| 91 | + if [ -n "$(whereIsBinary shasum)" ]; then |
| 92 | + echo "$SHASUM_GRADLE_WRAPPER_FILES" | shasum -c -; |
| 93 | + exit 0; |
| 94 | + fi |
| 95 | + |
| 96 | + echo " Warning: shasum not found, skip the control process" |
| 97 | + exit 1; |
| 98 | +fi |
| 99 | +echo " Nothing todo" |
0 commit comments