|
@@ -55,515 +55,525 @@ WEBSERVER_LOG_LEVEL='warn'
|
55
|
55
|
|
56
|
56
|
# test a domain name to see if it's valid
|
57
|
57
|
function validate_domain_name {
|
58
|
|
- # count the number of dots in the domain name
|
59
|
|
- dots=${TEST_DOMAIN_NAME//[^.]}
|
60
|
|
- no_of_dots=${#dots}
|
61
|
|
- if (( $no_of_dots > 3 )); then
|
62
|
|
- TEST_DOMAIN_NAME=$"The domain $TEST_DOMAIN_NAME has too many subdomains. It should be of the type w.x.y.z, x.y.z or y.z"
|
63
|
|
- fi
|
64
|
|
- if (( $no_of_dots == 0 )); then
|
65
|
|
- TEST_DOMAIN_NAME=$"The domain $TEST_DOMAIN_NAME has no top level domain. It should be of the type w.x.y.z, x.y.z or y.z"
|
66
|
|
- fi
|
|
58
|
+ # count the number of dots in the domain name
|
|
59
|
+ dots=${TEST_DOMAIN_NAME//[^.]}
|
|
60
|
+ no_of_dots=${#dots}
|
|
61
|
+ if (( $no_of_dots > 3 )); then
|
|
62
|
+ TEST_DOMAIN_NAME=$"The domain $TEST_DOMAIN_NAME has too many subdomains. It should be of the type w.x.y.z, x.y.z or y.z"
|
|
63
|
+ fi
|
|
64
|
+ if (( $no_of_dots == 0 )); then
|
|
65
|
+ TEST_DOMAIN_NAME=$"The domain $TEST_DOMAIN_NAME has no top level domain. It should be of the type w.x.y.z, x.y.z or y.z"
|
|
66
|
+ fi
|
67
|
67
|
}
|
68
|
68
|
|
69
|
69
|
function nginx_disable_sniffing {
|
70
|
|
- domain_name=$1
|
71
|
|
- filename=/etc/nginx/sites-available/$domain_name
|
72
|
|
- echo ' add_header X-Frame-Options DENY;' >> $filename
|
73
|
|
- echo ' add_header X-Content-Type-Options nosniff;' >> $filename
|
74
|
|
- echo '' >> $filename
|
|
70
|
+ domain_name=$1
|
|
71
|
+ filename=/etc/nginx/sites-available/$domain_name
|
|
72
|
+ echo ' add_header X-Frame-Options DENY;' >> $filename
|
|
73
|
+ echo ' add_header X-Content-Type-Options nosniff;' >> $filename
|
|
74
|
+ echo '' >> $filename
|
75
|
75
|
}
|
76
|
76
|
|
77
|
77
|
function nginx_limits {
|
78
|
|
- domain_name=$1
|
79
|
|
- max_body='20m'
|
80
|
|
- if [ $2 ]; then
|
81
|
|
- max_body=$2
|
82
|
|
- fi
|
83
|
|
- filename=/etc/nginx/sites-available/$domain_name
|
84
|
|
- echo " client_max_body_size ${max_body};" >> $filename
|
85
|
|
- echo ' client_body_buffer_size 128k;' >> $filename
|
86
|
|
- echo '' >> $filename
|
87
|
|
- echo ' limit_conn conn_limit_per_ip 10;' >> $filename
|
88
|
|
- echo ' limit_req zone=req_limit_per_ip burst=10 nodelay;' >> $filename
|
89
|
|
- echo '' >> $filename
|
|
78
|
+ domain_name=$1
|
|
79
|
+ max_body='20m'
|
|
80
|
+ if [ $2 ]; then
|
|
81
|
+ max_body=$2
|
|
82
|
+ fi
|
|
83
|
+ filename=/etc/nginx/sites-available/$domain_name
|
|
84
|
+ echo " client_max_body_size ${max_body};" >> $filename
|
|
85
|
+ echo ' client_body_buffer_size 128k;' >> $filename
|
|
86
|
+ echo '' >> $filename
|
|
87
|
+ echo ' limit_conn conn_limit_per_ip 10;' >> $filename
|
|
88
|
+ echo ' limit_req zone=req_limit_per_ip burst=10 nodelay;' >> $filename
|
|
89
|
+ echo '' >> $filename
|
|
90
|
+}
|
|
91
|
+
|
|
92
|
+function nginx_stapling {
|
|
93
|
+ domain_name=$1
|
|
94
|
+ filename=/etc/nginx/sites-available/$domain_name
|
|
95
|
+ echo " ssl_stapling on;" >> $filename
|
|
96
|
+ echo ' ssl_stapling_verify on;' >> $filename
|
|
97
|
+ echo ' ssl_trusted_certificate /etc/ssl/certs/${domain_name}.pem;' >> $filename
|
|
98
|
+ echo '' >> $filename
|
90
|
99
|
}
|
91
|
100
|
|
92
|
101
|
function nginx_http_redirect {
|
93
|
|
- # redirect port 80 to https
|
94
|
|
- domain_name=$1
|
95
|
|
- filename=/etc/nginx/sites-available/$domain_name
|
96
|
|
- echo 'server {' > $filename
|
97
|
|
- echo ' listen 80;' >> $filename
|
98
|
|
- echo ' listen [::]:80;' >> $filename
|
99
|
|
- echo " server_name ${domain_name};" >> $filename
|
100
|
|
- echo " root /var/www/${domain_name}/htdocs;" >> $filename
|
101
|
|
- echo ' access_log off;' >> $filename
|
102
|
|
- echo " error_log /var/log/nginx/${domain_name}_error.log $WEBSERVER_LOG_LEVEL;" >> $filename
|
103
|
|
- function_check nginx_limits
|
104
|
|
- nginx_limits $domain_name
|
105
|
|
- echo ' rewrite ^ https://$server_name$request_uri? permanent;' >> $filename
|
106
|
|
- echo '}' >> $filename
|
107
|
|
- echo '' >> $filename
|
|
102
|
+ # redirect port 80 to https
|
|
103
|
+ domain_name=$1
|
|
104
|
+ filename=/etc/nginx/sites-available/$domain_name
|
|
105
|
+ echo 'server {' > $filename
|
|
106
|
+ echo ' listen 80;' >> $filename
|
|
107
|
+ echo ' listen [::]:80;' >> $filename
|
|
108
|
+ echo " server_name ${domain_name};" >> $filename
|
|
109
|
+ echo " root /var/www/${domain_name}/htdocs;" >> $filename
|
|
110
|
+ echo ' access_log off;' >> $filename
|
|
111
|
+ echo " error_log /var/log/nginx/${domain_name}_error.log $WEBSERVER_LOG_LEVEL;" >> $filename
|
|
112
|
+ function_check nginx_limits
|
|
113
|
+ nginx_limits $domain_name
|
|
114
|
+ echo ' rewrite ^ https://$server_name$request_uri? permanent;' >> $filename
|
|
115
|
+ echo '}' >> $filename
|
|
116
|
+ echo '' >> $filename
|
108
|
117
|
}
|
109
|
118
|
|
110
|
119
|
function nginx_ssl {
|
111
|
|
- # creates the SSL/TLS section for a website
|
112
|
|
- domain_name=$1
|
113
|
|
- filename=/etc/nginx/sites-available/$domain_name
|
114
|
|
- echo ' ssl on;' >> $filename
|
115
|
|
- echo " ssl_certificate /etc/ssl/certs/${domain_name}.crt;" >> $filename
|
116
|
|
- echo " ssl_certificate_key /etc/ssl/private/${domain_name}.key;" >> $filename
|
117
|
|
- echo " ssl_dhparam /etc/ssl/certs/${domain_name}.dhparam;" >> $filename
|
118
|
|
- echo '' >> $filename
|
119
|
|
- echo ' ssl_session_timeout 60m;' >> $filename
|
120
|
|
- echo ' ssl_prefer_server_ciphers on;' >> $filename
|
121
|
|
- echo " ssl_protocols $SSL_PROTOCOLS;" >> $filename
|
122
|
|
- echo " ssl_ciphers '$SSL_CIPHERS';" >> $filename
|
|
120
|
+ # creates the SSL/TLS section for a website
|
|
121
|
+ domain_name=$1
|
|
122
|
+ filename=/etc/nginx/sites-available/$domain_name
|
|
123
|
+ echo ' ssl on;' >> $filename
|
|
124
|
+ echo " ssl_certificate /etc/ssl/certs/${domain_name}.crt;" >> $filename
|
|
125
|
+ echo " ssl_certificate_key /etc/ssl/private/${domain_name}.key;" >> $filename
|
|
126
|
+ echo " ssl_dhparam /etc/ssl/certs/${domain_name}.dhparam;" >> $filename
|
|
127
|
+ echo '' >> $filename
|
|
128
|
+ echo ' ssl_session_timeout 60m;' >> $filename
|
|
129
|
+ echo ' ssl_prefer_server_ciphers on;' >> $filename
|
|
130
|
+ echo " ssl_protocols $SSL_PROTOCOLS;" >> $filename
|
|
131
|
+ echo " ssl_ciphers '$SSL_CIPHERS';" >> $filename
|
|
132
|
+ nginx_stapling $1
|
123
|
133
|
}
|
124
|
134
|
|
125
|
135
|
# check an individual domain name
|
126
|
136
|
function test_domain_name {
|
127
|
|
- if [ $1 ]; then
|
128
|
|
- TEST_DOMAIN_NAME=$1
|
129
|
|
- function_check validate_domain_name
|
130
|
|
- validate_domain_name
|
131
|
|
- if [[ $TEST_DOMAIN_NAME != $1 ]]; then
|
132
|
|
- echo $TEST_DOMAIN_NAME
|
133
|
|
- exit 8528
|
134
|
|
- fi
|
135
|
|
- fi
|
|
137
|
+ if [ $1 ]; then
|
|
138
|
+ TEST_DOMAIN_NAME=$1
|
|
139
|
+ function_check validate_domain_name
|
|
140
|
+ validate_domain_name
|
|
141
|
+ if [[ $TEST_DOMAIN_NAME != $1 ]]; then
|
|
142
|
+ echo $TEST_DOMAIN_NAME
|
|
143
|
+ exit 8528
|
|
144
|
+ fi
|
|
145
|
+ fi
|
136
|
146
|
}
|
137
|
147
|
|
138
|
148
|
# Checks whether certificates were generated for the given hostname
|
139
|
149
|
function check_certificates {
|
140
|
|
- if [ ! $1 ]; then
|
141
|
|
- return
|
142
|
|
- fi
|
143
|
|
- USE_LETSENCRYPT='no'
|
144
|
|
- if [ $2 ]; then
|
145
|
|
- USE_LETSENCRYPT=$2
|
146
|
|
- fi
|
147
|
|
- if [[ $USE_LETSENCRYPT == 'no' ]]; then
|
148
|
|
- if [ ! -f /etc/ssl/private/$1.key ]; then
|
149
|
|
- echo $"Private certificate for $CHECK_HOSTNAME was not created"
|
150
|
|
- exit 63959
|
151
|
|
- fi
|
152
|
|
- if [ ! -f /etc/ssl/certs/$1.crt ]; then
|
153
|
|
- echo $"Public certificate for $CHECK_HOSTNAME was not created"
|
154
|
|
- exit 7679
|
155
|
|
- fi
|
156
|
|
- else
|
157
|
|
- if [ ! -f /etc/letsencrypt/live/${1}/privkey.pem ]; then
|
158
|
|
- echo $"Private certificate for $CHECK_HOSTNAME was not created"
|
159
|
|
- exit 6282
|
160
|
|
- fi
|
161
|
|
- if [ ! -f /etc/letsencrypt/live/${1}/fullchain.pem ]; then
|
162
|
|
- echo $"Public certificate for $CHECK_HOSTNAME was not created"
|
163
|
|
- exit 5328
|
164
|
|
- fi
|
165
|
|
- fi
|
166
|
|
- if [ ! -f /etc/ssl/certs/$1.dhparam ]; then
|
167
|
|
- echo $"Diffie–Hellman parameters for $CHECK_HOSTNAME were not created"
|
168
|
|
- exit 5989
|
169
|
|
- fi
|
|
150
|
+ if [ ! $1 ]; then
|
|
151
|
+ return
|
|
152
|
+ fi
|
|
153
|
+ USE_LETSENCRYPT='no'
|
|
154
|
+ if [ $2 ]; then
|
|
155
|
+ USE_LETSENCRYPT=$2
|
|
156
|
+ fi
|
|
157
|
+ if [[ $USE_LETSENCRYPT == 'no' ]]; then
|
|
158
|
+ if [ ! -f /etc/ssl/private/$1.key ]; then
|
|
159
|
+ echo $"Private certificate for $CHECK_HOSTNAME was not created"
|
|
160
|
+ exit 63959
|
|
161
|
+ fi
|
|
162
|
+ if [ ! -f /etc/ssl/certs/$1.crt ]; then
|
|
163
|
+ echo $"Public certificate for $CHECK_HOSTNAME was not created"
|
|
164
|
+ exit 7679
|
|
165
|
+ fi
|
|
166
|
+ else
|
|
167
|
+ if [ ! -f /etc/letsencrypt/live/${1}/privkey.pem ]; then
|
|
168
|
+ echo $"Private certificate for $CHECK_HOSTNAME was not created"
|
|
169
|
+ exit 6282
|
|
170
|
+ fi
|
|
171
|
+ if [ ! -f /etc/letsencrypt/live/${1}/fullchain.pem ]; then
|
|
172
|
+ echo $"Public certificate for $CHECK_HOSTNAME was not created"
|
|
173
|
+ exit 5328
|
|
174
|
+ fi
|
|
175
|
+ fi
|
|
176
|
+ if [ ! -f /etc/ssl/certs/$1.dhparam ]; then
|
|
177
|
+ echo $"Diffie–Hellman parameters for $CHECK_HOSTNAME were not created"
|
|
178
|
+ exit 5989
|
|
179
|
+ fi
|
170
|
180
|
}
|
171
|
181
|
|
172
|
182
|
function create_site_certificate {
|
173
|
|
- SITE_DOMAIN_NAME="$1"
|
174
|
|
-
|
175
|
|
- # if yes then only "valid" certs are allowed, not self-signed
|
176
|
|
- NO_SELF_SIGNED='no'
|
177
|
|
- if [ $2 ]; then
|
178
|
|
- NO_SELF_SIGNED="$2"
|
179
|
|
- fi
|
180
|
|
-
|
181
|
|
- if [[ $ONION_ONLY == "no" ]]; then
|
182
|
|
- if [ ! -f /etc/ssl/certs/$SITE_DOMAIN_NAME.dhparam ]; then
|
183
|
|
- if [[ $LETSENCRYPT_ENABLED != "yes" ]]; then
|
184
|
|
- ${PROJECT_NAME}-addcert -h $SITE_DOMAIN_NAME --dhkey $DH_KEYLENGTH
|
185
|
|
- function_check check_certificates
|
186
|
|
- check_certificates $SITE_DOMAIN_NAME
|
187
|
|
- else
|
188
|
|
- ${PROJECT_NAME}-addcert -e $SITE_DOMAIN_NAME -s $LETSENCRYPT_SERVER --dhkey $DH_KEYLENGTH --email $MY_EMAIL_ADDRESS
|
189
|
|
- if [ ! "$?" = "0" ]; then
|
190
|
|
- if [[ $NO_SELF_SIGNED == 'no' ]]; then
|
191
|
|
- echo $"Lets Encrypt failed for $SITE_DOMAIN_NAME, so try making a self-signed cert"
|
192
|
|
- ${PROJECT_NAME}-addcert -h $SITE_DOMAIN_NAME --dhkey $DH_KEYLENGTH
|
193
|
|
- function_check check_certificates
|
194
|
|
- check_certificates $SITE_DOMAIN_NAME
|
195
|
|
- else
|
196
|
|
- echo $"Lets Encrypt failed for $SITE_DOMAIN_NAME"
|
197
|
|
- exit 682529
|
198
|
|
- fi
|
199
|
|
- else
|
200
|
|
- function_check check_certificates
|
201
|
|
- check_certificates $SITE_DOMAIN_NAME 'yes'
|
202
|
|
- fi
|
203
|
|
- fi
|
204
|
|
- fi
|
205
|
|
- fi
|
|
183
|
+ SITE_DOMAIN_NAME="$1"
|
|
184
|
+
|
|
185
|
+ # if yes then only "valid" certs are allowed, not self-signed
|
|
186
|
+ NO_SELF_SIGNED='no'
|
|
187
|
+ if [ $2 ]; then
|
|
188
|
+ NO_SELF_SIGNED="$2"
|
|
189
|
+ fi
|
|
190
|
+
|
|
191
|
+ if [[ $ONION_ONLY == "no" ]]; then
|
|
192
|
+ if [ ! -f /etc/ssl/certs/$SITE_DOMAIN_NAME.dhparam ]; then
|
|
193
|
+ if [[ $LETSENCRYPT_ENABLED != "yes" ]]; then
|
|
194
|
+ ${PROJECT_NAME}-addcert -h $SITE_DOMAIN_NAME --dhkey $DH_KEYLENGTH
|
|
195
|
+ function_check check_certificates
|
|
196
|
+ check_certificates $SITE_DOMAIN_NAME
|
|
197
|
+ else
|
|
198
|
+ ${PROJECT_NAME}-addcert -e $SITE_DOMAIN_NAME -s $LETSENCRYPT_SERVER --dhkey $DH_KEYLENGTH --email $MY_EMAIL_ADDRESS
|
|
199
|
+ if [ ! "$?" = "0" ]; then
|
|
200
|
+ if [[ $NO_SELF_SIGNED == 'no' ]]; then
|
|
201
|
+ echo $"Lets Encrypt failed for $SITE_DOMAIN_NAME, so try making a self-signed cert"
|
|
202
|
+ ${PROJECT_NAME}-addcert -h $SITE_DOMAIN_NAME --dhkey $DH_KEYLENGTH
|
|
203
|
+ function_check check_certificates
|
|
204
|
+ check_certificates $SITE_DOMAIN_NAME
|
|
205
|
+ else
|
|
206
|
+ echo $"Lets Encrypt failed for $SITE_DOMAIN_NAME"
|
|
207
|
+ exit 682529
|
|
208
|
+ fi
|
|
209
|
+ else
|
|
210
|
+ function_check check_certificates
|
|
211
|
+ check_certificates $SITE_DOMAIN_NAME 'yes'
|
|
212
|
+ fi
|
|
213
|
+ fi
|
|
214
|
+ fi
|
|
215
|
+ fi
|
206
|
216
|
}
|
207
|
217
|
|
208
|
218
|
# script to automatically renew any Let's Encrypt certificates
|
209
|
219
|
function letsencrypt_renewals {
|
210
|
|
- if [[ $ONION_ONLY != "no" ]]; then
|
211
|
|
- return
|
212
|
|
- fi
|
213
|
|
-
|
214
|
|
- renewals_script=/etc/cron.monthly/letsencrypt
|
215
|
|
- renewals_retry_script=/etc/cron.daily/letsencrypt
|
216
|
|
- renewal_failure_msg=$'The certificate for $LETSENCRYPT_DOMAIN could not be renewed'
|
217
|
|
- renewal_email_title=$'${PROJECT_NAME} Lets Encrypt certificate renewal'
|
218
|
|
-
|
219
|
|
- # the main script tries to renew once per month
|
220
|
|
- echo '#!/bin/bash' > $renewals_script
|
221
|
|
- echo '' >> $renewals_script
|
222
|
|
- echo "PROJECT_NAME='${PROJECT_NAME}'" >> $renewals_script
|
223
|
|
- echo 'COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt' >> $renewals_script
|
224
|
|
- echo '' >> $renewals_script
|
225
|
|
- echo 'if [ -d /etc/letsencrypt ]; then' >> $renewals_script
|
226
|
|
- echo ' if [ -f ~/letsencrypt_failed ]; then' >> $renewals_script
|
227
|
|
- echo ' rm ~/letsencrypt_failed' >> $renewals_script
|
228
|
|
- echo ' fi' >> $renewals_script
|
229
|
|
- echo -n ' ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | ' >> $renewals_script
|
230
|
|
- echo -n "awk -F ':' '{print " >> $renewals_script
|
231
|
|
- echo -n '$2' >> $renewals_script
|
232
|
|
- echo "}')" >> $renewals_script
|
233
|
|
- echo ' ADMIN_EMAIL_ADDRESS=$ADMIN_USERNAME@$HOSTNAME' >> $renewals_script
|
234
|
|
- echo ' for d in /etc/letsencrypt/live/*/ ; do' >> $renewals_script
|
235
|
|
- echo -n ' LETSENCRYPT_DOMAIN=$(echo "$d" | ' >> $renewals_script
|
236
|
|
- echo -n "awk -F '/' '{print " >> $renewals_script
|
237
|
|
- echo -n '$5' >> $renewals_script
|
238
|
|
- echo "}')" >> $renewals_script
|
239
|
|
- echo ' if [ -f /etc/nginx/sites-available/$LETSENCRYPT_DOMAIN ]; then' >> $renewals_script
|
240
|
|
- echo ' ${PROJECT_NAME}-renew-cert -h $LETSENCRYPT_DOMAIN -p letsencrypt' >> $renewals_script
|
241
|
|
- echo ' if [ ! "$?" = "0" ]; then' >> $renewals_script
|
242
|
|
- echo " echo \"${renewal_failure_msg}\" > ~/temp_renewletsencrypt.txt" >> $renewals_script
|
243
|
|
- echo ' echo "" >> ~/temp_renewletsencrypt.txt' >> $renewals_script
|
244
|
|
- echo ' ${PROJECT_NAME}-renew-cert -h $LETSENCRYPT_DOMAIN -p letsencrypt 2>> ~/temp_renewletsencrypt.txt' >> $renewals_script
|
245
|
|
- echo -n " cat ~/temp_renewletsencrypt.txt | mail -s \"${renewal_email_title}\" " >> $renewals_script
|
246
|
|
- echo '$ADMIN_EMAIL_ADDRESS' >> $renewals_script
|
247
|
|
- echo ' rm ~/temp_renewletsencrypt.txt' >> $renewals_script
|
248
|
|
- echo ' if [ ! -f ~/letsencrypt_failed ]; then' >> $renewals_script
|
249
|
|
- echo ' touch ~/letsencrypt_failed' >> $renewals_script
|
250
|
|
- echo ' fi' >> $renewals_script
|
251
|
|
- echo ' fi' >> $renewals_script
|
252
|
|
- echo ' fi' >> $renewals_script
|
253
|
|
- echo ' done' >> $renewals_script
|
254
|
|
- echo 'fi' >> $renewals_script
|
255
|
|
- chmod +x $renewals_script
|
256
|
|
-
|
257
|
|
- # a secondary script keeps trying to renew after a failure
|
258
|
|
- echo '#!/bin/bash' > $renewals_retry_script
|
259
|
|
- echo '' >> $renewals_retry_script
|
260
|
|
- echo "PROJECT_NAME='${PROJECT_NAME}'" >> $renewals_retry_script
|
261
|
|
- echo 'COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt' >> $renewals_retry_script
|
262
|
|
- echo '' >> $renewals_retry_script
|
263
|
|
- echo 'if [ -d /etc/letsencrypt ]; then' >> $renewals_retry_script
|
264
|
|
- echo ' if [ -f ~/letsencrypt_failed ]; then' >> $renewals_retry_script
|
265
|
|
- echo ' rm ~/letsencrypt_failed' >> $renewals_retry_script
|
266
|
|
- echo -n ' ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | ' >> $renewals_retry_script
|
267
|
|
- echo -n "awk -F ':' '{print " >> $renewals_retry_script
|
268
|
|
- echo -n '$2' >> $renewals_retry_script
|
269
|
|
- echo "}')" >> $renewals_retry_script
|
270
|
|
- echo ' ADMIN_EMAIL_ADDRESS=$ADMIN_USERNAME@$HOSTNAME' >> $renewals_retry_script
|
271
|
|
- echo ' for d in /etc/letsencrypt/live/*/ ; do' >> $renewals_retry_script
|
272
|
|
- echo -n ' LETSENCRYPT_DOMAIN=$(echo "$d" | ' >> $renewals_retry_script
|
273
|
|
- echo -n "awk -F '/' '{print " >> $renewals_retry_script
|
274
|
|
- echo -n '$5' >> $renewals_retry_script
|
275
|
|
- echo "}')" >> $renewals_retry_script
|
276
|
|
- echo ' if [ -f /etc/nginx/sites-available/$LETSENCRYPT_DOMAIN ]; then' >> $renewals_retry_script
|
277
|
|
- echo ' ${PROJECT_NAME}-renew-cert -h $LETSENCRYPT_DOMAIN -p letsencrypt' >> $renewals_retry_script
|
278
|
|
- echo ' if [ ! "$?" = "0" ]; then' >> $renewals_retry_script
|
279
|
|
- echo " echo \"${renewal_failure_msg}\" > ~/temp_renewletsencrypt.txt" >> $renewals_retry_script
|
280
|
|
- echo ' echo "" >> ~/temp_renewletsencrypt.txt' >> $renewals_retry_script
|
281
|
|
- echo ' ${PROJECT_NAME}-renew-cert -h $LETSENCRYPT_DOMAIN -p letsencrypt 2>> ~/temp_renewletsencrypt.txt' >> $renewals_retry_script
|
282
|
|
- echo -n " cat ~/temp_renewletsencrypt.txt | mail -s \"${renewal_email_title}\" " >> $renewals_retry_script
|
283
|
|
- echo '$ADMIN_EMAIL_ADDRESS' >> $renewals_retry_script
|
284
|
|
- echo ' rm ~/temp_renewletsencrypt.txt' >> $renewals_retry_script
|
285
|
|
- echo ' if [ ! -f ~/letsencrypt_failed ]; then' >> $renewals_retry_script
|
286
|
|
- echo ' touch ~/letsencrypt_failed' >> $renewals_retry_script
|
287
|
|
- echo ' fi' >> $renewals_retry_script
|
288
|
|
- echo ' fi' >> $renewals_retry_script
|
289
|
|
- echo ' fi' >> $renewals_retry_script
|
290
|
|
- echo ' done' >> $renewals_retry_script
|
291
|
|
- echo ' fi' >> $renewals_retry_script
|
292
|
|
- echo 'fi' >> $renewals_retry_script
|
293
|
|
- chmod +x $renewals_retry_script
|
|
220
|
+ if [[ $ONION_ONLY != "no" ]]; then
|
|
221
|
+ return
|
|
222
|
+ fi
|
|
223
|
+
|
|
224
|
+ renewals_script=/etc/cron.monthly/letsencrypt
|
|
225
|
+ renewals_retry_script=/etc/cron.daily/letsencrypt
|
|
226
|
+ renewal_failure_msg=$'The certificate for $LETSENCRYPT_DOMAIN could not be renewed'
|
|
227
|
+ renewal_email_title=$'${PROJECT_NAME} Lets Encrypt certificate renewal'
|
|
228
|
+
|
|
229
|
+ # the main script tries to renew once per month
|
|
230
|
+ echo '#!/bin/bash' > $renewals_script
|
|
231
|
+ echo '' >> $renewals_script
|
|
232
|
+ echo "PROJECT_NAME='${PROJECT_NAME}'" >> $renewals_script
|
|
233
|
+ echo 'COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt' >> $renewals_script
|
|
234
|
+ echo '' >> $renewals_script
|
|
235
|
+ echo 'if [ -d /etc/letsencrypt ]; then' >> $renewals_script
|
|
236
|
+ echo ' if [ -f ~/letsencrypt_failed ]; then' >> $renewals_script
|
|
237
|
+ echo ' rm ~/letsencrypt_failed' >> $renewals_script
|
|
238
|
+ echo ' fi' >> $renewals_script
|
|
239
|
+ echo -n ' ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | ' >> $renewals_script
|
|
240
|
+ echo -n "awk -F ':' '{print " >> $renewals_script
|
|
241
|
+ echo -n '$2' >> $renewals_script
|
|
242
|
+ echo "}')" >> $renewals_script
|
|
243
|
+ echo ' ADMIN_EMAIL_ADDRESS=$ADMIN_USERNAME@$HOSTNAME' >> $renewals_script
|
|
244
|
+ echo ' for d in /etc/letsencrypt/live/*/ ; do' >> $renewals_script
|
|
245
|
+ echo -n ' LETSENCRYPT_DOMAIN=$(echo "$d" | ' >> $renewals_script
|
|
246
|
+ echo -n "awk -F '/' '{print " >> $renewals_script
|
|
247
|
+ echo -n '$5' >> $renewals_script
|
|
248
|
+ echo "}')" >> $renewals_script
|
|
249
|
+ echo ' if [ -f /etc/nginx/sites-available/$LETSENCRYPT_DOMAIN ]; then' >> $renewals_script
|
|
250
|
+ echo ' ${PROJECT_NAME}-renew-cert -h $LETSENCRYPT_DOMAIN -p letsencrypt' >> $renewals_script
|
|
251
|
+ echo ' if [ ! "$?" = "0" ]; then' >> $renewals_script
|
|
252
|
+ echo " echo \"${renewal_failure_msg}\" > ~/temp_renewletsencrypt.txt" >> $renewals_script
|
|
253
|
+ echo ' echo "" >> ~/temp_renewletsencrypt.txt' >> $renewals_script
|
|
254
|
+ echo ' ${PROJECT_NAME}-renew-cert -h $LETSENCRYPT_DOMAIN -p letsencrypt 2>> ~/temp_renewletsencrypt.txt' >> $renewals_script
|
|
255
|
+ echo -n " cat ~/temp_renewletsencrypt.txt | mail -s \"${renewal_email_title}\" " >> $renewals_script
|
|
256
|
+ echo '$ADMIN_EMAIL_ADDRESS' >> $renewals_script
|
|
257
|
+ echo ' rm ~/temp_renewletsencrypt.txt' >> $renewals_script
|
|
258
|
+ echo ' if [ ! -f ~/letsencrypt_failed ]; then' >> $renewals_script
|
|
259
|
+ echo ' touch ~/letsencrypt_failed' >> $renewals_script
|
|
260
|
+ echo ' fi' >> $renewals_script
|
|
261
|
+ echo ' fi' >> $renewals_script
|
|
262
|
+ echo ' fi' >> $renewals_script
|
|
263
|
+ echo ' done' >> $renewals_script
|
|
264
|
+ echo 'fi' >> $renewals_script
|
|
265
|
+ chmod +x $renewals_script
|
|
266
|
+
|
|
267
|
+ # a secondary script keeps trying to renew after a failure
|
|
268
|
+ echo '#!/bin/bash' > $renewals_retry_script
|
|
269
|
+ echo '' >> $renewals_retry_script
|
|
270
|
+ echo "PROJECT_NAME='${PROJECT_NAME}'" >> $renewals_retry_script
|
|
271
|
+ echo 'COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt' >> $renewals_retry_script
|
|
272
|
+ echo '' >> $renewals_retry_script
|
|
273
|
+ echo 'if [ -d /etc/letsencrypt ]; then' >> $renewals_retry_script
|
|
274
|
+ echo ' if [ -f ~/letsencrypt_failed ]; then' >> $renewals_retry_script
|
|
275
|
+ echo ' rm ~/letsencrypt_failed' >> $renewals_retry_script
|
|
276
|
+ echo -n ' ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | ' >> $renewals_retry_script
|
|
277
|
+ echo -n "awk -F ':' '{print " >> $renewals_retry_script
|
|
278
|
+ echo -n '$2' >> $renewals_retry_script
|
|
279
|
+ echo "}')" >> $renewals_retry_script
|
|
280
|
+ echo ' ADMIN_EMAIL_ADDRESS=$ADMIN_USERNAME@$HOSTNAME' >> $renewals_retry_script
|
|
281
|
+ echo ' for d in /etc/letsencrypt/live/*/ ; do' >> $renewals_retry_script
|
|
282
|
+ echo -n ' LETSENCRYPT_DOMAIN=$(echo "$d" | ' >> $renewals_retry_script
|
|
283
|
+ echo -n "awk -F '/' '{print " >> $renewals_retry_script
|
|
284
|
+ echo -n '$5' >> $renewals_retry_script
|
|
285
|
+ echo "}')" >> $renewals_retry_script
|
|
286
|
+ echo ' if [ -f /etc/nginx/sites-available/$LETSENCRYPT_DOMAIN ]; then' >> $renewals_retry_script
|
|
287
|
+ echo ' ${PROJECT_NAME}-renew-cert -h $LETSENCRYPT_DOMAIN -p letsencrypt' >> $renewals_retry_script
|
|
288
|
+ echo ' if [ ! "$?" = "0" ]; then' >> $renewals_retry_script
|
|
289
|
+ echo " echo \"${renewal_failure_msg}\" > ~/temp_renewletsencrypt.txt" >> $renewals_retry_script
|
|
290
|
+ echo ' echo "" >> ~/temp_renewletsencrypt.txt' >> $renewals_retry_script
|
|
291
|
+ echo ' ${PROJECT_NAME}-renew-cert -h $LETSENCRYPT_DOMAIN -p letsencrypt 2>> ~/temp_renewletsencrypt.txt' >> $renewals_retry_script
|
|
292
|
+ echo -n " cat ~/temp_renewletsencrypt.txt | mail -s \"${renewal_email_title}\" " >> $renewals_retry_script
|
|
293
|
+ echo '$ADMIN_EMAIL_ADDRESS' >> $renewals_retry_script
|
|
294
|
+ echo ' rm ~/temp_renewletsencrypt.txt' >> $renewals_retry_script
|
|
295
|
+ echo ' if [ ! -f ~/letsencrypt_failed ]; then' >> $renewals_retry_script
|
|
296
|
+ echo ' touch ~/letsencrypt_failed' >> $renewals_retry_script
|
|
297
|
+ echo ' fi' >> $renewals_retry_script
|
|
298
|
+ echo ' fi' >> $renewals_retry_script
|
|
299
|
+ echo ' fi' >> $renewals_retry_script
|
|
300
|
+ echo ' done' >> $renewals_retry_script
|
|
301
|
+ echo ' fi' >> $renewals_retry_script
|
|
302
|
+ echo 'fi' >> $renewals_retry_script
|
|
303
|
+ chmod +x $renewals_retry_script
|
294
|
304
|
}
|
295
|
305
|
|
296
|
306
|
function configure_php {
|
297
|
|
- sed -i "s/memory_limit = 128M/memory_limit = ${MAX_PHP_MEMORY}M/g" /etc/php5/fpm/php.ini
|
298
|
|
- sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php5/fpm/php.ini
|
299
|
|
- sed -i "s/memory_limit = -1/memory_limit = ${MAX_PHP_MEMORY}M/g" /etc/php5/cli/php.ini
|
300
|
|
- sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 50M/g" /etc/php5/fpm/php.ini
|
301
|
|
- sed -i "s/post_max_size = 8M/post_max_size = 50M/g" /etc/php5/fpm/php.ini
|
|
307
|
+ sed -i "s/memory_limit = 128M/memory_limit = ${MAX_PHP_MEMORY}M/g" /etc/php5/fpm/php.ini
|
|
308
|
+ sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php5/fpm/php.ini
|
|
309
|
+ sed -i "s/memory_limit = -1/memory_limit = ${MAX_PHP_MEMORY}M/g" /etc/php5/cli/php.ini
|
|
310
|
+ sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 50M/g" /etc/php5/fpm/php.ini
|
|
311
|
+ sed -i "s/post_max_size = 8M/post_max_size = 50M/g" /etc/php5/fpm/php.ini
|
302
|
312
|
}
|
303
|
313
|
|
304
|
314
|
function install_web_server_access_control {
|
305
|
|
- if [ ! -f /etc/pam.d/nginx ]; then
|
306
|
|
- echo '#%PAM-1.0' > /etc/pam.d/nginx
|
307
|
|
- echo '@include common-auth' >> /etc/pam.d/nginx
|
308
|
|
- echo '@include common-account' >> /etc/pam.d/nginx
|
309
|
|
- echo '@include common-session' >> /etc/pam.d/nginx
|
310
|
|
- fi
|
|
315
|
+ if [ ! -f /etc/pam.d/nginx ]; then
|
|
316
|
+ echo '#%PAM-1.0' > /etc/pam.d/nginx
|
|
317
|
+ echo '@include common-auth' >> /etc/pam.d/nginx
|
|
318
|
+ echo '@include common-account' >> /etc/pam.d/nginx
|
|
319
|
+ echo '@include common-session' >> /etc/pam.d/nginx
|
|
320
|
+ fi
|
311
|
321
|
}
|
312
|
322
|
|
313
|
323
|
function install_dynamicdns {
|
314
|
|
- if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
|
315
|
|
- return
|
316
|
|
- fi
|
317
|
|
- if [[ $ONION_ONLY != "no" ]]; then
|
318
|
|
- return
|
319
|
|
- fi
|
320
|
|
-
|
321
|
|
- # update to the next commit
|
322
|
|
- function_check set_repo_commit
|
323
|
|
- set_repo_commit $INSTALL_DIR/inadyn "inadyn commit" "$INADYN_COMMIT" $INADYN_REPO
|
324
|
|
-
|
325
|
|
- if grep -Fxq "install_dynamicdns" $COMPLETION_FILE; then
|
326
|
|
- return
|
327
|
|
- fi
|
328
|
|
-
|
329
|
|
- # Here we compile from source because the current package
|
330
|
|
- # doesn't support https, which could result in passwords
|
331
|
|
- # being leaked
|
332
|
|
- # Debian version 1.99.4-1
|
333
|
|
- # https version 1.99.8
|
334
|
|
-
|
335
|
|
- apt-get -y install build-essential curl libgnutls28-dev automake1.11
|
336
|
|
- if [ ! -d $INSTALL_DIR/inadyn ]; then
|
337
|
|
- git_clone $INADYN_REPO $INSTALL_DIR/inadyn
|
338
|
|
- fi
|
339
|
|
- if [ ! -d $INSTALL_DIR/inadyn ]; then
|
340
|
|
- echo 'inadyn repo not cloned'
|
341
|
|
- echo -n | openssl s_client -showcerts -connect github.com:443 -CApath /etc/ssl/certs
|
342
|
|
- exit 6785
|
343
|
|
- fi
|
344
|
|
- cd $INSTALL_DIR/inadyn
|
345
|
|
- git checkout $INADYN_COMMIT -b $INADYN_COMMIT
|
346
|
|
- if ! grep -q "inadyn commit" $COMPLETION_FILE; then
|
347
|
|
- echo "inadyn commit:$INADYN_COMMIT" >> $COMPLETION_FILE
|
348
|
|
- else
|
349
|
|
- sed -i "s/inadyn commit.*/inadyn commit:$INADYN_COMMIT/g" $COMPLETION_FILE
|
350
|
|
- fi
|
351
|
|
-
|
352
|
|
- ./configure
|
353
|
|
- if [ ! "$?" = "0" ]; then
|
354
|
|
- exit 74890
|
355
|
|
- fi
|
356
|
|
- USE_OPENSSL=1 make
|
357
|
|
- if [ ! "$?" = "0" ]; then
|
358
|
|
- exit 74858
|
359
|
|
- fi
|
360
|
|
- make install
|
361
|
|
- if [ ! "$?" = "0" ]; then
|
362
|
|
- exit 3785
|
363
|
|
- fi
|
364
|
|
-
|
365
|
|
- # create an unprivileged user
|
366
|
|
- #useradd -r -s /bin/false debian-inadyn
|
367
|
|
-
|
368
|
|
- # create a configuration file
|
369
|
|
- echo 'background' > /etc/inadyn.conf
|
370
|
|
- echo 'verbose 1' >> /etc/inadyn.conf
|
371
|
|
- echo 'period 300' >> /etc/inadyn.conf
|
372
|
|
- echo 'startup-delay 60' >> /etc/inadyn.conf
|
373
|
|
- echo 'cache-dir /run/inadyn' >> /etc/inadyn.conf
|
374
|
|
- echo 'logfile /dev/null' >> /etc/inadyn.conf
|
375
|
|
- chmod 600 /etc/inadyn.conf
|
376
|
|
-
|
377
|
|
- echo '[Unit]' > /etc/systemd/system/inadyn.service
|
378
|
|
- echo 'Description=inadyn (DynDNS updater)' >> /etc/systemd/system/inadyn.service
|
379
|
|
- echo 'After=network.target' >> /etc/systemd/system/inadyn.service
|
380
|
|
- echo '' >> /etc/systemd/system/inadyn.service
|
381
|
|
- echo '[Service]' >> /etc/systemd/system/inadyn.service
|
382
|
|
- echo 'ExecStart=/usr/local/sbin/inadyn --config /etc/inadyn.conf' >> /etc/systemd/system/inadyn.service
|
383
|
|
- echo 'Restart=always' >> /etc/systemd/system/inadyn.service
|
384
|
|
- echo 'Type=forking' >> /etc/systemd/system/inadyn.service
|
385
|
|
- echo '' >> /etc/systemd/system/inadyn.service
|
386
|
|
- echo '[Install]' >> /etc/systemd/system/inadyn.service
|
387
|
|
- echo 'WantedBy=multi-user.target' >> /etc/systemd/system/inadyn.service
|
388
|
|
- systemctl enable inadyn
|
389
|
|
- systemctl start inadyn
|
390
|
|
- systemctl daemon-reload
|
391
|
|
-
|
392
|
|
- echo 'install_dynamicdns' >> $COMPLETION_FILE
|
|
324
|
+ if [[ $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
|
|
325
|
+ return
|
|
326
|
+ fi
|
|
327
|
+ if [[ $ONION_ONLY != "no" ]]; then
|
|
328
|
+ return
|
|
329
|
+ fi
|
|
330
|
+
|
|
331
|
+ # update to the next commit
|
|
332
|
+ function_check set_repo_commit
|
|
333
|
+ set_repo_commit $INSTALL_DIR/inadyn "inadyn commit" "$INADYN_COMMIT" $INADYN_REPO
|
|
334
|
+
|
|
335
|
+ if grep -Fxq "install_dynamicdns" $COMPLETION_FILE; then
|
|
336
|
+ return
|
|
337
|
+ fi
|
|
338
|
+
|
|
339
|
+ # Here we compile from source because the current package
|
|
340
|
+ # doesn't support https, which could result in passwords
|
|
341
|
+ # being leaked
|
|
342
|
+ # Debian version 1.99.4-1
|
|
343
|
+ # https version 1.99.8
|
|
344
|
+
|
|
345
|
+ apt-get -y install build-essential curl libgnutls28-dev automake1.11
|
|
346
|
+ if [ ! -d $INSTALL_DIR/inadyn ]; then
|
|
347
|
+ git_clone $INADYN_REPO $INSTALL_DIR/inadyn
|
|
348
|
+ fi
|
|
349
|
+ if [ ! -d $INSTALL_DIR/inadyn ]; then
|
|
350
|
+ echo 'inadyn repo not cloned'
|
|
351
|
+ echo -n | openssl s_client -showcerts -connect github.com:443 -CApath /etc/ssl/certs
|
|
352
|
+ exit 6785
|
|
353
|
+ fi
|
|
354
|
+ cd $INSTALL_DIR/inadyn
|
|
355
|
+ git checkout $INADYN_COMMIT -b $INADYN_COMMIT
|
|
356
|
+ if ! grep -q "inadyn commit" $COMPLETION_FILE; then
|
|
357
|
+ echo "inadyn commit:$INADYN_COMMIT" >> $COMPLETION_FILE
|
|
358
|
+ else
|
|
359
|
+ sed -i "s/inadyn commit.*/inadyn commit:$INADYN_COMMIT/g" $COMPLETION_FILE
|
|
360
|
+ fi
|
|
361
|
+
|
|
362
|
+ ./configure
|
|
363
|
+ if [ ! "$?" = "0" ]; then
|
|
364
|
+ exit 74890
|
|
365
|
+ fi
|
|
366
|
+ USE_OPENSSL=1 make
|
|
367
|
+ if [ ! "$?" = "0" ]; then
|
|
368
|
+ exit 74858
|
|
369
|
+ fi
|
|
370
|
+ make install
|
|
371
|
+ if [ ! "$?" = "0" ]; then
|
|
372
|
+ exit 3785
|
|
373
|
+ fi
|
|
374
|
+
|
|
375
|
+ # create an unprivileged user
|
|
376
|
+ #useradd -r -s /bin/false debian-inadyn
|
|
377
|
+
|
|
378
|
+ # create a configuration file
|
|
379
|
+ echo 'background' > /etc/inadyn.conf
|
|
380
|
+ echo 'verbose 1' >> /etc/inadyn.conf
|
|
381
|
+ echo 'period 300' >> /etc/inadyn.conf
|
|
382
|
+ echo 'startup-delay 60' >> /etc/inadyn.conf
|
|
383
|
+ echo 'cache-dir /run/inadyn' >> /etc/inadyn.conf
|
|
384
|
+ echo 'logfile /dev/null' >> /etc/inadyn.conf
|
|
385
|
+ chmod 600 /etc/inadyn.conf
|
|
386
|
+
|
|
387
|
+ echo '[Unit]' > /etc/systemd/system/inadyn.service
|
|
388
|
+ echo 'Description=inadyn (DynDNS updater)' >> /etc/systemd/system/inadyn.service
|
|
389
|
+ echo 'After=network.target' >> /etc/systemd/system/inadyn.service
|
|
390
|
+ echo '' >> /etc/systemd/system/inadyn.service
|
|
391
|
+ echo '[Service]' >> /etc/systemd/system/inadyn.service
|
|
392
|
+ echo 'ExecStart=/usr/local/sbin/inadyn --config /etc/inadyn.conf' >> /etc/systemd/system/inadyn.service
|
|
393
|
+ echo 'Restart=always' >> /etc/systemd/system/inadyn.service
|
|
394
|
+ echo 'Type=forking' >> /etc/systemd/system/inadyn.service
|
|
395
|
+ echo '' >> /etc/systemd/system/inadyn.service
|
|
396
|
+ echo '[Install]' >> /etc/systemd/system/inadyn.service
|
|
397
|
+ echo 'WantedBy=multi-user.target' >> /etc/systemd/system/inadyn.service
|
|
398
|
+ systemctl enable inadyn
|
|
399
|
+ systemctl start inadyn
|
|
400
|
+ systemctl daemon-reload
|
|
401
|
+
|
|
402
|
+ echo 'install_dynamicdns' >> $COMPLETION_FILE
|
393
|
403
|
}
|
394
|
404
|
|
395
|
405
|
function install_command_line_browser {
|
396
|
|
- if grep -Fxq "install_command_line_browser" $COMPLETION_FILE; then
|
397
|
|
- return
|
398
|
|
- fi
|
399
|
|
- apt-get -y install elinks
|
400
|
|
-
|
401
|
|
- # set the home page
|
402
|
|
- if ! grep -q "WWW_HOME" /home/$MY_USERNAME/.bashrc; then
|
403
|
|
- if ! grep -q 'control' /home/$MY_USERNAME/.bashrc; then
|
404
|
|
- echo "export WWW_HOME=$DEFAULT_SEARCH" >> /home/$MY_USERNAME/.bashrc
|
405
|
|
- else
|
406
|
|
- sed -i "/control/i export WWW_HOME=$DEFAULT_SEARCH" /home/$MY_USERNAME/.bashrc
|
407
|
|
- fi
|
408
|
|
- fi
|
409
|
|
-
|
410
|
|
- echo 'install_command_line_browser' >> $COMPLETION_FILE
|
|
406
|
+ if grep -Fxq "install_command_line_browser" $COMPLETION_FILE; then
|
|
407
|
+ return
|
|
408
|
+ fi
|
|
409
|
+ apt-get -y install elinks
|
|
410
|
+
|
|
411
|
+ # set the home page
|
|
412
|
+ if ! grep -q "WWW_HOME" /home/$MY_USERNAME/.bashrc; then
|
|
413
|
+ if ! grep -q 'control' /home/$MY_USERNAME/.bashrc; then
|
|
414
|
+ echo "export WWW_HOME=$DEFAULT_SEARCH" >> /home/$MY_USERNAME/.bashrc
|
|
415
|
+ else
|
|
416
|
+ sed -i "/control/i export WWW_HOME=$DEFAULT_SEARCH" /home/$MY_USERNAME/.bashrc
|
|
417
|
+ fi
|
|
418
|
+ fi
|
|
419
|
+
|
|
420
|
+ echo 'install_command_line_browser' >> $COMPLETION_FILE
|
411
|
421
|
}
|
412
|
422
|
|
413
|
423
|
function mesh_web_server {
|
414
|
|
- if [ -d /etc/apache2 ]; then
|
415
|
|
- chroot "$rootdir" apt-get -y remove --purge apache2
|
416
|
|
- chroot "$rootdir" rm -rf /etc/apache2
|
417
|
|
- fi
|
|
424
|
+ if [ -d /etc/apache2 ]; then
|
|
425
|
+ chroot "$rootdir" apt-get -y remove --purge apache2
|
|
426
|
+ chroot "$rootdir" rm -rf /etc/apache2
|
|
427
|
+ fi
|
418
|
428
|
|
419
|
|
- chroot "$rootdir" apt-get -y install nginx
|
|
429
|
+ chroot "$rootdir" apt-get -y install nginx
|
420
|
430
|
|
421
|
|
- if [ ! -d $rootdir/etc/nginx ]; then
|
422
|
|
- echo $'Unable to install web server'
|
423
|
|
- exit 346825
|
424
|
|
- fi
|
|
431
|
+ if [ ! -d $rootdir/etc/nginx ]; then
|
|
432
|
+ echo $'Unable to install web server'
|
|
433
|
+ exit 346825
|
|
434
|
+ fi
|
425
|
435
|
}
|
426
|
436
|
|
427
|
437
|
function install_web_server {
|
428
|
|
- if [ $INSTALLING_MESH ]; then
|
429
|
|
- mesh_web_server
|
430
|
|
- return
|
431
|
|
- fi
|
432
|
|
- if [[ $SYSTEM_TYPE == "$VARIANT_CHAT" ]]; then
|
433
|
|
- return
|
434
|
|
- fi
|
435
|
|
-
|
436
|
|
- # update to the next commit
|
437
|
|
- function_check set_repo_commit
|
438
|
|
- set_repo_commit $INSTALL_DIR/nginx_ensite "Nginx-ensite commit" "$NGINX_ENSITE_COMMIT" $NGINX_ENSITE_REPO
|
439
|
|
-
|
440
|
|
- if grep -Fxq "install_web_server" $COMPLETION_FILE; then
|
441
|
|
- return
|
442
|
|
- fi
|
443
|
|
- # remove apache
|
444
|
|
- apt-get -y remove --purge apache2
|
445
|
|
- if [ -d /etc/apache2 ]; then
|
446
|
|
- rm -rf /etc/apache2
|
447
|
|
- fi
|
448
|
|
- # install nginx
|
449
|
|
- apt-get -y install nginx php5-fpm git
|
450
|
|
-
|
451
|
|
- # limit the number of php processes
|
452
|
|
- sed -i 's/; process.max =.*/process.max = 32/g' /etc/php5/fpm/php-fpm.conf
|
453
|
|
- #sed -i 's/;process_control_timeout =.*/process_control_timeout = 300/g' /etc/php5/fpm/php-fpm.conf
|
454
|
|
-
|
455
|
|
- if ! grep -q "pm.max_children" /etc/php5/fpm/php-fpm.conf; then
|
456
|
|
- echo 'pm.max_children = 10' >> /etc/php5/fpm/php-fpm.conf
|
457
|
|
- echo 'pm.start_servers = 2' >> /etc/php5/fpm/php-fpm.conf
|
458
|
|
- echo 'pm.min_spare_servers = 2' >> /etc/php5/fpm/php-fpm.conf
|
459
|
|
- echo 'pm.max_spare_servers = 5' >> /etc/php5/fpm/php-fpm.conf
|
460
|
|
- echo 'pm.max_requests = 50' >> /etc/php5/fpm/php-fpm.conf
|
461
|
|
- fi
|
462
|
|
-
|
463
|
|
- if [ ! -d /etc/nginx ]; then
|
464
|
|
- echo $"ERROR: nginx does not appear to have installed. $CHECK_MESSAGE"
|
465
|
|
- exit 51
|
466
|
|
- fi
|
467
|
|
-
|
468
|
|
- # Nginx settings
|
469
|
|
- echo 'user www-data;' > /etc/nginx/nginx.conf
|
470
|
|
- #echo "worker_processes; $CPU_CORES" >> /etc/nginx/nginx.conf
|
471
|
|
- echo 'pid /run/nginx.pid;' >> /etc/nginx/nginx.conf
|
472
|
|
- echo '' >> /etc/nginx/nginx.conf
|
473
|
|
- echo 'events {' >> /etc/nginx/nginx.conf
|
474
|
|
- echo ' worker_connections 50;' >> /etc/nginx/nginx.conf
|
475
|
|
- echo ' # multi_accept on;' >> /etc/nginx/nginx.conf
|
476
|
|
- echo '}' >> /etc/nginx/nginx.conf
|
477
|
|
- echo '' >> /etc/nginx/nginx.conf
|
478
|
|
- echo 'http {' >> /etc/nginx/nginx.conf
|
479
|
|
- echo ' # limit the number of connections per single IP' >> /etc/nginx/nginx.conf
|
480
|
|
- echo ' limit_conn_zone $binary_remote_addr zone=conn_limit_per_ip:10m;' >> /etc/nginx/nginx.conf
|
481
|
|
- echo '' >> /etc/nginx/nginx.conf
|
482
|
|
- echo ' # limit the number of requests for a given session' >> /etc/nginx/nginx.conf
|
483
|
|
- echo ' limit_req_zone $binary_remote_addr zone=req_limit_per_ip:10m rate=140r/s;' >> /etc/nginx/nginx.conf
|
484
|
|
- echo '' >> /etc/nginx/nginx.conf
|
485
|
|
- echo ' # if the request body size is more than the buffer size, then the entire (or partial) request body is written into a temporary file' >> /etc/nginx/nginx.conf
|
486
|
|
- echo ' client_body_buffer_size 128k;' >> /etc/nginx/nginx.conf
|
487
|
|
- echo '' >> /etc/nginx/nginx.conf
|
488
|
|
- echo ' # headerbuffer size for the request header from client, its set for testing purpose' >> /etc/nginx/nginx.conf
|
489
|
|
- echo ' client_header_buffer_size 3m;' >> /etc/nginx/nginx.conf
|
490
|
|
- echo '' >> /etc/nginx/nginx.conf
|
491
|
|
- echo ' # maximum number and size of buffers for large headers to read from client request' >> /etc/nginx/nginx.conf
|
492
|
|
- echo ' large_client_header_buffers 4 256k;' >> /etc/nginx/nginx.conf
|
493
|
|
- echo '' >> /etc/nginx/nginx.conf
|
494
|
|
- echo ' # read timeout for the request body from client, its set for testing purpose' >> /etc/nginx/nginx.conf
|
495
|
|
- echo ' client_body_timeout 3m;' >> /etc/nginx/nginx.conf
|
496
|
|
- echo '' >> /etc/nginx/nginx.conf
|
497
|
|
- echo ' # how long to wait for the client to send a request header, its set for testing purpose' >> /etc/nginx/nginx.conf
|
498
|
|
- echo ' client_header_timeout 3m;' >> /etc/nginx/nginx.conf
|
499
|
|
- echo '' >> /etc/nginx/nginx.conf
|
500
|
|
- echo ' ##' >> /etc/nginx/nginx.conf
|
501
|
|
- echo ' # Basic Settings' >> /etc/nginx/nginx.conf
|
502
|
|
- echo ' ##' >> /etc/nginx/nginx.conf
|
503
|
|
- echo '' >> /etc/nginx/nginx.conf
|
504
|
|
- echo ' sendfile on;' >> /etc/nginx/nginx.conf
|
505
|
|
- echo ' tcp_nopush on;' >> /etc/nginx/nginx.conf
|
506
|
|
- echo ' tcp_nodelay on;' >> /etc/nginx/nginx.conf
|
507
|
|
- echo ' keepalive_timeout 65;' >> /etc/nginx/nginx.conf
|
508
|
|
- echo ' types_hash_max_size 2048;' >> /etc/nginx/nginx.conf
|
509
|
|
- echo ' server_tokens off;' >> /etc/nginx/nginx.conf
|
510
|
|
- echo '' >> /etc/nginx/nginx.conf
|
511
|
|
- echo ' # server_names_hash_bucket_size 64;' >> /etc/nginx/nginx.conf
|
512
|
|
- echo ' # server_name_in_redirect off;' >> /etc/nginx/nginx.conf
|
513
|
|
- echo '' >> /etc/nginx/nginx.conf
|
514
|
|
- echo ' include /etc/nginx/mime.types;' >> /etc/nginx/nginx.conf
|
515
|
|
- echo ' default_type application/octet-stream;' >> /etc/nginx/nginx.conf
|
516
|
|
- echo '' >> /etc/nginx/nginx.conf
|
517
|
|
- echo ' ##' >> /etc/nginx/nginx.conf
|
518
|
|
- echo ' # Logging Settings' >> /etc/nginx/nginx.conf
|
519
|
|
- echo ' ##' >> /etc/nginx/nginx.conf
|
520
|
|
- echo '' >> /etc/nginx/nginx.conf
|
521
|
|
- echo ' access_log /var/log/nginx/access.log;' >> /etc/nginx/nginx.conf
|
522
|
|
- echo ' error_log /var/log/nginx/error.log;' >> /etc/nginx/nginx.conf
|
523
|
|
- echo '' >> /etc/nginx/nginx.conf
|
524
|
|
- echo ' ###' >> /etc/nginx/nginx.conf
|
525
|
|
- echo ' # Gzip Settings' >> /etc/nginx/nginx.conf
|
526
|
|
- echo ' ##' >> /etc/nginx/nginx.conf
|
527
|
|
- echo ' gzip on;' >> /etc/nginx/nginx.conf
|
528
|
|
- echo ' gzip_disable "msie6";' >> /etc/nginx/nginx.conf
|
529
|
|
- echo '' >> /etc/nginx/nginx.conf
|
530
|
|
- echo ' # gzip_vary on;' >> /etc/nginx/nginx.conf
|
531
|
|
- echo ' # gzip_proxied any;' >> /etc/nginx/nginx.conf
|
532
|
|
- echo ' # gzip_comp_level 6;' >> /etc/nginx/nginx.conf
|
533
|
|
- echo ' # gzip_buffers 16 8k;' >> /etc/nginx/nginx.conf
|
534
|
|
- echo ' # gzip_http_version 1.1;' >> /etc/nginx/nginx.conf
|
535
|
|
- echo ' # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;' >> /etc/nginx/nginx.conf
|
536
|
|
- echo '' >> /etc/nginx/nginx.conf
|
537
|
|
- echo ' ##' >> /etc/nginx/nginx.conf
|
538
|
|
- echo ' # Virtual Host Configs' >> /etc/nginx/nginx.conf
|
539
|
|
- echo ' ##' >> /etc/nginx/nginx.conf
|
540
|
|
- echo '' >> /etc/nginx/nginx.conf
|
541
|
|
- echo ' include /etc/nginx/conf.d/*.conf;' >> /etc/nginx/nginx.conf
|
542
|
|
- echo ' include /etc/nginx/sites-enabled/*;' >> /etc/nginx/nginx.conf
|
543
|
|
- echo '}' >> /etc/nginx/nginx.conf
|
544
|
|
-
|
545
|
|
- # install a script to easily enable and disable nginx virtual hosts
|
546
|
|
- if [ ! -d $INSTALL_DIR ]; then
|
547
|
|
- mkdir $INSTALL_DIR
|
548
|
|
- fi
|
549
|
|
- cd $INSTALL_DIR
|
550
|
|
- function_check git_clone
|
551
|
|
- git_clone $NGINX_ENSITE_REPO $INSTALL_DIR/nginx_ensite
|
552
|
|
- cd $INSTALL_DIR/nginx_ensite
|
553
|
|
- git checkout $NGINX_ENSITE_COMMIT -b $NGINX_ENSITE_COMMIT
|
554
|
|
- if ! grep -q "Nginx-ensite commit" $COMPLETION_FILE; then
|
555
|
|
- echo "Nginx-ensite commit:$NGINX_ENSITE_COMMIT" >> $COMPLETION_FILE
|
556
|
|
- else
|
557
|
|
- sed -i "s/Nginx-ensite commit.*/Nginx-ensite commit:$NGINX_ENSITE_COMMIT/g" $COMPLETION_FILE
|
558
|
|
- fi
|
559
|
|
-
|
560
|
|
- make install
|
561
|
|
- nginx_dissite default
|
562
|
|
-
|
563
|
|
- function_check configure_firewall_for_web_access
|
564
|
|
- configure_firewall_for_web_access
|
565
|
|
-
|
566
|
|
- echo 'install_web_server' >> $COMPLETION_FILE
|
|
438
|
+ if [ $INSTALLING_MESH ]; then
|
|
439
|
+ mesh_web_server
|
|
440
|
+ return
|
|
441
|
+ fi
|
|
442
|
+ if [[ $SYSTEM_TYPE == "$VARIANT_CHAT" ]]; then
|
|
443
|
+ return
|
|
444
|
+ fi
|
|
445
|
+
|
|
446
|
+ # update to the next commit
|
|
447
|
+ function_check set_repo_commit
|
|
448
|
+ set_repo_commit $INSTALL_DIR/nginx_ensite "Nginx-ensite commit" "$NGINX_ENSITE_COMMIT" $NGINX_ENSITE_REPO
|
|
449
|
+
|
|
450
|
+ if grep -Fxq "install_web_server" $COMPLETION_FILE; then
|
|
451
|
+ return
|
|
452
|
+ fi
|
|
453
|
+ # remove apache
|
|
454
|
+ apt-get -y remove --purge apache2
|
|
455
|
+ if [ -d /etc/apache2 ]; then
|
|
456
|
+ rm -rf /etc/apache2
|
|
457
|
+ fi
|
|
458
|
+ # install nginx
|
|
459
|
+ apt-get -y install nginx php5-fpm git
|
|
460
|
+
|
|
461
|
+ # limit the number of php processes
|
|
462
|
+ sed -i 's/; process.max =.*/process.max = 32/g' /etc/php5/fpm/php-fpm.conf
|
|
463
|
+ #sed -i 's/;process_control_timeout =.*/process_control_timeout = 300/g' /etc/php5/fpm/php-fpm.conf
|
|
464
|
+
|
|
465
|
+ if ! grep -q "pm.max_children" /etc/php5/fpm/php-fpm.conf; then
|
|
466
|
+ echo 'pm.max_children = 10' >> /etc/php5/fpm/php-fpm.conf
|
|
467
|
+ echo 'pm.start_servers = 2' >> /etc/php5/fpm/php-fpm.conf
|
|
468
|
+ echo 'pm.min_spare_servers = 2' >> /etc/php5/fpm/php-fpm.conf
|
|
469
|
+ echo 'pm.max_spare_servers = 5' >> /etc/php5/fpm/php-fpm.conf
|
|
470
|
+ echo 'pm.max_requests = 50' >> /etc/php5/fpm/php-fpm.conf
|
|
471
|
+ fi
|
|
472
|
+
|
|
473
|
+ if [ ! -d /etc/nginx ]; then
|
|
474
|
+ echo $"ERROR: nginx does not appear to have installed. $CHECK_MESSAGE"
|
|
475
|
+ exit 51
|
|
476
|
+ fi
|
|
477
|
+
|
|
478
|
+ # Nginx settings
|
|
479
|
+ echo 'user www-data;' > /etc/nginx/nginx.conf
|
|
480
|
+ #echo "worker_processes; $CPU_CORES" >> /etc/nginx/nginx.conf
|
|
481
|
+ echo 'pid /run/nginx.pid;' >> /etc/nginx/nginx.conf
|
|
482
|
+ echo '' >> /etc/nginx/nginx.conf
|
|
483
|
+ echo 'events {' >> /etc/nginx/nginx.conf
|
|
484
|
+ echo ' worker_connections 50;' >> /etc/nginx/nginx.conf
|
|
485
|
+ echo ' # multi_accept on;' >> /etc/nginx/nginx.conf
|
|
486
|
+ echo '}' >> /etc/nginx/nginx.conf
|
|
487
|
+ echo '' >> /etc/nginx/nginx.conf
|
|
488
|
+ echo 'http {' >> /etc/nginx/nginx.conf
|
|
489
|
+ echo ' # limit the number of connections per single IP' >> /etc/nginx/nginx.conf
|
|
490
|
+ echo ' limit_conn_zone $binary_remote_addr zone=conn_limit_per_ip:10m;' >> /etc/nginx/nginx.conf
|
|
491
|
+ echo '' >> /etc/nginx/nginx.conf
|
|
492
|
+ echo ' # limit the number of requests for a given session' >> /etc/nginx/nginx.conf
|
|
493
|
+ echo ' limit_req_zone $binary_remote_addr zone=req_limit_per_ip:10m rate=140r/s;' >> /etc/nginx/nginx.conf
|
|
494
|
+ echo '' >> /etc/nginx/nginx.conf
|
|
495
|
+ echo ' # if the request body size is more than the buffer size, then the entire (or partial) request body is written into a temporary file' >> /etc/nginx/nginx.conf
|
|
496
|
+ echo ' client_body_buffer_size 128k;' >> /etc/nginx/nginx.conf
|
|
497
|
+ echo '' >> /etc/nginx/nginx.conf
|
|
498
|
+ echo ' # headerbuffer size for the request header from client, its set for testing purpose' >> /etc/nginx/nginx.conf
|
|
499
|
+ echo ' client_header_buffer_size 3m;' >> /etc/nginx/nginx.conf
|
|
500
|
+ echo '' >> /etc/nginx/nginx.conf
|
|
501
|
+ echo ' # maximum number and size of buffers for large headers to read from client request' >> /etc/nginx/nginx.conf
|
|
502
|
+ echo ' large_client_header_buffers 4 256k;' >> /etc/nginx/nginx.conf
|
|
503
|
+ echo '' >> /etc/nginx/nginx.conf
|
|
504
|
+ echo ' # read timeout for the request body from client, its set for testing purpose' >> /etc/nginx/nginx.conf
|
|
505
|
+ echo ' client_body_timeout 3m;' >> /etc/nginx/nginx.conf
|
|
506
|
+ echo '' >> /etc/nginx/nginx.conf
|
|
507
|
+ echo ' # how long to wait for the client to send a request header, its set for testing purpose' >> /etc/nginx/nginx.conf
|
|
508
|
+ echo ' client_header_timeout 3m;' >> /etc/nginx/nginx.conf
|
|
509
|
+ echo '' >> /etc/nginx/nginx.conf
|
|
510
|
+ echo ' ##' >> /etc/nginx/nginx.conf
|
|
511
|
+ echo ' # Basic Settings' >> /etc/nginx/nginx.conf
|
|
512
|
+ echo ' ##' >> /etc/nginx/nginx.conf
|
|
513
|
+ echo '' >> /etc/nginx/nginx.conf
|
|
514
|
+ echo ' sendfile on;' >> /etc/nginx/nginx.conf
|
|
515
|
+ echo ' tcp_nopush on;' >> /etc/nginx/nginx.conf
|
|
516
|
+ echo ' tcp_nodelay on;' >> /etc/nginx/nginx.conf
|
|
517
|
+ echo ' keepalive_timeout 65;' >> /etc/nginx/nginx.conf
|
|
518
|
+ echo ' types_hash_max_size 2048;' >> /etc/nginx/nginx.conf
|
|
519
|
+ echo ' server_tokens off;' >> /etc/nginx/nginx.conf
|
|
520
|
+ echo '' >> /etc/nginx/nginx.conf
|
|
521
|
+ echo ' # server_names_hash_bucket_size 64;' >> /etc/nginx/nginx.conf
|
|
522
|
+ echo ' # server_name_in_redirect off;' >> /etc/nginx/nginx.conf
|
|
523
|
+ echo '' >> /etc/nginx/nginx.conf
|
|
524
|
+ echo ' include /etc/nginx/mime.types;' >> /etc/nginx/nginx.conf
|
|
525
|
+ echo ' default_type application/octet-stream;' >> /etc/nginx/nginx.conf
|
|
526
|
+ echo '' >> /etc/nginx/nginx.conf
|
|
527
|
+ echo ' ##' >> /etc/nginx/nginx.conf
|
|
528
|
+ echo ' # Logging Settings' >> /etc/nginx/nginx.conf
|
|
529
|
+ echo ' ##' >> /etc/nginx/nginx.conf
|
|
530
|
+ echo '' >> /etc/nginx/nginx.conf
|
|
531
|
+ echo ' access_log /var/log/nginx/access.log;' >> /etc/nginx/nginx.conf
|
|
532
|
+ echo ' error_log /var/log/nginx/error.log;' >> /etc/nginx/nginx.conf
|
|
533
|
+ echo '' >> /etc/nginx/nginx.conf
|
|
534
|
+ echo ' ###' >> /etc/nginx/nginx.conf
|
|
535
|
+ echo ' # Gzip Settings' >> /etc/nginx/nginx.conf
|
|
536
|
+ echo ' ##' >> /etc/nginx/nginx.conf
|
|
537
|
+ echo ' gzip on;' >> /etc/nginx/nginx.conf
|
|
538
|
+ echo ' gzip_disable "msie6";' >> /etc/nginx/nginx.conf
|
|
539
|
+ echo '' >> /etc/nginx/nginx.conf
|
|
540
|
+ echo ' # gzip_vary on;' >> /etc/nginx/nginx.conf
|
|
541
|
+ echo ' # gzip_proxied any;' >> /etc/nginx/nginx.conf
|
|
542
|
+ echo ' # gzip_comp_level 6;' >> /etc/nginx/nginx.conf
|
|
543
|
+ echo ' # gzip_buffers 16 8k;' >> /etc/nginx/nginx.conf
|
|
544
|
+ echo ' # gzip_http_version 1.1;' >> /etc/nginx/nginx.conf
|
|
545
|
+ echo ' # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;' >> /etc/nginx/nginx.conf
|
|
546
|
+ echo '' >> /etc/nginx/nginx.conf
|
|
547
|
+ echo ' ##' >> /etc/nginx/nginx.conf
|
|
548
|
+ echo ' # Virtual Host Configs' >> /etc/nginx/nginx.conf
|
|
549
|
+ echo ' ##' >> /etc/nginx/nginx.conf
|
|
550
|
+ echo '' >> /etc/nginx/nginx.conf
|
|
551
|
+ echo ' include /etc/nginx/conf.d/*.conf;' >> /etc/nginx/nginx.conf
|
|
552
|
+ echo ' include /etc/nginx/sites-enabled/*;' >> /etc/nginx/nginx.conf
|
|
553
|
+ echo '}' >> /etc/nginx/nginx.conf
|
|
554
|
+
|
|
555
|
+ # install a script to easily enable and disable nginx virtual hosts
|
|
556
|
+ if [ ! -d $INSTALL_DIR ]; then
|
|
557
|
+ mkdir $INSTALL_DIR
|
|
558
|
+ fi
|
|
559
|
+ cd $INSTALL_DIR
|
|
560
|
+ function_check git_clone
|
|
561
|
+ git_clone $NGINX_ENSITE_REPO $INSTALL_DIR/nginx_ensite
|
|
562
|
+ cd $INSTALL_DIR/nginx_ensite
|
|
563
|
+ git checkout $NGINX_ENSITE_COMMIT -b $NGINX_ENSITE_COMMIT
|
|
564
|
+ if ! grep -q "Nginx-ensite commit" $COMPLETION_FILE; then
|
|
565
|
+ echo "Nginx-ensite commit:$NGINX_ENSITE_COMMIT" >> $COMPLETION_FILE
|
|
566
|
+ else
|
|
567
|
+ sed -i "s/Nginx-ensite commit.*/Nginx-ensite commit:$NGINX_ENSITE_COMMIT/g" $COMPLETION_FILE
|
|
568
|
+ fi
|
|
569
|
+
|
|
570
|
+ make install
|
|
571
|
+ nginx_dissite default
|
|
572
|
+
|
|
573
|
+ function_check configure_firewall_for_web_access
|
|
574
|
+ configure_firewall_for_web_access
|
|
575
|
+
|
|
576
|
+ echo 'install_web_server' >> $COMPLETION_FILE
|
567
|
577
|
}
|
568
|
578
|
|
569
|
579
|
# NOTE: deliberately no exit 0
|