Created
March 1, 2021 21:50
-
-
Save websharik/80648327c84f497711e66c43fd0fbfc2 to your computer and use it in GitHub Desktop.
Universal bash script to fix "CertStorageError: expected /etc/letsencrypt/live/example.com/cert.pem to be a symlink" without renew cert's
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#FixError CertStorageError: expected /etc/letsencrypt/live/example.com/cert.pem to be a symlink | |
letsencryptdir="." | |
while read -r domain ; do | |
#get domain | |
domain=$(echo "$domain" | cut -f3 -d'/') | |
#check symlink | |
link="${letsencryptdir}/live/${domain}/cert.pem" | |
if [ -L ${link} ] && [ -e ${link} ] ; then #is symlink and valid | |
echo "${domain}: ok!" | |
continue | |
else | |
echo -e "\e[31m${domain}: fail! fixing...\e[0m" | |
fi | |
#get latest num from archive | |
count=$(find ${letsencryptdir}/archive/${domain} -type f -name 'cert*.pem' -printf x | wc -c) | |
#recreate symlinks | |
rm -f ${letsencryptdir}/live/$domain/*.pem | |
ln -s ../../archive/${domain}/cert${count}.pem ${letsencryptdir}/live/${domain}/cert.pem | |
ln -s ../../archive/${domain}/chain${count}.pem ${letsencryptdir}/live/${domain}/chain.pem | |
ln -s ../../archive/${domain}/fullchain${count}.pem ${letsencryptdir}/live/${domain}/fullchain.pem | |
ln -s ../../archive/${domain}/privkey${count}.pem ${letsencryptdir}/live/${domain}/privkey.pem | |
done < <(ls -d ${letsencryptdir}/live/*/) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment