From 60a5c7ca221eb00ad85480092a86c58d154fa011 Mon Sep 17 00:00:00 2001 From: Massimiliano Adamo <massimiliano.adamo@geant.org> Date: Tue, 1 Jun 2021 23:08:23 +0200 Subject: [PATCH] add self-update option to shell script --- .gitlab-ci-psnc.yml | 3 --- acme-downloader.sh | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci-psnc.yml b/.gitlab-ci-psnc.yml index 3882299..e2229f7 100644 --- a/.gitlab-ci-psnc.yml +++ b/.gitlab-ci-psnc.yml @@ -25,7 +25,6 @@ upload_linux_shell: stage: upload_linux_shell only: - tags - - branches image: curlimages/curl:7.76.1 script: - 'curl -sSf -H "X-JFrog-Art-Api:${ARTIFACTORY_TOKEN}" -X PUT -T ./acme-downloader.sh ${ARTIFACTORY_BASE_URL}/${ARTIFACT_NAME}.sh' @@ -36,7 +35,6 @@ upload_linux_amd64_binary: stage: upload_linux_amd64_binary only: - tags - - branches script: - ./build.sh --os=linux --arch=amd64 --version=$CI_COMMIT_TAG --upx - 'curl -sSf -H "X-JFrog-Art-Api:${ARTIFACTORY_TOKEN}" -X PUT -T ./acme-downloader ${ARTIFACTORY_BASE_URL}/${ARTIFACT_NAME}_linux_amd64' @@ -47,7 +45,6 @@ upload_windows_amd64_binary: stage: upload_windows_amd64_binary only: - tags - - branches script: - ./build.sh --os=windows --arch=amd64 --version=$CI_COMMIT_TAG --upx - 'curl -sSf -H "X-JFrog-Art-Api:${ARTIFACTORY_TOKEN}" -X PUT -T ./acme-downloader.exe ${ARTIFACTORY_BASE_URL}/${ARTIFACT_NAME}_windows_amd64.exe' diff --git a/acme-downloader.sh b/acme-downloader.sh index 9f692b7..a24517b 100755 --- a/acme-downloader.sh +++ b/acme-downloader.sh @@ -66,7 +66,7 @@ usage() { echo " --redis-token (Redis access token)" echo " --vault-token (Vault access token)" echo " --cert-name (Certificate name)" - echo " --team-name (Team name: swd, dream_team, it, ne, ti...)" + echo " --team-name (Team name: swd, dream_team, it, ne, ti, nmaas...)" echo " --days [OPTIONAL check days before expiration. Default: 30)" echo " --type [OPTIONAL. OV or EV. Default: EV]" echo " --cert-destination [OPTIONAL Default: ${CERT_BASE}/<cert-name>.crt]" @@ -74,6 +74,7 @@ usage() { echo " --key-destination [OPTIONAL Default: ${KEY_BASE}/<cert-name>.key]" echo " --ca-destination [OPTIONAL Default: ${CERT_BASE}/COMODO_<type>.crt]" echo " --wildcard [OPTIONAL if the certificate is wildcard]" + echo " --update [OPTIONAL self-updates the script and exit]" echo "" clean_up } @@ -130,6 +131,9 @@ while true; do --wildcard) WILDCARD='WILDCARD' ;; + --update) + UPDATE='UPDATE' + ;; --) shift break @@ -140,6 +144,18 @@ done TYPE=$(echo $TYPE | tr '[:lower:]' '[:upper:]') +if [ -n $UPDATE ]; then + curl $SCRIPT_URL -o $0 + UPDATE_STATUS=$? + if [ $UPDATE_STATUS == 0 ]; then + echo -e "\n$0 updated successfully\n" + else + echo -e "\nfailed to update $0" + echo -e "Please download the script manually from this URL: ${SCRIPT_URL}\n" + fi + exit $UPDATE_STATUS +fi + if [[ -z $REDIS_TOKEN ]] || [[ -z $VAULT_TOKEN ]] || [[ -z $CERT_NAME ]] || [[ -z $TEAM_NAME ]]; then echo -e "\n--redis-token, --vault-token, --cert-name and --team-name are mandatory\n" usage -- GitLab