blob: 1e45921575723bdeaf878112d95f4fff00301811 [file] [log] [blame]
Carmelo Cascone7c82bcf2019-02-08 22:57:18 -08001#!/bin/bash
2# -----------------------------------------------------------------------------
3# Builds dependencies and copies stratum_bmv2 binary to a remote node.
4# -----------------------------------------------------------------------------
5
Carmelo Casconea4dc3c12019-02-12 17:30:00 -08006set -e
7
Carmelo Cascone7c82bcf2019-02-08 22:57:18 -08008function _usage () {
9cat << _EOF_
10usage:
11 $(basename $0) [node]
12
13options:
14- [node] : remote node to install Stratum on.
15
16summary:
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
36md5cmd=''
37md5cmdprm=''
38case "$OSTYPE" in
39 darwin*) md5cmd='md5' ; md5cmdprm='-q' ;;
40 *) md5cmd='md5sum';;
41esac
42
43node=${1:-$OCN}
44remote=${ONOS_USER}@${node}
45
46stratumRoot="/home/${ONOS_USER}/stratum"
47stratumExportLine="export STRATUM_ROOT=${stratumRoot}"
48stratumMd5=$(${md5cmd} ${md5cmdprm} ${STRATUM_BMV2_TAR})
49stratumInstalled="~/.stratum_bmv2_installed_${stratumMd5}"
50
51p4ToolsScript=${ONOS_ROOT}/tools/dev/p4vm/install-p4-tools.sh
52p4ToolsMd5=$(${md5cmd} ${md5cmdprm} ${p4ToolsScript})
53p4ToolsInstalled="~/.stratum_deps_installed_${p4ToolsMd5}"
54
55function 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
69function 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 Cascone87c32972019-03-07 18:53:57 -080076 rm -rf ${stratumRoot} && mkdir ${stratumRoot} && \
77 tar xvf /tmp/stratum_bmv2.tar.gz -C ${stratumRoot} --strip-components 1 \
Carmelo Cascone7c82bcf2019-02-08 22:57:18 -080078 && touch ${stratumInstalled} \
79 && grep -qF -- \"${stratumExportLine}\" ~/.bash_aliases || echo \"${stratumExportLine}\" >> ~/.bash_aliases
80 "
81 fi
82}
83
84do_deps
85do_stratum_bin