3 # A simple script that installs VPPTop utility including
4 # all requirements. The binary API is built from the local
5 # vpp data. 'make install-dep' is recommended to call first.
11 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12 cd "${SCRIPT_DIR}"/../../
14 BUILD_DIR=${VPP_DIR}/extras/vpptop/build
19 [ -z "${GOROOT}" ] && GOROOT="${HOME}/.go"
20 [ -z "${GOPATH}" ] && GOPATH="${HOME}/go"
22 function dep_install() {
23 echo "Installing VPPTop dependencies"
25 apt-get install git wget curl -y
28 # Install latest GO version
29 function go_install() {
32 # Search for existing golang installation
33 echo "Looking for pre-installed GO.."
34 local installed_ver installed_ver_fmt
35 if [[ -f "${GOROOT}/bin/go" ]]; then
36 installed_ver=$(cd ${GOROOT}/bin && ./go version)
37 installed_ver_fmt=${installed_ver#"go version go"}
38 export PATH=$GOROOT/bin:$PATH
39 export PATH=$GOPATH/bin:$PATH
40 echo "Found installed version ${installed_ver_fmt}"
44 # install golang when missing
45 echo ".. none was found. Installing the latest one"
47 mkdir -p "${GOPATH}/"{src,pkg,bin}
49 wget "https://dl.google.com/go/$(curl https://golang.org/VERSION?m=text).linux-amd64.tar.gz" -O "${TMP}/go.tar.gz"
50 tar -C "$GOROOT" --strip-components=1 -xzf "${TMP}/go.tar.gz"
52 rm -f "${TMP}/go.tar.gz"
54 # export for current session so the VPPTop can be installed
55 export GOROOT=${GOROOT}
57 export PATH=$GOROOT/bin:$PATH
58 export PATH=$GOPATH/bin:$PATH
61 Installed $(go version)
62 Note: following variables were exported for the current session:
65 Both were added to PATH
69 # Install GoVPP binary API generator. GoLang required
70 # to be installed in version 1.13 or higher
71 function install_binapi_gen() {
72 echo "Installing GoVPP binary API generator"
75 # master required for latest VPPTop
76 if [[ ! -f "${GOROOT}/bin/go" ]]; then
77 echo "GO is not installed"
80 cd ${GOROOT}/bin && ./go get git.fd.io/govpp.git/cmd/binapi-generator@master
82 local installed_ver installed_ver_fmt
83 installed_ver=$(cd ${GOPATH}/bin && ./binapi-generator -version)
84 installed_ver_fmt=${installed_ver#"govpp "}
85 echo "Binary API generator ${installed_ver_fmt} installed"
88 # Generate binary API files in the VPPTop directory using
89 # the local VPP sources
90 function generate_binary_api() {
91 # note: build-root dir is planned to be removed, update the path by then
92 local api_dir=${VPP_DIR}/build-root/install-vpp-native/vpp/share/vpp/api
93 local out_dir=${BUILD_DIR}/vpptop/stats/local/binapi
95 if [[ ! -f "${GOPATH}/bin/binapi-generator" ]]; then
98 if [ ! -d "${BUILD_DIR}" ]; then
99 echo "VPPTop directory does not exist"
101 elif [ ! -d "${out_dir}" ]; then
102 mkdir -p "${out_dir}"
104 if [ ! -d "${api_dir}" ]; then
105 echo "JSON API files missing, call 'make json-api-files' first"
109 echo "Generating API"
110 cd ${GOPATH}/bin && ./binapi-generator --output-dir="${out_dir}" -input-dir="${api_dir}" \
111 "${api_dir}"/plugins/dhcp.api.json \
112 "${api_dir}"/core/interface.api.json \
113 "${api_dir}"/core/ip.api.json \
114 "${api_dir}"/core/vpe.api.json
117 # Retrieve VPPTop repository
118 function get_vpptop() {
119 echo "Fetching VPPTop"
120 if [ ! -d "${BUILD_DIR}/vpptop" ]; then
122 cd "${BUILD_DIR}" && git clone https://github.com/PANTHEONtech/vpptop.git
124 echo "VPPTop directory already exists"
128 # Resolve VPPTop dependencies and install the binary
129 function vpptop_install() {
133 echo "Installing VPPTop"
134 if [ ! -d "${BUILD_DIR}" ]; then
135 echo "VPPTop directory does not exist"
139 gopath=${GOROOT}/bin/go
141 cd "${BUILD_DIR}"/vpptop && go mod download
142 cd "${BUILD_DIR}"/vpptop && make install
144 if [[ ! -x "$(command -v vpptop)" ]] && [[ ! -f "${GOPATH}/bin/vpptop" ]] ; then
145 echo "VPPTop was not successfully installed"
148 if [[ ! -x "$(command -v vpptop)" ]] ; then
149 echo "VPPTop was installed to ${GOPATH}/bin/vpptop"
157 Following binaries were installed:
158 ${GOPATH}/bin/binapi-generator
163 # Starts the vpptop binary
164 function vpptop_start() {
165 if [[ -f "${GOPATH}/bin/vpptop" ]] ; then
166 cd ${GOPATH}/bin && ./vpptop
170 echo "VPPTop is not installed, use 'make vpptop-install' first"
173 # Remove VPPTop repository from extras
175 echo "Cleaning up VPPTop"
176 rm -rf "${BUILD_DIR}"
179 # Show available commands
184 Run 'make install-dep' before the installation
187 Installs VPPTop requirements (latest GO, GoVPP binary API generator),
188 retrieves VPPTop repository, generates binary API and installs the
192 Removes VPPTop repository
200 # Resolve chosen option and call appropriate functions
201 function resolve_option() {
218 *) echo invalid option ;;
222 if [[ -n ${OPT_ARG} ]]; then
223 resolve_option "${OPT_ARG}"
226 options=("install" "cleanup" "help")
227 select option in "${options[@]}"; do
228 resolve_option "${option}"