Thomas Vachuska | 0483bee | 2016-05-04 19:37:51 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 2 | # ----------------------------------------------------------------------------- |
| 3 | # Runs the custom version of Buck required by ONOS. |
| 4 | # ----------------------------------------------------------------------------- |
| 5 | |
| 6 | set -e |
| 7 | |
Ray Milkey | 5193cb7 | 2018-02-09 11:21:32 -0800 | [diff] [blame] | 8 | BUCK_URL="http://repo1.maven.org/maven2/org/onosproject/onos-buck/v2018.02.09.01/buck-v2018.02.09.01.zip" |
| 9 | BUCK_SHA="45d8bd28f441991257babf89f7a317edb3a2b536" |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 10 | |
Yuta HIGUCHI | 28bcaf1 | 2018-02-13 12:12:16 -0800 | [diff] [blame^] | 11 | # onos-yang-tools buck plugin version |
| 12 | YANG_VER="2.4" |
| 13 | |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 14 | [ "-U" = "$1" ] && shift && FORCE_UPDATE=True |
| 15 | |
Brian O'Connor | 4ed68b6 | 2016-10-27 21:08:37 -0700 | [diff] [blame] | 16 | ROOT_DIR=${ONOS_ROOT:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )"} |
| 17 | |
| 18 | mkdir -p $ROOT_DIR/bin |
| 19 | pushd $ROOT_DIR/bin > /dev/null |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 20 | |
Brian O'Connor | 1b55bfb | 2017-03-21 15:30:38 -0700 | [diff] [blame] | 21 | if [ -n "$FORCE_UPDATE" ] || [ ! -f "buck" ] || [ "$BUCK_SHA" != "$(cat .buck_sha)" ]; then |
Thomas Vachuska | 96f2b2c | 2017-07-19 10:08:30 -0700 | [diff] [blame] | 22 | echo "Updating Buck..." >&2 |
Brian O'Connor | 1b55bfb | 2017-03-21 15:30:38 -0700 | [diff] [blame] | 23 | rm -fr .buck_version .buck_sha buck plugins |
Thomas Vachuska | ae9ba21 | 2016-10-26 15:44:05 -0700 | [diff] [blame] | 24 | mkdir -p cache |
| 25 | BUCK_FILE=$(basename $BUCK_URL) |
| 26 | # Check the local cache; download to cache if required |
| 27 | [ -f "cache/$BUCK_FILE" ] || curl -o cache/$BUCK_FILE -L $BUCK_URL |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 28 | if [ -n "$(which shasum)" ]; then |
Thomas Vachuska | ae9ba21 | 2016-10-26 15:44:05 -0700 | [diff] [blame] | 29 | SHA=$(shasum cache/$BUCK_FILE | cut -d' ' -f1) |
Brian O'Connor | 1b55bfb | 2017-03-21 15:30:38 -0700 | [diff] [blame] | 30 | if [ "$SHA" != "$BUCK_SHA" ]; then |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 31 | echo "ERROR: Downloaded SHA ($SHA) does not match expected SHA ($BUCK_SHA)" && |
Brian O'Connor | e1c02f4 | 2016-12-02 12:49:55 -0800 | [diff] [blame] | 32 | rm -f cache/$BUCK_FILE && exit 1 |
Brian O'Connor | 1b55bfb | 2017-03-21 15:30:38 -0700 | [diff] [blame] | 33 | else |
| 34 | echo "$SHA" > .buck_sha |
| 35 | fi |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 36 | else |
| 37 | echo "SHA cannot be verified" |
| 38 | fi |
Thomas Vachuska | ae9ba21 | 2016-10-26 15:44:05 -0700 | [diff] [blame] | 39 | unzip cache/$BUCK_FILE |
| 40 | # Kill buckd |
| 41 | ps -ef | egrep buckd | grep -v egrep | cut -c7-11 | xargs kill 2>/dev/null || : |
Brian O'Connor | 4ed68b6 | 2016-10-27 21:08:37 -0700 | [diff] [blame] | 42 | rm -rf $ROOT_DIR/buck-out |
| 43 | printf "Successfully updated Buck in $ROOT_DIR/bin/buck to $BUCK_FILE\n\n" |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 44 | fi |
Yuta HIGUCHI | 28bcaf1 | 2018-02-13 12:12:16 -0800 | [diff] [blame^] | 45 | |
| 46 | # Fetch & install onos yang tools buck plugin |
| 47 | YANG_PLUGIN_CACHE="cache/onos-yang-compiler-buck-plugin-$YANG_VER.jar" |
| 48 | if hash mvn 2>/dev/null; then |
| 49 | if [[ $YANG_VER = *"-SNAPSHOT" ]] || [ ! -f "$YANG_PLUGIN_CACHE" ]; then |
| 50 | ARTIFACT="org.onosproject:onos-yang-compiler-buck-plugin:$YANG_VER" |
| 51 | mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.2:copy \ |
| 52 | -Dartifact=$ARTIFACT \ |
| 53 | -Dtransitive=false -Dmdep.overWriteSnapshots=true \ |
| 54 | -DoutputDirectory=cache > /dev/null |
| 55 | fi |
| 56 | else |
| 57 | if [ ! -f "$YANG_PLUGIN_CACHE" ]; then |
| 58 | if [[ $YANG_VER = *"-SNAPSHOT" ]]; then |
| 59 | echo "mvn command must be installed to handle SNAPSHOT version" |
| 60 | exit 1 |
| 61 | fi |
| 62 | |
| 63 | curl -o "$YANG_PLUGIN_CACHE" \ |
| 64 | -L https://repo1.maven.org/maven2/org/onosproject/onos-yang-compiler-buck-plugin/$YANG_VER/onos-yang-compiler-buck-plugin-$YANG_VER.jar |
| 65 | fi |
| 66 | |
| 67 | if [[ $YANG_VER != *"-SNAPSHOT" ]] && hash shasum 2>/dev/null; then |
| 68 | SHA=$(shasum $YANG_PLUGIN_CACHE | cut -d' ' -f1) |
| 69 | if [ ! -f "$YANG_PLUGIN_CACHE".sha1 ]; then |
| 70 | curl -o "$YANG_PLUGIN_CACHE".sha1 \ |
| 71 | -L https://repo1.maven.org/maven2/org/onosproject/onos-yang-compiler-buck-plugin/$YANG_VER/onos-yang-compiler-buck-plugin-$YANG_VER.jar.sha1 |
| 72 | fi |
| 73 | YANG_PLUGIN_SHA=$(cat "$YANG_PLUGIN_CACHE".sha1) |
| 74 | if [ "$SHA" != "$YANG_PLUGIN_SHA" ]; then |
| 75 | echo "ERROR: Downloaded SHA ($SHA) did not match expected SHA ($YANG_PLUGIN_SHA)" && |
| 76 | rm -f $YANG_PLUGIN_CACHE $YANG_PLUGIN_CACHE.sha1 && exit 1 |
| 77 | fi |
| 78 | else |
| 79 | echo "SHA verification skipped" |
| 80 | fi |
| 81 | fi |
| 82 | install -Cv "$YANG_PLUGIN_CACHE" plugins/yang.jar |
| 83 | |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 84 | popd > /dev/null |
| 85 | |
Brian O'Connor | 4ed68b6 | 2016-10-27 21:08:37 -0700 | [diff] [blame] | 86 | BUCK=$ROOT_DIR/bin/buck |
Brian O'Connor | e8468b5 | 2016-07-25 13:42:36 -0700 | [diff] [blame] | 87 | |
Yuta HIGUCHI | b1fa40d | 2017-02-22 11:28:13 -0800 | [diff] [blame] | 88 | if [ "${ONOS_NO_BUCKD:-1}" == "1" ]; then |
| 89 | export NO_BUCKD=1 |
| 90 | fi |
| 91 | |
Thomas Vachuska | b51707b | 2018-02-07 09:05:09 -0800 | [diff] [blame] | 92 | # HACK: Clean-up frequent problem-causers from buck-out |
| 93 | rm -fr \ |
| 94 | $ONOS_ROOT/buck-out/bin/lib/.netty \ |
| 95 | $ONOS_ROOT/buck-out/bin/lib/.KRYO |
| 96 | |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 97 | # Finally, run the Buck command... |
Yuta HIGUCHI | b1fa40d | 2017-02-22 11:28:13 -0800 | [diff] [blame] | 98 | $BUCK "$@" |