| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | set -eu |
| 4 | |
| 5 | die() { |
| 6 | echo >&2 "$@" |
| 7 | exit 1 |
| 8 | } |
| 9 | |
| 10 | # shellcheck disable=SC1007 |
| 11 | THIS_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) |
| 12 | # shellcheck source=../.environment.sh |
| 13 | . "${THIS_DIR}/../.environment.sh" |
| 14 | |
| 15 | check_bats_core() { |
| 16 | if ! "${TEST_DIR}/lib/bats-core/bin/bats" --version >/dev/null 2>&1; then |
| 17 | die "ERROR: the bats-* submodules are required. Please run 'git submodule init; git submodule update' and retry." |
| 18 | fi |
| 19 | } |
| 20 | |
| 21 | check_curl() { |
| 22 | if ! command -v curl >/dev/null; then |
| 23 | die "missing required program 'curl'" |
| 24 | fi |
| 25 | } |
| 26 | |
| 27 | check_python3() { |
| 28 | if ! command -v python3 >/dev/null; then |
| 29 | die "missing required program 'python3'" |
| 30 | fi |
| 31 | } |
| 32 | |
| 33 | check_jq() { |
| 34 | if ! command -v jq >/dev/null; then |
| 35 | die "Missing required program 'jq'" |
| 36 | fi |
| 37 | } |
| 38 | |
| 39 | check_nc() { |
| 40 | if ! command -v nc >/dev/null; then |
| 41 | die "missing required program 'nc' (package 'netcat-openbsd')" |
| 42 | fi |
| 43 | } |
| 44 | |
| 45 | check_base64() { |
| 46 | if ! command -v base64 >/dev/null; then |
| 47 | die "missing required program 'base64'" |
| 48 | fi |
| 49 | } |
| 50 | |
| 51 | check_pkill() { |
| 52 | if ! command -v pkill >/dev/null; then |
| 53 | die "missing required program 'pkill'" |
| 54 | fi |
| 55 | } |
| 56 | |
| 57 | check_yq() { |
| 58 | # shellcheck disable=SC2016 |
| 59 | howto_install='You can install it with your favorite package manager (including snap) or with "go install github.com/mikefarah/yq/v4@latest" and add ~/go/bin to $PATH.' |
| 60 | if ! command -v yq >/dev/null; then |
| 61 | die "Missing required program 'yq'. ${howto_install}" |
| 62 | fi |
| 63 | if ! (yq --version | grep mikefarah >/dev/null); then |
| 64 | die "yq exists but it's not the one we need (mikefarah/yq). ${howto_install}" |
| 65 | fi |
| 66 | } |
| 67 | |
| 68 | check_daemonizer() { |
| 69 | if ! command -v daemonize >/dev/null; then |
| 70 | die "missing required program 'daemonize' (package 'daemonize' or 'https://github.com/bmc/daemonize')" |
| 71 | fi |
| 72 | } |
| 73 | |
| 74 | check_cfssl() { |
| 75 | # shellcheck disable=SC2016 |
| 76 | howto_install='You can install it with "go install github.com/cloudflare/cfssl/cmd/cfssl@latest" and add ~/go/bin to $PATH.' |
| 77 | if ! command -v cfssl >/dev/null; then |
| 78 | die "Missing required program 'cfssl'. ${howto_install}" |
| 79 | fi |
| 80 | } |
| 81 | |
| 82 | check_cfssljson() { |
| 83 | # shellcheck disable=SC2016 |
| 84 | howto_install='You can install it with "go install github.com/cloudflare/cfssl/cmd/cfssljson@latest" and add ~/go/bin to $PATH.' |
| 85 | if ! command -v cfssljson >/dev/null; then |
| 86 | die "Missing required program 'cfssljson'. ${howto_install}" |
| 87 | fi |
| 88 | } |
| 89 | |
| 90 | check_gocovmerge() { |
| 91 | if ! command -v gocovmerge >/dev/null; then |
| 92 | die "missing required program 'gocovmerge'. You can install it with \"go install github.com/wadey/gocovmerge@latest\"" |
| 93 | fi |
| 94 | } |
| 95 | |
| 96 | check_bats_core |
| 97 | check_curl |
| 98 | check_daemonizer |
| 99 | check_cfssl |
| 100 | check_cfssljson |
| 101 | check_jq |
| 102 | check_nc |
| 103 | check_base64 |
| 104 | check_python3 |
| 105 | check_yq |
| 106 | check_pkill |
| 107 | if [[ -n "${TEST_COVERAGE}" ]]; then |
| 108 | check_gocovmerge |
| 109 | fi |
| 110 |