forked from sclorg/container-common-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.sh
executable file
·177 lines (152 loc) · 5.47 KB
/
generate.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
# This script is used to create image directories using distgen, cp or ln
# It requires "$MANIFEST_FILE" (defaults to manifest.sh) file to be present in
# image repository.
# The manifest file should contain set of rules in form:
# <rules_type>="
# src=<path to source>
# dest=<path to destination>
# mode=<destination file mode (optional)>;
# ...;
# "
#
# Supported type rules are now COPY_RULES, DISTGEN_RULES and SYMLINKS_RULES
# for real example see https://github.com/sclorg/postgresql-container/blob/master/manifest.sh
source "$MANIFEST_FILE"
die () { echo "FATAL: $*" ; exit 1 ; }
nl='
'
test -f auto_targets.mk && rm auto_targets.mk
DG="${DG-/bin/dg}"
[ ! -x "$DG" ] && echo " Error: distgen binary not found or not executable in $DG" && \
echo " Make sure distgen is properly installed on your host in $DG, or provide a path to your distgen binary via \$DG" && exit 1
DISTGEN_COMBINATIONS=$("$DG" --multispec specs/multispec.yml --multispec-combinations)
clean_rule_variables(){
src=""
dest=""
mode=""
link_target=""
link_name=""
}
parse_rules() {
targets=""
OLD_IFS=$IFS
IFS=";"
for rule in $rules; do
if [ -z $(echo "$rule"| tr -d '[:space:]') ]; then
continue
fi
clean_rule_variables
eval $rule
cdir='$(CDIR)'
case "$creator" in
copy)
[[ -z "$src" ]] && echo "src has to be specified in copy rule" && exit 1
[[ -z "$dest" ]] && echo "dest has to be specified in copy rule" && exit 1
core_subst=$core
prolog="\$(V_CP)$cdir"
;;
distgen)
[[ -z "$src" ]] && echo "src has to be specified in distgen rule" && exit 1
[[ -z "$dest" ]] && echo "dest has to be specified in distgen rule" && exit 1
core_subst=$core
prolog="\$(V_DG)$cdir"
;;
distgen_multi)
[[ -z "$src" ]] && echo "src has to be specified in distgen rule" && exit 1
[[ -z "$dest" ]] && echo "dest has to be specified in distgen rule" && exit 1
if [[ "$dest" == "Dockerfile.rhel7" ]]; then
if ! [[ "$DG_CONF" =~ rhel-7-x86_64.yaml ]]; then
continue
fi
elif [[ "$dest" == "Dockerfile.rhel8" ]]; then
if ! [[ "$DG_CONF" =~ rhel-8-x86_64.yaml ]]; then
continue
fi
elif [[ "$dest" == *"Dockerfile.fedora" ]]; then
if ! [[ "$DG_CONF" =~ fedora-[0-9]{,2}-x86_64.yaml ]]; then
continue
fi
elif [[ "$dest" == *"Dockerfile" ]]; then
if ! [[ "$DG_CONF" =~ centos-[0-9]{,2}-x86_64.yaml ]]; then
continue
fi
fi
prolog="\$(V_DGM)$cdir"
core_subst=$core
;;
link)
[[ -z "$link_name" ]] && echo "link_name has to be specified in link rule" && exit 1
[[ -z "$link_target" ]] && echo "link_target has to be specified in link rule" && exit 1
dest="$link_name"
core_subst=$(echo $core | sed -e "s~__link_target__~"${link_target}"~g")
prolog="\$(V_LN)$cdir"
;;
esac
case $version$dest$src in
*' '*) die "space not allowed in version, dest, src" ;;
esac
target=$version/$dest
targets+="\\$nl $target"
cat >> auto_targets.mk << EOF
$nl$target: $src \$(MANIFEST_FILE)
$prolog \\
$core_subst${mode:+"; \\
chmod $mode '\$@'"}
EOF
done
IFS=$OLD_IFS
}
for version in ${VERSIONS}; do
# Get a working combination of distgen options for this version
while read -r combination; do
# line looks like: --distro rhel-7-x86_64.yaml --multispec-selector version=9.4
echo "$combination" | grep "version=$version" &>/dev/null && break
done <<< "$DISTGEN_COMBINATIONS"
[ -z "$combination" ] && die "Could not find a working distgen options combination for version $version"
# copy targets
rules="$COPY_RULES"
core="cp \$< \$@"
creator="copy"
parse_rules
COPY_TARGETS+="$targets"
# distgen targets
rules="$DISTGEN_RULES"
core="\$(DG) --multispec specs/multispec.yml \\
--template \"\$<\" $combination --output \"\$@\""
creator="distgen"
parse_rules
DISTGEN_TARGETS+="$targets"
rules=$SYMLINK_RULES
core="ln -nfs __link_target__ \$@"
creator="link"
parse_rules
SYMLINK_TARGETS+="$targets"
done
while read -r combination; do
# line looks like: --distro rhel-7-x86_64.yaml --multispec-selector version=9.4
eval 'set -- $combination'
case $4 in
version=*) version=${4##*=} ;;
*) die "version not found"
esac
case $2 in
*x86_64*) DG_CONF=$2 ;;
*) die "invalid --distro option"
esac
# distgen multi targets
rules="$DISTGEN_MULTI_RULES"
core="\$(DG) --multispec specs/multispec.yml \\
--template \"\$<\" \\
--output \"\$@\" \\
$combination"
creator="distgen_multi"
parse_rules
DISTGEN_MULTI_TARGETS+="$targets"
done <<< "$DISTGEN_COMBINATIONS"
cat -v >> auto_targets.mk <<EOF
COPY_TARGETS = $COPY_TARGETS
DISTGEN_TARGETS = $DISTGEN_TARGETS
DISTGEN_MULTI_TARGETS = $DISTGEN_MULTI_TARGETS
SYMLINK_TARGETS = $SYMLINK_TARGETS
EOF