-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·77 lines (62 loc) · 1.86 KB
/
configure
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
#!/bin/bash
# PROGNAME=$(basename $0)
# RELEASE="Revision 1.0.5"
# AUTHOR="Paul Bargewell <paul.bargewell@opusvl.com>"
# COPYTRIGHT="Copyright 2021, Opus Vision Limited T/A OpusVL"
# LICENSE="SPDX-License-Identifier: AGPL-3.0-or-later"
source .env
if [[ ! -f ".env" ]]; then
echo "ERROR: You need to create a .env file first (see .env.example)."
exit 1
fi
SUDO=$(which sudo)
if [[ -z "${SUDO}" ]]; then
echo "We need to elevate privileges using 'sudo' which can't be found."
exit 1
fi
readonly PYTHON_JINJA2="import os;
import sys;
import jinja2;
from dotenv import load_dotenv;
reload(sys)
sys.setdefaultencoding('utf-8')
load_dotenv(verbose=True)
sys.stdout.write(
jinja2.Template
(sys.stdin.read()
).render(env=os.environ))"
function render() {
if [[ -f "$1" ]]; then
echo "Templating: $1"
# cat "$1" | python -c "${PYTHON_JINJA2}" > "${1//\.template/}"
< "$1" python -c "${PYTHON_JINJA2}" > "${1//\.template/}"
else
echo "$1 File not found."
exit 1
fi
}
# Render the templates first
TEMPLATES=(prosody/etc/conf.d/modules.cfg.template.lua
prosody/etc/ldap-roster.template.py
prosody/etc/prosody.cfg.template.lua
prosody/etc/conf.d/extra.cfg.template.lua
prosody/etc/conf.d/logging.cfg.template.lua
prosody/etc/vhost.d/vhost.cfg.template.lua
rest/create_realm.template.json
rest/create_ldap.template.json
nginx/nginx.template.conf
nginx/deploy/10-prosody-certs.template
)
for TEMPLATE in "${TEMPLATES[@]}"
do
render "$TEMPLATE"
done
# Deliver template to Nginx
${SUDO} cp nginx/deploy/{10-prosody-certs,20-reload-nginx} /etc/letsencrypt/renewal-hooks/deploy/
${SUDO} cp ./nginx/nginx.conf "/etc/nginx/conf.d/${SERIAL}.conf"
TEST=(nginx -t)
RELOAD=(systemctl reload nginx)
if [[ $(${SUDO} "${TEST[@]}") -ne 0 ]] && [[ $(${SUDO} "${RELOAD[@]}") -ne 0 ]]; then
echo "NGINX: Failure to reload."
exit 1
fi