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