setup-ssl 808 B

123456789101112131415161718
  1. #!/usr/bin/env bash
  2. [ -z "$1" ] && echo "Please specify a domain (ex. mydomain.test)" && exit
  3. # Generate certificate authority if not already setup
  4. if ! bin/docker-compose exec -T -u root app cat /root/.local/share/mkcert/rootCA.pem | grep -q 'BEGIN CERTIFICATE'; then
  5. bin/setup-ssl-ca
  6. fi
  7. # Generate the certificate for the specified domain
  8. DOMAIN_WITHOUT_PORT=$(echo "$@" | cut -d ':' -f1)
  9. bin/docker-compose exec -T -u root app mkcert -key-file nginx.key -cert-file nginx.crt "$DOMAIN_WITHOUT_PORT"
  10. echo "Moving key and cert to /etc/nginx/certs/..."
  11. bin/docker-compose exec -T -u root app chown app:app nginx.key nginx.crt
  12. bin/docker-compose exec -T -u root app mv nginx.key nginx.crt /etc/nginx/certs/
  13. # Restart nginx to apply the updates
  14. echo "Restarting containers to apply updates..."
  15. bin/restart