blob: 212949044d75893aecbd349f9977847c3eecacd5 [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
Brian O'Connorbee19492016-12-02 13:03:45 -08008BUCK_URL="http://onlab.vicci.org/onos/third-party/buck-v2016.12.02.01.zip"
9BUCK_SHA="c7b1b46f998c08a175adec37f210c14092f84216"
10REQUIRED_VERSION="buck version c4e714c9c0c774cbb674c2fde0a4419824f0cfdb"
Brian O'Connor9be23632016-04-08 18:23:45 -070011
12[ "-U" = "$1" ] && shift && FORCE_UPDATE=True
13
Brian O'Connor4ed68b62016-10-27 21:08:37 -070014ROOT_DIR=${ONOS_ROOT:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )"}
15
16mkdir -p $ROOT_DIR/bin
17pushd $ROOT_DIR/bin > /dev/null
Brian O'Connor9be23632016-04-08 18:23:45 -070018
19if [ -n "$FORCE_UPDATE" ] || [ ! -f "buck" ] || [ "$REQUIRED_VERSION" != "$(cat .buck_version)" ]; then
Thomas Vachuskaae9ba212016-10-26 15:44:05 -070020 echo "Updating Buck..."
21 rm -fr .buck_version buck plugins
22 mkdir -p cache
23 BUCK_FILE=$(basename $BUCK_URL)
24 # Check the local cache; download to cache if required
25 [ -f "cache/$BUCK_FILE" ] || curl -o cache/$BUCK_FILE -L $BUCK_URL
Brian O'Connor9be23632016-04-08 18:23:45 -070026 if [ -n "$(which shasum)" ]; then
Thomas Vachuskaae9ba212016-10-26 15:44:05 -070027 SHA=$(shasum cache/$BUCK_FILE | cut -d' ' -f1)
Brian O'Connor9be23632016-04-08 18:23:45 -070028 [ "$SHA" != "$BUCK_SHA" ] &&
29 echo "ERROR: Downloaded SHA ($SHA) does not match expected SHA ($BUCK_SHA)" &&
Brian O'Connore1c02f42016-12-02 12:49:55 -080030 rm -f cache/$BUCK_FILE && exit 1
Brian O'Connor9be23632016-04-08 18:23:45 -070031 else
32 echo "SHA cannot be verified"
33 fi
Thomas Vachuskaae9ba212016-10-26 15:44:05 -070034 unzip cache/$BUCK_FILE
35 # Kill buckd
36 ps -ef | egrep buckd | grep -v egrep | cut -c7-11 | xargs kill 2>/dev/null || :
Brian O'Connor4ed68b62016-10-27 21:08:37 -070037 rm -rf $ROOT_DIR/buck-out
38 printf "Successfully updated Buck in $ROOT_DIR/bin/buck to $BUCK_FILE\n\n"
Brian O'Connor9be23632016-04-08 18:23:45 -070039fi
40popd > /dev/null
41
Brian O'Connor4ed68b62016-10-27 21:08:37 -070042BUCK=$ROOT_DIR/bin/buck
Brian O'Connore8468b52016-07-25 13:42:36 -070043
Brian O'Connor9be23632016-04-08 18:23:45 -070044# Finally, run the Buck command...
Thomas Vachuskacedacd42016-12-02 12:21:58 -080045NO_BUCKD=1 $BUCK "$@"