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 | 8f4a929 | 2016-07-29 11:08:24 -0700 | [diff] [blame] | 8 | BUCK_URL="https://github.com/bocon13/buck/releases/download/v2016.07.29.01-wip/buck" |
| 9 | BUCK_SHA="31b2925f0c7935cd581b11a52f4e7fc53ade125e" |
| 10 | REQUIRED_VERSION="buck version b1271d04f2c319784f8af9abc92ed2d01d10ed3a" |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 11 | |
| 12 | [ "-U" = "$1" ] && shift && FORCE_UPDATE=True |
| 13 | |
| 14 | mkdir -p $ONOS_ROOT/bin |
| 15 | pushd $ONOS_ROOT/bin > /dev/null |
| 16 | |
| 17 | if [ -n "$FORCE_UPDATE" ] || [ ! -f "buck" ] || [ "$REQUIRED_VERSION" != "$(cat .buck_version)" ]; then |
| 18 | echo "Downloading Buck..." |
| 19 | rm -f .buck_version buck |
| 20 | curl -o ./buck -L $BUCK_URL |
| 21 | if [ -n "$(which shasum)" ]; then |
| 22 | SHA=$(shasum ./buck | cut -d' ' -f1) |
| 23 | [ "$SHA" != "$BUCK_SHA" ] && |
| 24 | echo "ERROR: Downloaded SHA ($SHA) does not match expected SHA ($BUCK_SHA)" && |
| 25 | exit 1 |
| 26 | else |
| 27 | echo "SHA cannot be verified" |
| 28 | fi |
| 29 | chmod 555 ./buck |
Brian O'Connor | 2fdbe0d1 | 2016-04-08 19:14:04 -0700 | [diff] [blame] | 30 | echo $(./buck --version 2>/dev/null) > .buck_version |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 31 | chmod 444 .buck_version |
Brian O'Connor | 2fdbe0d1 | 2016-04-08 19:14:04 -0700 | [diff] [blame] | 32 | rm -rf ./buck-out |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 33 | printf "Successfully downloaded Buck to $ONOS_ROOT/bin/buck\n\n" |
| 34 | fi |
| 35 | popd > /dev/null |
| 36 | |
Brian O'Connor | e8468b5 | 2016-07-25 13:42:36 -0700 | [diff] [blame^] | 37 | BUCK=$ONOS_ROOT/bin/buck |
| 38 | PLUGINS=$ONOS_ROOT/bucklets/plugins |
| 39 | ONOS_PLUGIN=$PLUGINS/onosjar.jar |
| 40 | |
| 41 | if [ ! -f "$ONOS_PLUGIN" -o -n "$ONOS_BUILD_PLUGIN" ]; then |
| 42 | echo "Building ONOS Buck plugins..." |
| 43 | |
| 44 | # Build it first |
| 45 | pluginJar=$(NO_BUCKD=1 $BUCK build //tools/build/buck-plugin:onosjar --show-output 2>/dev/null | grep onosjar.jar | cut -d\ -f2) |
| 46 | |
| 47 | CHK_NEW=$(cksum $pluginJar | cut -d' ' -f1-2) |
| 48 | CHK_OLD=$(cksum $ONOS_PLUGIN 2>/dev/null | cut -d' ' -f1-2) |
| 49 | if [ "$CHK_NEW" != "$CHK_OLD" ]; then |
| 50 | # diff plugins... if different, copy and restart buckd |
| 51 | # Then install it |
| 52 | mkdir -p $PLUGINS |
| 53 | cp $ONOS_ROOT/$pluginJar $PLUGINS |
| 54 | echo "Updated to the latest plugin." |
| 55 | $BUCK clean 2>/dev/null |
| 56 | else |
| 57 | echo "Plugin was already up to date." |
| 58 | fi |
| 59 | fi |
| 60 | |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 61 | # Finally, run the Buck command... |
Brian O'Connor | e8468b5 | 2016-07-25 13:42:36 -0700 | [diff] [blame^] | 62 | $BUCK "$@" |