local section="$1"
local use_staging
local retries
+ local use_auto_staging
local infinite_retries
config_get_bool use_staging "$section" use_staging
+ config_get_bool use_auto_staging "$section" use_auto_staging
+ config_get_bool enabled "$section" enabled
config_get retries "$section" retries
[ -z "$retries" ] && retries=1
+ [ -z "$use_auto_staging" ] && use_auto_staging=0
[ "$retries" -eq "0" ] && infinite_retries=1
+ [ "$enabled" -eq "1" ] || return 0
while true; do
issue_cert "$1"; ret=$?
# An error occurred while retrieving the certificate.
retries="$((retries-1))"
+ if [ "$use_auto_staging" -eq "1" ] && [ "$use_staging" -eq "0" ]; then
+ log "Production certificate could not be obtained. Switching to staging server."
+ use_staging=1
+ uci set "acme.$1.use_staging=1"
+ uci commit acme
+ fi
+
if [ -z "$infinite_retries" ] && [ "$retries" -lt "1" ]; then
log "An error occurred while retrieving the certificate. Retries exceeded."
return "$ret"
sleep "$sleeptime"
continue
else
- return "$ret";
+ if [ "$use_auto_staging" -eq "1" ]; then
+ if [ "$use_staging" -eq "0" ]; then
+ log "Production certificate obtained. Exiting."
+ else
+ log "Staging certificate obtained. Continuing with production server."
+ use_staging=0
+ uci set "acme.$1.use_staging=0"
+ uci commit acme
+ continue
+ fi
+ fi
+
+ return "$ret"
fi
done
}