Skip to content

Commit b0135b4

Browse files
Zdravko GenovZdravko-Genov
authored andcommitted
Improved healt.sh, added health.ps, added instruction for use under win
1 parent 4ee605a commit b0135b4

File tree

3 files changed

+108
-67
lines changed

3 files changed

+108
-67
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,19 @@ Build Tools for VMware Aria provides development and release management tools fo
3939
- node: 22.x.x (only 14 is supported for vcd-ng)
4040
- maven: 3.9.x
4141
- jdk: 17, 21, 24
42+
- openssl
4243

43-
To check if the dependencies are met, you can run:
44+
To check if the dependencies are met on Linux, you can run:
4445

4546
```sh
4647
curl -o- https://raw.githubusercontent.com/vmware/build-tools-for-vmware-aria/main/health.sh | bash
4748
```
4849

50+
To check if the dependencies are met on Windows, you can run:
51+
```ps
52+
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'))
53+
```
54+
4955
## Support
5056

5157
You can find detailed support statement [here](./SUPPORT.md)

health.ps1

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
$ErrorActionPreference= 'silentlycontinue'
2+
3+
[regex]$regex = "\d+\.\d+\.*\d*"
4+
$yes = "`u{2714} "
5+
$no = "`u{274c}"
6+
7+
$allChecks = $true
8+
9+
Write-Host "Starting Build Tools for VMware Aria Checks..."
10+
11+
# version should be at lest <major.minor>
12+
# OpenSSL is not following the guidelines
13+
@(
14+
@{ name = "Java"; cmd="java --version"; min="17.0"; max="24.0" },
15+
@{ name = "Maven"; cmd="mvn --version"; min="3.2"; max="4.0" },
16+
@{ name = "Node.js"; cmd="node --version"; min="12.0"; max="24.0" },
17+
@{ name = "Python"; cmd="python --version"; min="3.2"; max="3.14" },
18+
@{ name = "Pip"; cmd="pip --version"; min="25.0"; max="26.0" },
19+
@{ name = "OpenSSL"; cmd="openssl version"; min="10.0"; max="17.0" }
20+
) | ForEach-Object {
21+
$name = $_.name
22+
$command = $_.cmd
23+
$min = [Version]::Parse($_.min)
24+
$max = [Version]::Parse($_.max)
25+
26+
$result = (Invoke-Expression $command)
27+
if ($result -eq $null)
28+
{
29+
Write-Host "$no $name is not installed" -ForegroundColor Red
30+
$allChecks = $false
31+
return
32+
}
33+
34+
$versionString = $result.Split([Environment]::NewLine)[0]
35+
$version = [Version]::Parse($regex.Matches($versionString)[0].Value)
36+
37+
if ($version.CompareTo($min) -ge 0 -and $version.CompareTo($max) -le 0)
38+
{
39+
Write-Host "$yes $name version '$version' is within the required range ($min - $max)." -ForegroundColor Green
40+
} else {
41+
$allChecks=$false
42+
Write-Host "$no $name version '$version' is outside of the range ($min - $max)." -ForegroundColor Red
43+
}
44+
$result = $null
45+
}
46+
47+
if ( $all_checks_passed ) {
48+
Write-Host "All checks passed successfully." -ForegroundColor Green
49+
} else {
50+
Write-Host "Some checks failed. Please review the above messages." -ForegroundColor Red
51+
}

health.sh

Lines changed: 50 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,67 @@
1-
#!/bin/bash
2-
3-
# Required Versions Ranges
4-
MIN_NODE_VERSION="22"
5-
MAX_NODE_VERSION="22"
6-
MIN_MAVEN_VERSION="3.9"
7-
MIN_JAVA_VERSION="17"
8-
MAX_JAVA_VERSION="24"
9-
10-
# Color Codes
111
GREEN="\033[0;32m"
122
RED="\033[0;31m"
13-
NC="\033[0m" # No Color
3+
NC="\033[0m"
144

15-
# Success flags
165
all_checks_passed=true
6+
regex="[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+"
177

