2020-09-17 15:35:39 +02:00
|
|
|
#!/bin/bash
|
|
|
|
set -eu
|
|
|
|
|
2024-06-10 15:49:14 +02:00
|
|
|
file="Dockerfile"
|
|
|
|
|
2020-09-17 15:35:39 +02:00
|
|
|
if [ "${BUILD_DIST+x}" != "x" ]; then
|
|
|
|
echo "Not running in an OBS build container"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
BUILD_DATA="${BUILD_DIST/.dist/.data}"
|
|
|
|
if [ -e "${BUILD_DATA}" ]; then
|
|
|
|
. "${BUILD_DATA}"
|
|
|
|
|
|
|
|
# The build script renames the recipe (to strip _service:foo:), but doesn't update .data
|
2024-06-10 15:49:14 +02:00
|
|
|
file="${RECIPEFILE##*:}"
|
2020-09-17 15:35:39 +02:00
|
|
|
|
2024-06-10 15:49:14 +02:00
|
|
|
if [[ ! "${file}" =~ ^Dockerfile.* ]]; then
|
|
|
|
echo "Recipe ${file} is not a Dockerfile - exiting"
|
2020-09-17 15:35:39 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2022-07-21 14:51:19 +02:00
|
|
|
# Note: Avoid assigning to $1 etc. as that converts whitespace (field separators) to single spaces.
|
2020-09-17 15:35:39 +02:00
|
|
|
gawk -i inplace '
|
2021-07-23 11:50:31 +02:00
|
|
|
match($0, /^# labelprefix=(.*)$/, m) { labelprefix=m[1]; next }
|
2023-03-01 08:55:24 +01:00
|
|
|
labelprefix != "" && match($0, /^(PREFIXED)?LABEL[[:space:]]+[^=]*\.([^.=]*)=(.*)$/, m) { printf "LABEL %s.%s=%s\n", labelprefix, m[2], m[3]; gsub(/^PREFIXEDLABEL/, "LABEL") }
|
2021-07-23 11:50:31 +02:00
|
|
|
match($0, /^# endlabelprefix/) { labelprefix=""; next }
|
2024-06-10 15:49:14 +02:00
|
|
|
1' "${file}"
|