3 # Script to deploy certificate to a Gitlab hosted page
5 # The following variables exported from environment will be used.
6 # If not set then values previously saved in domain.conf file are used.
8 # All the variables are required
10 # export GITLAB_TOKEN="xxxxxxx"
11 # export GITLAB_PROJECT_ID=012345
12 # export GITLAB_DOMAIN="mydomain.com"
21 _debug _cdomain
"$_cdomain"
23 _debug _ccert
"$_ccert"
25 _debug _cfullchain
"$_cfullchain"
27 if [ -z "$GITLAB_TOKEN" ]; then
28 if [ -z "$Le_Deploy_gitlab_token" ]; then
29 _err
"GITLAB_TOKEN not defined."
33 Le_Deploy_gitlab_token
="$GITLAB_TOKEN"
34 _savedomainconf Le_Deploy_gitlab_token
"$Le_Deploy_gitlab_token"
37 if [ -z "$GITLAB_PROJECT_ID" ]; then
38 if [ -z "$Le_Deploy_gitlab_project_id" ]; then
39 _err
"GITLAB_PROJECT_ID not defined."
43 Le_Deploy_gitlab_project_id
="$GITLAB_PROJECT_ID"
44 _savedomainconf Le_Deploy_gitlab_project_id
"$Le_Deploy_gitlab_project_id"
47 if [ -z "$GITLAB_DOMAIN" ]; then
48 if [ -z "$Le_Deploy_gitlab_domain" ]; then
49 _err
"GITLAB_DOMAIN not defined."
53 Le_Deploy_gitlab_domain
="$GITLAB_DOMAIN"
54 _savedomainconf Le_Deploy_gitlab_domain
"$Le_Deploy_gitlab_domain"
57 string_fullchain
=$
(_url_encode
<"$_cfullchain")
58 string_key
=$
(_url_encode
<"$_ckey")
60 body
="certificate=$string_fullchain&key=$string_key"
62 export _H1
="PRIVATE-TOKEN: $Le_Deploy_gitlab_token"
64 gitlab_url
="https://gitlab.com/api/v4/projects/$Le_Deploy_gitlab_project_id/pages/domains/$Le_Deploy_gitlab_domain"
66 _response
=$
(_post
"$body" "$gitlab_url" 0 PUT | _dbase64
"multiline")
68 error_response
="error"
70 if test "${_response#*"$error_response"}" != "$_response"; then
71 _err
"Error in deploying certificate:"
76 _debug response
"$_response"
77 _info
"Certificate successfully deployed"