1
0
intel-media-ffmpeg/scripts/build-dockerfile.sh
James P. Ketrenos 38a05c61b0 Updated to latest xe-solutions
Signed-off-by: James P. Ketrenos <james.p.ketrenos@intel.com>
2019-12-03 14:12:06 -08:00

113 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
# Bring in the variables from SOLUTION file, supporting
# nested substitution
. SOLUTION
. MANIFEST
VARS=($(sed -nE "s,(^[^#][^=]*).*$,\1,pg" SOLUTION))
VARS+=($(sed -nE "s,(^[^#][^=]*).*$,\1,pg" MANIFEST))
for var in ${VARS[@]}; do
export ${var}
done
case "${OS_DISTRO}" in
rhel)
SOLUTION_SUFFIX=".rhel-8.0"
;;
ubuntu)
SOLUTION_SUFFIX=""
;;
*)
SOLUTION_SUFFIX=".${OS_DISTRO}-${OS_RELEASE}"
[[ -d "templates/${OS_DISTRO}" ]] || {
echo "Unrecognized OS_DISTRO: '${OS_DISTRO}'"
exit -1
}
;;
esac
[[ ! -e "Dockerfile.solution${SOLUTION_SUFFIX}" ]] && {
cat << EOF
'${OS_DISTRO}' set as OS_DISTRO, but Dockerfile.solution${SOLUTION_SUFFIX} does
not exist.
Using Dockerfile.solution instead.
EOF
SOLUTION_SUFFIX=""
}
export DOCKERFILE="Dockerfile${SOLUTION_SUFFIX}"
export SOLUTION="Dockerfile.solution${SOLUTION_SUFFIX}"
VARS+=("DOCKERFILE")
VARS+=("SOLUTION")
echo "Using '${SOLUTION}' to generate '${DOCKERFILE}'."
# Build a SHELL-FORMAT value to pass to envsubst.
# Only those variables matched in SHELL-FORMAT will
# be escaped by envsubst.
ENV=''
for var in ${VARS[@]}; do
ENV=${ENV}'$'${var}
done
# Remove the Dockerfile if it exists; should check
# if it is clean first, and abort if not.
#
[ -e ${DOCKERFILE} ] && rm ${DOCKERFILE}
cat << EOM > ${DOCKERFILE}
#
# DO NOT EDIT THIS DOCKERFILE
#
# This file is auto-generated via scripts/build-dockerfile
# by using environment substitution while concatenating the
# contents of templates/*, and then adding the contents
# of ${SOLUTION}
#
# Most solution specific changes should be isolated in
# ${SOLUTION}. After making changes, you can then re-run
# scripts/build-dockerfile
#
EOM
for snippet in templates/${OS_DISTRO}/??-*.in; do
cat << EOM >> ${DOCKERFILE}
#
# Template from ${snippet}
#
EOM
envsubst ${ENV} < $snippet >> ${DOCKERFILE}
done
cat << EOM >> ${DOCKERFILE}
#
# Solution begins here (from ${SOLUTION})
#
EOM
envsubst ${ENV} < ${SOLUTION} >> ${DOCKERFILE}
cat << EOM >> ${DOCKERFILE}
#
# Standard ending begins here (from templates/ending.in)
#
EOM
envsubst ${ENV} < templates/ending.in >> ${DOCKERFILE}
cat << EOM
${DOCKERFILE} has been updated.
To build the image, you can run:
OS_DISTRO=${OS_DISTRO} OS_RELEASE=${OS_RELEASE} scripts/build-image.sh
EOM