@@ -33,6 +33,18 @@ the purposes of CI/CD tasks.
3333%bcond_with python3
3434%endif
3535
36+ # Modern distributions (using RPM v4.19+; for example, Fedora 39+) do not
37+ # require the %%pre scriptlet for creating users/groups because the sysusers
38+ # feature is now built directly into RPM. Simply including the sysusers
39+ # `mock.conf` file in a package payload is sufficient to leverage this feature.
40+ # However, for older distributions that lack this capability, we still define
41+ # the %%pre scriptlet.
42+ %if (0%{ ?rhel} && 0%{ ?rhel} < 10) || (0%{ ?mageia} && 0%{ ?mageia} < 10) || (0%{ ?suse_version} && 0%{ ?suse_version} < 1660)
43+ %bcond_without sysusers_compat
44+ %else
45+ %bcond_with sysusers_compat
46+ %endif
47+
3648%global default_python %{ ?with_python3:python3} %{ ! ?with_python3:python2}
3749%global default_sitelib %{ ?with_python3:% python3_sitelib} %{ ! ?with_python3:% python_sitelib}
3850
@@ -82,6 +94,10 @@ BuildRequires: python-yaml
8294
8395Requires: %default_python-%srcname = %version-%release
8496
97+ %if %{ with sysusers_compat}
98+ Requires(pre): shadow-utils
99+ %endif
100+
85101Source0: https://github.com/praiskup/%name/releases/download/v%version/%name-@TARBALL_VERSION@.tar.gz
86102Source1: resalloc.service
87103Source5: resalloc-agent-spawner.service
@@ -116,7 +132,6 @@ Requires: python-sqlalchemy
116132Requires: python-yaml
117133%endif
118134
119- Requires(pre): /usr/sbin/useradd
120135%description server
121136%desc
122137
@@ -156,7 +171,6 @@ it shows page with information about resalloc resources.
156171%package agent-spawner
157172Summary: %sum - daemon starting agent-like resources
158173
159- Requires(pre): /usr/sbin/useradd
160174Requires: python3-copr-common >= 0.23
161175Requires: python3-daemon
162176Requires: python3-redis
@@ -219,6 +233,16 @@ restorecon -R %_var/www/cgi-%{name} || :
219233rm -r resalloc_agent_spawner
220234%endif
221235
236+ # Create sysusers.d config files
237+ cat >resalloc.sysusers.conf <<EOF
238+ u resalloc - ' %sysuser service user' %_homedir /bin /bash
239+ m resalloc %sysgroup
240+ EOF
241+ cat >resalloc-agent-spawner.sysusers.conf <<EOF
242+ u resalloc-agent-spawner - ' %agent_user service user' - -
243+ m resalloc-agent-spawner %agent_group
244+ EOF
245+
222246
223247%build
224248%if %{with python2}
@@ -266,6 +290,9 @@ rm %buildroot%_bindir/%name-agent-*
266290rm %buildroot%_sysconfdir/resalloc-agent-spawner/config.yaml
267291%endif
268292
293+ install -m0644 -D resalloc.sysusers.conf %{ buildroot} %{ _sysusersdir} /resalloc.conf
294+ install -m0644 -D resalloc-agent-spawner.sysusers.conf %{ buildroot} %{ _sysusersdir} /resalloc-agent-spawner.conf
295+
269296
270297%if %{ with check}
271298%check
@@ -281,8 +308,10 @@ make check TEST_PYTHONS="python3"
281308ln -s "%{ default_sitelib} /%{ name} server" %buildroot%_homedir/project
282309
283310
311+ %if %{ with sysusers_compat}
284312%pre server
285313%create_user_group %sysuser %sysgroup /bin/bash %_homedir
314+ %endif
286315
287316%post server
288317%systemd_post resalloc.service
@@ -292,8 +321,10 @@ ln -s "%{default_sitelib}/%{name}server" %buildroot%_homedir/project
292321
293322
294323%if %{ with python3}
324+ %if %{ with sysusers_compat}
295325%pre agent-spawner
296326%create_user_group %agent_user %agent_group /bin/false /
327+ %endif
297328
298329%post agent-spawner
299330%systemd_post resalloc-agent-spawner.service
@@ -346,6 +377,7 @@ ln -s "%{default_sitelib}/%{name}server" %buildroot%_homedir/project
346377%config %_sysconfdir/logrotate.d/resalloc-server
347378%_libexecdir/resalloc-merge-hook-logs
348379%config %attr(0755, root, root) %{ _sysconfdir} /cron.hourly/resalloc
380+ %{ _sysusersdir} /resalloc.conf
349381
350382
351383%files helpers
@@ -361,6 +393,7 @@ ln -s "%{default_sitelib}/%{name}server" %buildroot%_homedir/project
361393%{ default_sitelib} /%{ name} _agent_spawner
362394%_unitdir/resalloc-agent-spawner.service
363395%config(noreplace) %_sysconfdir/resalloc-agent-spawner
396+ %{ _sysusersdir} /resalloc-agent-spawner.conf
364397
365398%files webui
366399%doc %doc_files
0 commit comments