From 0416e04b08cad564b3f74bc41926523237c07e25 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Wed, 12 Feb 2025 08:14:11 +0100 Subject: [PATCH] Use the RPM built-in sysusers feature Built on top of: https://src.fedoraproject.org/rpms/resalloc/pull-request/3 https://github.com/rpm-software-management/mock/pull/1498 --- NEWS | 9 +++++++++ rpm/resalloc.spec.tpl | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index cb3b1eb..20650a5 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,14 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +New in v???: + +* Enhancements + + - Resalloc packages use the RPM built-in mechanism for handling + system users (modern distributions only). + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + New in v5.9: * Enhancements diff --git a/rpm/resalloc.spec.tpl b/rpm/resalloc.spec.tpl index 7fefa28..3b1ebcc 100644 --- a/rpm/resalloc.spec.tpl +++ b/rpm/resalloc.spec.tpl @@ -33,6 +33,18 @@ the purposes of CI/CD tasks. %bcond_with python3 %endif +# Modern distributions (using RPM v4.19+; for example, Fedora 39+) do not +# require the %%pre scriptlet for creating users/groups because the sysusers +# feature is now built directly into RPM. Simply including the sysusers +# `mock.conf` file in a package payload is sufficient to leverage this feature. +# However, for older distributions that lack this capability, we still define +# the %%pre scriptlet. +%if (0%{?rhel} && 0%{?rhel} < 10) || (0%{?mageia} && 0%{?mageia} < 10) || (0%{?suse_version} && 0%{?suse_version} < 1660) +%bcond_without sysusers_compat +%else +%bcond_with sysusers_compat +%endif + %global default_python %{?with_python3:python3}%{!?with_python3:python2} %global default_sitelib %{?with_python3:%python3_sitelib}%{!?with_python3:%python_sitelib} @@ -82,6 +94,10 @@ BuildRequires: python-yaml Requires: %default_python-%srcname = %version-%release +%if %{with sysusers_compat} +Requires(pre): shadow-utils +%endif + Source0: https://github.com/praiskup/%name/releases/download/v%version/%name-@TARBALL_VERSION@.tar.gz Source1: resalloc.service Source5: resalloc-agent-spawner.service @@ -116,7 +132,6 @@ Requires: python-sqlalchemy Requires: python-yaml %endif -Requires(pre): /usr/sbin/useradd %description server %desc @@ -156,7 +171,6 @@ it shows page with information about resalloc resources. %package agent-spawner Summary: %sum - daemon starting agent-like resources -Requires(pre): /usr/sbin/useradd Requires: python3-copr-common >= 0.23 Requires: python3-daemon Requires: python3-redis @@ -219,6 +233,16 @@ restorecon -R %_var/www/cgi-%{name} || : rm -r resalloc_agent_spawner %endif +# Create sysusers.d config files +cat >resalloc.sysusers.conf <resalloc-agent-spawner.sysusers.conf <