18-
# Helper function to compare versions
19-
version_ge() {
20-
# Returns 0 if $1 >= $2, 1 otherwise
21-
printf '%s\n%s\n' "$2" "$1" | sort -C -V
22-
}
23-
24-
# Check Node.js Version Range (22.x to 22.x)
25-
check_node_version() {
26-
node_version=$(node -v 2>/dev/null | sed 's/v//')
27-
node_major_version=$(echo "$node_version" | cut -d. -f1)
8+
# OpenSSL is not following the guidelines
9+
declare -a prerequisites=(
10+
"Java java --version 17 24"
11+
"Maven mvn --version 3.2"
12+
"Node.js nodejs --version 12 24"
13+
"Python python --version 3.2 3.14"
14+
"Pip pip --version 25.0 26.0"
15+
"OpenSSL openssl version 10 17.0"
16+
)
2817

29-
if [ -z "$node_version" ]; then
30-
echo -e "${RED}✘ Node.js is not installed.${NC}"
31-
all_checks_passed=false
32-
elif [ "$node_major_version" -ge "$MIN_NODE_VERSION" ] && [ "$node_major_version" -le "$MAX_NODE_VERSION" ]; then
33-
echo -e "${GREEN}✔ Node.js version $node_version is within the required range ($MIN_NODE_VERSION - $MAX_NODE_VERSION).${NC}"
34-
else
35-
echo -e "${RED}✘ Node.js version $node_version is outside the required range ($MIN_NODE_VERSION - $MAX_NODE_VERSION).${NC}"
36-
all_checks_passed=false
37-
fi
18+
v_compare() {
19+
# Returns 0 if $1 >= $2, 1 otherwise
20+
printf '%s\n%s\n' "$2" "$1" | sort -C -V
3821
}
3922

40-
# Check Maven Version (3.9.x or newer)
41-
check_maven_version() {
42-
maven_version=$(mvn -v 2>/dev/null | awk '/Apache Maven/ {print $3}')
23+
echo "Starting Build Tools for VMware Aria Checks..."
4324

44-
if [ -z "$maven_version" ]; then
45-
echo -e "${RED}✘ Maven is not installed.${NC}"
46-
all_checks_passed=false
47-
elif version_ge "$maven_version" "$MIN_MAVEN_VERSION"; then
48-
echo -e "${GREEN}✔ Maven version $maven_version meets the minimum requirement (>= $MIN_MAVEN_VERSION).${NC}"
49-
else
50-
echo -e "${RED}✘ Maven version $maven_version is older than the required version (>= $MIN_MAVEN_VERSION).${NC}"
51-
all_checks_passed=false
52-
fi
53-
}
25+
for prerequisite in "${prerequisites[@]}"; do
26+
# uses default whitespace IFS
27+
read -a properties <<< "$prerequisite"
5428

55-
# Check Java Version (must be between 17 and 21)
56-
check_java_version() {
57-
java_version=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}')
58-
java_major_version=$(echo "$java_version" | cut -d. -f1)
29+
name=${properties[0]}
30+
command=${properties[1]}
31+
action=${properties[2]}
32+
min=${properties[3]}
33+
max=${properties[4]:-default}
5934

60-
if [ -z "$java_version" ]; then
61-
echo -e "${RED}✘ Java is not installed.${NC}"
62-
all_checks_passed=false
63-
elif [ "$java_major_version" -ge "$MIN_JAVA_VERSION" ] && [ "$java_major_version" -le "$MAX_JAVA_VERSION" ]; then
64-
echo -e "${GREEN}✔ Java version $java_version is within the required range ($MIN_JAVA_VERSION - $MAX_JAVA_VERSION).${NC}"
65-
else
66-
echo -e "${RED}✘ Java version $java_version is outside the required range ($MIN_JAVA_VERSION - $MAX_JAVA_VERSION).${NC}"
67-
all_checks_passed=false
68-
fi
69-
}
35+
# first line is containing version
36+
actual=$($command $action 2>/dev/null | head -n 1)
7037

71-
# Run all checks
72-
echo "Starting Build Tools for VMware Aria Checks..."
38+
if [[ $actual =~ $regex ]]; then
39+
actualVersion=${BASH_REMATCH[0]}
40+
is_min_ok=false
41+
is_max_ok=false
42+
43+
if v_compare "$actualVersion" "$min"; then
44+
is_min_ok=true
45+
fi
46+
47+
if v_compare "$max" "$actualVersion"; then
48+
is_max_ok=true
49+
fi
7350

74-
check_node_version
75-
check_maven_version
76-
check_java_version
51+
if $is_min_ok && $is_max_ok; then
52+
echo -e "${GREEN}${name} version '${actualVersion}' is within the required range (${min} - ${max}).${NC}"
53+
else
54+
all_checks_passed=false
55+
echo -e "${RED}${name} version '${actualVersion}' is outside of the range (${min} - ${max}).${NC}"
56+
fi
57+
else
58+
echo -e "${RED}${name} is not installed.${NC}"
59+
all_checks_passed=false
60+
fi
61+
done
7762

78-
# Display summary
7963
if [ "$all_checks_passed" = true ]; then
80-
echo -e "${GREEN}All checks passed successfully.${NC}"
64+
echo -e "${GREEN}All checks passed successfully.${NC}"
8165
else
82-
echo -e "${RED}Some checks failed. Please review the above messages.${NC}"
66+
echo -e "${RED}Some checks failed. Please review the above messages.${NC}"
8367
fi

0 commit comments

Comments
 (0)