|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2025 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 | +# renovate: datasource=github-releases depName=kubernetes-sigs/controller-tools |
| 18 | +CONTROLLER_TOOLS_GENERATOR_VERSION=v0.15.0 |
| 19 | +# renovate: datasource=github-releases depName=golangci/golangci-lint |
| 20 | +GOLANG_CI_LINTER_VERSION=v2.0.2 |
| 21 | + |
| 22 | +# Execute |
| 23 | +# scripts/install-tools.sh |
| 24 | +# scripts/install-tools.sh -h |
| 25 | +# scripts/install-tools.sh --generator |
| 26 | +# scripts/install-tools.sh --golangci |
| 27 | + |
| 28 | +show_help() { |
| 29 | +cat << EOF |
| 30 | +'external-dns' helm linter helper commands |
| 31 | +
|
| 32 | +Usage: $(basename "$0") <options> |
| 33 | + -h, --help Display help |
| 34 | + --generator Install generator |
| 35 | + --golangci Install golangci linter |
| 36 | +EOF |
| 37 | +} |
| 38 | + |
| 39 | +install_generator() { |
| 40 | + # https://github.com/kubernetes-sigs/controller-tools/blob/main/cmd/controller-gen/main.go |
| 41 | + local install=false |
| 42 | + if [[ -x $(which controller-gen) ]]; then |
| 43 | + local version=$(controller-gen --version | sed 's/Version: //') |
| 44 | + if [[ "${version}" == "${CONTROLLER_TOOLS_GENERATOR_VERSION}" ]]; then |
| 45 | + install=false |
| 46 | + else |
| 47 | + install=true |
| 48 | + fi |
| 49 | + else |
| 50 | + install=true |
| 51 | + fi |
| 52 | + if [[ "$install" == true ]]; then |
| 53 | + set -ex ;\ |
| 54 | + go install sigs.k8s.io/controller-tools/cmd/controller-gen@${CONTROLLER_TOOLS_GENERATOR_VERSION} ; |
| 55 | + fi |
| 56 | +} |
| 57 | + |
| 58 | +install_golangci() { |
| 59 | + local install=false |
| 60 | + if [[ -x $(which golangci-lint) ]]; then |
| 61 | + local version=$(golangci-lint version --short) |
| 62 | + if [[ "${version}" == "${GOLANG_CI_LINTER_VERSION#v}" ]]; then |
| 63 | + install=false |
| 64 | + else |
| 65 | + install=true |
| 66 | + fi |
| 67 | + else |
| 68 | + install=true |
| 69 | + fi |
| 70 | + if [[ "$install" == true ]]; then |
| 71 | + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/cc3567e3127d8530afb69be1b7bd20ba9ebcc7c1/install.sh \ |
| 72 | + | sh -s -- -b $(go env GOPATH)/bin "${GOLANG_CI_LINTER_VERSION}" |
| 73 | + fi |
| 74 | +} |
| 75 | + |
| 76 | +function main() { |
| 77 | + case $1 in |
| 78 | + --generator) |
| 79 | + install_generator |
| 80 | + ;; |
| 81 | + --golangci) |
| 82 | + install_golangci |
| 83 | + ;; |
| 84 | + -h|--help) |
| 85 | + show_help |
| 86 | + ;; |
| 87 | + *) |
| 88 | + echo "unknown sub-command" >&2 |
| 89 | + show_help |
| 90 | + exit 1 |
| 91 | + ;; |
| 92 | + esac |
| 93 | +} |
| 94 | + |
| 95 | +main "$@" |
0 commit comments