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