Skip to content

Instantly share code, notes, and snippets.

@un1ko85
Created May 19, 2016 08:24
Show Gist options
  • Select an option

  • Save un1ko85/d962f5d5c26b7d10ce3eadd2a23f465f to your computer and use it in GitHub Desktop.

Select an option

Save un1ko85/d962f5d5c26b7d10ce3eadd2a23f465f to your computer and use it in GitHub Desktop.
Letsencrypt FreeBSD deploy
#!/bin/sh
domain="example.net"
letsencryptdir="/usr/local/etc/letsencrypt.sh"
targets="mail http"
for jail in ${targets}; do
targetdir="/usr/jails/${jail}/etc/ssl"
# Check if the certificate has changed
[ -z "`diff -rq ${letsencryptdir}/certs/${domain}/fullchain.pem ${targetdir}/certs/${domain}.pem`" ] && continue
cp -L "${letsencryptdir}/certs/${domain}/privkey.pem" "${targetdir}/priv/${domain}.pem"
cp -L "${letsencryptdir}/certs/${domain}/fullchain.pem" "${targetdir}/certs/${domain}.pem"
chmod 400 "${targetdir}/priv/${domain}.pem"
chmod 644 "${targetdir}/certs/${domain}.pem"
# Restart/-load relevant services
[ "${jail}" = "http" ] && jexec ${jail} service apache24 restart
[ "${jail}" = "mail" ] && jexec ${jail} service smtpd restart
done
# Clean up old keys and certs
/usr/local/bin/letsencrypt.sh --cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment