#!/usr/bin/env bash set -e #set -x LETSENCRYPT_IMAGE=dkregistry.xai-corp.net:5000/xaicorp/acme-certbot LETSENCRYPT_MOUNT=/opt/shared/letsencrypt-2-staging LOG=$(mktemp) ##export LOCAL_IMAGE #export REMOTE_IMAGE ##export TAG ### run() { if [ "$ENVIRONMENT" == 'prod' ]; then LETSENCRYPT_MOUNT=/opt/shared/letsencrypt-2 fi update } update() { export DOCKER_HOST=${DOCKER_HOST:-'dkhost:2376'} export LETSENCRYPT_MOUNT export LETSENCRYPT_IMAGE # shellcheck disable=SC2086 docker-compose \ -f docker-compose.tools.yml \ run renew ${OPTIONS} } function trap_exit() { code=$? if [ $code -gt 0 ]; then echo rm "$LOG" echo -e "\033[31mFailed updating production certs \033[39m" exit $code fi rm "$LOG" echo -e "\033[32mSuccess:\033[39m ssl certs have been updated" } trap trap_exit EXIT print_usage() { printf "Usage: %s: [-b] [-t] [-s] \n" "$0" echo -r rollback echo -t smoke tests echo -s tag as latest echo -h help exit 0 } ###### ENVIRONMENT=dev OPTIONS='' while getopts de: name do case $name in d) OPTIONS="$OPTIONS --dryrun" ;; e) if [ $OPTARG == 'prod' ]; then ENVIRONMENT=prod else OPTIONS="$OPTIONS --test-cert" fi ;; : ) echo "Invalid option: $OPTARG requires an argument" 1>&2 ;; *) print_usage;; esac done # shellcheck disable=SC2068 run $@