diff --git a/ci/install_yq.sh b/ci/install_yq.sh index e33537a596..302c39ab2d 100755 --- a/ci/install_yq.sh +++ b/ci/install_yq.sh @@ -14,20 +14,38 @@ die() { exit 1 } +function verify_yq_exists() { + local yq_path=$1 + local yq_version=$2 + local expected="yq (https://github.com/mikefarah/yq/) version $yq_version" + if [ -x "${yq_path}" ] && [ "$($yq_path --version)"X == "$expected"X ]; then + return 0 + else + return 1 + fi +} + # Install the yq yaml query package from the mikefarah github repo # Install via binary download, as we may not have golang installed at this point function install_yq() { local yq_pkg="github.com/mikefarah/yq" local yq_version=v4.40.7 local precmd="" + local yq_path="" INSTALL_IN_GOPATH=${INSTALL_IN_GOPATH:-true} - if [ "${INSTALL_IN_GOPATH}" == "true" ];then + if [ "${INSTALL_IN_GOPATH}" == "true" ]; then GOPATH=${GOPATH:-${HOME}/go} mkdir -p "${GOPATH}/bin" - local yq_path="${GOPATH}/bin/yq" + yq_path="${GOPATH}/bin/yq" else yq_path="/usr/local/bin/yq" + fi + if verify_yq_exists "$yq_path" "$yq_version"; then + echo "yq is already installed in correct version" + return + fi + if [ "${yq_path}" == "/usr/local/bin/yq" ]; then # Check if we need sudo to install yq if [ ! -w "/usr/local/bin" ]; then # Check if we have sudo privileges @@ -38,7 +56,6 @@ function install_yq() { fi fi fi - [ -x "${yq_path}" ] && [ "`${yq_path} --version`"X == "yq (https://github.com/mikefarah/yq/) version ${yq_version}"X ] && return read -r -a sysInfo <<< "$(uname -sm)"