diff --git a/README.md b/README.md index 7e3768a61..661138cb5 100644 --- a/README.md +++ b/README.md @@ -39,13 +39,19 @@ Build Tools for VMware Aria provides development and release management tools fo - node: 22.x.x (only 14 is supported for vcd-ng) - maven: 3.9.x - jdk: 17, 21, 24 +- openssl -To check if the dependencies are met, you can run: +To check if the dependencies are met on Linux, you can run: ```sh curl -o- https://raw.githubusercontent.com/vmware/build-tools-for-vmware-aria/main/health.sh | bash ``` +To check if the dependencies are met on Windows, you can run: +```ps +Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/vmware/build-tools-for-vmware-aria/main/health.ps1')) +``` + ## Support You can find detailed support statement [here](./SUPPORT.md) diff --git a/health.ps1 b/health.ps1 new file mode 100644 index 000000000..9f0fefa66 --- /dev/null +++ b/health.ps1 @@ -0,0 +1,51 @@ +$ErrorActionPreference= 'silentlycontinue' + +[regex]$regex = "\d+\.\d+\.*\d*" +$yes = "`u{2714} " +$no = "`u{274c}" + +$allChecks = $true + +Write-Host "Starting Build Tools for VMware Aria Checks..." + +# version should be at lest +# OpenSSL is not following the guidelines +@( + @{ name = "Java"; cmd="java --version"; min="17.0"; max="24.0" }, + @{ name = "Maven"; cmd="mvn --version"; min="3.2"; max="4.0" }, + @{ name = "Node.js"; cmd="node --version"; min="12.0"; max="24.0" }, + @{ name = "Python"; cmd="python --version"; min="3.2"; max="3.14" }, + @{ name = "Pip"; cmd="pip --version"; min="25.0"; max="26.0" }, + @{ name = "OpenSSL"; cmd="openssl version"; min="10.0"; max="17.0" } +) | ForEach-Object { + $name = $_.name + $command = $_.cmd + $min = [Version]::Parse($_.min) + $max = [Version]::Parse($_.max) + + $result = (Invoke-Expression $command) + if ($result -eq $null) + { + Write-Host "$no $name is not installed" -ForegroundColor Red + $allChecks = $false + return + } + + $versionString = $result.Split([Environment]::NewLine)[0] + $version = [Version]::Parse($regex.Matches($versionString)[0].Value) + + if ($version.CompareTo($min) -ge 0 -and $version.CompareTo($max) -le 0) + { + Write-Host "$yes $name version '$version' is within the required range ($min - $max)." -ForegroundColor Green + } else { + $allChecks=$false + Write-Host "$no $name version '$version' is outside of the range ($min - $max)." -ForegroundColor Red + } + $result = $null +} + +if ( $all_checks_passed ) { + Write-Host "All checks passed successfully." -ForegroundColor Green +} else { + Write-Host "Some checks failed. Please review the above messages." -ForegroundColor Red +} diff --git a/health.sh b/health.sh index a1792c7eb..c97d7b22d 100755 --- a/health.sh +++ b/health.sh @@ -1,83 +1,67 @@ -#!/bin/bash - -# Required Versions Ranges -MIN_NODE_VERSION="22" -MAX_NODE_VERSION="22" -MIN_MAVEN_VERSION="3.9" -MIN_JAVA_VERSION="17" -MAX_JAVA_VERSION="24" - -# Color Codes GREEN="\033[0;32m" RED="\033[0;31m" -NC="\033[0m" # No Color +NC="\033[0m" -# Success flags all_checks_passed=true +regex="[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+" -# Helper function to compare versions -version_ge() { - # Returns 0 if $1 >= $2, 1 otherwise - printf '%s\n%s\n' "$2" "$1" | sort -C -V -} - -# Check Node.js Version Range (22.x to 22.x) -check_node_version() { - node_version=$(node -v 2>/dev/null | sed 's/v//') - node_major_version=$(echo "$node_version" | cut -d. -f1) +# OpenSSL is not following the guidelines +declare -a prerequisites=( + "Java java --version 17 24" + "Maven mvn --version 3.2" + "Node.js nodejs --version 12 24" + "Python python --version 3.2 3.14" + "Pip pip --version 25.0 26.0" + "OpenSSL openssl version 10 17.0" +) - if [ -z "$node_version" ]; then - echo -e "${RED}✘ Node.js is not installed.${NC}" - all_checks_passed=false - elif [ "$node_major_version" -ge "$MIN_NODE_VERSION" ] && [ "$node_major_version" -le "$MAX_NODE_VERSION" ]; then - echo -e "${GREEN}✔ Node.js version $node_version is within the required range ($MIN_NODE_VERSION - $MAX_NODE_VERSION).${NC}" - else - echo -e "${RED}✘ Node.js version $node_version is outside the required range ($MIN_NODE_VERSION - $MAX_NODE_VERSION).${NC}" - all_checks_passed=false - fi +v_compare() { + # Returns 0 if $1 >= $2, 1 otherwise + printf '%s\n%s\n' "$2" "$1" | sort -C -V } -# Check Maven Version (3.9.x or newer) -check_maven_version() { - maven_version=$(mvn -v 2>/dev/null | awk '/Apache Maven/ {print $3}') +echo "Starting Build Tools for VMware Aria Checks..." - if [ -z "$maven_version" ]; then - echo -e "${RED}✘ Maven is not installed.${NC}" - all_checks_passed=false - elif version_ge "$maven_version" "$MIN_MAVEN_VERSION"; then - echo -e "${GREEN}✔ Maven version $maven_version meets the minimum requirement (>= $MIN_MAVEN_VERSION).${NC}" - else - echo -e "${RED}✘ Maven version $maven_version is older than the required version (>= $MIN_MAVEN_VERSION).${NC}" - all_checks_passed=false - fi -} +for prerequisite in "${prerequisites[@]}"; do + # uses default whitespace IFS + read -a properties <<< "$prerequisite" -# Check Java Version (must be between 17 and 21) -check_java_version() { - java_version=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}') - java_major_version=$(echo "$java_version" | cut -d. -f1) + name=${properties[0]} + command=${properties[1]} + action=${properties[2]} + min=${properties[3]} + max=${properties[4]:-default} - if [ -z "$java_version" ]; then - echo -e "${RED}✘ Java is not installed.${NC}" - all_checks_passed=false - elif [ "$java_major_version" -ge "$MIN_JAVA_VERSION" ] && [ "$java_major_version" -le "$MAX_JAVA_VERSION" ]; then - echo -e "${GREEN}✔ Java version $java_version is within the required range ($MIN_JAVA_VERSION - $MAX_JAVA_VERSION).${NC}" - else - echo -e "${RED}✘ Java version $java_version is outside the required range ($MIN_JAVA_VERSION - $MAX_JAVA_VERSION).${NC}" - all_checks_passed=false - fi -} + # first line is containing version + actual=$($command $action 2>/dev/null | head -n 1) -# Run all checks -echo "Starting Build Tools for VMware Aria Checks..." + if [[ $actual =~ $regex ]]; then + actualVersion=${BASH_REMATCH[0]} + is_min_ok=false + is_max_ok=false + + if v_compare "$actualVersion" "$min"; then + is_min_ok=true + fi + + if v_compare "$max" "$actualVersion"; then + is_max_ok=true + fi -check_node_version -check_maven_version -check_java_version + if $is_min_ok && $is_max_ok; then + echo -e "${GREEN}✔ ${name} version '${actualVersion}' is within the required range (${min} - ${max}).${NC}" + else + all_checks_passed=false + echo -e "${RED}✘ ${name} version '${actualVersion}' is outside of the range (${min} - ${max}).${NC}" + fi + else + echo -e "${RED}✘ ${name} is not installed.${NC}" + all_checks_passed=false + fi +done -# Display summary if [ "$all_checks_passed" = true ]; then - echo -e "${GREEN}All checks passed successfully.${NC}" + echo -e "${GREEN}All checks passed successfully.${NC}" else - echo -e "${RED}Some checks failed. Please review the above messages.${NC}" + echo -e "${RED}Some checks failed. Please review the above messages.${NC}" fi