blob: 6c39e6144f5c97205d5bd90c6ffdc6211bae7c4f [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'Connor8f4a9292016-07-29 11:08:24 -07008BUCK_URL="https://github.com/bocon13/buck/releases/download/v2016.07.29.01-wip/buck"
9BUCK_SHA="31b2925f0c7935cd581b11a52f4e7fc53ade125e"
10REQUIRED_VERSION="buck version b1271d04f2c319784f8af9abc92ed2d01d10ed3a"
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"
34fi
35popd > /dev/null
36
Brian O'Connore8468b52016-07-25 13:42:36 -070037BUCK=$ONOS_ROOT/bin/buck
38PLUGINS=$ONOS_ROOT/bucklets/plugins
39ONOS_PLUGIN=$PLUGINS/onosjar.jar
40
41if [ ! -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
59fi
60
Brian O'Connor9be23632016-04-08 18:23:45 -070061# Finally, run the Buck command...
Brian O'Connore8468b52016-07-25 13:42:36 -070062$BUCK "$@"