Current File : //scripts/unwanted_dovecot_conf_delete.sh |
#!/bin/bash
# Directory where domain config files are located
config_dir="/etc/dovecot/domains"
# Directory where live Let's Encrypt certificates are located
certs_dir="/etc/letsencrypt/live"
# Loop through each config file in the dovecot domains directory
for config_file in "$config_dir"/*; do
# Check if config file is a regular file
if [ -f "$config_file" ]; then
# Extract domain name from the config filename or its content
domain=$(grep 'local_name' "$config_file" | awk '{print $2}')
# Construct the cert file path
cert_file="$certs_dir/${domain}/cert.pem"
# Check if cert file exists
if [ ! -f "$cert_file" ]; then
echo "Certificate file for ${domain} does not exist: $cert_file"
echo "Deleting configuration file: $config_file"
rm "$config_file" # Uncomment this line to actually delete the files
# else
# echo "Certificate file exists for ${domain}: $cert_file"
fi
fi
done