2019-01-09 11:39:18 +01:00
|
|
|
#!/bin/bash
|
2021-02-01 11:56:23 +01:00
|
|
|
# Not using -o pipefail, as SIGPIPE is annoying to deal with
|
|
|
|
set -eu
|
2020-07-08 17:10:37 +02:00
|
|
|
shopt -s nullglob
|
2019-01-09 11:39:18 +01:00
|
|
|
|
|
|
|
if [ "${BUILD_DIST+x}" != "x" ]; then
|
|
|
|
echo "Not running in an OBS build container"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
BUILD_DATA="${BUILD_DIST/.dist/.data}"
|
2020-07-08 17:10:37 +02:00
|
|
|
if [ -e "${BUILD_DATA}" ]; then
|
|
|
|
. "${BUILD_DATA}"
|
|
|
|
|
|
|
|
# The build script renames the recipe (to strip _service:foo:), but doesn't update .data
|
|
|
|
RECIPEFILE="${RECIPEFILE##*:}"
|
|
|
|
|
2020-08-27 09:09:01 +02:00
|
|
|
if [ "${RECIPEFILE##*.}" != "kiwi" ] && [ "${RECIPEFILE}" != "Dockerfile" ] && [ "${RECIPEFILE}" != "Chart.yaml" ]; then
|
2020-08-27 09:14:20 +02:00
|
|
|
echo "Recipe is neither Dockerfile, kiwi recipe nor helm chart - exiting"
|
2020-07-08 17:10:37 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
files=("${RECIPEFILE}")
|
2022-01-14 16:12:10 +01:00
|
|
|
# generate %SOURCEURL% based on DISTURL with a special case for build.suse.de
|
|
|
|
prj=$(echo ${DISTURL} | cut -d/ -f4)
|
|
|
|
localpath=$(echo ${DISTURL} | cut -d/ -f6-)
|
|
|
|
rev=$(echo ${localpath} | cut -d- -f1)
|
|
|
|
packagename=$(echo ${localpath} | cut -d- -f2-)
|
|
|
|
if [[ "${DISTURL}" == obs://build.suse.de/* ]]; then
|
|
|
|
SOURCEURL="https://sources.suse.com/${prj}/${packagename}/${rev}/"
|
|
|
|
else
|
|
|
|
SOURCEURL="https://$(echo ${DISTURL} | cut -d/ -f3)/package/show/${prj}/${packagename}?rev=${rev}"
|
|
|
|
fi
|
2020-07-08 17:10:37 +02:00
|
|
|
else
|
|
|
|
echo "Warning: No build data found - chroot build?"
|
|
|
|
DISTURL="local"
|
|
|
|
RELEASE=0
|
|
|
|
|
|
|
|
# Guess the build recipe
|
2020-08-27 09:09:01 +02:00
|
|
|
files=(*.kiwi Dockerfile* Chart.yaml*)
|
2020-07-08 17:10:37 +02:00
|
|
|
if [ "${#files}" -eq 0 ]; then
|
2020-08-27 09:14:20 +02:00
|
|
|
echo "No kiwi recipe, Dockerfile or helm chart found - exiting"
|
2020-07-08 17:10:37 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
2019-01-09 11:39:18 +01:00
|
|
|
fi
|
|
|
|
|
2021-01-27 16:16:08 +01:00
|
|
|
# Print all rpm files which contain os-release
|
|
|
|
find_release_rpms() {
|
|
|
|
find ./repos -name \*-release\*.rpm | while read rpm; do
|
2021-02-01 11:56:23 +01:00
|
|
|
if rpm -qlp "${rpm}" | grep -qE '^(/etc/os-release|/usr/lib/os-release)$'; then
|
2021-01-27 16:16:08 +01:00
|
|
|
echo "${rpm}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
2019-01-15 11:27:59 +01:00
|
|
|
|
2021-01-27 16:16:08 +01:00
|
|
|
if grep -q "%OS_" ${files[@]}; then
|
|
|
|
# Needs os-release, search for RPMs
|
|
|
|
relpkgs=($(find_release_rpms))
|
|
|
|
|
|
|
|
if [ ${#relpkgs[@]} -lt 1 ]; then
|
|
|
|
echo "No release package found, but recipe uses %OS_*% placeholders"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ${#relpkgs[@]} -gt 1 ]; then
|
|
|
|
echo "Multiple release packages found, don't know which os-release to use"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Extract the content
|
|
|
|
tempdir=$(mktemp -d)
|
|
|
|
trap "rm -r ${tempdir}" EXIT
|
|
|
|
rpm2cpio "${relpkgs[0]}" | cpio -idD "${tempdir}"
|
|
|
|
|
|
|
|
# And source it
|
|
|
|
[ -f "${tempdir}/usr/lib/os-release" ] && . "${tempdir}/usr/lib/os-release"
|
|
|
|
[ -f "${tempdir}/etc/os-release" ] && . "${tempdir}/etc/os-release"
|
|
|
|
|
|
|
|
# Special case for SLE X "SP 0", make sure it has .0
|
|
|
|
VERSION_ID_SP="${VERSION_ID}"
|
|
|
|
[[ "${VERSION_ID_SP%}" == *"."* ]] || VERSION_ID_SP="${VERSION_ID}.0"
|
|
|
|
|
2021-06-21 13:24:12 +02:00
|
|
|
# Provide various modified spellings of PRETTY_NAME useful for writing
|
|
|
|
# KIWI image definitions with reduced diff between SLE, Leap and Tumbleweed:
|
|
|
|
#
|
|
|
|
# VENDOR: openSUSE
|
|
|
|
# PRETTY_NAME_DASHED: openSUSE-Leap-15.3
|
|
|
|
# PRETTY_NAME_BEFORE_PAREN: openSUSE Leap 15.3
|
|
|
|
# PRETTY_NAME_BEFORE_PAREN_DASHED: openSUSE-Leap-15.3
|
|
|
|
#
|
|
|
|
# VENDOR: SUSE
|
|
|
|
# PRETTY_NAME_DASHED: SUSE-Linux-Enterprise-Server-15-SP3-Snapshot-16
|
|
|
|
# PRETTY_NAME_BEFORE_PAREN: SUSE Linux Enterprise Server 15 SP3
|
|
|
|
# PRETTY_NAME_BEFORE_PAREN_DASHED: SUSE-Linux-Enterprise-Server-15-SP3
|
|
|
|
|
|
|
|
# First word of PRETTY_NAME, typically used as vendor name e.g. SUSE or openSUSE.
|
|
|
|
VENDOR="${PRETTY_NAME%% *}"
|
|
|
|
|
|
|
|
# KIWI image name attribute must not contain spaces, replace with dash
|
|
|
|
PRETTY_NAME_DASHED="${PRETTY_NAME//[^[:alnum:].]/-}"
|
|
|
|
# Remove repeated dashes from parentheses surrounding SLE release labels
|
|
|
|
PRETTY_NAME_DASHED="${PRETTY_NAME_DASHED//--/-}"
|
|
|
|
# Remove dash at end from parentheses surrounding SLE release labels
|
|
|
|
PRETTY_NAME_DASHED="${PRETTY_NAME_DASHED%%-}"
|
|
|
|
|
|
|
|
# Special case for SLE release labels e.g. RC1. Keep only up to (space) open paren.
|
|
|
|
# Provides a stable project name for third-party integrations e.g. app store submissions
|
|
|
|
PRETTY_NAME_BEFORE_PAREN="${PRETTY_NAME// (*/}"
|
|
|
|
|
|
|
|
# KIWI image name attribute must not contain spaces, replace with dash
|
|
|
|
PRETTY_NAME_BEFORE_PAREN_DASHED="${PRETTY_NAME_BEFORE_PAREN//[^[:alnum:].]/-}"
|
|
|
|
|
2021-01-27 16:16:08 +01:00
|
|
|
sed -i"" \
|
|
|
|
-e "s/%OS_VERSION_ID%/${VERSION_ID}/g" \
|
|
|
|
-e "s/%OS_PRETTY_NAME%/${PRETTY_NAME}/g" \
|
2021-06-21 13:24:12 +02:00
|
|
|
-e "s/%OS_VENDOR%/${VENDOR}/g" \
|
|
|
|
-e "s/%OS_PRETTY_NAME_DASHED%/${PRETTY_NAME_DASHED}/g" \
|
|
|
|
-e "s/%OS_PRETTY_NAME_BEFORE_PAREN%/${PRETTY_NAME_BEFORE_PAREN}/g" \
|
|
|
|
-e "s/%OS_PRETTY_NAME_BEFORE_PAREN_DASHED%/${PRETTY_NAME_BEFORE_PAREN_DASHED}/g" \
|
2021-01-27 16:16:08 +01:00
|
|
|
-e "s/%OS_VERSION_ID_SP%/${VERSION_ID_SP}/g" "${files[@]}"
|
|
|
|
fi
|
2019-01-15 11:27:59 +01:00
|
|
|
|
2020-07-08 17:10:37 +02:00
|
|
|
sed -i"" \
|
|
|
|
-e "s#%DISTURL%#${DISTURL}#g" \
|
2022-01-14 16:12:10 +01:00
|
|
|
-e "s#%SOURCEURL%#${SOURCEURL}#g" \
|
2020-07-08 17:10:37 +02:00
|
|
|
-e "s/%RELEASE%/${RELEASE}/g" \
|
2021-01-27 16:16:08 +01:00
|
|
|
-e "s/%BUILDTIME%/$(date --utc +%FT%T.%NZ)/g" "${files[@]}"
|