-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-jdk-versions.sh
More file actions
executable file
·47 lines (36 loc) · 1.17 KB
/
get-jdk-versions.sh
File metadata and controls
executable file
·47 lines (36 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
# Store the current directory
current_dir=$(pwd)
# Check if a version argument was provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <major_java_version>" >&2
exit 1
fi
major_version=$1
# Change to the directory where the script is located
cd "$(dirname "$0")" || exit
# Call install-sdk.sh and redirect output
# For silence:
./install-sdk.sh > /dev/null 2>&1
# Or, to redirect all output to stderr:
#./install-sdk.sh 2>&1 >&2
# Initialize SDKMAN
if [[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]]; then
source "$HOME/.sdkman/bin/sdkman-init.sh"
install-jdk-versions.sh > /dev/null 2>&1
else
echo "SDKMAN is not installed or not found."
exit 2
fi
# Change back to the original directory
cd "$current_dir" || exit
# Initialize SDKMAN
source "$HOME/.sdkman/bin/sdkman-init.sh"
# Find and output the Temurin JDK version identifier for the given major version
identifier=$(PAGER=cat sdk list java | grep -E " $major_version\\.0.*-tem" | awk -v ver="$major_version" '$0 ~ " " ver "\\.0.*-tem" {print $NF}' | head -n 1)
if [ -n "$identifier" ]; then
echo "$identifier"
else
echo "No Temurin JDK version found for Java $major_version" >&2
exit 2
fi