renew ssl certs automatically and clear out expired
Letsencrypt used to auto fix your expired certs. This no longer happens. Here's a script to do it. Flags: --delete : remove expired certs --renew: renew soon-to-expire certs (3< days) #!/bin/bash # check-certs.sh base="/etc/letsencrypt/archive" delete_mode=0 renew_mode=0 if [ "$1" == "--delete" ]; then delete_mode=1 elif [ "$1" == "--renew" ]; then renew_mode=1 fi # First: find all current certs in archive declare -A cert_status find "$base" -type f -name "cert*.pem" | while read cert; do domain=$(echo "$cert" | sed -E "s|$base/([^/]+)/cert[0-9]+\.pem|\1|") expiry=$(openssl x509 -enddate -noout -in "$cert" | cut -d= -f2) exp_epoch=$(date -d "$expiry" +%s) now_epoch=$(date +%s) days_left=$(( (exp_epoch - now_epoch) / 86400 )) echo "$domain: $expiry ($days_left days left)" if [ $delete_mode -eq 1 ] && [ $days_left -lt...