From d45d8a16b3325f4d00a3a844c1946bd006288826 Mon Sep 17 00:00:00 2001 From: Derrick Anderson Date: Thu, 25 Jan 2018 08:40:29 -0500 Subject: prereq check (#8151) --- Makefile | 5 ++++- scripts/prereq-check.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100755 scripts/prereq-check.sh diff --git a/Makefile b/Makefile index 93f439d1a..2e4225aca 100644 --- a/Makefile +++ b/Makefile @@ -300,6 +300,9 @@ update-zoom-plugin: ## Updates Zoom plugin. check-licenses: ## Checks license status. ./scripts/license-check.sh $(TE_PACKAGES) $(EE_PACKAGES) +check-prereqs: ## Checks prerequisite software status. + ./scripts/prereq-check.sh + check-style: govet gofmt check-licenses ## Runs govet and gofmt against all packages. test-te-race: ## Checks for race conditions in the team edition. @@ -400,7 +403,7 @@ run-client-fullmap: ## Runs the webapp with source code mapping (slower; better cd $(BUILD_WEBAPP_DIR) && $(MAKE) run-fullmap -run: run-server run-client ## Runs the server and webapp. +run: check-prereqs run-server run-client ## Runs the server and webapp. run-fullmap: run-server run-client-fullmap ## Same as run but with a full sourcemap for client. diff --git a/scripts/prereq-check.sh b/scripts/prereq-check.sh new file mode 100755 index 000000000..1c9ae8405 --- /dev/null +++ b/scripts/prereq-check.sh @@ -0,0 +1,49 @@ +#!/bin/bash +check_version() +{ + local version=$1 check=$2 + local winner=$(echo -e "$version\n$check" | sed '/^$/d' | sort -nr | head -1) + [[ "$winner" = "$version" ]] && return 0 + return 1 +} + +check_prereq() +{ + if [ ! $# == 3 ]; then + echo "Unable to determine '$1' version! Ensure that '$1' is in your path and try again." && exit 1 + fi + + local dependency=$1 required_version=$2 installed_version=$3 + + type $dependency >/dev/null 2>&1 || { echo >&2 "Mattermost requires '$dependency' but it doesn't appear to be installed. Aborting."; exit 1; } + + if check_version $installed_version $required_version; then + echo "$dependency minimum requirement met. Required: $required_version, Found: $installed_version" + else + echo "WARNING! Mattermost did not find the minimum supported version of '$dependency' installed. Required: $required_version, Found: $installed_version" + echo "We highly recommend stopping installation and updating dependencies before continuing" + read -p "Enter Y to continue anyway (not recommended)." -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]] + then + exit 1 + fi + fi +} + +echo "Checking prerequisites" + +REQUIREDNODEVERSION=8.9.0 +REQUIREDNPMVERSION=5.6.0 +REQUIREDGOVERSION=1.9.2 +REQUIREDDOCKERVERSION=17.0 + +NODEVERSION=$(sed 's/v//' <<< $(node -v)) +NPMVERSION=$(npm -v) +GOVERSION=$(sed -ne 's/[^0-9]*\(\([0-9]\.\)\{0,4\}[0-9][^.]\).*/\1/p' <<< $(go version)) +DOCKERVERSION=$(docker version --format '{{.Server.Version}}' | sed 's/[a-z-]//g') + +check_prereq 'node' $REQUIREDNODEVERSION $NODEVERSION +check_prereq 'npm' $REQUIREDNPMVERSION $NPMVERSION +check_prereq 'go' $REQUIREDGOVERSION $GOVERSION +check_prereq 'docker' $REQUIREDDOCKERVERSION $DOCKERVERSION \ No newline at end of file -- cgit v1.2.3-1-g7c22