You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.9 KiB

5 years ago
  1. #!/usr/bin/env bash
  2. # This script used to automatically deploy dokku
  3. # global wildcard domain's certificate.
  4. # If your dokku global domain is dokku.example.com
  5. # and you dokku app is domains-app-enabled
  6. # and the app heve domains like dokku.example.com
  7. # *.dokku.example.com, this script will
  8. # automatic execute `dokku certs:update app <certs`
  9. # to enable and update the app SSL certificate.
  10. # DOKKU_SSL_DOCUMENTATION='http://dokku.viewdocs.io/dokku/configuration/ssl/'
  11. ######## Public functions #####################
  12. # domain keyfile certfile cafile fullchain
  13. dokku_deploy() {
  14. _cdomain="$1"
  15. _ckey="$2"
  16. _ccert="$3"
  17. _cca="$4"
  18. _cfullchain="$5"
  19. _debug _cdomain "$_cdomain"
  20. _debug _ckey "$_ckey"
  21. _debug _ccert "$_ccert"
  22. _debug _cca "$_cca"
  23. _debug _cfullchain "$_cfullchain"
  24. temp_dir=$(mktemp -d -t cert_pack-XXXXXX)
  25. _debug "Create temp dir at $temp_dir"
  26. cd "$temp_dir" || return 1
  27. cp "$_cfullchain" "server.crt"
  28. cp "$_ckey" "server.key"
  29. _debug "Create cert-key.tar at temp dir"
  30. tar cf cert-key.tar server.crt server.key
  31. _debug "Get dokku app list"
  32. apps=$(dokku apps:list --quiet)
  33. _debug "Dokku apps: $apps"
  34. _debug "Find domain $_cdomain in dokku domain enabled apps"
  35. for app in $apps; do
  36. app_enable=$(dokku domains:report "$app" --domains-app-enabled)
  37. if [[ $app_enable == "true" ]]; then
  38. app_vhosts=$(dokku domains:report "$app" --domains-app-vhosts)
  39. _debug "App '$app' domains: $app_vhosts"
  40. for domain in $app_vhosts; do
  41. if [[ $domain == "$_cdomain" || $domain == *.$_cdomain ]]; then
  42. _debug "Update dokku app '$app' cert"
  43. dokku certs:update "$app" <cert-key.tar
  44. _debug "Dokku app '$app' cert update finished"
  45. break
  46. fi
  47. done
  48. fi
  49. done
  50. cd - || return 0
  51. _debug "Remove temp dir: $temp_dir"
  52. rm -rf "$temp_dir"
  53. _debug "Clean."
  54. _debug "Deploy finish."
  55. return 0
  56. }