From 29126d06c0cbe11579be8f54252175e396e1d200e704eeaa52f7099a7cc3e48c Mon Sep 17 00:00:00 2001 From: Fabian Vogt Date: Wed, 27 Jan 2021 15:16:08 +0000 Subject: [PATCH] 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 --- kiwi_metainfo_helper | 52 +++++++++++++++++++----- obs-service-kiwi_metainfo_helper.changes | 6 +++ obs-service-kiwi_metainfo_helper.spec | 13 +++--- 3 files changed, 53 insertions(+), 18 deletions(-) diff --git a/kiwi_metainfo_helper b/kiwi_metainfo_helper index e519dd1..d1beb38 100644 --- a/kiwi_metainfo_helper +++ b/kiwi_metainfo_helper @@ -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[@]}" diff --git a/obs-service-kiwi_metainfo_helper.changes b/obs-service-kiwi_metainfo_helper.changes index 820930d..54d21a3 100644 --- a/obs-service-kiwi_metainfo_helper.changes +++ b/obs-service-kiwi_metainfo_helper.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Wed Jan 27 11:25:26 UTC 2021 - Fabian Vogt + +- 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 diff --git a/obs-service-kiwi_metainfo_helper.spec b/obs-service-kiwi_metainfo_helper.spec index cbc0589..e59ee28 100644 --- a/obs-service-kiwi_metainfo_helper.spec +++ b/obs-service-kiwi_metainfo_helper.spec @@ -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