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.

61 lines
1.7 KiB

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. curl -s --fail --request PUT --header "PRIVATE-TOKEN: $Le_Deploy_gitlab_token" --form "certificate=@$_cfullchain" --form "key=@$_ckey" "https://gitlab.com/api/v4/projects/$Le_Deploy_gitlab_project_id/pages/domains/$Le_Deploy_gitlab_domain" >/dev/null && exit 0
  48. # Exit curl status code if curl didn't work
  49. exit $?
  50. }