blob: ff8893c85c999a52467f173fbc2f560795152a24 [file] [log] [blame]
Thomas Vachuska0483bee2016-05-04 19:37:51 -07001#!/bin/bash
Brian O'Connor9be23632016-04-08 18:23:45 -07002# -----------------------------------------------------------------------------
3# Runs the custom version of Buck required by ONOS.
4# -----------------------------------------------------------------------------
5
6set -e
7
Yi Tsengd74fe382018-02-16 16:34:19 -08008BUCK_URL="http://repo1.maven.org/maven2/org/onosproject/onos-buck/v2018.01.17.01/buck-v2018.01.17.01.zip"
9BUCK_SHA="4a70a84ef40a06762a7248db25590696e80af9fe"
Brian O'Connor9be23632016-04-08 18:23:45 -070010
Yuta HIGUCHI28bcaf12018-02-13 12:12:16 -080011# onos-yang-tools buck plugin version
Yi Tsengd74fe382018-02-16 16:34:19 -080012YANG_VER="2.3.1"
Yuta HIGUCHI28bcaf12018-02-13 12:12:16 -080013
Brian O'Connor9be23632016-04-08 18:23:45 -070014[ "-U" = "$1" ] && shift && FORCE_UPDATE=True
15
Brian O'Connor4ed68b62016-10-27 21:08:37 -070016ROOT_DIR=${ONOS_ROOT:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )"}
17
18mkdir -p $ROOT_DIR/bin
19pushd $ROOT_DIR/bin > /dev/null
Brian O'Connor9be23632016-04-08 18:23:45 -070020
Brian O'Connor1b55bfb2017-03-21 15:30:38 -070021if [ -n "$FORCE_UPDATE" ] || [ ! -f "buck" ] || [ "$BUCK_SHA" != "$(cat .buck_sha)" ]; then
Thomas Vachuska96f2b2c2017-07-19 10:08:30 -070022 echo "Updating Buck..." >&2
Brian O'Connor1b55bfb2017-03-21 15:30:38 -070023 rm -fr .buck_version .buck_sha buck plugins
Thomas Vachuskaae9ba212016-10-26 15:44:05 -070024 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'Connor9be23632016-04-08 18:23:45 -070028 if [ -n "$(which shasum)" ]; then
Thomas Vachuskaae9ba212016-10-26 15:44:05 -070029 SHA=$(shasum cache/$BUCK_FILE | cut -d' ' -f1)
Brian O'Connor1b55bfb2017-03-21 15:30:38 -070030 if [ "$SHA" != "$BUCK_SHA" ]; then
Brian O'Connor9be23632016-04-08 18:23:45 -070031 echo "ERROR: Downloaded SHA ($SHA) does not match expected SHA ($BUCK_SHA)" &&
Brian O'Connore1c02f42016-12-02 12:49:55 -080032 rm -f cache/$BUCK_FILE && exit 1
Brian O'Connor1b55bfb2017-03-21 15:30:38 -070033 else
34 echo "$SHA" > .buck_sha
35 fi
Brian O'Connor9be23632016-04-08 18:23:45 -070036 else
37 echo "SHA cannot be verified"
38 fi
Thomas Vachuskaae9ba212016-10-26 15:44:05 -070039 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'Connor4ed68b62016-10-27 21:08:37 -070042 rm -rf $ROOT_DIR/buck-out
43 printf "Successfully updated Buck in $ROOT_DIR/bin/buck to $BUCK_FILE\n\n"
Brian O'Connor9be23632016-04-08 18:23:45 -070044fi
Yuta HIGUCHI28bcaf12018-02-13 12:12:16 -080045
46# Fetch & install onos yang tools buck plugin
47YANG_PLUGIN_CACHE="cache/onos-yang-compiler-buck-plugin-$YANG_VER.jar"
48if 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
56else
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
81fi
82install -Cv "$YANG_PLUGIN_CACHE" plugins/yang.jar
83
Brian O'Connor9be23632016-04-08 18:23:45 -070084popd > /dev/null
85
Brian O'Connor4ed68b62016-10-27 21:08:37 -070086BUCK=$ROOT_DIR/bin/buck
Brian O'Connore8468b52016-07-25 13:42:36 -070087
Yuta HIGUCHIb1fa40d2017-02-22 11:28:13 -080088if [ "${ONOS_NO_BUCKD:-1}" == "1" ]; then
89 export NO_BUCKD=1
90fi
91
Thomas Vachuskab51707b2018-02-07 09:05:09 -080092# HACK: Clean-up frequent problem-causers from buck-out
93rm -fr \
94 $ONOS_ROOT/buck-out/bin/lib/.netty \
95 $ONOS_ROOT/buck-out/bin/lib/.KRYO
96
Brian O'Connor9be23632016-04-08 18:23:45 -070097# Finally, run the Buck command...
Yuta HIGUCHIb1fa40d2017-02-22 11:28:13 -080098$BUCK "$@"