#!/bin/bash

echo "Attempting to renew certificates"
if [[ $STAGING = true ]] 
then
    echo "Using staging endpoint - THIS SHOULD BE USED FOR TESTING ONLY"
    certbot certonly --staging --non-interactive --agree-tos --dns-cloudflare --dns-cloudflare-propagation-seconds $PROPOGATION_TIME --dns-cloudflare-credentials /config/.secrets/cloudflare.ini --email $EMAIL -d $DOMAINS
    echo "Renewal attempt complete"
elif [[ $STAGING = false ]] 
then
    echo "Using production endpoint"
    certbot certonly --non-interactive --agree-tos --dns-cloudflare --dns-cloudflare-propagation-seconds $PROPOGATION_TIME --dns-cloudflare-credentials /config/.secrets/cloudflare.ini --email $EMAIL -d $DOMAINS
    echo "Renewal attempt complete"
else
    echo "Unrecognised option for STAGING variable - check your configuration"

    exit 8
fi