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 | |
Ray Milkey | 5193cb7 | 2018-02-09 11:21:32 -0800 | [diff] [blame] | 8 | BUCK_URL="http://repo1.maven.org/maven2/org/onosproject/onos-buck/v2018.02.09.01/buck-v2018.02.09.01.zip" |
| 9 | BUCK_SHA="45d8bd28f441991257babf89f7a317edb3a2b536" |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 10 | |
Yuta HIGUCHI | 28bcaf1 | 2018-02-13 12:12:16 -0800 | [diff] [blame] | 11 | # onos-yang-tools buck plugin version |
Yuta HIGUCHI | 57ba38e | 2018-05-15 15:30:07 -0700 | [diff] [blame] | 12 | YANG_VER="2.4.7" |
Ray Milkey | 9b001c9 | 2018-02-22 15:44:06 -0800 | [diff] [blame] | 13 | ONOS_PLUGIN_VER="1.0.3" |
Ray Milkey | d8e0f79 | 2018-02-22 08:50:07 -0800 | [diff] [blame] | 14 | MAVEN_BASE="https://repo1.maven.org/maven2" |
| 15 | MAVEN_ONOSPROJECT="$MAVEN_BASE/org/onosproject" |
Yuta HIGUCHI | 28bcaf1 | 2018-02-13 12:12:16 -0800 | [diff] [blame] | 16 | |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 17 | [ "-U" = "$1" ] && shift && FORCE_UPDATE=True |
| 18 | |
Brian O'Connor | 4ed68b6 | 2016-10-27 21:08:37 -0700 | [diff] [blame] | 19 | ROOT_DIR=${ONOS_ROOT:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )"} |
| 20 | |
| 21 | mkdir -p $ROOT_DIR/bin |
| 22 | pushd $ROOT_DIR/bin > /dev/null |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 23 | |
Brian O'Connor | 1b55bfb | 2017-03-21 15:30:38 -0700 | [diff] [blame] | 24 | if [ -n "$FORCE_UPDATE" ] || [ ! -f "buck" ] || [ "$BUCK_SHA" != "$(cat .buck_sha)" ]; then |
Thomas Vachuska | 96f2b2c | 2017-07-19 10:08:30 -0700 | [diff] [blame] | 25 | echo "Updating Buck..." >&2 |
Brian O'Connor | 1b55bfb | 2017-03-21 15:30:38 -0700 | [diff] [blame] | 26 | rm -fr .buck_version .buck_sha buck plugins |
Thomas Vachuska | ae9ba21 | 2016-10-26 15:44:05 -0700 | [diff] [blame] | 27 | 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'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 31 | if [ -n "$(which shasum)" ]; then |
Thomas Vachuska | ae9ba21 | 2016-10-26 15:44:05 -0700 | [diff] [blame] | 32 | SHA=$(shasum cache/$BUCK_FILE | cut -d' ' -f1) |
Brian O'Connor | 1b55bfb | 2017-03-21 15:30:38 -0700 | [diff] [blame] | 33 | if [ "$SHA" != "$BUCK_SHA" ]; then |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 34 | echo "ERROR: Downloaded SHA ($SHA) does not match expected SHA ($BUCK_SHA)" && |
Brian O'Connor | e1c02f4 | 2016-12-02 12:49:55 -0800 | [diff] [blame] | 35 | rm -f cache/$BUCK_FILE && exit 1 |
Brian O'Connor | 1b55bfb | 2017-03-21 15:30:38 -0700 | [diff] [blame] | 36 | else |
| 37 | echo "$SHA" > .buck_sha |
| 38 | fi |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 39 | else |
| 40 | echo "SHA cannot be verified" |
| 41 | fi |
Ray Milkey | d8e0f79 | 2018-02-22 08:50:07 -0800 | [diff] [blame] | 42 | unzip -qq cache/$BUCK_FILE |
Thomas Vachuska | ae9ba21 | 2016-10-26 15:44:05 -0700 | [diff] [blame] | 43 | # Kill buckd |
| 44 | ps -ef | egrep buckd | grep -v egrep | cut -c7-11 | xargs kill 2>/dev/null || : |
Brian O'Connor | 4ed68b6 | 2016-10-27 21:08:37 -0700 | [diff] [blame] | 45 | rm -rf $ROOT_DIR/buck-out |
| 46 | printf "Successfully updated Buck in $ROOT_DIR/bin/buck to $BUCK_FILE\n\n" |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 47 | fi |
Yuta HIGUCHI | 28bcaf1 | 2018-02-13 12:12:16 -0800 | [diff] [blame] | 48 | |
| 49 | # Fetch & install onos yang tools buck plugin |
| 50 | YANG_PLUGIN_CACHE="cache/onos-yang-compiler-buck-plugin-$YANG_VER.jar" |
| 51 | if hash mvn 2>/dev/null; then |
| 52 | if [[ $YANG_VER = *"-SNAPSHOT" ]] || [ ! -f "$YANG_PLUGIN_CACHE" ]; then |
Ray Milkey | d8e0f79 | 2018-02-22 08:50:07 -0800 | [diff] [blame] | 53 | echo "Updating Yang plugin $YANG_VER..." >&2 |
Yuta HIGUCHI | 28bcaf1 | 2018-02-13 12:12:16 -0800 | [diff] [blame] | 54 | 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 |
| 60 | else |
| 61 | if [ ! -f "$YANG_PLUGIN_CACHE" ]; then |
Ray Milkey | d8e0f79 | 2018-02-22 08:50:07 -0800 | [diff] [blame] | 62 | echo "Updating Yang plugin $YANG_VER..." >&2 |
Yuta HIGUCHI | 28bcaf1 | 2018-02-13 12:12:16 -0800 | [diff] [blame] | 63 | 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 Milkey | d8e0f79 | 2018-02-22 08:50:07 -0800 | [diff] [blame] | 69 | -L $MAVEN_ONOSPROJECT/onos-yang-compiler-buck-plugin/$YANG_VER/onos-yang-compiler-buck-plugin-$YANG_VER.jar |
Yuta HIGUCHI | 28bcaf1 | 2018-02-13 12:12:16 -0800 | [diff] [blame] | 70 | 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 Milkey | d8e0f79 | 2018-02-22 08:50:07 -0800 | [diff] [blame] | 76 | -L $MAVEN_ONOSPROJECT/onos-yang-compiler-buck-plugin/$YANG_VER/onos-yang-compiler-buck-plugin-$YANG_VER.jar.sha1 |
Yuta HIGUCHI | 28bcaf1 | 2018-02-13 12:12:16 -0800 | [diff] [blame] | 77 | 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 |
| 86 | fi |
Ray Milkey | d8e0f79 | 2018-02-22 08:50:07 -0800 | [diff] [blame] | 87 | install -Cv "$YANG_PLUGIN_CACHE" plugins/yang.jar >/dev/null |
| 88 | |
| 89 | # Fetch & install onos buck plugin |
| 90 | |
| 91 | ONOS_PLUGIN_CACHE="cache/onos-buck-plugin-$ONOS_PLUGIN_VER.jar" |
| 92 | |
| 93 | if [ ! -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 |
| 97 | fi |
| 98 | |
| 99 | |
| 100 | if 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 |
| 111 | else |
| 112 | echo "SHA verification skipped" |
| 113 | fi |
| 114 | install -Cv "$ONOS_PLUGIN_CACHE" plugins/onos.jar >/dev/null |
Yuta HIGUCHI | 28bcaf1 | 2018-02-13 12:12:16 -0800 | [diff] [blame] | 115 | |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 116 | popd > /dev/null |
| 117 | |
Brian O'Connor | 4ed68b6 | 2016-10-27 21:08:37 -0700 | [diff] [blame] | 118 | BUCK=$ROOT_DIR/bin/buck |
Brian O'Connor | e8468b5 | 2016-07-25 13:42:36 -0700 | [diff] [blame] | 119 | |
Yuta HIGUCHI | b1fa40d | 2017-02-22 11:28:13 -0800 | [diff] [blame] | 120 | if [ "${ONOS_NO_BUCKD:-1}" == "1" ]; then |
| 121 | export NO_BUCKD=1 |
| 122 | fi |
| 123 | |
Thomas Vachuska | b51707b | 2018-02-07 09:05:09 -0800 | [diff] [blame] | 124 | # HACK: Clean-up frequent problem-causers from buck-out |
Yuta HIGUCHI | 0a8417e | 2018-03-05 20:27:54 -0800 | [diff] [blame] | 125 | #rm -fr \ |
| 126 | # $ONOS_ROOT/buck-out/bin/lib/.netty \ |
| 127 | # $ONOS_ROOT/buck-out/bin/lib/.KRYO |
Thomas Vachuska | b51707b | 2018-02-07 09:05:09 -0800 | [diff] [blame] | 128 | |
Brian O'Connor | 9be2363 | 2016-04-08 18:23:45 -0700 | [diff] [blame] | 129 | # Finally, run the Buck command... |
Yuta HIGUCHI | b1fa40d | 2017-02-22 11:28:13 -0800 | [diff] [blame] | 130 | $BUCK "$@" |