blob: aa5035de652a09dda7d35c11d17eb18f000b7df6 [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
Ray Milkey5193cb72018-02-09 11:21:32 -08008BUCK_URL="http://repo1.maven.org/maven2/org/onosproject/onos-buck/v2018.02.09.01/buck-v2018.02.09.01.zip"
9BUCK_SHA="45d8bd28f441991257babf89f7a317edb3a2b536"
Brian O'Connor9be23632016-04-08 18:23:45 -070010
Yuta HIGUCHI28bcaf12018-02-13 12:12:16 -080011# onos-yang-tools buck plugin version
Yuta HIGUCHI57ba38e2018-05-15 15:30:07 -070012YANG_VER="2.4.7"
Ray Milkey9b001c92018-02-22 15:44:06 -080013ONOS_PLUGIN_VER="1.0.3"
Ray Milkeyd8e0f792018-02-22 08:50:07 -080014MAVEN_BASE="https://repo1.maven.org/maven2"
15MAVEN_ONOSPROJECT="$MAVEN_BASE/org/onosproject"
Yuta HIGUCHI28bcaf12018-02-13 12:12:16 -080016
Brian O'Connor9be23632016-04-08 18:23:45 -070017[ "-U" = "$1" ] && shift && FORCE_UPDATE=True
18
Brian O'Connor4ed68b62016-10-27 21:08:37 -070019ROOT_DIR=${ONOS_ROOT:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )"}
20
21mkdir -p $ROOT_DIR/bin
22pushd $ROOT_DIR/bin > /dev/null
Brian O'Connor9be23632016-04-08 18:23:45 -070023
Brian O'Connor1b55bfb2017-03-21 15:30:38 -070024if [ -n "$FORCE_UPDATE" ] || [ ! -f "buck" ] || [ "$BUCK_SHA" != "$(cat .buck_sha)" ]; then
Thomas Vachuska96f2b2c2017-07-19 10:08:30 -070025 echo "Updating Buck..." >&2
Brian O'Connor1b55bfb2017-03-21 15:30:38 -070026 rm -fr .buck_version .buck_sha buck plugins
Thomas Vachuskaae9ba212016-10-26 15:44:05 -070027 mkdir -p cache
28 BUCK_FILE=$(basename $BUCK_URL)
29 # Check the local cache; download to cache if required
30 [ -f "cache/$BUCK_FILE" ] || curl -o cache/$BUCK_FILE -L $BUCK_URL
Brian O'Connor9be23632016-04-08 18:23:45 -070031 if [ -n "$(which shasum)" ]; then
Thomas Vachuskaae9ba212016-10-26 15:44:05 -070032 SHA=$(shasum cache/$BUCK_FILE | cut -d' ' -f1)
Brian O'Connor1b55bfb2017-03-21 15:30:38 -070033 if [ "$SHA" != "$BUCK_SHA" ]; then
Brian O'Connor9be23632016-04-08 18:23:45 -070034 echo "ERROR: Downloaded SHA ($SHA) does not match expected SHA ($BUCK_SHA)" &&
Brian O'Connore1c02f42016-12-02 12:49:55 -080035 rm -f cache/$BUCK_FILE && exit 1
Brian O'Connor1b55bfb2017-03-21 15:30:38 -070036 else
37 echo "$SHA" > .buck_sha
38 fi
Brian O'Connor9be23632016-04-08 18:23:45 -070039 else
40 echo "SHA cannot be verified"
41 fi
Ray Milkeyd8e0f792018-02-22 08:50:07 -080042 unzip -qq cache/$BUCK_FILE
Thomas Vachuskaae9ba212016-10-26 15:44:05 -070043 # Kill buckd
44 ps -ef | egrep buckd | grep -v egrep | cut -c7-11 | xargs kill 2>/dev/null || :
Brian O'Connor4ed68b62016-10-27 21:08:37 -070045 rm -rf $ROOT_DIR/buck-out
46 printf "Successfully updated Buck in $ROOT_DIR/bin/buck to $BUCK_FILE\n\n"
Brian O'Connor9be23632016-04-08 18:23:45 -070047fi
Yuta HIGUCHI28bcaf12018-02-13 12:12:16 -080048
49# Fetch & install onos yang tools buck plugin
50YANG_PLUGIN_CACHE="cache/onos-yang-compiler-buck-plugin-$YANG_VER.jar"
51if hash mvn 2>/dev/null; then
52 if [[ $YANG_VER = *"-SNAPSHOT" ]] || [ ! -f "$YANG_PLUGIN_CACHE" ]; then
Ray Milkeyd8e0f792018-02-22 08:50:07 -080053 echo "Updating Yang plugin $YANG_VER..." >&2
Yuta HIGUCHI28bcaf12018-02-13 12:12:16 -080054 ARTIFACT="org.onosproject:onos-yang-compiler-buck-plugin:$YANG_VER"
55 mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.2:copy \
56 -Dartifact=$ARTIFACT \
57 -Dtransitive=false -Dmdep.overWriteSnapshots=true \
58 -DoutputDirectory=cache > /dev/null
59 fi
60else
61 if [ ! -f "$YANG_PLUGIN_CACHE" ]; then
Ray Milkeyd8e0f792018-02-22 08:50:07 -080062 echo "Updating Yang plugin $YANG_VER..." >&2
Yuta HIGUCHI28bcaf12018-02-13 12:12:16 -080063 if [[ $YANG_VER = *"-SNAPSHOT" ]]; then
64 echo "mvn command must be installed to handle SNAPSHOT version"
65 exit 1
66 fi
67
68 curl -o "$YANG_PLUGIN_CACHE" \
Ray Milkeyd8e0f792018-02-22 08:50:07 -080069 -L $MAVEN_ONOSPROJECT/onos-yang-compiler-buck-plugin/$YANG_VER/onos-yang-compiler-buck-plugin-$YANG_VER.jar
Yuta HIGUCHI28bcaf12018-02-13 12:12:16 -080070 fi
71
72 if [[ $YANG_VER != *"-SNAPSHOT" ]] && hash shasum 2>/dev/null; then
73 SHA=$(shasum $YANG_PLUGIN_CACHE | cut -d' ' -f1)
74 if [ ! -f "$YANG_PLUGIN_CACHE".sha1 ]; then
75 curl -o "$YANG_PLUGIN_CACHE".sha1 \
Ray Milkeyd8e0f792018-02-22 08:50:07 -080076 -L $MAVEN_ONOSPROJECT/onos-yang-compiler-buck-plugin/$YANG_VER/onos-yang-compiler-buck-plugin-$YANG_VER.jar.sha1
Yuta HIGUCHI28bcaf12018-02-13 12:12:16 -080077 fi
78 YANG_PLUGIN_SHA=$(cat "$YANG_PLUGIN_CACHE".sha1)
79 if [ "$SHA" != "$YANG_PLUGIN_SHA" ]; then
80 echo "ERROR: Downloaded SHA ($SHA) did not match expected SHA ($YANG_PLUGIN_SHA)" &&
81 rm -f $YANG_PLUGIN_CACHE $YANG_PLUGIN_CACHE.sha1 && exit 1
82 fi
83 else
84 echo "SHA verification skipped"
85 fi
86fi
Ray Milkeyd8e0f792018-02-22 08:50:07 -080087install -Cv "$YANG_PLUGIN_CACHE" plugins/yang.jar >/dev/null
88
89# Fetch & install onos buck plugin
90
91ONOS_PLUGIN_CACHE="cache/onos-buck-plugin-$ONOS_PLUGIN_VER.jar"
92
93if [ ! -f "$ONOS_PLUGIN_CACHE" ]; then
94 echo "Updating ONOS plugin $ONOS_PLUGIN_VER..." >&2
95 curl -o "$ONOS_PLUGIN_CACHE" \
96 -L $MAVEN_ONOSPROJECT/onos-buck-plugin/$ONOS_PLUGIN_VER/onos-buck-plugin-$ONOS_PLUGIN_VER.jar
97fi
98
99
100if hash shasum 2>/dev/null; then
101 SHA=$(shasum $ONOS_PLUGIN_CACHE | cut -d' ' -f1)
102 if [ ! -f "$ONOS_PLUGIN_CACHE".sha1 ]; then
103 curl -o "$ONOS_PLUGIN_CACHE".sha1 \
104 -L $MAVEN_ONOSPROJECT/onos-buck-plugin/$ONOS_PLUGIN_VER/onos-buck-plugin-$ONOS_PLUGIN_VER.jar.sha1
105 fi
106 ONOS_PLUGIN_SHA=$(cat "$ONOS_PLUGIN_CACHE".sha1)
107 if [ "$SHA" != "$ONOS_PLUGIN_SHA" ]; then
108 echo "ERROR: Downloaded SHA ($SHA) did not match expected SHA ($ONOS_PLUGIN_SHA)" &&
109 rm -f $ONOS_PLUGIN_CACHE $ONOS_PLUGIN_CACHE.sha1 && exit 1
110 fi
111else
112 echo "SHA verification skipped"
113fi
114install -Cv "$ONOS_PLUGIN_CACHE" plugins/onos.jar >/dev/null
Yuta HIGUCHI28bcaf12018-02-13 12:12:16 -0800115
Brian O'Connor9be23632016-04-08 18:23:45 -0700116popd > /dev/null
117
Brian O'Connor4ed68b62016-10-27 21:08:37 -0700118BUCK=$ROOT_DIR/bin/buck
Brian O'Connore8468b52016-07-25 13:42:36 -0700119
Yuta HIGUCHIb1fa40d2017-02-22 11:28:13 -0800120if [ "${ONOS_NO_BUCKD:-1}" == "1" ]; then
121 export NO_BUCKD=1
122fi
123
Thomas Vachuskab51707b2018-02-07 09:05:09 -0800124# HACK: Clean-up frequent problem-causers from buck-out
Yuta HIGUCHI0a8417e2018-03-05 20:27:54 -0800125#rm -fr \
126# $ONOS_ROOT/buck-out/bin/lib/.netty \
127# $ONOS_ROOT/buck-out/bin/lib/.KRYO
Thomas Vachuskab51707b2018-02-07 09:05:09 -0800128
Brian O'Connor9be23632016-04-08 18:23:45 -0700129# Finally, run the Buck command...
Yuta HIGUCHIb1fa40d2017-02-22 11:28:13 -0800130$BUCK "$@"