blob: e11f1de3d328c55c28ad8a85779020566d027a19 [file] [log] [blame]
#!/bin/bash
# -----------------------------------------------------------------------------
# Runs the custom version of Buck required by ONOS.
# -----------------------------------------------------------------------------
set -e
BUCK_URL="http://repo1.maven.org/maven2/org/onosproject/onos-buck/v2018.02.09.01/buck-v2018.02.09.01.zip"
BUCK_SHA="45d8bd28f441991257babf89f7a317edb3a2b536"
# onos-yang-tools buck plugin version
YANG_VER="2.4.1"
ONOS_PLUGIN_VER="1.0.2"
MAVEN_BASE="https://repo1.maven.org/maven2"
MAVEN_ONOSPROJECT="$MAVEN_BASE/org/onosproject"
[ "-U" = "$1" ] && shift && FORCE_UPDATE=True
ROOT_DIR=${ONOS_ROOT:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )"}
mkdir -p $ROOT_DIR/bin
pushd $ROOT_DIR/bin > /dev/null
if [ -n "$FORCE_UPDATE" ] || [ ! -f "buck" ] || [ "$BUCK_SHA" != "$(cat .buck_sha)" ]; then
echo "Updating Buck..." >&2
rm -fr .buck_version .buck_sha buck plugins
mkdir -p cache
BUCK_FILE=$(basename $BUCK_URL)
# Check the local cache; download to cache if required
[ -f "cache/$BUCK_FILE" ] || curl -o cache/$BUCK_FILE -L $BUCK_URL
if [ -n "$(which shasum)" ]; then
SHA=$(shasum cache/$BUCK_FILE | cut -d' ' -f1)
if [ "$SHA" != "$BUCK_SHA" ]; then
echo "ERROR: Downloaded SHA ($SHA) does not match expected SHA ($BUCK_SHA)" &&
rm -f cache/$BUCK_FILE && exit 1
else
echo "$SHA" > .buck_sha
fi
else
echo "SHA cannot be verified"
fi
unzip -qq cache/$BUCK_FILE
# Kill buckd
ps -ef | egrep buckd | grep -v egrep | cut -c7-11 | xargs kill 2>/dev/null || :
rm -rf $ROOT_DIR/buck-out
printf "Successfully updated Buck in $ROOT_DIR/bin/buck to $BUCK_FILE\n\n"
fi
# Fetch & install onos yang tools buck plugin
YANG_PLUGIN_CACHE="cache/onos-yang-compiler-buck-plugin-$YANG_VER.jar"
if hash mvn 2>/dev/null; then
if [[ $YANG_VER = *"-SNAPSHOT" ]] || [ ! -f "$YANG_PLUGIN_CACHE" ]; then
echo "Updating Yang plugin $YANG_VER..." >&2
ARTIFACT="org.onosproject:onos-yang-compiler-buck-plugin:$YANG_VER"
mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.2:copy \
-Dartifact=$ARTIFACT \
-Dtransitive=false -Dmdep.overWriteSnapshots=true \
-DoutputDirectory=cache > /dev/null
fi
else
if [ ! -f "$YANG_PLUGIN_CACHE" ]; then
echo "Updating Yang plugin $YANG_VER..." >&2
if [[ $YANG_VER = *"-SNAPSHOT" ]]; then
echo "mvn command must be installed to handle SNAPSHOT version"
exit 1
fi
curl -o "$YANG_PLUGIN_CACHE" \
-L $MAVEN_ONOSPROJECT/onos-yang-compiler-buck-plugin/$YANG_VER/onos-yang-compiler-buck-plugin-$YANG_VER.jar
fi
if [[ $YANG_VER != *"-SNAPSHOT" ]] && hash shasum 2>/dev/null; then
SHA=$(shasum $YANG_PLUGIN_CACHE | cut -d' ' -f1)
if [ ! -f "$YANG_PLUGIN_CACHE".sha1 ]; then
curl -o "$YANG_PLUGIN_CACHE".sha1 \
-L $MAVEN_ONOSPROJECT/onos-yang-compiler-buck-plugin/$YANG_VER/onos-yang-compiler-buck-plugin-$YANG_VER.jar.sha1
fi
YANG_PLUGIN_SHA=$(cat "$YANG_PLUGIN_CACHE".sha1)
if [ "$SHA" != "$YANG_PLUGIN_SHA" ]; then
echo "ERROR: Downloaded SHA ($SHA) did not match expected SHA ($YANG_PLUGIN_SHA)" &&
rm -f $YANG_PLUGIN_CACHE $YANG_PLUGIN_CACHE.sha1 && exit 1
fi
else
echo "SHA verification skipped"
fi
fi
install -Cv "$YANG_PLUGIN_CACHE" plugins/yang.jar >/dev/null
# Fetch & install onos buck plugin
ONOS_PLUGIN_CACHE="cache/onos-buck-plugin-$ONOS_PLUGIN_VER.jar"
if [ ! -f "$ONOS_PLUGIN_CACHE" ]; then
echo "Updating ONOS plugin $ONOS_PLUGIN_VER..." >&2
curl -o "$ONOS_PLUGIN_CACHE" \
-L $MAVEN_ONOSPROJECT/onos-buck-plugin/$ONOS_PLUGIN_VER/onos-buck-plugin-$ONOS_PLUGIN_VER.jar
fi
if hash shasum 2>/dev/null; then
SHA=$(shasum $ONOS_PLUGIN_CACHE | cut -d' ' -f1)
if [ ! -f "$ONOS_PLUGIN_CACHE".sha1 ]; then
curl -o "$ONOS_PLUGIN_CACHE".sha1 \
-L $MAVEN_ONOSPROJECT/onos-buck-plugin/$ONOS_PLUGIN_VER/onos-buck-plugin-$ONOS_PLUGIN_VER.jar.sha1
fi
ONOS_PLUGIN_SHA=$(cat "$ONOS_PLUGIN_CACHE".sha1)
if [ "$SHA" != "$ONOS_PLUGIN_SHA" ]; then
echo "ERROR: Downloaded SHA ($SHA) did not match expected SHA ($ONOS_PLUGIN_SHA)" &&
rm -f $ONOS_PLUGIN_CACHE $ONOS_PLUGIN_CACHE.sha1 && exit 1
fi
else
echo "SHA verification skipped"
fi
install -Cv "$ONOS_PLUGIN_CACHE" plugins/onos.jar >/dev/null
popd > /dev/null
BUCK=$ROOT_DIR/bin/buck
if [ "${ONOS_NO_BUCKD:-1}" == "1" ]; then
export NO_BUCKD=1
fi
# HACK: Clean-up frequent problem-causers from buck-out
rm -fr \
$ONOS_ROOT/buck-out/bin/lib/.netty \
$ONOS_ROOT/buck-out/bin/lib/.KRYO
# Finally, run the Buck command...
$BUCK "$@"