-
Notifications
You must be signed in to change notification settings - Fork 9
/
init.sh
executable file
·183 lines (148 loc) · 5.21 KB
/
init.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash
#
function config_nginx() {
config_file=$1
if [ ! -f "${config_file}" ]; then
echo "config file ${config_file} not found"
exit 1
fi
if [ -z "${HTTP_PORT}" ]; then
HTTP_PORT=80
fi
if [ -z "${USE_LB}" ]; then
USE_LB=1
fi
if [ "${USE_IPV6}" == "1" ]; then
sed -i "s@# listen \[::\]:80;@listen \[::\]:80;@g" "${config_file}"
if [ -f "/etc/nginx/conf.d/default.conf" ]; then
sed -i "s@# listen \[::\]:51980;@listen \[::\]:51980;@g" /etc/nginx/conf.d/default.conf
fi
fi
if [ "${HTTP_PORT}" != "80" ]; then
sed -i "s@listen 80;@listen ${HTTP_PORT};@g" "${config_file}"
if [ "${USE_IPV6}" == "1" ]; then
sed -i "s@listen \[::\]:80;@listen \[::\]:${HTTP_PORT};@g" "${config_file}"
fi
fi
if [ -n "${SERVER_NAME}" ]; then
SERVER_NAME=$(echo "$SERVER_NAME" | sed 's/,/ /g; s/ *$//')
sed -i "s@# server_name .*;@server_name ${SERVER_NAME};@g" "${config_file}"
fi
if [ -n "${CLIENT_MAX_BODY_SIZE}" ]; then
sed -i "s@client_max_body_size .*;@client_max_body_size ${CLIENT_MAX_BODY_SIZE};@g" /etc/nginx/conf.d/*.conf
fi
if [ "${USE_LB}" == "1" ]; then
sed -i 's@proxy_set_header X-Forwarded-For .*;@proxy_set_header X-Forwarded-For $remote_addr;@g' "${config_file}"
else
sed -i 's@proxy_set_header X-Forwarded-For .*;@proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;@g' "${config_file}"
fi
}
# helm-charts mount
# https://github.com/jumpserver/helm-charts/blob/main/charts/jumpserver/templates/web/deployment-nginx.yaml#L60
function config_helm() {
rm -f /etc/nginx/conf.d/*.conf
config_file=/etc/nginx/conf.d/jms.conf
cp -f /etc/nginx/sites-enabled/jms.conf "${config_file}"
config_nginx "${config_file}"
if [ -f "/etc/init.d/cron" ]; then
/etc/init.d/cron start
fi
}
# Installer mount
# https://github.com/jumpserver/installer/blob/dev/compose/docker-compose-lb.yml#L14
function config_http() {
config_file=/etc/nginx/conf.d/http_server.conf
if [ -f "${config_file}" ]; then
rm -f "${config_file}"
fi
cp -f /etc/nginx/sites-enabled/http_server.conf "${config_file}"
config_nginx "${config_file}"
}
function config_https() {
config_file=/etc/nginx/conf.d/https_server.conf
if [ -f "${config_file}" ]; then
rm -f "${config_file}"
fi
cp -f /etc/nginx/sites-enabled/https_server.conf "${config_file}"
config_nginx "${config_file}"
if [ -z "${HTTPS_PORT}" ]; then
HTTPS_PORT=443
fi
sed -i "s@server web:.*;@server localhost:51980;@g" "${config_file}"
if [ "${USE_IPV6}" == "1" ]; then
sed -i "s@# listen \[::\]:443@listen \[::\]:443@g" "${config_file}"
fi
if [ "${HTTPS_PORT}" != "443" ]; then
sed -i "s@listen 443@listen ${HTTPS_PORT}@g" "${config_file}"
sed -i "s@https://\$server_name\$request_uri;@https://\$server_name:${HTTPS_PORT}\$request_uri;@g" "${config_file}"
if [ "${USE_IPV6}" == "1" ]; then
sed -i "s@listen \[::\]:443@listen \[::\]:${HTTPS_PORT}@g" "${config_file}"
fi
fi
if [ -n "${SSL_CERTIFICATE}" ] && [ -f "/etc/nginx/cert/${SSL_CERTIFICATE}" ]; then
sed -i "s@ssl_certificate .*;@ssl_certificate cert/${SSL_CERTIFICATE};@g" "${config_file}"
fi
if [ -n "${SSL_CERTIFICATE_KEY}" ] && [ -f "/etc/nginx/cert/${SSL_CERTIFICATE_KEY}" ]; then
sed -i "s@ssl_certificate_key .*;@ssl_certificate_key cert/${SSL_CERTIFICATE_KEY};@g" "${config_file}"
fi
if [ -n "${CLIENT_MAX_BODY_SIZE}" ]; then
sed -i "s@client_max_body_size .*;@client_max_body_size ${CLIENT_MAX_BODY_SIZE};@g" "${config_file}"
fi
}
function safe_move() {
if [ -f "$1" ]; then
mv "$1" "$2"
fi
}
# config components
function config_components() {
if [ "${CORE_ENABLED}" == "0" ]; then
safe_move /etc/nginx/includes/core.conf /etc/nginx/includes/core.conf.disabled
fi
if [ "${KOKO_ENABLED}" == "0" ]; then
safe_move /etc/nginx/includes/koko.conf /etc/nginx/includes/koko.conf.disabled
fi
if [ "${LION_ENABLED}" == "0" ]; then
safe_move /etc/nginx/includes/lion.conf /etc/nginx/includes/lion.conf.disabled
fi
if [ "${CHEN_ENABLED}" == "0" ]; then
safe_move /etc/nginx/includes/chen.conf /etc/nginx/includes/chen.conf.disabled
fi
if [ "${FACELIVE_ENABLED}" == "0" ]; then
safe_move /etc/nginx/includes/facelive.conf /etc/nginx/includes/facelive.conf.disabled
fi
if [[ "${USE_XPACK}" == "1" && "${RAZOR_ENABLED}" != "0" ]]; then
safe_move /etc/nginx/includes/razor.conf.disabled /etc/nginx/includes/razor.conf
fi
if [[ "${USE_XPACK}" == "1" && "${FACELIVE_ENABLED}" == "1" ]]; then
safe_move /etc/nginx/includes/facelive.conf.disabled /etc/nginx/includes/facelive.conf
fi
}
function copy_versions_to_core() {
if [[ -f "/opt/download/versions.txt" && -d "/opt/jumpserver/data/" ]]; then
cp -f /opt/download/versions.txt /opt/jumpserver/data/version.txt
fi
}
function config_gzip() {
if [[ "${GZIP}" == "off" ]]; then
sed -i "s@gzip .*;@gzip ${GZIP};@g" /etc/nginx/nginx.conf
fi
}
function main() {
if [ -f "/etc/nginx/sites-enabled/jms.conf" ]; then
config_helm
exit 0
fi
if [ -f "/etc/nginx/sites-enabled/https_server.conf" ]; then
config_https
else
config_http
fi
config_components
if [ -f "/etc/init.d/cron" ]; then
/etc/init.d/cron start
fi
copy_versions_to_core
config_gzip
}
main