From b611b4b5aa9b0356a0e6e3989488f499c81a7bee Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Thu, 1 Aug 2019 13:17:22 +0200 Subject: [PATCH] MON-486 add requirements check script --- README.md | 4 ++-- scripts/00_requirements.sh | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100755 scripts/00_requirements.sh diff --git a/README.md b/README.md index 3a2515e..a53577c 100644 --- a/README.md +++ b/README.md @@ -31,11 +31,11 @@ After any change on this repo, you need to run the `./scripts/auto_update.sh ./` ### Terraform ### -Version >= 0.12 is required to use these modules of monitors. +Here is the minimum version required to use these modules of integrations. ``` terraform { - required_version = "~> 0.12" + required_version = ">= 0.12.6" } ``` diff --git a/scripts/00_requirements.sh b/scripts/00_requirements.sh new file mode 100755 index 0000000..9889c2d --- /dev/null +++ b/scripts/00_requirements.sh @@ -0,0 +1,48 @@ +#!/bin/bash +set -u + +source "$(dirname $0)/utils.sh" +goto_root + +function check_command() { + local cmd="$1" + if ! command -v ${cmd} > /dev/null 2>&1; then + echo "This requires ${cmd} command, please install it first." + exit 1 + fi +} + +function verlte() { + [ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ] +} + +function verlt() { + [ "$1" = "$2" ] && return 1 || verlte $1 $2 +} + +function check_version() { + if [[ "$1" == "terraform" ]]; then + tmp_dir=$(mktemp -d) + cd ${tmp_dir} + cur_ver=$(terraform version | head -n 1 | cut -d' ' -f2) + cur_ver=${cur_ver#"v"} + cd - > /dev/null + rm -fr ${tmp_dir} + req_ver=$(grep required_version README.md | awk '{print $4}') + req_ver=${req_ver%'"'} + elif [[ "$1" == "terraform-docs" ]]; then + req_ver="0.6.0" + cur_ver=$(terraform-docs --version) + else + return + fi + if ! verlte $req_ver $cur_ver; then + echo "This requires at least version ${req_ver} of $1, please upgrade (current version is ${cur_ver})" + exit 2 + fi +} + +for cmd in terraform terraform-docs; do + check_command $cmd + check_version $cmd +done