#!/bin/bash HOST="kivitendo" TLD="example.com" FQDN="$HOST.$TLD" LABEL="DATA" CERT_DIR=/$LABEL/CERTS CERT_APACHE=/$LABEL/etc/ssl/apache2 GETREPO="" GETUSER="" GETPASS="" function getCurrentVersion() { # Get hash from latest revision git log --format=format:%H -1 } cd $CERT_DIR if [ -z "$GETREPO" ]; then GIT_REVISION=0 GIT_NEW_REVISION=1 cd $FQDN elif [ ! -d "$FQDN" ]; then GIT_REVISION=0 git clone "https://$GETUSER:$GETPASS@$GETREPO" cd $FQDN GIT_NEW_REVISION=$(getCurrentVersion) else cd $FQDN GIT_REVISION=$(getCurrentVersion) git commit -m "CRON: auto commit" git fetch git merge origin/master -m "Auto Merge" GIT_NEW_REVISION=$(getCurrentVersion) fi echo "old: $GIT_REVISION" echo "new: $GIT_NEW_REVISION" if [ $GIT_REVISION != $GIT_NEW_REVISION ] then echo "Update Apache certificate..." mkdir -p $CERT_APACHE cp $CERT_DIR/$FQDN/$FQDN-fullchain.pem $CERT_APACHE/server.crt cp $CERT_DIR/KEYS/$FQDN-key.pem $CERT_APACHE/server.key echo "Restarting Apache..." systemctl is-active --quiet apache2 && systemctl restart apache2 fi exit 0