blob: b65c438622793134adcf1c28aa6e6010ed4d0784 [file] [log] [blame]
Thomas Vachuska52e65802014-12-08 09:26:01 -08001#!/bin/bash
2# -----------------------------------------------------------------------------
3# Remotely pushes bits to a remote node in preparation for install.
4# -----------------------------------------------------------------------------
Ayaka Koshibef17f34a2015-09-24 19:31:48 -07005function _usage () {
6cat << _EOF_
7usage:
8 $(basename $0) [node]
9
10options:
11- [node] : the target node to prime for installation
12
13summary:
14 Remotely pushes bits to a remote node in preparation for install.
15
16 $(basename $0) is invoked as part of 'onos-install', and shouldn't be
17 directly invoked for the most part.
18
19_EOF_
20}
21
Bob Lantz02ba2d12016-02-10 23:41:53 -080022[ $# -gt 1 ] || [ "$1" = "-h" ] && _usage && exit 0
23[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT isn't set correctly" >&2 && exit 1
24set -e
25set -u
Thomas Vachuska52e65802014-12-08 09:26:01 -080026. $ONOS_ROOT/tools/build/envDefaults
Bob Lantz02ba2d12016-02-10 23:41:53 -080027[ ! -f "$ONOS_TAR" ] && echo "$ONOS_TAR does not exist - run onos-package?" >&2 && exit 1
Thomas Vachuska52e65802014-12-08 09:26:01 -080028
29node=${1:-$OCI}
30remote=$ONOS_USER@$node
Yuta HIGUCHI3dcd2862017-02-02 15:22:12 -080031SSH_OPTIONS=" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
32 -o ControlMaster=auto -o ControlPath=~/.ssh/mux-%r@%h:%p \
33 -o ControlPersist=300 "
Thomas Vachuska52e65802014-12-08 09:26:01 -080034
Yuta HIGUCHI3dcd2862017-02-02 15:22:12 -080035USE_RSYNC=${USE_RSYNC:-'false'}
36if [ "$USE_RSYNC" = "true" ]; then
37 if ssh $remote $SSH_OPTIONS which rsync >&2 > /dev/null; then
38 echo "Using rsync"
39 else
40 echo "Installing rsync"
41 # TODO check remote OS and use proper method to install rsync
42 ssh $remote sudo apt-get install -y rsync || USE_RSYNC='false'
43 fi
44fi
Thomas Vachuska52e65802014-12-08 09:26:01 -080045
Yuta HIGUCHI3dcd2862017-02-02 15:22:12 -080046if [ "$USE_RSYNC" = "clean" ]; then
47 # clean remote rsync stage directory
48 ssh $remote rm -rf "/tmp/$ONOS_BITS"
49fi
50
51if [ "$USE_RSYNC" = "true" ]; then
52 # local rsync stage directory
53 RSYNC_STAGE=`mktemp -d -t onostar` || exit 1
54 trap "rm -rf $RSYNC_STAGE" EXIT
55
56 tar xf $ONOS_TAR -C $RSYNC_STAGE
57 tar tf $ONOS_TAR > $RSYNC_STAGE/files
58 touch -r $ONOS_TAR $RSYNC_STAGE/files
59
60 # initialize remote stage with remote ONOS tar.
61 # This is a workaround to benefit from onos-push-bits-through-proxy.
62 # TODO would like to use tar hash to skip rsync when possible,
63 # but couldn't due to tarball chksum mismatch, described below.
64 ssh $remote $SSH_OPTIONS \
65 "mkdir -p \"/tmp/$ONOS_BITS\" && \
66 tar xzf \"/tmp/`basename ${ONOS_TAR}`\" -C \"/tmp/$ONOS_BITS\" || exit 0 "
67
68 # sync contents of $ONOS_TAR
69 rsync -az --delete --checksum --omit-dir-times --progress \
70 -e "ssh $SSH_OPTIONS" \
71 --rsync-path="mkdir -p /tmp/$ONOS_BITS/ && rsync" \
72 $RSYNC_STAGE/ $remote:/tmp/$ONOS_BITS
73
74 # create $ONOS_TAR equivalent tar ball remotely
75 # TODO hash will not be the same as local one, probably due to different uid, etc.
76 echo "Rebuilding ONOS tar on $node"
77 ssh $remote $SSH_OPTIONS tar czf "/tmp/`basename ${ONOS_TAR}`" -C "/tmp/$ONOS_BITS" --no-recursion -T "/tmp/$ONOS_BITS/files"
Thomas Vachuska52e65802014-12-08 09:26:01 -080078else
Yuta HIGUCHI3dcd2862017-02-02 15:22:12 -080079 echo "Using scp"
80
81 locHash=$(cksum $ONOS_TAR | cut -d' ' -f1,2)
82 remHash=$(ssh $remote cksum $ONOS_TAR 2>/dev/null | cut -d' ' -f1,2)
83
84 if [ -n "$locHash" ] && [ "$locHash" = "$remHash" ]; then
85 echo "ONOS bits $ONOS_TAR already up-to-date on $node..."
86 else
87 scp -q $ONOS_TAR $remote:/tmp
88 fi
Thomas Vachuska52e65802014-12-08 09:26:01 -080089fi