Skip to content

Commit

Permalink
mock: avoid the %pre scriptlet if possible
Browse files Browse the repository at this point in the history
Complements: rpm-software-management#1367
Relates: rpm-software-management#289
Closes: rpm-software-management#1498
Relates: fedora-copr/copr#2789
Co-authored-by: Neal Gompa (ニール・ゴンパ) <[email protected]>
  • Loading branch information
praiskup and Conan-Kudo committed Nov 11, 2024
1 parent 9ad3ee8 commit 55bdb65
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 20 additions & 5 deletions mock/mock.spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
%bcond_with lint
%bcond_without tests

# In modern distributions with RPM v4.19+ (e.g., Fedora 39+), the %%pre
# scriptlet for creating users/groups is no longer necessary due to the built-in
# sysusers feature. To enable it, we simply include the `mock.conf` file in the
# package payload so that RPM knows what actions to take. For older
# distributions, however, %%pre is needed. On some of those older distros the
# %%sysusers_*_compat macros could help (but not everywhere), so turns out it is
# just way easier and to expand those macros and hardcode them in this specfile.
%if 0%{?fedora} || 0%{?rhel} >= 10
%bcond_with sysusers_compat
%else
%bcond_without sysusers_compat
%endif

%global __python %{__python3}
%global python_sitelib %{python3_sitelib}

Expand Down Expand Up @@ -147,7 +160,9 @@ Summary: Mock filesystem layout
Requires(pre): shadow-utils
BuildRequires: systemd-rpm-macros

%{?sysusers_requires_compat}
%if %{with sysusers_compat}
Requires(pre): shadow-utils
%endif

%description filesystem
Filesystem layout and group for Mock.
Expand All @@ -171,9 +186,6 @@ done

./precompile-bash-completion "mock.complete"

# this is what %%sysusers_create_compat will expand to
%{_rpmconfigdir}/sysusers.generate-pre.sh mock.conf > sysusers_script

argparse-manpage --pyfile ./py/mock-hermetic-repo.py --function _argparser > mock-hermetic-repo.1


Expand Down Expand Up @@ -230,7 +242,10 @@ sed -i 's/^_MOCK_NVR = None$/_MOCK_NVR = "%name-%version-%release"/' \
%{buildroot}%{_libexecdir}/mock/mock


%pre filesystem -f sysusers_script
%if %{with sysusers_compat}
%pre filesystem
getent group 'mock' >/dev/null || groupadd -f -g '135' -r 'mock' || :
%endif


%check
Expand Down
2 changes: 2 additions & 0 deletions releng/release-notes-next/sysusers-on-mageia.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The %pre scriptlet is not generated for modern distributions like Fedora 39+ or
Mageia (group/user additions are handled by an RPM built-in feature).

0 comments on commit 55bdb65

Please sign in to comment.