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 | |
Brian O'Connor | bee1949 | 2016-12-02 13:03:45 -0800 | [diff] [blame^] | 8 | BUCK_URL="http://onlab.vicci.org/onos/third-party/buck-v2016.12.02.01.zip" |
| 9 | BUCK_SHA="c7b1b46f998c08a175adec37f210c14092f84216" |
| 10 | REQUIRED_VERSION="buck version c4e714c9c0c774cbb674c2fde0a4419824f0cfdb" |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 11 | |
| 12 | [ "-U" = "$1" ] && shift && FORCE_UPDATE=True |
| 13 | |
Brian O'Connor | 4ed68b6 | 2016-10-27 21:08:37 -0700 | [diff] [blame] | 14 | ROOT_DIR=${ONOS_ROOT:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )"} |
| 15 | |
| 16 | mkdir -p $ROOT_DIR/bin |
| 17 | pushd $ROOT_DIR/bin > /dev/null |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 18 | |
| 19 | if [ -n "$FORCE_UPDATE" ] || [ ! -f "buck" ] || [ "$REQUIRED_VERSION" != "$(cat .buck_version)" ]; then |
Thomas Vachuska | ae9ba21 | 2016-10-26 15:44:05 -0700 | [diff] [blame] | 20 | 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'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 26 | if [ -n "$(which shasum)" ]; then |
Thomas Vachuska | ae9ba21 | 2016-10-26 15:44:05 -0700 | [diff] [blame] | 27 | SHA=$(shasum cache/$BUCK_FILE | cut -d' ' -f1) |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 28 | [ "$SHA" != "$BUCK_SHA" ] && |
| 29 | 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] | 30 | rm -f cache/$BUCK_FILE && exit 1 |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 31 | else |
| 32 | echo "SHA cannot be verified" |
| 33 | fi |
Thomas Vachuska | ae9ba21 | 2016-10-26 15:44:05 -0700 | [diff] [blame] | 34 | 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'Connor | 4ed68b6 | 2016-10-27 21:08:37 -0700 | [diff] [blame] | 37 | rm -rf $ROOT_DIR/buck-out |
| 38 | 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] | 39 | fi |
| 40 | popd > /dev/null |
| 41 | |
Brian O'Connor | 4ed68b6 | 2016-10-27 21:08:37 -0700 | [diff] [blame] | 42 | BUCK=$ROOT_DIR/bin/buck |
Brian O'Connor | e8468b5 | 2016-07-25 13:42:36 -0700 | [diff] [blame] | 43 | |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 44 | # Finally, run the Buck command... |
Thomas Vachuska | cedacd4 | 2016-12-02 12:21:58 -0800 | [diff] [blame] | 45 | NO_BUCKD=1 $BUCK "$@" |