#!/bin/env bash # RUN ME $> bash <(curl -sL https://raw.githubusercontent.com/laboperator-gmbh/installation/main/requirements-check.sh ) > report.txt # RUN ME in docker image $> docker run -it : bash -c "bash <(curl -sL https://raw.githubusercontent.com/laboperator-gmbh/installation/main/requirements-check.sh )" FAIL=0 export LANG=en function validate() { str_to_validate=$1 hide="${2:-no}" bullet="${3}" if [[ "$hide" == "no" ]]; then echo "$bullet$str_to_validate" fi if [[ "$str_to_validate" == *"FAILED." ]]; then FAIL=1 fi } function curl_request() { URL=$1 response=$(curl -s -v -o /dev/null $URL 2>&1 | awk "/HTTP\/.+ (2[0-9][0-9]|3[0-9][0-9]).*/ {success=1} END { if (1 == success) { printf \"$URL safely reachable - OK. \n\"; } else printf \"$URL safely unreachable - FAILED.\n\"; }") validate "$response" "no" " > " } function check_domain_resolution() { local domain="$1" ips=$(dig "$domain" +short | wc -l) if [[ "$ips" == "0" ]]; then validate " > DNS $domain FAILED." else echo " > DNS $domain OK." fi } echo "Under which root DNS would the applications be installed?" read -e domain echo "Testing DNS mapping" check_domain_resolution "account.$domain" check_domain_resolution "admin-console.$domain" check_domain_resolution "app.$domain" check_domain_resolution "connector-manager.$domain" check_domain_resolution "fos.$domain" check_domain_resolution "workflow-editor.$domain" TESTS=$(builtin type -P awk > /dev/null || echo "Unable to find awk command. Make sure that it is installed and in the user PATH. FAILED."; \ builtin type -P curl > /dev/null || echo "Unable to find curl command. Make sure that it is installed and in the user PATH. FAILED."; \ builtin type -P free > /dev/null || echo "Unable to find free command. Make sure that it is installed and in the user PATH. FAILED."; \ builtin type -P lscpu > /dev/null || echo "Unable to find lscpu command. Make sure that it is installed and in the user PATH. FAILED.") validate "$TESTS" # 150GB = 157286400 kilobytes TEST_AVAILABLE_SPACE=$(df -Pk /var /var/lib /var/lib/kubelet 2> /dev/null | tail -1 | awk -F ' ' 'BEGIN{kilobytes=0}{ if ($4+0>kilobytes) kilobytes=$4+0; source=$6;} END {if (kilobytes 157286400 < 1) printf "Not enough disk space. There`s only %d (kilobytes) available. The installation requires at least 150 GB of diskspace. FAILED.", kilobytes; else printf "Mountpoint \"%s\" has enough disk space - OK.", source}') validate "$TEST_AVAILABLE_SPACE" echo "Checking hardware specs" TEST_CPU_CORES=$(lscpu 2>/dev/null| awk -F: 'IGNORECASE = 1;/^CPU\(s\):/{vcores=$2; minimumVCores=4} END { if (vcores < minimumVCores) printf "Not enough vcores. At least %d vcores needed. Found only %d \n", minimumVCores, vcores; else printf "Enough vcores: %i - OK. \n", vcores; } ' | grep -i cores) validate "$TEST_CPU_CORES" "hide" TEST_CPU_CLOCK=$(lscpu 2>/dev/null| awk -F: 'IGNORECASE = 1;/MHz:/ { mhz=$2 } IGNORECASE = 1;/max MHz:/ {max=$2 } END { if (max > mhz) mhz = max; if (mhz < 2600) printf "Not enough clock. Minimum required is 2600, measured: %d Mhz\n", mhz; else printf "Enough clock speed: %d Mhz - OK. \n", mhz } ' | grep -i Mhz) validate "$TEST_CPU_CLOCK" "hide" TEST_MEM=$(free --giga | awk -F' ' '/^Mem:/ {total=$2; minimumGB=4} END { if (total < minimumGB) printf "Not enough total memory. %d GB is the minimun requirement. Memory found: %d FAILED.\n", minimumGB, total; else printf "Total memory: %s - OK. \n", total ; exit total < minimumGB}') validate "$TEST_MEM" echo "Network access" curl_request 'https://ec2.amazonaws.com' curl_request 'https://k8s.kurl.sh' curl_request 'https://replicated.app' curl_request 'https://kots.io' curl_request 'https://github.com' curl_request 'https://k8s.gcr.io' echo "These are the contents of /etc/*release:" && cat /etc/*release | grep -i name | grep -v -i "CODE" | grep -v -i "_NAME" if test $FAIL -ne 0 then echo "***********************************************************************"; echo "One or more requirement tests failed !"; echo "You need to fix these problems before proceeding with the installation. "; echo "Run this script as many times as required." echo "Fixing these items above is required for the installation appointment." echo "If you have any questions get in touch with our support." echo "***********************************************************************"; else echo "***********************************************************************"; echo "This system has met the minimal requirements for the installation."; echo "***********************************************************************"; fi