summaryrefslogtreecommitdiff
path: root/dehydrated/cron.weekly/local-dehydrated
blob: 6c2a4cc408ab6f5689de0ebd97f702fdcdbd1a37 (plain)
  1. #!/bin/sh
  2. #
  3. # Renew letsencrypt certificates
  4. set -eu
  5. REALM=$(cat /etc/local-ORG/realm) || true
  6. # resolve hostnames of service installed and registered with Redpill
  7. servicehosts() {
  8. SERVICE=$1; shift
  9. for binary in "$@"; do
  10. > /dev/null which -- "$binary" || exit
  11. done
  12. cat "/etc/local-REDPILL/$REALM/${SERVICE}host" \
  13. "/etc/local-REDPILL/$REALM/${SERVICE}althosts" \
  14. 2> /dev/null \
  15. | perl -0777 -pe 's/\s*\#.*//gm;s/^\s+//;s/\s+$//;s/\s+/|/g'
  16. }
  17. MAILHOSTS=$(servicehosts mail postconf) || true
  18. mailname=$(cat /etc/mailname) || true
  19. fqdn=$(hostname --fqdn)
  20. domain=$(hostname --domain)
  21. # mailhost is either mailname listed as a Redpill mailhost,
  22. # or default Redpill mailhost if mailname equals domain
  23. mailhost=''
  24. case "$mailname" in
  25. "$MAILHOSTS")
  26. mailhost=$mailname
  27. ;;
  28. "$domain")
  29. mailhost=$(cat "/etc/local-REDPILL/$REALM/mailhost") || true
  30. ;;
  31. esac
  32. # update non-EC mailhost cert if resolvable and not a certdomain
  33. if [ -n "$mailhost" ]; then
  34. if [ -n "$fqdn" ] && [ "$mailhost" != "$fqdn" ]; then
  35. extradomains=${extradomains:+$extradomains }$fqdn
  36. fi
  37. if [ -n "$domain" ] && [ "$mailhost" != "$domain" ] && [ "$fqdn" != "$domain" ]; then
  38. extradomains=${extradomains:+$extradomains }$domain
  39. fi
  40. if ! grep ^"$mailhost" /etc/dehydrated/domains.txt; then
  41. dehydrated --cron --domain "$mailhost $extradomains" --algo rsa
  42. fi
  43. fi
  44. # update certdomain certs
  45. dehydrated --cron "$@"