frenky666

haproxy letsecrypt deploy hook

Aug 26th, 2025 (edited)
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.89 KB | Cybersecurity | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. declare -a _DOMAINS
  4.  
  5. # domains are given in a variable, space separated
  6. if [ ! -z "$RENEWED_DOMAINS" ]; then
  7.         echo $RENEWED_DOMAINS
  8.         _DOMAINS=($RENEWED_DOMAINS)
  9. else
  10.         exit
  11. fi
  12.  
  13. for _DOMAIN in "${_DOMAINS[@]}"; do
  14.         echo "Deploying certificate for '${_DOMAIN}'"
  15.  
  16.         # check for wildcard domain, files are stored without *. prefix
  17.         if [[ "$_DOMAIN" =~ ^\*\..*$ ]]; then
  18.                 _DOMAIN=${_DOMAIN:2}
  19.         fi
  20.  
  21.         # check if domain files exist before deploying them
  22.         if [ -f /etc/letsencrypt/live/${_DOMAIN}/fullchain.pem -a -f /etc/letsencrypt/live/${_DOMAIN}/privkey.pem ]; then
  23.                 cat /etc/letsencrypt/live/${_DOMAIN}/fullchain.pem /etc/letsencrypt/live/${_DOMAIN}/privkey.pem > /etc/haproxy/certs/${_DOMAIN}.pem
  24.         else
  25.                 echo "Missing certificate files"
  26.         fi
  27. done
Advertisement
Add Comment
Please, Sign In to add comment