Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Builds dependencies and copies stratum_bmv2 binary to a remote node. |
| 4 | # ----------------------------------------------------------------------------- |
| 5 | |
Carmelo Cascone | a4dc3c1 | 2019-02-12 17:30:00 -0800 | [diff] [blame] | 6 | set -e |
| 7 | |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 8 | function _usage () { |
| 9 | cat << _EOF_ |
| 10 | usage: |
| 11 | $(basename $0) [node] |
| 12 | |
| 13 | options: |
| 14 | - [node] : remote node to install Stratum on. |
| 15 | |
| 16 | summary: |
| 17 | Builds dependencies and copies stratum_bmv2 binary to a remote node. |
| 18 | |
| 19 | If [node] is not specified the default target is \$OCN. |
| 20 | |
| 21 | This script requires env STRATUM_BMV2_TAR to be set and to point to a tar file |
| 22 | containing the following files (pre-built stratum_bmv2 binaries): |
| 23 | - stratum/bazel-bin/stratum/hal/bin/bmv2/stratum_bmv2 |
| 24 | - stratum/stratum/hal/bin/bmv2/dummy.json |
| 25 | |
| 26 | _EOF_ |
| 27 | } |
| 28 | |
| 29 | [[ "$1" = "-h" ]] && _usage && exit 0 |
| 30 | |
| 31 | [[ ! -d "$ONOS_ROOT" ]] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 32 | . ${ONOS_ROOT}/tools/build/envDefaults |
| 33 | |
| 34 | [[ ! -f ${STRATUM_BMV2_TAR} ]] && echo "STRATUM_BMV2_TAR is not defined or points to an invalid file" && exit 1 |
| 35 | |
| 36 | md5cmd='' |
| 37 | md5cmdprm='' |
| 38 | case "$OSTYPE" in |
| 39 | darwin*) md5cmd='md5' ; md5cmdprm='-q' ;; |
| 40 | *) md5cmd='md5sum';; |
| 41 | esac |
| 42 | |
| 43 | node=${1:-$OCN} |
| 44 | remote=${ONOS_USER}@${node} |
| 45 | |
| 46 | stratumRoot="/home/${ONOS_USER}/stratum" |
| 47 | stratumExportLine="export STRATUM_ROOT=${stratumRoot}" |
| 48 | stratumMd5=$(${md5cmd} ${md5cmdprm} ${STRATUM_BMV2_TAR}) |
| 49 | stratumInstalled="~/.stratum_bmv2_installed_${stratumMd5}" |
| 50 | |
| 51 | p4ToolsScript=${ONOS_ROOT}/tools/dev/p4vm/install-p4-tools.sh |
| 52 | p4ToolsMd5=$(${md5cmd} ${md5cmdprm} ${p4ToolsScript}) |
| 53 | p4ToolsInstalled="~/.stratum_deps_installed_${p4ToolsMd5}" |
| 54 | |
| 55 | function do_deps { |
| 56 | if ssh ${remote} stat "${p4ToolsInstalled}" \> /dev/null 2\>\&1 ; then |
| 57 | echo "stratum deps already up-to-date on ${node}" |
| 58 | else |
| 59 | ssh ${remote} "sudo rm -f /tmp/install-p4-tools.sh" |
| 60 | scp -qr ${p4ToolsScript} ${ONOS_USER}@[${node}]:/tmp/install-p4-tools.sh |
| 61 | ssh -tt ${remote} " |
| 62 | USE_STRATUM=true DEBUG_FLAGS=false FAST_BUILD=true CLEAN_UP=true \ |
| 63 | bash /tmp/install-p4-tools.sh bmv2 \ |
| 64 | && touch ${p4ToolsInstalled} |
| 65 | " |
| 66 | fi |
| 67 | } |
| 68 | |
| 69 | function do_stratum_bin { |
| 70 | if ssh ${remote} stat "${stratumInstalled}" \> /dev/null 2\>\&1 ; then |
| 71 | echo "stratum_bmv2 already up-to-date on ${node}" |
| 72 | else |
| 73 | ssh ${remote} "sudo rm -f /tmp/stratum_bmv2.tar.gz" |
| 74 | scp -qr ${STRATUM_BMV2_TAR} ${ONOS_USER}@[${node}]:/tmp/stratum_bmv2.tar.gz |
| 75 | ssh -tt ${remote} " |
Carmelo Cascone | 87c3297 | 2019-03-07 18:53:57 -0800 | [diff] [blame] | 76 | rm -rf ${stratumRoot} && mkdir ${stratumRoot} && \ |
| 77 | tar xvf /tmp/stratum_bmv2.tar.gz -C ${stratumRoot} --strip-components 1 \ |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 78 | && touch ${stratumInstalled} \ |
| 79 | && grep -qF -- \"${stratumExportLine}\" ~/.bash_aliases || echo \"${stratumExportLine}\" >> ~/.bash_aliases |
| 80 | " |
| 81 | fi |
| 82 | } |
| 83 | |
| 84 | do_deps |
| 85 | do_stratum_bin |