forked from domogik/domogik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssl_activate.sh
executable file
·48 lines (43 loc) · 1.53 KB
/
ssl_activate.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
#!/bin/bash
# This script will generate a self signed SSL certificate which will be valid for 2 years.
# The certificate will have no passphrase
DIR=/var/lib/domogik
echo "----------------------------------------------------------"
echo "Generating the certificate and key !"
echo "----------------------------------------------------------"
echo ""
echo "Certificates will be generated in the folder '$DIR'"
openssl req -x509 -newkey rsa:2048 -keyout $DIR/ssl_key.pem -out $DIR/ssl_cert.pem -days 730 -nodes << EOF
FR
Domogik state
Domogik city
Domogik inc
.
.
.
.
EOF
if [[ ! -f $DIR/ssl_key.pem || ! -f $DIR/ssl_cert.pem ]] ; then
echo "[ ERROR ] An error occured, please check the lines before!"
exit 1
fi
echo ""
echo "[ OK ] SSL certificate and key created. "
echo ""
echo ""
echo "----------------------------------------------------------"
echo "Setting domogik configuration..."
echo "----------------------------------------------------------"
echo ""
sed -i "s/^use_ssl.*/use_ssl = True/" /etc/domogik/domogik.cfg
sed -i "s#^ssl_certificate.*#ssl_certificate = $DIR/ssl_cert.pem#" /etc/domogik/domogik.cfg
sed -i "s#^ssl_key.*#ssl_key = $DIR/ssl_key.pem#" /etc/domogik/domogik.cfg
if [[ $? -ne 0 ]] ; then
echo "[ ERROR ] An error occured, please check the lines before!"
exit 2
fi
echo "[ OK ] Configuration file updated!"
echo ""
echo "----------------------------------------------------------"
echo "==> All is OK, please restart Domoweb! <=="
echo "----------------------------------------------------------"