Jordan Halterman | 6b38425 | 2018-10-26 19:13:25 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Remotely pushes bits to a remote node in preparation for install. |
| 4 | # ----------------------------------------------------------------------------- |
| 5 | function _usage () { |
| 6 | cat << _EOF_ |
| 7 | usage: |
| 8 | $(basename $0) [node] |
| 9 | |
| 10 | options: |
| 11 | - [node] : the target node to prime for installation |
| 12 | |
| 13 | summary: |
| 14 | Remotely pushes Atomix bits to a remote node in preparation for install. |
| 15 | |
| 16 | $(basename $0) is invoked as part of 'atomix-install', and shouldn't be |
| 17 | directly invoked for the most part. |
| 18 | |
| 19 | _EOF_ |
| 20 | } |
| 21 | |
| 22 | [ $# -gt 1 ] || [ "$1" = "-h" ] && _usage && exit 0 |
| 23 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT isn't set correctly" >&2 && exit 1 |
| 24 | |
| 25 | set -e |
| 26 | |
| 27 | . $ONOS_ROOT/tools/build/envDefaults |
| 28 | |
| 29 | ATOMIX_VERSION=${ATOMIX_VERSION:-3.0.7} |
| 30 | ATOMIX_MAVEN=~/.m2/repository/io/atomix/atomix-dist/$ATOMIX_VERSION/atomix-dist-$ATOMIX_VERSION.tar.gz |
| 31 | ATOMIX_LOCAL=/tmp/atomix-$ATOMIX_VERSION.tar.gz |
| 32 | ATOMIX_REMOTE=https://oss.sonatype.org/content/repositories/releases/io/atomix/atomix-dist/$ATOMIX_VERSION/atomix-dist-$ATOMIX_VERSION.tar.gz |
| 33 | |
| 34 | node=${1:-$OCI} |
| 35 | remote=$ONOS_USER@$node |
| 36 | remote_with_bracket=$ONOS_USER@[$node] |
| 37 | SSH_OPTIONS=" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \ |
| 38 | -o ControlMaster=auto -o ControlPath=~/.ssh/mux-%r@%h:%p \ |
| 39 | -o ControlPersist=300 " |
| 40 | |
| 41 | if [ ! -z "$ATOMIX_ROOT" ]; then |
| 42 | echo "Pushing to $node from $ATOMIX_ROOT" |
| 43 | ATOMIX_TAR=$ATOMIX_ROOT/dist/target/atomix.tar.gz |
| 44 | elif [ -e $ATOMIX_MAVEN ]; then |
| 45 | echo "Pushing to $node from $ATOMIX_MAVEN" |
| 46 | ATOMIX_TAR=$ATOMIX_MAVEN |
| 47 | else |
| 48 | echo "Pushing to $node from $ATOMIX_LOCAL" |
| 49 | rm $ATOMIX_LOCAL |
| 50 | wget -O $ATOMIX_LOCAL $ATOMIX_REMOTE |
| 51 | ATOMIX_TAR=$ATOMIX_LOCAL |
| 52 | fi |
| 53 | |
| 54 | echo "Using scp" |
| 55 | |
| 56 | locHash=$(cksum $ATOMIX_TAR | cut -d' ' -f1,2) |
| 57 | remHash=$(ssh $remote cksum /tmp/atomix.tar.gz 2>/dev/null | cut -d' ' -f1,2) |
| 58 | |
| 59 | if [ -n "$locHash" ] && [ "$locHash" = "$remHash" ]; then |
| 60 | echo "Atomix bits /tmp/atomix.tar.gz already up-to-date on $node..." |
| 61 | else |
| 62 | ssh $remote rm -f $ATOMIX_TAR |
| 63 | scp -q $ATOMIX_TAR $remote_with_bracket:/tmp/atomix.tar.gz |
| 64 | fi |