-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate.JDK.sh
More file actions
64 lines (53 loc) · 1.72 KB
/
Copy pathUpdate.JDK.sh
File metadata and controls
64 lines (53 loc) · 1.72 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
set -e
REQUIRED_MAJOR=25
INSTALL_DIR="/usr/local/java25"
check_java_version() {
if ! command -v java &> /dev/null; then
return 1
fi
local version_str
version_str=$(java -version 2>&1 | head -n 1 | cut -d '"' -f 2)
local major_version
major_version=$(echo "$version_str" | cut -d '.' -f 1)
if [ "$major_version" -ge "$REQUIRED_MAJOR" ]; then
echo "Found Java version $version_str (Matches requirement JDK $REQUIRED_MAJOR+)."
return 0
else
echo "Found older Java version: $version_str."
return 1
fi
}
install_jdk25() {
echo "Downloading and installing JDK 25..."
# Detect Architecture
local arch
arch=$(uname -m)
if [ "$arch" = "x86_64" ]; then
local url="https://oracle.com"
elif [ "$arch" = "aarch64" ]; then
local url="https://oracle.com"
else
echo "Unsupported architecture: $arch" >&2
exit 1
fi
# Download and extract
sudo mkdir -p "$INSTALL_DIR"
curl -sSL "$url" | sudo tar -xzf - -C "$INSTALL_DIR" --strip-components=1
# Update system alternatives
sudo update-alternatives --install /usr/bin/java java "$INSTALL_DIR/bin/java" 2000
sudo update-alternatives --install /usr/bin/javac javac "$INSTALL_DIR/bin/javac" 2000
sudo update-alternatives --set java "$INSTALL_DIR/bin/java"
sudo update-alternatives --set javac "$INSTALL_DIR/bin/javac"
echo "JDK 25 installed and activated successfully."
}
# Main execution flow
if check_java_version; then
echo "Environment verified. Ready to run."
else
if [ "$EUID" -ne 0 ]; then
echo "Please re-run this script with 'sudo' or as root to update Java."
exit 1
fi
install_jdk25
fi