-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.sh
executable file
·82 lines (66 loc) · 1.64 KB
/
update.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
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
set -eo pipefail
variants=(
open
blacklist
whitelist
)
function create_variant() {
declare -a features=(
"-DWANT_FULLSCRAPE"
"-DWANT_FULLLOG_NETWORKS"
"-DWANT_LOG_NUMWANT"
"-DWANT_MODEST_FULLSCRAPES"
"-DWANT_SPOT_WOODPECKER"
)
variant=$1
variant_file="$variant.Dockerfile"
touch "${variant_file}"
template="Dockerfile.template"
cat <<__EOF__ >"${variant_file}"
#
# NOTE: THIS DOCKERFILE IS GENERATED VIA update.sh from ${template}
#
# PLEASE DO NOT EDIT IT DIRECTLY.
#
__EOF__
cat "$template" >>"$variant_file"
echo "updating $variant_file"
case "$variant" in
open)
features+=()
extra_sed_confs=''
;;
blacklist)
features+=("-DWANT_ACCESSLIST_BLACK")
extra_sed_confs="-e 's!(.*)(access.blacklist)(.*)!\\\2 /etc/opentracker/blacklist!g;'"
;;
whitelist)
features+=("-DWANT_ACCESSLIST_WHITE")
extra_sed_confs="-e 's!(.*)(access.whitelist)(.*)!\\\2 /etc/opentracker/whitelist!g;'"
;;
esac
features_sed_string=''
for i in "${features[@]}"; do
# Add extra slashes to escape on below sed substitution
features_sed_string+="FEATURES+=${i} \\\\\n "
done
# Replace MAKEFILE_FEATURES variable from template
sed -ri \
-e 's@%%MAKEFILE_FEATURES%%@'"${features_sed_string}"'@g;' \
"$variant_file"
# Replace OPENTRACKER_CONFS variable from template
sed -ri \
-e 's@%%OPENTRACKER_CONFS%%@'"${extra_sed_confs}"'@g;' \
"$variant_file"
}
if [ -z "$1" ]; then
for variant in "${variants[@]}"; do
create_variant "$variant"
done
elif [[ ${variants[*]} =~ $1 ]]; then
create_variant "$1"
else
echo "Value ${1} Invalid!"
exit 1
fi