forked from postgis/docker-postgis
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapply-templates.sh
executable file
·86 lines (67 loc) · 2.44 KB
/
apply-templates.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
83
84
85
86
#!/usr/bin/env bash
set -Eeuo pipefail
# Source environment variables and necessary configurations
source tools/environment_init.sh
# This code derived from:
# - URL: https://github.com/docker-library/postgres/blob/master/apply-templates.sh
# - Copyright: (c) Docker PostgreSQL Authors
# - MIT License, https://github.com/docker-library/postgres/blob/master/LICENSE
# Check dependencies
[ -f ./versions.json ]
cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
jqt='.jq-template.awk'
if [ -n "${BASHBREW_SCRIPTS:-}" ]; then
jqt="$BASHBREW_SCRIPTS/jq-template.awk"
elif [ "${BASH_SOURCE[0]}" -nt "$jqt" ]; then
# https://github.com/docker-library/bashbrew/blob/master/scripts/jq-template.awk
wget -qO "$jqt" 'https://github.com/docker-library/bashbrew/raw/9f6a35772ac863a0241f147c820354e4008edf38/scripts/jq-template.awk'
fi
jqf='.template-helper-functions.jq'
if [ -n "${BASHBREW_SCRIPTS:-}" ]; then
jqf="$BASHBREW_SCRIPTS/template-helper-functions.jq"
elif [ "${BASH_SOURCE[0]}" -nt "$jqf" ]; then
wget -qO "$jqf" 'https://github.com/docker-library/bashbrew/raw/master/scripts/template-helper-functions.jq'
fi
if [ "$#" -eq 0 ]; then
versions="$(jq -r 'keys | map(@sh) | join(" ")' versions.json)"
eval "set -- $versions"
fi
echo "versions = $versions"
generated_warning() {
cat <<-EOH
#
# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh"
# source: "$1"
# PLEASE DO NOT EDIT IT DIRECTLY.
#
EOH
}
for version; do
export version
bundleType="$(echo "$version" | cut -d '-' -f 3)"
variants="$(jq -r '.[env.version]| keys | map(@sh) | join(" ")' versions.json)"
eval "variants=( $variants )"
for variant in "${variants[@]}"; do
export variant
dir="$version/$variant"
echo "processing $dir ..."
template="$(jq -r '.[env.version][env.variant].template' versions.json)"
echo " template=$template"
initfile="$(jq -r '.[env.version][env.variant].initfile' versions.json)"
echo " initfile=$initfile"
tags="$(jq -r '.[env.version][env.variant].tags' versions.json)"
echo " tags=$tags"
cp -a "$initfile" "$dir/"
if [ -z "$bundleType" ]; then
cp -a update-postgis.sh "$dir/"
fi
echo "$tags" >"$dir/tags"
{
generated_warning "$template"
gawk -f "$jqt" "$template"
} >"$dir/Dockerfile"
done
done
echo " "
echo " apply-template : done"
echo " "