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 | 3231e1b | 2016-09-13 16:54:16 -0700 | [diff] [blame] | 8 | BUCK_URL="https://github.com/bocon13/buck/releases/download/v2016.09.13.01/buck" |
| 9 | BUCK_SHA="e72cf2e9ef719fa81fd4e0d1b620f20448c10a9d" |
| 10 | REQUIRED_VERSION="buck version 0b60c3d7f8d54b2e6e6607749b748c0f240a6eb3" |
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" |
Ray Milkey | effde07 | 2016-09-13 17:16:12 -0700 | [diff] [blame] | 34 | ONOS_BUILD_PLUGIN="true" |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 35 | fi |
| 36 | popd > /dev/null |
| 37 | |
Brian O'Connor | e8468b5 | 2016-07-25 13:42:36 -0700 | [diff] [blame] | 38 | BUCK=$ONOS_ROOT/bin/buck |
| 39 | PLUGINS=$ONOS_ROOT/bucklets/plugins |
| 40 | ONOS_PLUGIN=$PLUGINS/onosjar.jar |
| 41 | |
| 42 | if [ ! -f "$ONOS_PLUGIN" -o -n "$ONOS_BUILD_PLUGIN" ]; then |
| 43 | echo "Building ONOS Buck plugins..." |
| 44 | |
| 45 | # Build it first |
| 46 | pluginJar=$(NO_BUCKD=1 $BUCK build //tools/build/buck-plugin:onosjar --show-output 2>/dev/null | grep onosjar.jar | cut -d\ -f2) |
| 47 | |
Charles Chan | f6a460e | 2016-09-16 13:37:27 -0700 | [diff] [blame^] | 48 | CHK_NEW=$(cksum $ONOS_ROOT/$pluginJar | cut -d' ' -f1-2) |
Brian O'Connor | e8468b5 | 2016-07-25 13:42:36 -0700 | [diff] [blame] | 49 | CHK_OLD=$(cksum $ONOS_PLUGIN 2>/dev/null | cut -d' ' -f1-2) |
| 50 | if [ "$CHK_NEW" != "$CHK_OLD" ]; then |
| 51 | # diff plugins... if different, copy and restart buckd |
| 52 | # Then install it |
| 53 | mkdir -p $PLUGINS |
| 54 | cp $ONOS_ROOT/$pluginJar $PLUGINS |
| 55 | echo "Updated to the latest plugin." |
| 56 | $BUCK clean 2>/dev/null |
| 57 | else |
| 58 | echo "Plugin was already up to date." |
| 59 | fi |
| 60 | fi |
| 61 | |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 62 | # Finally, run the Buck command... |
Brian O'Connor | e8468b5 | 2016-07-25 13:42:36 -0700 | [diff] [blame] | 63 | $BUCK "$@" |