Skip to content

Commit 8d92be2

Browse files
committed
Fixed bugs to openJdk 8
1 parent 764e481 commit 8d92be2

File tree

1 file changed

+48
-30
lines changed

1 file changed

+48
-30
lines changed

install_certs.sh

+48-30
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,66 @@
33
GREEN='\033[0;32m'
44
NC='\033[0m'
55

6-
println () {
7-
local message="$1"
8-
echo -e "${GREEN}[INFO]${NC} - ${message}"
6+
JAVA_VENDOR=$(java -version 2>&1 | head -n 3 | awk -F 'Runtime' '{print $2}' | tr '\n' ' ')
7+
JAVA_VENDOR_OUT=($JAVA_VENDOR)
8+
JAVA_ONLY_VERSION=$(java -version 2>&1 | head -n 1 | awk -F '"' '{print $2}')
9+
JAVA_ONLY_VERSION_OUT=($JAVA_ONLY_VERSION)
10+
11+
println() {
12+
local message="$1"
13+
echo -e "${GREEN}[INFO]${NC} - ${message}"
914
}
1015

11-
transform_crt_to_der () {
12-
local fileName=$(basename -- "$1")
13-
local fileNameWithoutExtension="${fileName%.*}"
14-
println "Converter $fileName to .der extensions."
15-
16-
openssl x509 -in "$fileName" -outform der -out "$fileNameWithoutExtension.der"
16+
transform_crt_to_der() {
17+
local fileName=$(basename -- "$1")
18+
local fileNameWithoutExtension="${fileName%.*}"
19+
println "Converter $fileName to .der extensions."
20+
21+
openssl x509 -in "$fileName" -outform der -out "$fileNameWithoutExtension.der"
1722
}
1823

19-
import_keys_to_java_cacerts () {
20-
local fileName=$(basename -- "$1")
21-
local fileNameWithoutExtension="${fileName%.*}"
22-
println "Import it key $fileName to java path: $javaPath ."
23-
24-
keytool -importcert -trustcacerts -alias "$fileNameWithoutExtension" -keystore "$javaPath" -storepass changeit -file "./$fileName"
24+
import_keys_to_java_cacerts() {
25+
local fileName=$(basename -- "$1")
26+
local fileNameWithoutExtension="${fileName%.*}"
27+
println "Import it key $fileName to java path: $JAVA_HOME ."
28+
29+
if [[ "${JAVA_ONLY_VERSION_OUT[*]}" =~ '1.8.' ]]; then
30+
if [[ "${JAVA_VENDOR_OUT[*]}" =~ 'LTS' || "${JAVA_VENDOR_OUT[*]}" =~ 'Correto' || "${JAVA_VENDOR_OUT[*]}" =~ 'Termurin' ]]; then
31+
sudo $JAVA_HOME/bin/keytool -importcert -file "./$fileName" -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -alias "$fileNameWithoutExtension" -noprompt
32+
else
33+
sudo $JAVA_HOME/bin/keytool -importcert -file "./$fileName" -keystore $JAVA_HOME/lib/security/cacerts -storepass changeit -alias "$fileNameWithoutExtension" -noprompt
34+
fi
35+
else
36+
sudo $JAVA_HOME/bin/keytool -importcert -file "./$fileName" -cacerts -storepass changeit -alias "$fileNameWithoutExtension" -noprompt
37+
fi
2538
}
2639

27-
load_der_files () {
28-
for file in ./*.der; do
29-
import_keys_to_java_cacerts "$file"
30-
done
40+
load_der_files() {
41+
for file in ./*.der; do
42+
if [ -d "$file" ]; then
43+
for dir in "$file/*"; do
44+
for fileSubDir in "$dir"; do
45+
import_keys_to_java_cacerts "$fileSubDir"
46+
done
47+
done
48+
else
49+
import_keys_to_java_cacerts "$file"
50+
fi
51+
done
3152
}
3253

33-
load_crt_files () {
34-
for file in ./*.crt; do
35-
transform_crt_to_der "$file"
36-
done
54+
load_crt_files() {
55+
for file in ./*.crt; do
56+
transform_crt_to_der "$file"
57+
done
3758
}
3859

39-
while getopts j:k: flag
40-
do
41-
case "${flag}" in
42-
j) javaPath=${OPTARG};;
43-
k) keyPath=${OPTARG};;
44-
esac
60+
while getopts j:k: flag; do
61+
case "${flag}" in
62+
k) keyPath=${OPTARG} ;;
63+
esac
4564
done
4665

47-
4866
println "Import all keys to java path."
4967
cd $keyPath
5068
load_crt_files

0 commit comments

Comments
 (0)