mirror of
https://github.com/dehydrated-io/dehydrated.git
synced 2026-04-27 18:57:02 +02:00
Destroyed Gitlab hook script (markdown)
@@ -1,63 +0,0 @@
|
|||||||
# Hook script to update a key in Gitlab pages
|
|
||||||
|
|
||||||
The script pushes the challenge to the pages git defined in $REPO, waits for it to be deployed, receives the key, uploads it to Gitlab and cleans up the repo afterwads.
|
|
||||||
|
|
||||||
## Code
|
|
||||||
|
|
||||||
```bash
|
|
||||||
#!/bin/sh -e
|
|
||||||
#
|
|
||||||
# dehydrated hook script to deploy a key to Gitlab.
|
|
||||||
#
|
|
||||||
# https://github.com/lukas2511/dehydrated/wiki/Gitlab-hook-script
|
|
||||||
#
|
|
||||||
# Add the following options to your config file:
|
|
||||||
# TOKEN= # API token, generate in Gitlab profile settings (select API access)
|
|
||||||
# PROJECT= # ID or URL-encoded path of the project (replace / with %2F)
|
|
||||||
# REPO= # path to local git repo of your pages project
|
|
||||||
|
|
||||||
. "$BASEDIR/$CONFIG"
|
|
||||||
|
|
||||||
deploy_challenge() {
|
|
||||||
DOMAIN="$1"
|
|
||||||
TOKEN_FILENAME="$2"
|
|
||||||
mkdir -p "$REPO/public/.well-known/acme-challenge"
|
|
||||||
cp "$WELLKNOWN/$TOKEN_FILENAME" "$REPO/public/.well-known/acme-challenge/"
|
|
||||||
git -C "$REPO" add public/.well-known/acme-challenge/"$TOKEN_FILENAME"
|
|
||||||
git -C "$REPO" commit -m "Let's Encrypt challenge"
|
|
||||||
git -C "$REPO" push
|
|
||||||
sleep 20
|
|
||||||
while ! curl --output /dev/null --silent --head --location --fail "https://$DOMAIN/.well-known/acme-challenge/$TOKEN_FILENAME"; do
|
|
||||||
echo "Waiting for challenge to be deployed"
|
|
||||||
sleep 5
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
clean_challenge() {
|
|
||||||
TOKEN_FILENAME="$2"
|
|
||||||
git -C "$REPO" reset HEAD~
|
|
||||||
rm -r "$REPO/public/"
|
|
||||||
git -C "$REPO" push --force-with-lease
|
|
||||||
}
|
|
||||||
|
|
||||||
# https://docs.gitlab.com/ee/api/pages_domains.html
|
|
||||||
deploy_cert() {
|
|
||||||
DOMAIN="$1"
|
|
||||||
KEYFILE="$2"
|
|
||||||
FULLCHAINFILE="$4"
|
|
||||||
curl --output /dev/null --silent --fail --request PUT --header "PRIVATE-TOKEN: $TOKEN" --form "certificate=@$FULLCHAINFILE" --form "key=@$KEYFILE" "https://gitlab.com/api/v4/projects/$PROJECT/pages/domains/$DOMAIN"
|
|
||||||
}
|
|
||||||
|
|
||||||
HANDLER="$1"; shift
|
|
||||||
case "$HANDLER" in
|
|
||||||
deploy_challenge)
|
|
||||||
deploy_challenge "$@"
|
|
||||||
;;
|
|
||||||
clean_challenge)
|
|
||||||
clean_challenge "$@"
|
|
||||||
;;
|
|
||||||
deploy_cert)
|
|
||||||
deploy_cert "$@"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
```
|
|
||||||
Reference in New Issue
Block a user