blob: 72622cd14a6eb59e7740f2ad23bd89aed758ca85 [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
6function _usage () {
7cat << _EOF_
8usage:
9 $(basename $0) [node]
10
11options:
12- [node] : remote node to install Stratum on.
13
14summary:
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
34md5cmd=''
35md5cmdprm=''
36case "$OSTYPE" in
37 darwin*) md5cmd='md5' ; md5cmdprm='-q' ;;
38 *) md5cmd='md5sum';;
39esac
40
41node=${1:-$OCN}
42remote=${ONOS_USER}@${node}
43
44stratumRoot="/home/${ONOS_USER}/stratum"
45stratumExportLine="export STRATUM_ROOT=${stratumRoot}"
46stratumMd5=$(${md5cmd} ${md5cmdprm} ${STRATUM_BMV2_TAR})
47stratumInstalled="~/.stratum_bmv2_installed_${stratumMd5}"
48
49p4ToolsScript=${ONOS_ROOT}/tools/dev/p4vm/install-p4-tools.sh
50p4ToolsMd5=$(${md5cmd} ${md5cmdprm} ${p4ToolsScript})
51p4ToolsInstalled="~/.stratum_deps_installed_${p4ToolsMd5}"
52
53function 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
67function 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
82do_deps
83do_stratum_bin