Skip to content

Commit 5c8b88f

Browse files
Fixed bug in certbot.sh that would lead to a failure to validate a domain breaking out of the retry logic, and lead to the domain being skipped. Also updated to Ubuntu 18.04 bionic, and replaced deprecated certbot-auto with certbot (via apt-get). (#51)
1 parent 814bde3 commit 5c8b88f

File tree

3 files changed

+25
-29
lines changed

3 files changed

+25
-29
lines changed

Dockerfile

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#use 16.04 lts, install certbot-auto to get newest certbot version
2-
FROM ubuntu:16.04
1+
#use 18.04 lts
2+
FROM ubuntu:18.04
33

44
#set default env variables
55
ENV DEBIAN_FRONTEND=noninteractive \
@@ -10,14 +10,7 @@ ENV DEBIAN_FRONTEND=noninteractive \
1010

1111
# http://stackoverflow.com/questions/33548530/envsubst-command-getting-stuck-in-a-container
1212
RUN apt-get update && \
13-
apt-get -y install cron supervisor curl && \
14-
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
15-
16-
# install certbot-auto
17-
RUN curl -o /root/certbot-auto https://dl.eff.org/certbot-auto && \
18-
chmod a+x /root/certbot-auto && \
19-
/root/certbot-auto --version --non-interactive && \
20-
apt-get purge -y --auto-remove gcc libc6-dev && \
13+
apt-get -y install cron supervisor curl certbot && \
2114
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
2215

2316
# Add supervisord.conf

certbot.sh

100644100755
Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,43 +31,46 @@ fi
3131

3232
for var in $(env | grep -P 'DOMAIN_\d+' | sed -e 's/=.*//'); do
3333
cur_domains=${!var};
34-
3534
declare -a arr=$cur_domains;
3635

3736
DOMAINDIRECTORY="/etc/letsencrypt/live/${arr[0]}";
3837
dom="";
3938
for i in "${arr[@]}"
4039
do
41-
let exitcode=tries=0
40+
let validated=tries=0
4241
until [ $tries -ge $MAXRETRIES ]
4342
do
4443
tries=$[$tries+1]
45-
certbot-auto certonly --dry-run "${args[@]}" -d "$i" | grep -q 'The dry run was successful.' && break
46-
exitcode=$?
47-
48-
if [ $tries -eq $MAXRETRIES ]; then
49-
printf "${RED}Unable to verify domain ownership after ${tries} attempts.${NC}\n"
44+
certbot certonly --dry-run "${args[@]}" -d "$i" | grep -q 'The dry run was successful.'
45+
if [ $? -eq 0 ]; then
46+
validated=1
47+
break
5048
else
51-
printf "${RED}Unable to verify domain ownership, we try again in ${TIMEOUT} seconds.${NC}\n"
52-
sleep $TIMEOUT
49+
if [ $tries -eq $MAXRETRIES ]; then
50+
printf "${RED}Unable to verify domain ownership after ${tries} attempts.${NC}\n"
51+
else
52+
printf "${RED}Unable to verify domain ownership, we try again in ${TIMEOUT} seconds.${NC}\n"
53+
sleep $TIMEOUT
54+
fi
5355
fi
54-
done
5556

56-
if [ $exitcode -eq 0 ]; then
57+
done
58+
echo "Validated is $validated"
59+
if [ $validated -eq 1 ]; then
5760
printf "Domain $i successfully validated\n"
5861
dom="$dom -d $i"
5962
fi
6063
done
61-
64+
6265
#only if we have successfully validated at least a single domain we have to continue
6366
if [ -n "$dom" ]; then
6467
# check if DOMAINDIRECTORY exists, if it exists use --cert-name to prevent 0001 0002 0003 folders
6568
if [ -d "$DOMAINDIRECTORY" ]; then
66-
printf "\nUse certbot-auto certonly %s --cert-name %s\n" "${args[*]}" "${arr[0]}";
67-
certbot-auto certonly "${args[@]}" --cert-name "${arr[0]}" $dom
69+
printf "\nUse certbot certonly %s --cert-name %s\n" "${args[*]}" "${arr[0]}";
70+
certbot certonly "${args[@]}" --cert-name "${arr[0]}" $dom
6871
else
69-
printf "\nUse certbot-auto certonly %s\n" "${args[*]}";
70-
certbot-auto certonly "${args[@]}" $dom
72+
printf "\nUse certbot certonly %s\n" "${args[*]}";
73+
certbot certonly "${args[@]}" $dom
7174
fi
7275
fi
7376

renewAndSendToProxy.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ done
5858

5959
#full path is needed or it is not started when run as cron
6060

61-
#--no-bootstrap: prevent the certbot-auto script from installing OS-level dependencies
62-
#--no-self-upgrade: revent the certbot-auto script from upgrading itself to newer released versions
63-
/root/certbot-auto renew --no-bootstrap --no-self-upgrade > /var/log/dockeroutput.log
61+
#--no-bootstrap: prevent certbot from installing OS-level dependencies
62+
#--no-self-upgrade: prevent certbot from upgrading itself to newer released versions
63+
certbot renew --no-bootstrap --no-self-upgrade > /var/log/dockeroutput.log
6464

6565
echo $PROXY_ADDRESS | tr ',' '\n' | while read proxy_addr; do
6666
printf "Docker Flow: Proxy DNS-Name: ${GREEN}$proxy_addr${NC}\n";

0 commit comments

Comments
 (0)