|
@@ -146,7 +146,9 @@ if [ ! -d /etc/ssl/mycerts ]; then
|
146
|
146
|
mkdir /etc/ssl/mycerts
|
147
|
147
|
fi
|
148
|
148
|
|
149
|
|
-if [ $LETSENCRYPT_HOSTNAME ]; then
|
|
149
|
+CERTFILE=$HOSTNAME
|
|
150
|
+
|
|
151
|
+function add_cert_letsencrypt {
|
150
|
152
|
CERTFILE=$LETSENCRYPT_HOSTNAME
|
151
|
153
|
|
152
|
154
|
if [ ! -d $INSTALL_DIR ]; then
|
|
@@ -170,7 +172,6 @@ if [ $LETSENCRYPT_HOSTNAME ]; then
|
170
|
172
|
systemctl stop nginx
|
171
|
173
|
|
172
|
174
|
cd ${INSTALL_DIR}/letsencrypt
|
173
|
|
- # TODO this requires user interaction - is there a non-interactive mode?
|
174
|
175
|
./letsencrypt-auto certonly --server $LETSENCRYPT_SERVER --standalone -d $LETSENCRYPT_HOSTNAME
|
175
|
176
|
if [ ! "$?" = "0" ]; then
|
176
|
177
|
echo $"Failed to install letsencrypt for domain $LETSENCRYPT_HOSTNAME"
|
|
@@ -192,8 +193,8 @@ if [ $LETSENCRYPT_HOSTNAME ]; then
|
192
|
193
|
if [ -f /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key ]; then
|
193
|
194
|
if [ ! -f /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key.old ]; then
|
194
|
195
|
mv /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key.old
|
195
|
|
- else
|
196
|
|
- rm -f /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key
|
|
196
|
+ else
|
|
197
|
+ rm -f /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key
|
197
|
198
|
fi
|
198
|
199
|
fi
|
199
|
200
|
ln -s /etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}/privkey.pem /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key
|
|
@@ -202,8 +203,8 @@ if [ $LETSENCRYPT_HOSTNAME ]; then
|
202
|
203
|
if [ -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem ]; then
|
203
|
204
|
if [ ! -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem.old ]; then
|
204
|
205
|
mv /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem.old
|
205
|
|
- else
|
206
|
|
- rm -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem
|
|
206
|
+ else
|
|
207
|
+ rm -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem
|
207
|
208
|
fi
|
208
|
209
|
fi
|
209
|
210
|
ln -s /etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}/fullchain.pem /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem
|
|
@@ -217,8 +218,9 @@ if [ $LETSENCRYPT_HOSTNAME ]; then
|
217
|
218
|
echo $"Certificate for $LETSENCRYPT_HOSTNAME could not be pinned"
|
218
|
219
|
exit 62878
|
219
|
220
|
fi
|
220
|
|
-else
|
221
|
|
- CERTFILE=$HOSTNAME
|
|
221
|
+}
|
|
222
|
+
|
|
223
|
+function add_cert_selfsigned {
|
222
|
224
|
if [[ $ORGANISATION == "Freedombone-CA" ]]; then
|
223
|
225
|
CERTFILE="ca-$HOSTNAME"
|
224
|
226
|
fi
|
|
@@ -236,21 +238,39 @@ else
|
236
|
238
|
echo $"Certificate for $CERTFILE could not be pinned"
|
237
|
239
|
exit 62879
|
238
|
240
|
fi
|
239
|
|
-fi
|
|
241
|
+}
|
240
|
242
|
|
241
|
|
-# generate DH params
|
242
|
|
-if [ ! $NODH ]; then
|
243
|
|
- if [ ! -f /etc/ssl/certs/${CERTFILE}.dhparam ]; then
|
244
|
|
- ${PROJECT_NAME}-dhparam -h ${CERTFILE} --fast yes
|
|
243
|
+function generate_dh_params {
|
|
244
|
+ if [ ! $NODH ]; then
|
|
245
|
+ if [ ! -f /etc/ssl/certs/${CERTFILE}.dhparam ]; then
|
|
246
|
+ ${PROJECT_NAME}-dhparam -h ${CERTFILE} --fast yes
|
|
247
|
+ fi
|
245
|
248
|
fi
|
246
|
|
-fi
|
|
249
|
+}
|
247
|
250
|
|
248
|
|
-if [ -f /etc/init.d/nginx ]; then
|
249
|
|
- /etc/init.d/nginx reload
|
250
|
|
-fi
|
|
251
|
+function restart_web_server {
|
|
252
|
+ if [ -f /etc/init.d/nginx ]; then
|
|
253
|
+ /etc/init.d/nginx reload
|
|
254
|
+ fi
|
|
255
|
+}
|
|
256
|
+
|
|
257
|
+function make_cert_bundle {
|
|
258
|
+ # Create a bundle of your certificates
|
|
259
|
+ cat /etc/ssl/mycerts/*.crt /etc/ssl/mycerts/*.pem > /etc/ssl/${PROJECT_NAME}-bundle.crt
|
|
260
|
+ tar -czvf /etc/ssl/${PROJECT_NAME}-certs.tar.gz /etc/ssl/mycerts/*.crt /etc/ssl/mycerts/*.pem
|
|
261
|
+}
|
|
262
|
+
|
|
263
|
+function create_cert {
|
|
264
|
+ if [ $LETSENCRYPT_HOSTNAME ]; then
|
|
265
|
+ add_cert_letsencrypt
|
|
266
|
+ else
|
|
267
|
+ add_cert_selfsigned
|
|
268
|
+ fi
|
|
269
|
+}
|
251
|
270
|
|
252
|
|
-# Create a bundle of your certificates
|
253
|
|
-cat /etc/ssl/mycerts/*.crt /etc/ssl/mycerts/*.pem > /etc/ssl/${PROJECT_NAME}-bundle.crt
|
254
|
|
-tar -czvf /etc/ssl/${PROJECT_NAME}-certs.tar.gz /etc/ssl/mycerts/*.crt /etc/ssl/mycerts/*.pem
|
|
271
|
+create_cert
|
|
272
|
+generate_dh_params
|
|
273
|
+restart_web_server
|
|
274
|
+make_cert_bundle
|
255
|
275
|
|
256
|
276
|
exit 0
|