-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
105 lines (88 loc) · 2.3 KB
/
setup.sh
File metadata and controls
105 lines (88 loc) · 2.3 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env bash
export log=/log.fifo
if [ -z "${nginx_server_name}" ]; then
export nginx_server_name="localhost"
fi
if [ -z "${nginx_http_port}" ]; then
export nginx_http_port="80"
fi
if [ -z "${nginx_https_port}" ]; then
export nginx_https_port="443"
fi
if [ -z "${nginx_timeout}" ]; then
export nginx_timeout="60"
fi
if [ -z "${nginx_ssl_letsencrypt}" ]; then
export nginx_ssl_letsencrypt="0"
fi
if [ -z "${nginx_ssl}" ]; then
export nginx_ssl="0"
elif [ "${nginx_ssl}" -eq "1" ]; then
if [ "${nginx_ssl_letsencrypt}" -eq "1" ]; then
export nginx_ssl_root="/etc/letsencrypt/live/${nginx_server_name}"
else
if [ -z "${nginx_ssl_root}" ]; then
if [ -z "${nginx_ssl_crt}" -a -z "${nginx_ssl_key}" ]; then
echo "ERROR: `nginx_ssl_root` or `nginx_ssl_{crt,key}` must exist if `nginx_ssl` -eq 1 "
exit 1
fi
fi
if [ ! -z "${nginx_ssl_crt}" -a ! -z "${nginx_ssl_key}" ]; then
export nginx_ssl_root=/ssl
mkdir -p "${nginx_ssl_root}"
echo "${nginx_ssl_crt}" | sed -e 's/;/\n/g' | tee "${nginx_ssl_root}/tls.crt"
echo "${nginx_ssl_key}" | sed -e 's/;/\n/g' | tee "${nginx_ssl_root}/tls.key"
fi
if [ ! -f "${nginx_ssl_root}/tls.key" ]; then
echo "ERROR: ${nginx_ssl_root}/tls.key must exist"
exit 1
elif [ ! -f "${nginx_ssl_root}/tls.crt" ]; then
echo "ERROR: ${nginx_ssl_root}/tls.crt must exist"
exit 1
fi
fi
fi
if [ -z "${nginx_ssl_redirect}" ]; then
export nginx_ssl_redirect="${nginx_ssl}"
fi
if [ -z "${nginx_gzip}" ]; then
export nginx_gzip="1"
fi
if [ -z "${nginx_buffering}" ]; then
export nginx_buffering="1"
fi
###
if [ -e $log ]; then
rm $log
fi
mkfifo $log
tail -f $log &
source ./setup-nginx.sh
ret="$?"
if [ "${ret}" -ne "0" ]; then
exit ${ret}
fi
if [ ! -z "${nginx_ssl_letsencrypt}" ]; then
if [ "${nginx_ssl_letsencrypt}" -eq "1" -a "$1" == "nginx" ]; then
source ./setup-letsencrypt.sh
ret="$?"
if [ "${ret}" -ne "0" ]; then
exit ${ret}
fi
echo "Starting letsencrypt renew loop..."
trap exit TERM
while :; do
certbot renew
nginx -s reload
sleep 12h
done &
wait ${NGINX_PID}
elif [ "${nginx_ssl_letsencrypt}" -eq "1" ]; then
echo "Warning: letsencrypt not setup"
exec "$@"
else
exec "$@"
fi
else
exec "$@"
fi