1
0

Accepting request 867214 from home:favogt:boo1180263

- Read os-release from the to be installed RPMs. This avoids pulling
  in distribution-release when not necessary (boo#1180263)

OBS-URL: https://build.opensuse.org/request/show/867214
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Tools/obs-service-kiwi_metainfo_helper?expand=0&rev=17
This commit is contained in:
Fabian Vogt 2021-01-27 15:16:08 +00:00 committed by Git OBS Bridge
parent 22e3d1aaec
commit 29126d06c0
3 changed files with 53 additions and 18 deletions

View File

@ -1,5 +1,5 @@
#!/bin/bash
set -eu
set -euo pipefail
shopt -s nullglob
if [ "${BUILD_DIST+x}" != "x" ]; then
@ -33,17 +33,49 @@ else
fi
fi
[ -f /usr/lib/os-release ] && . /usr/lib/os-release
[ -f /etc/os-release ] && . /etc/os-release
# Print all rpm files which contain os-release
find_release_rpms() {
find ./repos -name \*-release\*.rpm | while read rpm; do
if rpm -qlp "${rpm}" | grep -qE "^(/etc/os-release|/usr/lib/os-release)$"; then
echo "${rpm}"
fi
done
}
# 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"
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"
sed -i"" \
-e "s/%OS_VERSION_ID%/${VERSION_ID}/g" \
-e "s/%OS_PRETTY_NAME%/${PRETTY_NAME}/g" \
-e "s/%OS_VERSION_ID_SP%/${VERSION_ID_SP}/g" "${files[@]}"
fi
sed -i"" \
-e "s#%DISTURL%#${DISTURL}#g" \
-e "s/%RELEASE%/${RELEASE}/g" \
-e "s/%BUILDTIME%/$(date --utc +%FT%T.%NZ)/g" \
-e "s/%OS_VERSION_ID%/${VERSION_ID}/g" \
-e "s/%OS_PRETTY_NAME%/${PRETTY_NAME}/g" \
-e "s/%OS_VERSION_ID_SP%/${VERSION_ID_SP}/g" "${files[@]}"
-e "s/%BUILDTIME%/$(date --utc +%FT%T.%NZ)/g" "${files[@]}"

View File

@ -1,3 +1,9 @@
-------------------------------------------------------------------
Wed Jan 27 11:25:26 UTC 2021 - Fabian Vogt <fvogt@suse.com>
- Read os-release from the to be installed RPMs. This avoids pulling
in distribution-release when not necessary (boo#1180263)
-------------------------------------------------------------------
Tue Sep 1 08:42:45 UTC 2020 - Fabian Vogt <fvogt@suse.com>

View File

@ -1,7 +1,7 @@
#
# spec file for package obs-service-kiwi_metainfo_helper
#
# Copyright (c) 2020 SUSE LLC
# Copyright (c) 2021 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@ -17,7 +17,7 @@
Name: obs-service-kiwi_metainfo_helper
Version: 0.1
Version: 0.2
Release: 0
Summary: Service for substituting various variables in build recipes
License: GPL-2.0-or-later
@ -26,12 +26,9 @@ URL: https://build.opensuse.org
Source0: kiwi_metainfo_helper.service
Source1: kiwi_metainfo_helper
Source2: README
Requires: sed
# Technically, this should read os-release inside the built image, but doing
# that is much more complex. As obsrepositories:// has to be used anyway,
# using the system's os-release is fine for now.
Requires: (sles-release or openSUSE-release)
Conflicts: dummy-release
Requires: /usr/bin/find
Requires: /usr/bin/grep
Requires: /usr/bin/sed
BuildArch: noarch
%description