Skip to content

Commit b17b2ff

Browse files
DEV: update readability
split up if statements. Add spaces around heredoc. use install /dev/null rather than empty redirect to clear a file.
1 parent 35f932f commit b17b2ff

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

templates/web.letsencrypt.ssl.template.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,17 @@ hooks:
124124
chmod: "+x"
125125
contents: |
126126
#!/bin/bash
127-
if [ -z "$DISCOURSE_HOSTNAME" ]; then echo "DISCOURSE_HOSTNAME expected"; exit 1; fi
128-
if [ -z "$LETSENCRYPT_ACCOUNT_EMAIL" ]; then echo "LETSENCRYPT_ACCOUNT_EMAIL ENV not set. Skipping Let's Encrypt setup."; exit 0; fi
129-
if [[ ! "$LETSENCRYPT_ACCOUNT_EMAIL" =~ ([^@]+)@([^\.]+) ]]; then echo "LETSENCRYPT_ACCOUNT_EMAIL is not a valid email address"; exit 1; fi
127+
if [ -z "$DISCOURSE_HOSTNAME" ]; then
128+
echo "DISCOURSE_HOSTNAME expected"
129+
exit 1
130+
fi
131+
if [ -z "$LETSENCRYPT_ACCOUNT_EMAIL" ]; then
132+
echo "LETSENCRYPT_ACCOUNT_EMAIL ENV not set. Skipping Let's Encrypt setup."
133+
exit 0
134+
fi
135+
if [[ ! "$LETSENCRYPT_ACCOUNT_EMAIL" =~ ([^@]+)@([^\.]+) ]]; then
136+
echo "LETSENCRYPT_ACCOUNT_EMAIL is not a valid email address"
137+
exit 1
138+
fi
130139
/usr/local/bin/configure-ssl
131140
exec /usr/local/bin/configure-letsencrypt

templates/web.ssl.template.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ run:
55
chmod: "+x"
66
contents: |
77
#!/bin/bash
8-
if [ -z "$DISCOURSE_HOSTNAME" ]; then echo "DISCOURSE_HOSTNAME expected"; exit 1; fi
9-
if [ ! -z "$ENABLE_SSL" ]; then
8+
if [ -z "$DISCOURSE_HOSTNAME" ]; then
9+
echo "DISCOURSE_HOSTNAME expected"
10+
exit 1
11+
fi
12+
if [ -n "$ENABLE_SSL" ]; then
1013
exec /usr/local/bin/configure-ssl
1114
fi
1215
@@ -16,14 +19,15 @@ run:
1619
contents: |
1720
#!/bin/bash
1821
mkdir -p /shared/ssl/
22+
1923
cat << EOF > /etc/nginx/conf.d/outlets/before-server/20-redirect-http-to-https.conf
2024
server {
2125
listen 80;
2226
return 301 https://${DISCOURSE_HOSTNAME}$request_uri;
2327
}
2428
EOF
2529
26-
> /etc/nginx/conf.d/outlets/server/10-http.conf
30+
install /dev/null /etc/nginx/conf.d/outlets/server/10-http.conf
2731
2832
cat << EOF > /etc/nginx/conf.d/outlets/server/20-https.conf
2933
listen 443 ssl;
@@ -50,6 +54,7 @@ run:
5054
cat << EOF > /etc/nginx/conf.d/outlets/discourse/20-https.conf
5155
add_header Strict-Transport-Security 'max-age=31536000';
5256
EOF
57+
5358
if [ -f "/proc/net/if_inet6" ] ; then
5459
sed -i 's/listen 80;/listen 80;\nlisten [::]:80;/g' /etc/nginx/conf.d/outlets/before-server/20-redirect-http-to-https.conf
5560
sed -i 's/listen 443 ssl;/listen 443 ssl;\nlisten [::]:443 ssl;/g' /etc/nginx/conf.d/outlets/server/20-https.conf

0 commit comments

Comments
 (0)