-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathentrypoint.sh
62 lines (49 loc) · 1.71 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/ash -l
set -e
if [[ ! -d /etc/letsencrypt/live ]]; then
echo "Please ensure that /etc/letsencrypt is persistent! Or is this the first run?"
fi
if [[ "${CLOUDFLARE_API_TOKEN}" == "" ]]; then
echo "CLOUDFLARE_API_TOKEN not set. This is required."
exit 2
fi
if [[ "${DOMAIN}" == "" ]]; then
echo "DOMAIN variable not set."
exit 3
fi
if [[ "${EMAIL}" == "" ]]; then
echo "EMAIL variable not set."
exit 4
fi
echo "$(date) starting certbot scripts"
if [[ "$(whoami)" == "root" ]]; then
HOME_DIR=$( getent passwd "certbot" | cut -d: -f6 )
echo "runing as default user certbot, home $HOME_DIR"
chown -R certbot:certbot /etc/letsencrypt /var/lib/letsencrypt /var/log/letsencrypt /certs
echo "dns_cloudflare_api_token=${CLOUDFLARE_API_TOKEN}" > "$HOME_DIR/cloudflare.ini"
chmod 600 "$HOME_DIR/cloudflare.ini"
chown certbot:certbot "$HOME_DIR/cloudflare.ini"
sudo -u certbot certbot certonly --dns-cloudflare --dns-cloudflare-credentials "$HOME_DIR/cloudflare.ini" -d ${DOMAIN} --non-interactive --agree-tos -m ${EMAIL}
else
cd ~
echo "running as custom user $USER, home $(pwd)"
echo "dns_cloudflare_api_token=${CLOUDFLARE_API_TOKEN}" > ~/cloudflare.ini
chmod 600 ~/cloudflare.ini
certbot certonly --dns-cloudflare --dns-cloudflare-credentials ~/cloudflare.ini -d ${DOMAIN} --non-interactive --agree-tos -m ${EMAIL}
fi
echo "$(date) running renewal script"
if [[ "$(whoami)" == "root" ]]; then
echo "running as default user certbot"
sudo -u certbot /renew.sh
else
echo "running as custom user $USER"
/renew.sh
fi
echo "$(date) running crond in forefront."
if [[ "$(whoami)" == "root" ]]; then
echo "running as default user certbot"
sudo -u certbot crond -l 2 -f
else
echo "running as custom user $USER"
crond -l 2 -f
fi