Thomas Vachuska | 52e6580 | 2014-12-08 09:26:01 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Remotely pushes bits to a remote node in preparation for install. |
| 4 | # ----------------------------------------------------------------------------- |
Ayaka Koshibe | f17f34a | 2015-09-24 19:31:48 -0700 | [diff] [blame] | 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 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 Lantz | 02ba2d1 | 2016-02-10 23:41:53 -0800 | [diff] [blame] | 22 | [ $# -gt 1 ] || [ "$1" = "-h" ] && _usage && exit 0 |
| 23 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT isn't set correctly" >&2 && exit 1 |
| 24 | set -e |
| 25 | set -u |
Thomas Vachuska | 52e6580 | 2014-12-08 09:26:01 -0800 | [diff] [blame] | 26 | . $ONOS_ROOT/tools/build/envDefaults |
Bob Lantz | 02ba2d1 | 2016-02-10 23:41:53 -0800 | [diff] [blame] | 27 | [ ! -f "$ONOS_TAR" ] && echo "$ONOS_TAR does not exist - run onos-package?" >&2 && exit 1 |
Thomas Vachuska | 52e6580 | 2014-12-08 09:26:01 -0800 | [diff] [blame] | 28 | |
| 29 | node=${1:-$OCI} |
| 30 | remote=$ONOS_USER@$node |
DongRyeol Cha | 5c0a9f0 | 2018-05-17 14:32:55 +0900 | [diff] [blame] | 31 | remote_with_bracket=$ONOS_USER@[$node] |
Yuta HIGUCHI | 3dcd286 | 2017-02-02 15:22:12 -0800 | [diff] [blame] | 32 | SSH_OPTIONS=" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \ |
| 33 | -o ControlMaster=auto -o ControlPath=~/.ssh/mux-%r@%h:%p \ |
| 34 | -o ControlPersist=300 " |
Thomas Vachuska | 52e6580 | 2014-12-08 09:26:01 -0800 | [diff] [blame] | 35 | |
Yuta HIGUCHI | 3dcd286 | 2017-02-02 15:22:12 -0800 | [diff] [blame] | 36 | USE_RSYNC=${USE_RSYNC:-'false'} |
| 37 | if [ "$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 |
| 45 | fi |
Thomas Vachuska | 52e6580 | 2014-12-08 09:26:01 -0800 | [diff] [blame] | 46 | |
Yuta HIGUCHI | 3dcd286 | 2017-02-02 15:22:12 -0800 | [diff] [blame] | 47 | if [ "$USE_RSYNC" = "clean" ]; then |
| 48 | # clean remote rsync stage directory |
| 49 | ssh $remote rm -rf "/tmp/$ONOS_BITS" |
| 50 | fi |
| 51 | |
| 52 | if [ "$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 HIGUCHI | 99a2eab | 2018-06-13 18:27:55 -0700 | [diff] [blame] | 73 | $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 HIGUCHI | 3dcd286 | 2017-02-02 15:22:12 -0800 | [diff] [blame] | 76 | |
| 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 Vachuska | 52e6580 | 2014-12-08 09:26:01 -0800 | [diff] [blame] | 81 | else |
Yuta HIGUCHI | 3dcd286 | 2017-02-02 15:22:12 -0800 | [diff] [blame] | 82 | 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 Milkey | 3933295 | 2018-07-16 13:42:51 -0700 | [diff] [blame] | 90 | ssh $remote rm -f $ONOS_TAR |
DongRyeol Cha | 5c0a9f0 | 2018-05-17 14:32:55 +0900 | [diff] [blame] | 91 | scp -q $ONOS_TAR $remote_with_bracket:/tmp |
Yuta HIGUCHI | 3dcd286 | 2017-02-02 15:22:12 -0800 | [diff] [blame] | 92 | fi |
Thomas Vachuska | 52e6580 | 2014-12-08 09:26:01 -0800 | [diff] [blame] | 93 | fi |