Skip to content

Commit e13302d

Browse files
authored
Merge pull request #115 from alphagov/bau_better_bash
Make better use of bash's variable tests
2 parents b4bba98 + a937a33 commit e13302d

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

go.sh

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ cat > ${NGIX_CONF_DIR}/server_certs.conf <<-EOF_CERT_CONF
2121
ssl_dhparam ${NGIX_CONF_DIR}/dhparam.pem;
2222
EOF_CERT_CONF
2323

24-
if [ "${LOCATIONS_CSV}" == "" ]; then
25-
LOCATIONS_CSV=/
26-
fi
24+
: "${LOCATIONS_CSV:=/}"
2725

2826
INTERNAL_LISTEN_PORT="${INTERNAL_LISTEN_PORT:-10418}"
2927
NGIX_LISTEN_CONF="${NGIX_CONF_DIR}/nginx_listen.conf"
@@ -35,12 +33,12 @@ cat > ${NGIX_LISTEN_CONF} <<-EOF-LISTEN
3533
listen localhost:${INTERNAL_LISTEN_PORT} ssl;
3634
EOF-LISTEN
3735

38-
if [ "${CUSTOM_SECURITY_DEFAULTS}" == "TRUE" ]; then
36+
if [ "${CUSTOM_SECURITY_DEFAULTS:-}" == "TRUE" ]; then
3937
msg "Disabling inbuilt security headers add per location"
4038
> /usr/local/openresty/nginx/conf/security_defaults.conf
4139
fi
4240

43-
if [ "${LOAD_BALANCER_CIDR}" != "" ]; then
41+
if [ -n "${LOAD_BALANCER_CIDR:-}" ]; then
4442
msg "Using proxy_protocol from '$LOAD_BALANCER_CIDR' (real client ip is forwarded correctly by loadbalancer)..."
4543
export REMOTE_IP_VAR="proxy_protocol_addr"
4644
cat >> ${NGIX_LISTEN_CONF} <<-EOF-LISTEN-PP
@@ -63,7 +61,7 @@ fi
6361

6462
NGIX_SYSDIG_SERVER_CONF="${NGIX_CONF_DIR}/nginx_sysdig_server.conf"
6563
touch ${NGIX_SYSDIG_SERVER_CONF}
66-
if [ -z ${DISABLE_SYSDIG_METRICS+x} ]; then
64+
if [ -n "${DISABLE_SYSDIG_METRICS:-}" ]; then
6765
cat > ${NGIX_SYSDIG_SERVER_CONF} <<-EOF-SYSDIG-SERVER
6866
server {
6967
listen 10088;
@@ -84,7 +82,7 @@ if [ "${CUSTOM_PROXY_CONFIG}" != "TRUE" ]; then
8482
done
8583
fi
8684

87-
if [ "${NAME_RESOLVER}" == "" ]; then
85+
if [ -z "${NAME_RESOLVER:-}" ]; then
8886
if [ "${DNSMASK}" == "TRUE" ]; then
8987
dnsmasq -p 5462
9088
export NAME_RESOLVER=127.0.0.1:5462
@@ -111,7 +109,7 @@ echo "HTTPS_LISTEN_PORT=${HTTPS_LISTEN_PORT}">/tmp/readyness.cfg
111109
if [ -f ${UUID_FILE} ]; then
112110
export LOG_UUID=TRUE
113111
fi
114-
if [ "${CLIENT_MAX_BODY_SIZE}" != "" ]; then
112+
if [ -n "${CLIENT_MAX_BODY_SIZE:-}" ]; then
115113
UPLOAD_SETTING="client_max_body_size ${CLIENT_MAX_BODY_SIZE}m;"
116114
echo "${UPLOAD_SETTING}">${NGIX_CONF_DIR}/upload_size.conf
117115
msg "Setting '${UPLOAD_SETTING};'"
@@ -128,18 +126,18 @@ else
128126
fi
129127

130128
case "${LOG_FORMAT_NAME}" in
131-
"json" | "text")
129+
json|text)
132130
msg "Logging set to ${LOG_FORMAT_NAME}"
133131

134-
if [ "${NO_LOGGING_URL_PARAMS}" ]; then
132+
if [ "${NO_LOGGING_URL_PARAMS:-}" == TRUE ]; then
135133
sed -i -e 's/\$request_uri/\$uri/g' ${NGIX_CONF_DIR}/logging.conf
136134
fi
137135

138-
if [ "${NO_LOGGING_BODY}" == "TRUE" ]; then
136+
if [ "${NO_LOGGING_BODY:-}" == TRUE ]; then
139137
sed --in-place '/\$request_body/d' ${NGIX_CONF_DIR}/logging.conf
140138
fi
141139

142-
if [ "${NO_LOGGING_RESPONSE}" == "TRUE" ]; then
140+
if [ "${NO_LOGGING_RESPONSE:-}" == TRUE ]; then
143141
sed --in-place '/\$response_body/d' ${NGIX_CONF_DIR}/logging.conf
144142
touch ${NGIX_CONF_DIR}/response_body.conf
145143
else
@@ -166,12 +164,12 @@ EOF-LOGGING-BODY-TRUE
166164
;;
167165
esac
168166

169-
if [ "${ADD_NGINX_SERVER_CFG}" != "" ]; then
167+
if [ -n "${ADD_NGINX_SERVER_CFG:-}" ]; then
170168
msg "Adding extra config for server context."
171169
echo ${ADD_NGINX_SERVER_CFG}>${NGIX_CONF_DIR}/nginx_server_extras.conf
172170
fi
173171

174-
if [ "${ADD_NGINX_HTTP_CFG}" != "" ]; then
172+
if [ -n "${ADD_NGINX_HTTP_CFG:-}" ]; then
175173
msg "Adding extra config for http context."
176174
echo ${ADD_NGINX_HTTP_CFG}>${NGIX_CONF_DIR}/nginx_http_extras.conf
177175
fi
@@ -180,7 +178,7 @@ GEO_CFG="${NGIX_CONF_DIR}/nginx_geoip.conf"
180178
GEO_CFG_INIT="${NGIX_CONF_DIR}/nginx_geoip_init.conf"
181179
GEO_CFG_CONFIG="${NGIX_CONF_DIR}/nginx_geoip.conf"
182180

183-
if [ "${ALLOW_COUNTRY_CSV}" != "" ]; then
181+
if [ -n "${ALLOW_COUNTRY_CSV:-}" ]; then
184182
msg "Enabling Country codes detection: ${ALLOW_COUNTRY_CSV}"
185183

186184
cat > $GEO_CFG_INIT <<-EOF

0 commit comments

Comments
 (0)