GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support OpenJDK and Format code · unoexperto/install-java@2348c15

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • install-java.sh
  • uninstall-java.sh
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎install-java.sh‎

Copy file name to clipboardExpand all lines: install-java.sh
+40-38Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
java_dist=""
2121
java_dir=""
2222

23-
function help {
23+
function help() {
2424
echo ""
2525
echo "Usage: "
2626
echo "install-java.sh -f <java_dist> [-p] <java_dir>"
@@ -30,29 +30,28 @@ function help {
3030
echo ""
3131
}
3232

33-
confirm () {
33+
confirm() {
3434
# call with a prompt string or use a default
3535
read -r -p "${1:-Are you sure?} [y/N] " response
3636
case $response in
37-
[yY][eE][sS]|[yY])
38-
true
39-
;;
40-
*)
41-
false
42-
;;
37+
[yY][eE][sS] | [yY])
38+
true
39+
;;
40+
*)
41+
false
42+
;;
4343
esac
4444
}
4545

4646
# Make sure the script is running as root.
4747
if [ "$UID" -ne "0" ]; then
48-
echo "You must be root to run $0. Try following"; echo "sudo $0";
48+
echo "You must be root to run $0. Try following"
49+
echo "sudo $0"
4950
exit 9
5051
fi
5152

52-
53-
while getopts "f:p:" opts
54-
do
55-
case $opts in
53+
while getopts "f:p:" opts; do
54+
case $opts in
5655
f)
5756
java_dist=${OPTARG}
5857
;;
@@ -63,11 +62,11 @@ do
6362
help
6463
exit 1
6564
;;
66-
esac
65+
esac
6766
done
6867

6968
if [[ ! -f $java_dist ]]; then
70-
echo "Please specify the java distribution file (tar.gz)"
69+
echo "Please specify the Java distribution file (tar.gz)"
7170
help
7271
exit 1
7372
fi
@@ -86,17 +85,18 @@ fi
8685

8786
#Validate java directory
8887
if [[ ! -d $java_dir ]]; then
89-
echo "Please specify a valid java installation directory"
88+
echo "Please specify a valid Java installation directory"
9089
exit 1
9190
fi
9291

9392
# Validate Java Distribution
9493
java_dist_filename=$(basename $java_dist)
94+
echo "Installing $java_dist_filename"
9595

96-
java_78_dist_file_regex="jdk-([78])u([0-9]{1,3})-linux-(i586|x64)\.tar\.gz"
97-
java_9up_dist_file_regex="jdk-([91][0-9]?\.?[0-9]*\.?[0-9]*)_linux-x(32|64)_bin\.tar\.gz"
96+
java_78_dist_file_regex="^jdk-([78])u([0-9]{1,3})-linux-(i586|x64)\.tar\.gz$"
97+
java_9up_dist_file_regex="^(open)?jdk-([91][0-9]?\.?[0-9]*\.?[0-9]*)_linux-x(32|64)_bin\.tar\.gz$"
9898

99-
# JDK Directory with version
99+
# JDK Directory with version (tar -tzf $java_dist | head -1 | cut -f1 -d"/")
100100
jdk_dir=""
101101
# JDK Major Version
102102
jdk_major_version=""
@@ -105,10 +105,10 @@ if [[ $java_dist_filename =~ $java_78_dist_file_regex ]]; then
105105
jdk_dir=$(echo $java_dist_filename | sed -nE "s/$java_78_dist_file_regex/jdk1.\1.0_\2/p")
106106
jdk_major_version=$(echo $jdk_dir | sed -nE 's/jdk1\.([0-9]*).*/\1/p')
107107
elif [[ $java_dist_filename =~ $java_9up_dist_file_regex ]]; then
108-
jdk_dir=$(echo $java_dist_filename | sed -nE "s/$java_9up_dist_file_regex/jdk-\1/p")
108+
jdk_dir=$(echo $java_dist_filename | sed -nE "s/$java_9up_dist_file_regex/jdk-\2/p")
109109
jdk_major_version=$(echo $jdk_dir | sed -nE 's/jdk-([0-9]*).*/\1/p')
110110
else
111-
echo "Please specify a valid java distribution"
111+
echo "Please specify a valid Java distribution"
112112
exit 1
113113
fi
114114

