-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-domain.sh
executable file
·52 lines (39 loc) · 1.2 KB
/
create-domain.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
#!/usr/bin/env bash
. "$(dirname $0)/conf/config"
. "$(dirname $0)/conf/functions"
if [ $# -lt 1 ]
then
echo "No domain name specified"
echo "Usage: ${0} domain-name"
exit
fi
domain=$1
if [ ! -f "key/${domain}" ]; then
# generate domain key
openssl genrsa 4096 > "${key_dir}/${domain}"
# create CSR (if 2nd level domain, add version with www)
# detection is base simply on dot count in domain
dot_count=$(echo $domain | grep -o "\." | wc -l)
if [ $dot_count -ne 1 ]; then
openssl req -new -sha256 -key "${key_dir}/${domain}" \
-subj "/CN=${domain}" \
> "${csr_dir}/${domain}"
else
openssl req -new -sha256 -key "${key_dir}/${domain}" \
-subj "/" \
-reqexts SAN \
-config <(cat $ssl_conf <(printf "[SAN]\nsubjectAltName=DNS:${domain},DNS:www.${domain}")) \
> "${csr_dir}/${domain}"
fi
python $acme --account-key ${account_key} \
--csr "${csr_dir}/${domain}" \
--acme-dir "${challenge_dir}" \
> "${cert_dir}/${domain}"
if [ $web_server == "nginx" ];then
download_cross_signed
fi
setup_httpd $domain $web_server
else
echo "Domain file for ${domain} already exists"
exit
fi