--- /dev/null
+#!/bin/sh
+
+
+# cases are:
+# 1: /etc/letsencrypt does not exist
+# 2: /etc/letsencrypt exists
+# 2.1: /etc/letsencrypt.staging does not exist
+# 2.1.1: /etc/letsencrypt.from-pki differs from /etc/letsencrypt
+# 2.1.2: /etc/letsencrypt.from-pki is the same as /etc/letsencrypt
+# 2.2: /etc/letsencrypt.staging exists
+# 2.2.1: /etc/letsencrypt.from-pki differs from /etc/letsencrypt.staging
+# 2.2.2: /etc/letsencrypt.from-pki is the same as /etc/letsencrypt.staging
+
+
+LE_DIRECTORY=/etc/letsencrypt
+LE_FP_DIRECTORY=${LE_DIRECTORY}.from-pki
+LE_OLD_DIRECTORY=${LE_DIRECTORY}.old
+LE_STAGING_DIRECTORY=${LE_DIRECTORY}.staging
+
+CERTBOT_DIR=/etc/letsencrypt/live/useribm
+CERT_FILE=$CERTBOT_DIR/cert.pem
+KEY_FILE=$CERTBOT_DIR/privkey.pem
+P12_FILE=/opt/slycrm/certificate1.p12
+
+
+rm --force --recursive $LE_FP_DIRECTORY
+echo "getting letsencrypt directory from pki"
+/usr/bin/rsync \
+ --archive \
+ --delete-after \
+ --info=STATS \
+ pki.in.useribm.hu::letsencrypt \
+ $LE_FP_DIRECTORY
+if [ $? -ne 0 ]
+then
+ echo "cannot get letsencrypt directory from pki"
+ rm --force --recursive $LE_FP_DIRECTORY
+ exit 1
+fi
+
+if [ -d $LE_DIRECTORY ]
+then
+ # case 2
+ echo "$LE_DIRECTORY exists"
+ if [ -d $LE_STAGING_DIRECTORY ]
+ then
+ # case 2.2
+ echo " $LE_STAGING_DIRECTORY exists"
+ diff --brief --recursive $LE_FP_DIRECTORY $LE_STAGING_DIRECTORY
+ DIFFERS=$?
+ if [ $DIFFERS -eq 0 ]
+ then
+ # case 2.2.2
+ echo " $LE_FP_DIRECTORY the same as $LE_STAGING_DIRECTORY"
+ echo " moving $LE_STAGING_DIRECTORY to $LE_DIRECTORY"
+ rm --force --recursive $LE_FP_DIRECTORY
+ rm --force --recursive $LE_OLD_DIRECTORY
+ mv $LE_DIRECTORY $LE_OLD_DIRECTORY
+ mv $LE_STAGING_DIRECTORY $LE_DIRECTORY
+ openssl pkcs12 -export \
+ -in $CERT_FILE \
+ -inkey $KEY_FILE \
+ -out $P12_FILE \
+ -name slycrm \
+ -passout pass:password
+ systemctl restart slycrm.service
+ else
+ # case 2.2.1
+ echo " $LE_FP_DIRECTORY differs from $LE_STAGING_DIRECTORY"
+ echo " moving $LE_FP_DIRECTORY to $LE_STAGING_DIRECTORY"
+ rm --force --recursive $LE_STAGING_DIRECTORY
+ mv $LE_FP_DIRECTORY $LE_STAGING_DIRECTORY
+ fi
+ else
+ # case 2.1
+ echo " $LE_STAGING_DIRECTORY does not exist"
+ diff --brief --recursive $LE_FP_DIRECTORY $LE_DIRECTORY
+ DIFFERS=$?
+ if [ $DIFFERS -eq 0 ]
+ then
+ # case 2.1.2
+ echo " $LE_FP_DIRECTORY is the same as $LE_DIRECTORY"
+ echo " removing $LE_FP_DIRECTORY"
+ rm --force --recursive $LE_FP_DIRECTORY
+ else
+ # case 2.1.1
+ echo " $LE_FP_DIRECTORY differs from $LE_DIRECTORY"
+ echo " moving $LE_FP_DIRECTORY to $LE_STAGING_DIRECTORY"
+ mv $LE_FP_DIRECTORY $LE_STAGING_DIRECTORY
+ fi
+ fi
+else
+ # case 1
+ echo "$LE_DIRECTORY does not exist"
+ echo "moving $LE_FP_DIRECTORY to $LE_DIRECTORY"
+ mv $LE_FP_DIRECTORY $LE_DIRECTORY
+ openssl pkcs12 -export \
+ -in $CERT_FILE \
+ -inkey $KEY_FILE \
+ -out $P12_FILE \
+ -name slycrm \
+ -passout pass:password
+fi