-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgen-certs.sh
executable file
·53 lines (48 loc) · 1.44 KB
/
gen-certs.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
#!/usr/bin/env bash
. utils.sh
. checks/ca-cert-existence.sh
servers=$etcd_servers
if [ "$#" -gt 0 ]; then
servers=$@
fi
prnt "Generating certificates for $servers"
rm -f ${gendir}/*.crt
rm -f ${gendir}/*.key
count=0
for host_and_ip in $servers; do
host=$(echo $host_and_ip | cut -d':' -f1)
ip=$(echo $host_and_ip | cut -d':' -f2)
cp ./csr-template.json ${gendir}/${host}-csr.json
sed -i "s/#etcd-host#/${host}/g" ${gendir}/${host}-csr.json
cfssl gencert \
-ca=${etcd_ca} \
-ca-key=${etcd_key} \
-config=ca-csr.json \
-profile=client \
-hostname=${host},${ip},127.0.0.1,localhost \
${gendir}/${host}-csr.json | cfssljson -bare ${gendir}/${host}-client
cfssl gencert \
-ca=${etcd_ca} \
-ca-key=${etcd_key} \
-config=ca-csr.json \
-hostname=${host},${ip},127.0.0.1,localhost \
-profile=peer \
${gendir}/${host}-csr.json | cfssljson -bare ${gendir}/${host}-peer
cfssl gencert \
-ca=${etcd_ca} \
-ca-key=${etcd_key} \
-config=ca-csr.json \
-hostname=${host},${ip},127.0.0.1,localhost \
-profile=server \
${gendir}/${host}-csr.json | cfssljson -bare ${gendir}/${host}-server
prnt "Generated certs for $host"
((count++))
done
cd $gendir
rm ./*.json
rm ./*.csr
for file in $(ls . | grep "\-key.pem$"); do mv "$file" "${file%-*}.key"; done
for file in $(ls . | grep ".pem$"); do mv "$file" "${file%.*}.crt"; done
cd - &>/dev/null
count=$((count * 6))
tree | grep generated -A$count