sigs.k8s.io/cluster-api@v1.7.1/hack/ensure-trivy.sh (about) 1 #!/bin/bash 2 3 # Copyright 2023 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 set -o errexit 18 set -o nounset 19 set -o pipefail 20 21 if [[ "${TRACE-0}" == "1" ]]; then 22 set -o xtrace 23 fi 24 25 VERSION=${1} 26 27 GO_OS="$(go env GOOS)" 28 if [[ "${GO_OS}" == "linux" ]]; then 29 TRIVY_OS="Linux" 30 elif [[ "${GO_OS}" == "darwin"* ]]; then 31 TRIVY_OS="macOS" 32 fi 33 34 GO_ARCH="$(go env GOARCH)" 35 if [[ "${GO_ARCH}" == "amd" ]]; then 36 TRIVY_ARCH="32bit" 37 elif [[ "${GO_ARCH}" == "amd64"* ]]; then 38 TRIVY_ARCH="64bit" 39 elif [[ "${GO_ARCH}" == "arm" ]]; then 40 TRIVY_ARCH="ARM" 41 elif [[ "${GO_ARCH}" == "arm64" ]]; then 42 TRIVY_ARCH="ARM64" 43 fi 44 45 TOOL_BIN=hack/tools/bin 46 mkdir -p ${TOOL_BIN} 47 48 TRIVY="${TOOL_BIN}/trivy/${VERSION}/trivy" 49 50 # Downloads trivy scanner 51 if [ ! -f "$TRIVY" ]; then 52 curl -L -o ${TOOL_BIN}/trivy.tar.gz "https://github.com/aquasecurity/trivy/releases/download/v${VERSION}/trivy_${VERSION}_${TRIVY_OS}-${TRIVY_ARCH}.tar.gz" 53 mkdir -p "$(dirname "$0")/tools/bin/trivy/${VERSION}" 54 tar -xf "${TOOL_BIN}/trivy.tar.gz" -C "${TOOL_BIN}/trivy/${VERSION}" trivy 55 chmod +x "${TOOL_BIN}/trivy/${VERSION}/trivy" 56 rm "${TOOL_BIN}/trivy.tar.gz" 57 fi