blob: 9b2bac2270d0c0a41f73b493d3cad7a9f19a683e [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
DongRyeol Cha5c0a9f02018-05-17 14:32:55 +090031remote_with_bracket=$ONOS_USER@[$node]
Yuta HIGUCHI3dcd2862017-02-02 15:22:12 -080032SSH_OPTIONS=" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
33 -o ControlMaster=auto -o ControlPath=~/.ssh/mux-%r@%h:%p \
34 -o ControlPersist=300 "
Thomas Vachuska52e65802014-12-08 09:26:01 -080035
Yuta HIGUCHI3dcd2862017-02-02 15:22:12 -080036USE_RSYNC=${USE_RSYNC:-'false'}
37if [ "$USE_RSYNC" = "true" ]; then
38 if ssh $remote $SSH_OPTIONS which rsync >&2 > /dev/null; then
39 echo "Using rsync"
40 else
41 echo "Installing rsync"
42 # TODO check remote OS and use proper method to install rsync
43 ssh $remote sudo apt-get install -y rsync || USE_RSYNC='false'
44 fi
45fi
Thomas Vachuska52e65802014-12-08 09:26:01 -080046
Yuta HIGUCHI3dcd2862017-02-02 15:22:12 -080047if [ "$USE_RSYNC" = "clean" ]; then
48 # clean remote rsync stage directory
49 ssh $remote rm -rf "/tmp/$ONOS_BITS"
50fi
51
52if [ "$USE_RSYNC" = "true" ]; then
53 # local rsync stage directory
54 RSYNC_STAGE=`mktemp -d -t onostar` || exit 1
55 trap "rm -rf $RSYNC_STAGE" EXIT
56
57 tar xf $ONOS_TAR -C $RSYNC_STAGE
58 tar tf $ONOS_TAR > $RSYNC_STAGE/files
59 touch -r $ONOS_TAR $RSYNC_STAGE/files
60
61 # initialize remote stage with remote ONOS tar.
62 # This is a workaround to benefit from onos-push-bits-through-proxy.
63 # TODO would like to use tar hash to skip rsync when possible,
64 # but couldn't due to tarball chksum mismatch, described below.
65 ssh $remote $SSH_OPTIONS \
66 "mkdir -p \"/tmp/$ONOS_BITS\" && \
67 tar xzf \"/tmp/`basename ${ONOS_TAR}`\" -C \"/tmp/$ONOS_BITS\" || exit 0 "
68
69 # sync contents of $ONOS_TAR
70 rsync -az --delete --checksum --omit-dir-times --progress \
71 -e "ssh $SSH_OPTIONS" \
72 --rsync-path="mkdir -p /tmp/$ONOS_BITS/ && rsync" \
DongRyeol Cha5c0a9f02018-05-17 14:32:55 +090073 $RSYNC_STAGE/ $remote_with_bracket:/tmp/$ONOS_BITS
Yuta HIGUCHI3dcd2862017-02-02 15:22:12 -080074
75 # create $ONOS_TAR equivalent tar ball remotely
76 # TODO hash will not be the same as local one, probably due to different uid, etc.
77 echo "Rebuilding ONOS tar on $node"
78 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 -080079else
Yuta HIGUCHI3dcd2862017-02-02 15:22:12 -080080 echo "Using scp"
81
82 locHash=$(cksum $ONOS_TAR | cut -d' ' -f1,2)
83 remHash=$(ssh $remote cksum $ONOS_TAR 2>/dev/null | cut -d' ' -f1,2)
84
85 if [ -n "$locHash" ] && [ "$locHash" = "$remHash" ]; then
86 echo "ONOS bits $ONOS_TAR already up-to-date on $node..."
87 else
DongRyeol Cha5c0a9f02018-05-17 14:32:55 +090088 scp -q $ONOS_TAR $remote_with_bracket:/tmp
Yuta HIGUCHI3dcd2862017-02-02 15:22:12 -080089 fi
Thomas Vachuska52e65802014-12-08 09:26:01 -080090fi