-
Notifications
You must be signed in to change notification settings - Fork 0
/
acme.sh-wildcard-hetzner-dns
86 lines (63 loc) · 2.02 KB
/
acme.sh-wildcard-hetzner-dns
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
LANG=C
cmdname=`basename $0`
function usage() {
cat <<EOF
Usage: ${cmdname}
HETZNER DNS interactive script to download and install acme.sh wildcard certificate for your domain.com and *.domain.com.
-h --help : Help (this screen).
EOF
}
case "$1" in
-h|--help)
usage
exit
;;
esac
curl_bin=`which curl`;
if [ "$curl_bin" == "" ]
then
echo "Curl not installed. Proceed with install? (CTRL+C to Abort)"
echo "or run install manually: apt-get -y install curl"
read
apt-get -y install curl
fi
if [ ! -f "/root/.acme.sh/acme.sh" ]
then
echo "acme.sh not installed. Proceed with install? (CTRL+C to Abort)"
echo "or run install manually: curl https://get.acme.sh | sh"
read
echo "Please enter your email (CTRL+C to abort):"
read EMAILADDR
[ "${EMAILADDR}" == "" ] && echo "Error: Empty email!" && exit 1
curl https://get.acme.sh | sh
/root/.acme.sh/acme.sh --register-account -m ${EMAILADDR}
fi
cat <<EOF
STEP 1 - hetzner dns api token:
Your domain MUST be hosted at HETZNER DNS servers: https://dns.hetzner.com
First go to https://dns.hetzner.com/settings/api-token to obtain your hetzner api token.
Please enter your hetzner api token (CTRL+C to abort):
EOF
read HETZNERTOKEN
[ "${HETZNERTOKEN}" == "" ] && echo "Error: Empty Hetzner api token!" && exit 1
cat <<EOF
STEP 2:
Please enter your domain name (CTRL+C to abort):
EOF
read DOMAIN
[ "${DOMAIN}" == "" ] && echo "Error: Empty domain!" && exit 1
export HETZNER_Token="${HETZNERTOKEN}";
$HOME/.acme.sh/acme.sh --issue --dns dns_hetzner -d ${DOMAIN} -d *.${DOMAIN}
cat > /usr/local/bin/acme.sh-hetzner-dns-renew-${DOMAIN} <<EOF
#!/bin/bash
export HETZNER_Token="${HETZNERTOKEN}";
$HOME/.acme.sh/acme.sh --renew --dns dns_hetzner -d ${DOMAIN} -d *.${DOMAIN} --renew-hook "/etc/init.d/nginx reload"
EOF
chmod +x /usr/local/bin/acme.sh-hetzner-dns-renew-${DOMAIN};
cat <<EOF
# Add cron job to renew domain and reload nginx on success:
# "crontab -e"
# and enter the following:
0 2 * * * /usr/local/bin/acme.sh-hetzner-dns-renew-${DOMAIN} &> /dev/null
EOF