blob: c01bd6ab9d4ec58cc5adbb0f871639c56e443801 [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
Ray Milkey60b00592018-01-10 16:56:10 -08008BUCK_URL="http://repo1.maven.org/maven2/org/onosproject/onos-buck/v2017.09.01.01/buck-v2017.09.01.01.zip"
Ray Milkeye9019322017-09-01 10:19:17 -07009BUCK_SHA="9addcfd68518ee51b8f08135a7828b38dffb8fe5"
Brian O'Connor9be23632016-04-08 18:23:45 -070010
11[ "-U" = "$1" ] && shift && FORCE_UPDATE=True
12
Brian O'Connor4ed68b62016-10-27 21:08:37 -070013ROOT_DIR=${ONOS_ROOT:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )"}
14
15mkdir -p $ROOT_DIR/bin
16pushd $ROOT_DIR/bin > /dev/null
Brian O'Connor9be23632016-04-08 18:23:45 -070017
Brian O'Connor1b55bfb2017-03-21 15:30:38 -070018if [ -n "$FORCE_UPDATE" ] || [ ! -f "buck" ] || [ "$BUCK_SHA" != "$(cat .buck_sha)" ]; then
Thomas Vachuska96f2b2c2017-07-19 10:08:30 -070019 echo "Updating Buck..." >&2
Brian O'Connor1b55bfb2017-03-21 15:30:38 -070020 rm -fr .buck_version .buck_sha buck plugins
Thomas Vachuskaae9ba212016-10-26 15:44:05 -070021 mkdir -p cache
22 BUCK_FILE=$(basename $BUCK_URL)
23 # Check the local cache; download to cache if required
24 [ -f "cache/$BUCK_FILE" ] || curl -o cache/$BUCK_FILE -L $BUCK_URL
Brian O'Connor9be23632016-04-08 18:23:45 -070025 if [ -n "$(which shasum)" ]; then
Thomas Vachuskaae9ba212016-10-26 15:44:05 -070026 SHA=$(shasum cache/$BUCK_FILE | cut -d' ' -f1)
Brian O'Connor1b55bfb2017-03-21 15:30:38 -070027 if [ "$SHA" != "$BUCK_SHA" ]; then
Brian O'Connor9be23632016-04-08 18:23:45 -070028 echo "ERROR: Downloaded SHA ($SHA) does not match expected SHA ($BUCK_SHA)" &&
Brian O'Connore1c02f42016-12-02 12:49:55 -080029 rm -f cache/$BUCK_FILE && exit 1
Brian O'Connor1b55bfb2017-03-21 15:30:38 -070030 else
31 echo "$SHA" > .buck_sha
32 fi
Brian O'Connor9be23632016-04-08 18:23:45 -070033 else
34 echo "SHA cannot be verified"
35 fi
Thomas Vachuskaae9ba212016-10-26 15:44:05 -070036 unzip cache/$BUCK_FILE
37 # Kill buckd
38 ps -ef | egrep buckd | grep -v egrep | cut -c7-11 | xargs kill 2>/dev/null || :
Brian O'Connor4ed68b62016-10-27 21:08:37 -070039 rm -rf $ROOT_DIR/buck-out
40 printf "Successfully updated Buck in $ROOT_DIR/bin/buck to $BUCK_FILE\n\n"
Brian O'Connor9be23632016-04-08 18:23:45 -070041fi
42popd > /dev/null
43
Brian O'Connor4ed68b62016-10-27 21:08:37 -070044BUCK=$ROOT_DIR/bin/buck
Brian O'Connore8468b52016-07-25 13:42:36 -070045
Yuta HIGUCHIb1fa40d2017-02-22 11:28:13 -080046if [ "${ONOS_NO_BUCKD:-1}" == "1" ]; then
47 export NO_BUCKD=1
48fi
49
Brian O'Connor9be23632016-04-08 18:23:45 -070050# Finally, run the Buck command...
Yuta HIGUCHIb1fa40d2017-02-22 11:28:13 -080051$BUCK "$@"