-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-java-21.sh
More file actions
executable file
·110 lines (96 loc) · 3.05 KB
/
install-java-21.sh
File metadata and controls
executable file
·110 lines (96 loc) · 3.05 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env bash
# Break on any error
set -e
check_java_home() {
# echo "Checking if JAVA_HOME env is set"
if [ -z "$JAVA_HOME" ] || ! grep -q 'JAVA_HOME' "$HOME/.bashrc"; then
JAVA_HOME_LINE='export JAVA_HOME="$(dirname "$(dirname "$(readlink -f "$(which java)")")")"'
echo "JAVA_HOME is not set. Attempting to set automatically"
echo "Please ensure the following line is in your ~/.bashrc or ~/.zshrc file:"
echo "Script will attempt to now add it for you and run it, but this only adds to .bashrc"
echo $JAVA_HOME_LINE
echo "$JAVA_HOME_LINE" >> $HOME/.bashrc
echo "Adding JAVA_HOME to current environment"
eval $JAVA_HOME_LINE
echo "JAVA_HOME is now set to: $JAVA_HOME"
fi
}
# Check and install Java 21
check_java() {
# echo "Checking for Java 21..."
if command -v java >/dev/null 2>&1; then
java_version=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}')
# echo "Found Java version: $java_version"
if [[ "$java_version" == 21* ]] || [[ "$java_version" == 1.21* ]]; then
echo "✅ Java 21 is installed."
return 0
else
echo "⚠️ Java is installed but not version 21. Will attempt to install Java 21."
fi
else
echo "⚠️ Java not found. Will attempt to install Java 21."
fi
case "$(uname)" in
Linux)
if command -v apt >/dev/null 2>&1; then
echo "Installing Java 21 using apt..."
sudo apt install -y openjdk-21-jdk
elif command -v yum >/dev/null 2>&1; then
echo "Installing Java 21 using yum..."
sudo yum install -y java-21-openjdk-devel
else
echo "⚠️ Unsupported Linux distribution. Please install Java 21 manually."
return 1
fi
;;
Darwin)
if command -v brew >/dev/null 2>&1; then
echo "Installing Java 21 using Homebrew..."
brew tap adoptopenjdk/openjdk
brew install --cask adoptopenjdk21
else
echo "⚠️ Homebrew not found. Please install Java 21 manually."
return 1
fi
;;
MINGW*|MSYS*|CYGWIN*)
echo "On Windows, please install Java 21 manually from https://adoptopenjdk.net/"
return 1
;;
*)
echo "⚠️ Unsupported OS: $(uname). Please install Java 21 manually."
return 1
;;
esac
echo "✅ Java 21 installation complete."
return 0
}
check_system_update() {
echo ""
echo "Checking for system updates..."
echo ""
if [ "$(uname)" = "Linux" ]; then
sudo apt-get update && sudo apt-get upgrade -y
echo "System packages updated."
fi
}
check_system_update
check_java
check_java_home
if [ -f /var/run/reboot-required ]; then
echo ""
echo "⚠️ A system reboot is required to complete updates. Please reboot your system."
echo ""
echo "Then run 'cpilot' to get started"
echo ""
echo "Would you like to reboot now? (y/n)"
read -r response
if [[ ! "$response" =~ ^[Yy]$ ]]; then
echo "Reboot skipped. Please reboot manually to proceed."
else
sudo reboot
fi
else
echo ""
echo "Run 'cpilot' to get started"
fi