|
1 | 1 | #!/usr/bin/env sh |
2 | | -# Script to add ssl trust certs into the current truststore / keystore before we start our spring boot app |
3 | | -# We use self signed certificates in our dev and test environments so we need to add these to our chain of trust |
4 | | -# The kubernetes startup will load any self signed certificates into /etc/certs |
5 | | -# We load any certs found in the /etc/certs into the default keystore |
6 | | -# |
| 2 | +# Add any startup requirements in here |
7 | 3 | logmsg() { |
8 | 4 | SCRIPTNAME=$(basename $0) |
9 | 5 | echo "$SCRIPTNAME : $1" |
10 | 6 | } |
11 | 7 |
|
12 | | -logmsg "running and loading certificates ..." |
13 | | -if [ -z "$JAVA_HOME" ]; then |
14 | | - export JAVA_HOME="/usr/local/openjdk-21" |
15 | | -fi |
16 | | -export KEYSTORE="$JAVA_HOME/lib/security/cacerts" |
17 | | -if [ -z "$CERTS_DIR" ]; then |
18 | | - logmsg "Warning - expects \$CERTS_DIR to be set. i.e. export CERTS_DIR="/etc/certs |
19 | | - logmsg "Defaulting to /etc/certs" |
20 | | - export CERTS_DIR="/etc/certs" |
21 | | -fi |
22 | | - |
23 | | -if [ ! -f "$KEYSTORE" ]; then |
24 | | - logmsg "Error - expects keystore $KEYSTORE to already exist" |
25 | | - exit 1 |
26 | | -fi |
27 | | - |
28 | | -export count=1 |
29 | | -logmsg "Loading certificates from $CERTS_DIR into keystore $KEYSTORE" |
30 | | -for FILE in $(ls $CERTS_DIR) |
31 | | -do |
32 | | - alias="mojcert$count" |
33 | | - logmsg "Adding $CERTS_DIR/$FILE to keystore with alias $alias" |
34 | | - keytool -importcert -file $CERTS_DIR/$FILE -keystore $KEYSTORE -storepass changeit -alias $alias -noprompt |
35 | | - count=$((count+1)) |
36 | | -done |
37 | | - |
38 | | -keytool -list -keystore $KEYSTORE -storepass changeit | grep "Your keystore contains" |
39 | | - |
40 | 8 | export LOCALJARFILE=$(ls ./build/libs/*.jar 2>/dev/null | grep -v 'plain' | head -n1) |
41 | 9 | export DOCKERJARFILE=$(ls /app/*.jar 2>/dev/null | grep -v 'plain' | head -n1) |
42 | 10 | if [ -f "$DOCKERJARFILE" ]; then |
|
0 commit comments