Emissão de certificados usando o shell:
VHOST_DIR="/etc/nginx/sites-enabled"
files=($VHOST_DIR/*.conf)
count=1
declare -A DOMAIN_CMD
echo -e "\nScanning $VHOST_DIR for vhosts...\n"
for file in "${files[@]}"; do
[ -e "$file" ] || continue
# Grab the server_name, strip semicolons, strip hidden \r carriage returns, and clean it
domains=$(awk '/^[ \t]*server_name[ \t]/ {gsub(/;/, ""); gsub(/\r/, ""); gsub(/^[ \t]*server_name[ \t]+/, ""); print; exit}' "$file")
if [ -n "$domains" ]; then
read -ra domain_arr <<< "$domains"
primary="${domain_arr[0]}"
unset 'domain_arr[0]'
sans=$(IFS=,; echo "${domain_arr[*]}")
cmd="clpctl lets-encrypt:install:certificate --domainName=$primary"
if [ -n "$sans" ]; then
cmd="$cmd --subjectAlternativeName=$sans"
fi
DOMAIN_CMD[$count]="$cmd"
echo "[$count] Primary: $primary"
[ -n "$sans" ] && echo " Aliases: $sans"
echo " File: $(basename "$file")"
echo ""
((count++))
fi
done
read -p "Enter the number to generate SSL (or press Enter to cancel): " choice
if [[ -n "$choice" && -n "${DOMAIN_CMD[$choice]}" ]]; then
# Wrapped in brackets so you can spot invisible line breaks
echo -e "\nRunning: [${DOMAIN_CMD[$choice]}]\n"
eval "${DOMAIN_CMD[$choice]}"
else
echo -e "\nCanceled or invalid selection."
fiPadrões de vhost:
1.
2
3
4
5