diff --git a/Makefile b/Makefile index 59915dfd..0fde56c7 100644 --- a/Makefile +++ b/Makefile @@ -21,24 +21,30 @@ prereqs: ## Test if prerequisites are met, and installing missing dependencies GOFLAGS="" go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION} .PHONY: build -build: prepare lint +build: prepare lint ## Build the binary and run Lint @go build -o $(OUTPUT) cp -a ./oc/. ./$(DIST_DIR) cp -a ./res/. ./$(DIST_DIR)/network-observability-cli-resources .PHONY: image -image: +image: ## Build the docker image $(OCI_BIN) build -t network-observability-cli . .PHONY: lint lint: prereqs ## Lint code @echo "### Linting code" golangci-lint run ./... + @echo "### Run shellcheck against bash scripts" + find . -name '*.sh' | xargs shellcheck .PHONY: clean -clean: +clean: ## Clean up build directory @rm -rf $(DIST_DIR) .PHONY: oc-commands oc-commands: build sudo cp -a ./build/. /usr/bin/ + +.PHONY: help +help: ## Display this help. + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) diff --git a/res/functions.sh b/res/functions.sh index 0b671dd9..66e873ac 100644 --- a/res/functions.sh +++ b/res/functions.sh @@ -1,3 +1,6 @@ +#!/usr/bin/env bash +set -eux + function setup { echo "Setting up... " @@ -11,27 +14,27 @@ function setup { fi filename="" - mkdir -p ${BASH_SOURCE%/*}/current + mkdir -p "${BASH_SOURCE%/*}"/current - if [ $1 = "flows" ]; then + if [ "$1" = "flows" ]; then filename="flow-capture" - sed "s/{{FLOW_FILTER_VALUE}}/$2/gi" ${BASH_SOURCE%/*}/flow-capture.yml > ${BASH_SOURCE%/*}/current/agent.yml - elif [ $1 = "packets" ]; then + sed "s/{{FLOW_FILTER_VALUE}}/$2/gi" "${BASH_SOURCE%/*}"/flow-capture.yml > "${BASH_SOURCE%/*}"/current/agent.yml + elif [ "$1" = "packets" ]; then filename="packet-capture" - sed "s/{{PCA_FILTER_VALUE}}/$2/gi" ${BASH_SOURCE%/*}/packet-capture.yml > ${BASH_SOURCE%/*}/current/agent.yml + sed "s/{{PCA_FILTER_VALUE}}/$2/gi" "${BASH_SOURCE%/*}"/packet-capture.yml > "${BASH_SOURCE%/*}"/current/agent.yml else echo "invalid setup argument" return fi echo "creating netobserv-cli namespace" - oc apply -f ${BASH_SOURCE%/*}/namespace.yml + oc apply -f "${BASH_SOURCE%/*}"/namespace.yml echo "creating service account" - oc apply -f ${BASH_SOURCE%/*}/service-account.yml + oc apply -f "${BASH_SOURCE%/*}"/service-account.yml echo "creating $filename agents" - oc apply -f ${BASH_SOURCE%/*}/current/agent.yml + oc apply -f "${BASH_SOURCE%/*}"/current/agent.yml oc rollout status daemonset netobserv-cli -n netobserv-cli --timeout 60s echo "forwarding agents ports" @@ -43,8 +46,8 @@ function setup { do echo "forwarding $pod:9999 to local port $port" pkill --oldest --full "$port:9999" - oc port-forward $pod $port:9999 -n netobserv-cli & # run in background - node=$(oc get $pod -n netobserv-cli -o jsonpath='{.spec.nodeName}') + oc port-forward "$pod" $port:9999 -n netobserv-cli & # run in background + node=$(oc get "$pod" -n netobserv-cli -o jsonpath='{.spec.nodeName}') if [ -z "$ports" ] then nodes="$node" @@ -64,6 +67,7 @@ function cleanup { stty -F /dev/tty echo setterm -linewrap on + # shellcheck disable=SC2034 if output=$(oc whoami 2>&1); then printf "\nCleaning up... " oc delete namespace netobserv-cli