Automatically reload / renew java cacerts in keystore

In our current project we have a Nexus server as artifactory repository manager. Setup is not entirely finished and one drawback is that the certificate is only valid for 3 days.

The following script downloads the certificate and uses keytool to import the certificate only when it’s a new one (using the same alias)

#!/bin/bash
true | openssl s_client -connect nexus.mycompany.com:443 2>/dev/null | openssl x509 > ~/Downloads/nexus-crt.crt
DIFF=$(diff ~/Downloads/nexus-crt.crt ~/Downloads/nexus.mycompany.com.crt)
if [ "$DIFF" ]
then
   echo "Reloading Nexus certificate"
   cp ~/Downloads/nexus-crt.crt ~/Downloads/nexus.mycompany.com.crt
   cd ~/.sdkman/candidates/java/current/bin
   ./keytool -delete -alias nexus-crt -cacerts -storepass changeit
   ./keytool -importcert -noprompt -trustcacerts -cacerts -alias "nexus-crt" -file ~/Downloads/nexus.mycompany.com.crt -storepass changeit
   cd -
fi

If you want to display the certificates enddate:

echo "cert enddate: cat ~/Downloads/nexus-crt.crt | openssl x509 -noout -dates | tail -1 | sed 's/[^ ]*=//' "

gitlab git mvn pull all clean all

Suppose you have a directory /pub/gitlab with all your git projects, but also a logs directory which can be skipped.

user@server:~$ cat > cleanall
cd /pub/gitlab
for d in */ ; do
log=$(basename $d)
[[ $log =~ ^(logs)$ ]] && continue
cd "$d"
echo -n "$d : "
mvn clean
cd ..
done

user@server:~$ cat > pullall
cd /pub/gitlab
for d in */ ; do
log=$(basename $d)
[[ $log =~ ^(logs)$ ]] && continue
cd "$d"
echo -n "$d : "
git pull
cd ..
done