@@ -120,16 +120,20 @@ if [[ ! -d $extracted_dirname ]]; then
120120
echo "Extracting $java_dist to $java_dir"
121121
tar -xof $java_dist -C $java_dir
122122
echo "JDK is extracted to $extracted_dirname"
123-
else
124-
echo "JDK is already extracted to $extracted_dirname"
123+
else
124+
echo "WARN: JDK was not extracted to $extracted_dirname. The path already exists."
125125
fi
126126

127-
128127
if [[ ! -f $extracted_dirname"/bin/java" ]]; then
129-
echo "Couldn't check the extracted directory. Please check the installation script"
128+
echo "ERROR: The path $extracted_dirname is not a valid Java installation."
130129
exit 1
131130
fi
132131

132+
# print "Java version"
133+
echo "------------------------------------------------------------------------------"
134+
${extracted_dirname}/bin/java -version
135+
echo "------------------------------------------------------------------------------"
136+
133137
# Install Demos
134138

135139
if [[ $java_dist_filename =~ $java_78_dist_file_regex ]]; then
@@ -145,16 +149,15 @@ if [[ -f $demos_dist && ! -d $extracted_dirname/demo ]]; then
145149
fi
146150
fi
147151

148-
# Install Unlimited JCE Policy
152+
# Install Unlimited JCE Policy (only for Oracle JDK 7 & 8)
153+
# Java 9 and above: default JCE policy files already allow for \"unlimited\" cryptographic strengths.
149154

150155
unlimited_jce_policy_dist=""
151156

152157
if [[ "$java_dist_filename" =~ ^jdk-7.* ]]; then
153158
unlimited_jce_policy_dist="$(dirname $java_dist)/UnlimitedJCEPolicyJDK7.zip"
154-
elif [[ "$java_dist_filename" =~ ^jdk-8.* ]]; then
159+
elif [[ "$java_dist_filename" =~ ^jdk-8.* ]]; then
155160
unlimited_jce_policy_dist="$(dirname $java_dist)/jce_policy-8.zip"
156-
elif [[ "$java_dist_filename" =~ ^jdk-9.* ]]; then
157-
echo "Java 9 default JCE policy files already allow for \"unlimited\" cryptographic strengths."
158161
fi
159162

160163
if [[ -f $unlimited_jce_policy_dist ]]; then
@@ -166,13 +169,12 @@ fi
166169

167170
# Run update-alternatives commands
168171

169-
commands=( "jar" "java" "javac" "javadoc" "javah" "javap" "javaws" "jcmd" "jconsole" "jarsigner" "jhat" "jinfo" "jmap" "jmc" "jps" "jstack" "jstat" "jstatd" "jvisualvm" "keytool" "policytool" "wsgen" "wsimport" )
172+
commands=("jar" "java" "javac" "javadoc" "javah" "javap" "javaws" "jcmd" "jconsole" "jarsigner" "jhat" "jinfo" "jmap" "jmc" "jps" "jstack" "jstat" "jstatd" "jvisualvm" "keytool" "policytool" "wsgen" "wsimport")
170173

171174
if (confirm "Run update-alternatives commands?"); then
172175
echo "Running update-alternatives --install and --config for ${commands[@]} mozilla-javaplugin.so"
173176

174-
for i in "${commands[@]}"
175-
do
177+
for i in "${commands[@]}"; do
176178
command_path=$extracted_dirname/bin/$i
177179
if [[ -f $command_path ]]; then
178180
update-alternatives --install "/usr/bin/$i" "$i" "$command_path" 10000
@@ -181,7 +183,7 @@ if (confirm "Run update-alternatives commands?"); then
181183
done
182184

183185
lib_path=$extracted_dirname/jre/lib/amd64/libnpjp2.so
184-
if [[ -d "/usr/lib/mozilla/plugins/" && -d $lib_path ]]; then
186+
if [[ -d "/usr/lib/mozilla/plugins/" ]] && [[ -f $lib_path ]]; then
185187
update-alternatives --install "/usr/lib/mozilla/plugins/libjavaplugin.so" "mozilla-javaplugin.so" "$lib_path" 10000
186188
update-alternatives --set "mozilla-javaplugin.so" "$lib_path"
187189
fi
@@ -201,16 +203,16 @@ if (confirm "Do you want to set JAVA_HOME environment variable?"); then
201203
if grep -q "export JAVA_HOME=.*" $HOME/.bashrc; then
202204
sed -i "s|export JAVA_HOME=.*|export JAVA_HOME=$extracted_dirname|" $HOME/.bashrc
203205
else
204-
echo "export JAVA_HOME=$extracted_dirname" >> $HOME/.bashrc
206+
echo "export JAVA_HOME=$extracted_dirname" >>$HOME/.bashrc
205207
fi
206208
source $HOME/.bashrc
207209
fi
208210

