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 |
Yuta HIGUCHI | 3dcd286 | 2017-02-02 15:22:12 -0800 | [diff] [blame^] | 31 | SSH_OPTIONS=" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \ |
| 32 | -o ControlMaster=auto -o ControlPath=~/.ssh/mux-%r@%h:%p \ |
| 33 | -o ControlPersist=300 " |
Thomas Vachuska | 52e6580 | 2014-12-08 09:26:01 -0800 | [diff] [blame] | 34 | |
Yuta HIGUCHI | 3dcd286 | 2017-02-02 15:22:12 -0800 | [diff] [blame^] | 35 | USE_RSYNC=${USE_RSYNC:-'false'} |
| 36 | if [ "$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 |
| 44 | fi |
Thomas Vachuska | 52e6580 | 2014-12-08 09:26:01 -0800 | [diff] [blame] | 45 | |
Yuta HIGUCHI | 3dcd286 | 2017-02-02 15:22:12 -0800 | [diff] [blame^] | 46 | if [ "$USE_RSYNC" = "clean" ]; then |
| 47 | # clean remote rsync stage directory |
| 48 | ssh $remote rm -rf "/tmp/$ONOS_BITS" |
| 49 | fi |
| 50 | |
| 51 | if [ "$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 Vachuska | 52e6580 | 2014-12-08 09:26:01 -0800 | [diff] [blame] | 78 | else |
Yuta HIGUCHI | 3dcd286 | 2017-02-02 15:22:12 -0800 | [diff] [blame^] | 79 | 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 Vachuska | 52e6580 | 2014-12-08 09:26:01 -0800 | [diff] [blame] | 89 | fi |