forked from UKHomeOffice/docker-nginx-proxy
-
Notifications
You must be signed in to change notification settings - Fork 3
/
defaults.sh
executable file
·71 lines (62 loc) · 1.85 KB
/
defaults.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
#!/usr/bin/env bash
export DOWNLOAD_VIA_S3_VPC_ENDPOINT=${DOWNLOAD_VIA_S3_VPC_ENDPOINT:-'FALSE'}
export HTTP_LISTEN_PORT=${HTTP_LISTEN_PORT:-10080}
export HTTPS_LISTEN_PORT=${HTTPS_LISTEN_PORT:-10443}
export AWS_REGION=${AWS_REGION:-'eu-west-1'}
export UUID_VARIABLE_NAME=${UUID_VARIABLE_NAME:='$request_id'}
function download() {
file_url=$1
if [ $# -eq 3 ]; then
file_md5=$2
download_path=$3
else
download_path=$2
fi
file_path=${download_path}/$(basename ${file_url})
error=0
for i in {1..5}; do
if [ ${i} -gt 1 ]; then
msg "About to retry download for ${file_url}..."
sleep 1
fi
if [ "${DOWNLOAD_VIA_S3_VPC_ENDPOINT}" == "TRUE" ]; then
aws s3 cp --region "${AWS_REGION}" --endpoint-url https://s3-"${AWS_REGION}".amazonaws.com "${NAXSI_RULES_URL_CSV}" ${file_path}
error=$?
elif curl --max-time 30 --fail -s -o ${file_path} ${file_url} ; then
error=0
fi
if [ -n ${file_md5} ]; then
md5=$(md5sum ${file_path} | cut -d' ' -f1)
if [ "${md5}" == "${file_md5}" ] ; then
error=0
else
msg "Error: MD5 expecting '${file_md5}' but got '${md5}' for ${file_url}"
error=1
fi
fi
if [ ${error} -eq 0 ]; then
msg "File downloaded & OK:${file_url}"
break
fi
done
return ${error}
}
function get_id_var() {
LOCATION_ID=$1
VAR_NAME=$2
NEW_VAR_NAME="${VAR_NAME}_${LOCATION_ID}"
if [ "${!NEW_VAR_NAME}" == "" ]; then
NEW_VAR_NAME=${VAR_NAME}
fi
echo ${!NEW_VAR_NAME}
}
function msg() {
if [ "${LOCATION}" != "" ]; then
LOC_TXT=${LOCATION_ID}:${LOCATION}:
fi
echo "SETUP:${LOC_TXT}$1"
}
function exit_error_msg() {
echo "ERROR:$1"
exit 1
}