209211
applications_dir="$HOME/.local/share/applications"
210212

211213
create_jmc_shortcut() {
212-
shortcut_file="$applications_dir/jmc_$jdk_major_version.desktop"
213-
cat << _EOF_ > $shortcut_file
214+
shortcut_file="$applications_dir/jmc_$jdk_major_version.desktop"
215+
cat <<_EOF_ >$shortcut_file
214216
[Desktop Entry]
215217
Name=Java $jdk_major_version: JMC
216218
Comment=Oracle Java Mission Control for Java $jdk_major_version
@@ -219,10 +221,10 @@ Exec=$extracted_dirname/bin/jmc
219221
Icon=$extracted_dirname/lib/missioncontrol/icon.xpm
220222
Terminal=false
221223
_EOF_
222-
chmod +x $shortcut_file
224+
chmod +x $shortcut_file
223225
}
224226

225-
if [[ -d $applications_dir ]]; then
227+
if [[ -d $applications_dir ]] && [[ -f $extracted_dirname/bin/jmc ]]; then
226228
if (confirm "Do you want to create a desktop shortcut to JMC?"); then
227229
create_jmc_shortcut
228230
fi
Collapse file

‎uninstall-java.sh‎

Copy file name to clipboardExpand all lines: uninstall-java.sh
+15-17Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
java_dist_dir=""
2121

22-
function help {
22+
function help() {
2323
echo ""
2424
echo "Usage: "
2525
echo "uninstall-java.sh -p <java_dist_dir>"
@@ -28,37 +28,36 @@ function help {
2828
echo ""
2929
}
3030

31-
confirm () {
31+
confirm() {
3232
# call with a prompt string or use a default
3333
read -r -p "${1:-Are you sure?} [y/N] " response
3434
case $response in
35-
[yY][eE][sS]|[yY])
36-
true
37-
;;
38-
*)
39-
false
40-
;;
35+
[yY][eE][sS] | [yY])
36+
true
37+
;;
38+
*)
39+
false
40+
;;
4141
esac
4242
}
4343

4444
# Make sure the script is running as root.
4545
if [ "$UID" -ne "0" ]; then
46-
echo "You must be root to run $0. Try following"; echo "sudo $0";
46+
echo "You must be root to run $0. Try following"
47+
echo "sudo $0"
4748
exit 9
4849
fi
4950

50-
51-
while getopts "p:" opts
52-
do
53-
case $opts in
51+
while getopts "p:" opts; do
52+
case $opts in
5453
p)
5554
java_dist_dir=${OPTARG}
5655
;;
5756
\?)
5857
help
5958
exit 1
6059
;;
61-
esac
60+
esac
6261
done
6362

6463
if [[ ! -f $java_dist_dir/bin/java ]]; then
@@ -69,13 +68,12 @@ fi
6968

7069
# Run update-alternatives commands
7170

72-
commands=( "jar" "java" "javac" "javadoc" "javah" "javap" "javaws" "jcmd" "jconsole" "jarsigner" "jhat" "jinfo" "jmap" "jmc" "jps" "jstack" "jstat" "jstatd" "jvisualvm" "keytool" "policytool" "wsgen" "wsimport" )
71+
commands=("jar" "java" "javac" "javadoc" "javah" "javap" "javaws" "jcmd" "jconsole" "jarsigner" "jhat" "jinfo" "jmap" "jmc" "jps" "jstack" "jstat" "jstatd" "jvisualvm" "keytool" "policytool" "wsgen" "wsimport")
7372

7473
if (confirm "Run update-alternatives commands?"); then
7574
echo "Running update-alternatives --remove for ${commands[@]} mozilla-javaplugin.so"
7675

77-
for i in "${commands[@]}"
78-
do
76+
for i in "${commands[@]}"; do
7977
update-alternatives --remove "$i" "$java_dist_dir/bin/$i"
8078
done
8179

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.