-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_certs.sh
executable file
·69 lines (58 loc) · 1.95 KB
/
install_certs.sh
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
#!/bin/bash
GREEN='\033[0;32m'
NC='\033[0m'
JAVA_VENDOR=$(java -version 2>&1 | head -n 3 | awk -F 'Runtime' '{print $2}' | tr '\n' ' ')
JAVA_VENDOR_OUT=($JAVA_VENDOR)
JAVA_ONLY_VERSION=$(java -version 2>&1 | head -n 1 | awk -F '"' '{print $2}')
JAVA_ONLY_VERSION_OUT=($JAVA_ONLY_VERSION)
println() {
local message="$1"
echo -e "${GREEN}[INFO]${NC} - ${message}"
}
transform_crt_to_der() {
local fileName=$(basename -- "$1")
local fileNameWithoutExtension="${fileName%.*}"
println "Converter $fileName to .der extensions."
openssl x509 -in "$fileName" -outform der -out "$fileNameWithoutExtension.der"
}
import_keys_to_java_cacerts() {
local fileName=$(basename -- "$1")
local fileNameWithoutExtension="${fileName%.*}"
println "Import it key $fileName to java path: $JAVA_HOME ."
if [[ "${JAVA_ONLY_VERSION_OUT[*]}" =~ '1.8.' ]]; then
if [[ "${JAVA_VENDOR_OUT[*]}" =~ 'LTS' || "${JAVA_VENDOR_OUT[*]}" =~ 'Correto' || "${JAVA_VENDOR_OUT[*]}" =~ 'Termurin' ]]; then
sudo $JAVA_HOME/bin/keytool -importcert -file "./$fileName" -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -alias "$fileNameWithoutExtension" -noprompt
else
sudo $JAVA_HOME/bin/keytool -importcert -file "./$fileName" -keystore $JAVA_HOME/lib/security/cacerts -storepass changeit -alias "$fileNameWithoutExtension" -noprompt
fi
else
sudo $JAVA_HOME/bin/keytool -importcert -file "./$fileName" -cacerts -storepass changeit -alias "$fileNameWithoutExtension" -noprompt
fi
}
load_der_files() {
for file in ./*.der; do
if [ -d "$file" ]; then
for dir in "$file/*"; do
for fileSubDir in "$dir"; do
import_keys_to_java_cacerts "$fileSubDir"
done
done
else
import_keys_to_java_cacerts "$file"
fi
done
}
load_crt_files() {
for file in ./*.crt; do
transform_crt_to_der "$file"
done
}
while getopts j:k: flag; do
case "${flag}" in
k) keyPath=${OPTARG} ;;
esac
done
println "Import all keys to java path."
cd $keyPath
load_crt_files
load_der_files