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.

80 lines
2.0 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. #!/usr/bin/env sh
  2. # Script to deploy certificate to a Gitlab hosted page
  3. # The following variables exported from environment will be used.
  4. # If not set then values previously saved in domain.conf file are used.
  5. # All the variables are required
  6. # export GITLAB_TOKEN="xxxxxxx"
  7. # export GITLAB_PROJECT_ID=012345
  8. # export GITLAB_DOMAIN="mydomain.com"
  9. gitlab_deploy() {
  10. _cdomain="$1"
  11. _ckey="$2"
  12. _ccert="$3"
  13. _cca="$4"
  14. _cfullchain="$5"
  15. _debug _cdomain "$_cdomain"
  16. _debug _ckey "$_ckey"
  17. _debug _ccert "$_ccert"
  18. _debug _cca "$_cca"
  19. _debug _cfullchain "$_cfullchain"
  20. if [ -z "$GITLAB_TOKEN" ]; then
  21. if [ -z "$Le_Deploy_gitlab_token" ]; then
  22. _err "GITLAB_TOKEN not defined."
  23. return 1
  24. fi
  25. else
  26. Le_Deploy_gitlab_token="$GITLAB_TOKEN"
  27. _savedomainconf Le_Deploy_gitlab_token "$Le_Deploy_gitlab_token"
  28. fi
  29. if [ -z "$GITLAB_PROJECT_ID" ]; then
  30. if [ -z "$Le_Deploy_gitlab_project_id" ]; then
  31. _err "GITLAB_PROJECT_ID not defined."
  32. return 1
  33. fi
  34. else
  35. Le_Deploy_gitlab_project_id="$GITLAB_PROJECT_ID"
  36. _savedomainconf Le_Deploy_gitlab_project_id "$Le_Deploy_gitlab_project_id"
  37. fi
  38. if [ -z "$GITLAB_DOMAIN" ]; then
  39. if [ -z "$Le_Deploy_gitlab_domain" ]; then
  40. _err "GITLAB_DOMAIN not defined."
  41. return 1
  42. fi
  43. else
  44. Le_Deploy_gitlab_domain="$GITLAB_DOMAIN"
  45. _savedomainconf Le_Deploy_gitlab_domain "$Le_Deploy_gitlab_domain"
  46. fi
  47. string_fullchain=$(_url_encode <"$_cfullchain")
  48. string_key=$(_url_encode <"$_ckey")
  49. body="certificate=$string_fullchain&key=$string_key"
  50. export _H1="PRIVATE-TOKEN: $Le_Deploy_gitlab_token"
  51. gitlab_url="https://gitlab.com/api/v4/projects/$Le_Deploy_gitlab_project_id/pages/domains/$Le_Deploy_gitlab_domain"
  52. _response=$(_post "$body" "$gitlab_url" 0 PUT | _dbase64 "multiline")
  53. error_response="error"
  54. if test "${_response#*"$error_response"}" != "$_response"; then
  55. _err "Error in deploying certificate:"
  56. _err "$_response"
  57. return 1
  58. fi
  59. _debug response "$_response"
  60. _info "Certificate successfully deployed"
  61. return 0
  62. }