From 898835da9855f8745c7946658110708355e8af3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sat, 13 Jul 2024 16:31:28 +0200 Subject: [PATCH] Create rpm Requires generator The generator will generate a Requires on filesystem(unmerged-sbin-symlinks), i.e. effectively on a new-enough version of _this_ package. This is needed to solve the following problem: as packages are rebuilt in a merged-sbin environment, their payload paths change from /usr/sbin to /usr/bin. In all the cases where there were other packages that dependended on the old paths via explicit Requires, compat Provides on the old path was added along with Requires:filesystem(unmerged-sbin-symlinks). This means that those packages will not be installed with an older filesystem.rpm. But for packages that didn't need this special treatment, no dependency is generated. When they are installed into an upgraded environment which still has split-sbin and has an older copy of filesystem, the file is moved without the compat symlink being created. Thus, any scripts, or systemd service files, etc., referring to the old path are now broken. We need to require a new-enough filesystem.rpm to be installed so avoid breakage on such partially upgraded systems. --- filesystem.attr | 3 +++ filesystem.req | 18 ++++++++++++++++++ filesystem.spec | 26 +++++++++++++++++++++++++- macros.filesystem | 15 +++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 filesystem.attr create mode 100755 filesystem.req create mode 100644 macros.filesystem diff --git a/filesystem.attr b/filesystem.attr new file mode 100644 index 0000000..342b198 --- /dev/null +++ b/filesystem.attr @@ -0,0 +1,3 @@ +%__filesystem_requires %{_rpmconfigdir}/filesystem.req %{_datadir}/filesystem/sbin-filenames +%__filesystem_protocol multifile +%__filesystem_path ^(/usr)?/bin/.*$ diff --git a/filesystem.req b/filesystem.req new file mode 100755 index 0000000..985749b --- /dev/null +++ b/filesystem.req @@ -0,0 +1,18 @@ +#!/usr/bin/bash + +# Generate Requires: filesystem(unmerged-sbin-symlinks) if any +# of the filenames were known to reside in /usr/sbin. +# When the package with the files is being built, it's possible that +# %_sbindir==/usr/bin, so we cannot rely on the location to figure +# this out and we need a hardcoded list. + +sbin_filenames=${1:?} +declare -A "filenames=($(sed 's/.*/["\0"]=1/' <"${sbin_filenames}"))" + +while read -r path; do + filename="$(basename "$path")" + if [ -n "${filenames[$filename]}" ]; then + echo ";$path" + echo "filesystem(unmerged-sbin-symlinks)" + fi +done diff --git a/filesystem.spec b/filesystem.spec index a2ea286..dbb0351 100644 --- a/filesystem.spec +++ b/filesystem.spec @@ -10,6 +10,9 @@ Source1: https://pagure.io/filesystem/raw/master/f/lang-exceptions Source2: iso_639.sed Source3: iso_3166.sed Source4: sbin-filenames +Source5: filesystem.attr +Source6: filesystem.req +Source7: macros.filesystem BuildRequires: iso-codes Requires(pre): setup @@ -46,6 +49,14 @@ This subpackage of filesystem package contains just the file with the directories owned by the filesystem package. This can be used during the build process instead of calling rpm -ql filesystem. +%package srpm-macros +Summary: Macros for the sbin-merge +License: Public Domain + +%description srpm-macros +This subpackage of filesystem package contains rpm macro definitions +and an rpm attribute geneator. + %prep rm -f $RPM_BUILD_DIR/filelist @@ -147,11 +158,18 @@ for i in man{1,2,3,4,5,6,7,8,9,n,1x,2x,3x,4x,5x,6x,7x,8x,9x,0p,1p,3p}; do echo "/usr/share/man/$i" >>$RPM_BUILD_DIR/filelist done -mkdir -p %{buildroot}/usr/share/filesystem +mkdir -p %{buildroot}%{_datadir}/filesystem #find all dirs in the buildroot owned by filesystem and store them find %{buildroot} -mindepth 0 | sed -e 's|%{buildroot}|/|' -e 's|//|/|' \ | LC_ALL=C sort | grep -v filesystem >%{buildroot}%{_datadir}/filesystem/paths +cp -p %{SOURCE4} %{buildroot}%{_datadir}/filesystem/sbin-filenames + +mkdir -p %{buildroot}%{_fileattrsdir} %{buildroot}%{_rpmconfigdir} %{buildroot}%{rpmmacrodir} +cp -p %{SOURCE5} %{buildroot}%{_fileattrsdir}/filesystem.attr +cp -p %{SOURCE6} %{buildroot}%{_rpmconfigdir}/filesystem.req +cp -p %{SOURCE7} %{buildroot}%{rpmmacrodir}/macros.filesystem + %pretrans -p --# If we are running in pretrans in a fresh root, there is no /usr and --# symlinks. We cannot be sure, to be the very first rpm in the @@ -366,6 +384,12 @@ end %dir %{_datadir}/filesystem %{_datadir}/filesystem/paths +%files srpm-macros +%{_datadir}/filesystem/sbin-filenames +%{_fileattrsdir}/filesystem.attr +%{_rpmconfigdir}/filesystem.req +%{rpmmacrodir}/macros.filesystem + %files -f filelist %defattr(0755,root,root,0755) %dir %attr(555,root,root) / diff --git a/macros.filesystem b/macros.filesystem new file mode 100644 index 0000000..1a0b24c --- /dev/null +++ b/macros.filesystem @@ -0,0 +1,15 @@ +# Convenience macro for the transition to merged-sbin +# (https://fedoraproject.org/wiki/Changes/Unify_bin_and_sbin) +# Usage: +# List all files listed in %%files as %%_sbindir/foo. +# Example: +# %%sbin_merge_compat /usr/sbin/foobar +# %%{sbin_merge_compat /usr/sbin/bar1 +# /usr/sbin/bar2 +# } + +%sbin_merge_compat() \ +%if "%{_sbindir}" == "%{_bindir}" \ +Requires: filesystem(unmerged-sbin-symlinks) \ +Provides: %{shrink:%{?*}} \ +%endif