]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
rpm macros: add %sysusers_create_package
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 31 Jan 2018 15:07:59 +0000 (16:07 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 2 Feb 2018 09:40:24 +0000 (10:40 +0100)
This is close to %sysusers_create_inline and %sysusers_create that we had
already, but expects a file name and uses --replace= to implement proper
priority.

This is used like:
  %sysusers_create_package %{name} %SOURCE1
where %SOURCE1 is a file with called %{name}.conf that will be installed
into /usr/lib/sysusers.d/.

The tough part is that the file needs to be available before %prep,
i.e. outside of the source tarball. This is because the spec file is
parsed (and any macros expanded), before the sources are unpackaged.

v2:
- disallow the case case when --config-name= is given but there are no
  positional args. Most likely this would be a user error, so at least for now
  forbid it.
v3:
- replace --config-name= with --target=
- drop quotes around %1 and %2 — if necessary, the caller should add
  those.
v4:
- replace --target with --replace
- add a big comment

src/core/macros.systemd.in

index 940f1e895af0631d08444ff05718ba3131cfbdf7..cee9b89870355b64f99f0ff5df9b847e898462f8 100644 (file)
@@ -100,6 +100,7 @@ journalctl --update-catalog >/dev/null 2>&1 || : \
 systemd-tmpfiles --create %{?*} >/dev/null 2>&1 || : \
 %{nil}
 
+# Deprecated. Use %sysusers_create_package instead
 %sysusers_create() \
 systemd-sysusers %{?*} >/dev/null 2>&1 || : \
 %{nil}
@@ -108,6 +109,24 @@ systemd-sysusers %{?*} >/dev/null 2>&1 || : \
 echo %{?*} | systemd-sysusers - >/dev/null 2>&1 || : \
 %{nil}
 
+# This should be used by package installation scripts which
+# require users or groups to be present before the files installed
+# by the package are present on disk (for example because some files
+# are owned by those users or groups).
+#
+# Example:
+#   Source1: %{name}.conf
+#   ...
+#   %install
+#   install -Dt %{buildroot}%{sysusersdir} %SOURCE1
+#   %pre
+#   %sysusers_create_package %{name} %SOURCE1
+#   %files
+#   %{sysusersdir}/%{name}.conf
+%sysusers_create_package() \
+echo "%(cat %2)" | systemd-sysusers --replace=%_sysusersdir/%1.conf - >/dev/null 2>&1 || : \
+%{nil}
+
 %sysctl_apply() \
 @rootlibexecdir@/systemd-sysctl %{?*} >/dev/null 2>&1 || : \
 %{nil}