2
0

setup-ssl 1.1 KB

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env bash
  2. [ $# -eq 0 ] && echo "Please specify at least one 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. # Initialize an empty array to hold the processed domains
  8. DOMAINS_WITHOUT_PORT=()
  9. # Loop through each domain
  10. for domain in "$@"; do
  11. # Strip out the port number
  12. DOMAIN_WITHOUT_PORT=$(echo "$domain" | cut -d ':' -f1)
  13. # Append the processed domain to the array
  14. DOMAINS_WITHOUT_PORT+=("$DOMAIN_WITHOUT_PORT")
  15. done
  16. # Use the array in the mkcert command
  17. bin/docker-compose exec -T -u root app mkcert -key-file nginx.key -cert-file nginx.crt "${DOMAINS_WITHOUT_PORT[@]}"
  18. echo "Moving key and cert to /etc/nginx/certs/..."
  19. bin/docker-compose exec -T -u root app chown app:app nginx.key nginx.crt
  20. bin/docker-compose exec -T -u root app mv nginx.key nginx.crt /etc/nginx/certs/
  21. # Restart nginx to apply the updates
  22. echo "Restarting containers to apply updates..."
  23. bin/restart