blob: 2187edcc36bcfdba9514029861fffe2a9577934b [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" \
Yuta HIGUCHI99a2eab2018-06-13 18:27:55 -070073 $RSYNC_STAGE/ [$ONOS_USER@$node]:/tmp/$ONOS_BITS
74 # rsync < 3.0.6 cannot parse $ONOS_USER@[$node]
75 # https://bugzilla.samba.org/show_bug.cgi?id=6067
Yuta HIGUCHI3dcd2862017-02-02 15:22:12 -080076
77 # create $ONOS_TAR equivalent tar ball remotely
78 # TODO hash will not be the same as local one, probably due to different uid, etc.
79 echo "Rebuilding ONOS tar on $node"
80 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 -080081else
Yuta HIGUCHI3dcd2862017-02-02 15:22:12 -080082 echo "Using scp"
83
84 locHash=$(cksum $ONOS_TAR | cut -d' ' -f1,2)
85 remHash=$(ssh $remote cksum $ONOS_TAR 2>/dev/null | cut -d' ' -f1,2)
86
87 if [ -n "$locHash" ] && [ "$locHash" = "$remHash" ]; then
88 echo "ONOS bits $ONOS_TAR already up-to-date on $node..."
89 else
Ray Milkey39332952018-07-16 13:42:51 -070090 ssh $remote rm -f $ONOS_TAR
DongRyeol Cha5c0a9f02018-05-17 14:32:55 +090091 scp -q $ONOS_TAR $remote_with_bracket:/tmp
Yuta HIGUCHI3dcd2862017-02-02 15:22:12 -080092 fi
Thomas Vachuska52e65802014-12-08 09:26:01 -080093fi