blob: 721bf4603b7f040d5d737ccaec69b3446e0bc10f [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'Connor3231e1b2016-09-13 16:54:16 -07008BUCK_URL="https://github.com/bocon13/buck/releases/download/v2016.09.13.01/buck"
9BUCK_SHA="e72cf2e9ef719fa81fd4e0d1b620f20448c10a9d"
10REQUIRED_VERSION="buck version 0b60c3d7f8d54b2e6e6607749b748c0f240a6eb3"
Brian O'Connor9be23632016-04-08 18:23:45 -070011
12[ "-U" = "$1" ] && shift && FORCE_UPDATE=True
13
14mkdir -p $ONOS_ROOT/bin
15pushd $ONOS_ROOT/bin > /dev/null
16
17if [ -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'Connor2fdbe0d12016-04-08 19:14:04 -070030 echo $(./buck --version 2>/dev/null) > .buck_version
Brian O'Connor9be23632016-04-08 18:23:45 -070031 chmod 444 .buck_version
Brian O'Connor2fdbe0d12016-04-08 19:14:04 -070032 rm -rf ./buck-out
Brian O'Connor9be23632016-04-08 18:23:45 -070033 printf "Successfully downloaded Buck to $ONOS_ROOT/bin/buck\n\n"
Ray Milkeyeffde072016-09-13 17:16:12 -070034 ONOS_BUILD_PLUGIN="true"
Brian O'Connor9be23632016-04-08 18:23:45 -070035fi
36popd > /dev/null
37
Brian O'Connore8468b52016-07-25 13:42:36 -070038BUCK=$ONOS_ROOT/bin/buck
39PLUGINS=$ONOS_ROOT/bucklets/plugins
40ONOS_PLUGIN=$PLUGINS/onosjar.jar
41
42if [ ! -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 Chan9a9c8f82016-09-16 13:37:27 -070048 CHK_NEW=$(cksum $ONOS_ROOT/$pluginJar | cut -d' ' -f1-2)
Brian O'Connore8468b52016-07-25 13:42:36 -070049 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
60fi
61
Brian O'Connor9be23632016-04-08 18:23:45 -070062# Finally, run the Buck command...
Brian O'Connore8468b52016-07-25 13:42:36 -070063$BUCK "$@"