This macros works very similar than the tmpfiles one but handles sysusers files.
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- macros/systemd.macro | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/macros/systemd.macro b/macros/systemd.macro index 9dc74ff0..1453db95 100644 --- a/macros/systemd.macro +++ b/macros/systemd.macro @@ -1,5 +1,6 @@
SYSTEMD_TMPFILES_DIR = /usr/lib/tmpfiles.d +SYSTEMD_SYSUSERS_DIR = /usr/lib/sysusers.d
MACRO_INSTALL_SYSTEMD_FILES for file in %{DIR_SOURCE}/systemd/*; do @@ -19,3 +20,12 @@ MACRO_INSTALL_SYSTEMD_TMPFILES done unset file end + +MACRO_INSTALL_SYSTEMD_SYSUSERS + for file in %{DIR_SOURCE}/*.sysusers; do + [ -e "${file}" ] || continue + mkdir -p %{BUILDROOT}/%{SYSTEMD_SYSUSERS_DIR} + cp -vf ${file} %{BUILDROOT}/%{SYSTEMD_SYSUSERS_DIR}/$(basename ${file%*.sysusers}).conf + done + unset file +end
This macro can be called inside a build file and easily allows to apply any kind of users/groups specified in a sysusers file.
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- macros/systemd.macro | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/macros/systemd.macro b/macros/systemd.macro index 1453db95..27231094 100644 --- a/macros/systemd.macro +++ b/macros/systemd.macro @@ -2,6 +2,17 @@ SYSTEMD_TMPFILES_DIR = /usr/lib/tmpfiles.d SYSTEMD_SYSUSERS_DIR = /usr/lib/sysusers.d
+MACRO_APPLY_SYSTEMD_SYSUSERS + mkdir -pv %{SYSTEMD_SYSUSERS_DIR} + + for file in %{DIR_SOURCE}/*.sysusers; do + [ -e "${file}" ] || continue + cat ${file} | \ + systemd-sysusers --replace=%{SYSTEMD_SYSUSERS_DIR}/$(basename ${file%*.sysusers}).conf - + done + unset file +end + MACRO_INSTALL_SYSTEMD_FILES for file in %{DIR_SOURCE}/systemd/*; do [ -e "${file}" ] || continue
Hello Stefan,
Didn’t we decide on the phone call again doing this?
The downside is that this won’t work for any sysuser files that are in the tarball. So there is still the need to manually apply those?
It would be less consistent and potentially confusing?
-Michael
On 30 Mar 2023, at 07:52, Stefan Schantl stefan.schantl@ipfire.org wrote:
This macro can be called inside a build file and easily allows to apply any kind of users/groups specified in a sysusers file.
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org
macros/systemd.macro | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/macros/systemd.macro b/macros/systemd.macro index 1453db95..27231094 100644 --- a/macros/systemd.macro +++ b/macros/systemd.macro @@ -2,6 +2,17 @@ SYSTEMD_TMPFILES_DIR = /usr/lib/tmpfiles.d SYSTEMD_SYSUSERS_DIR = /usr/lib/sysusers.d
+MACRO_APPLY_SYSTEMD_SYSUSERS
- mkdir -pv %{SYSTEMD_SYSUSERS_DIR}
- for file in %{DIR_SOURCE}/*.sysusers; do
- [ -e "${file}" ] || continue
- cat ${file} | \
- systemd-sysusers --replace=%{SYSTEMD_SYSUSERS_DIR}/$(basename ${file%*.sysusers}).conf -
- done
- unset file
+end
MACRO_INSTALL_SYSTEMD_FILES for file in %{DIR_SOURCE}/systemd/*; do [ -e "${file}" ] || continue -- 2.30.2
Hello Michael,
yes I absolutely can remain our talk on the phone.
Please let me explain why I still sent this patch.
During development on the packages, which used the old %{create_users} declaraion and getent / adduser / addgroup stuff and replacing them by the corresponding systemd sysusers call and the sysusers file I stumbled accross that all of those look the same. They allways call the same binary, have the same filename layout, create the same directories etc.
So I thought about that fact a bit, that it would be very unpopular to copy the same code over and over again into multiple build files. It would be much more handy and of corse intuitive when reviewing or modifying them if there is something which can be called by a single "one-liner" and doing all the magic.
This avoids as already mentioned a lot of code duplication / dead code, reduces copy and paste mistakes and in my personal opinions is simple a bit more shiny.
So I decided to write the code for adding sysusers which are downstream (part of our git) once and simple call this macro and let it do it's job.
Hello Stefan,
Didn’t we decide on the phone call again doing this?
The downside is that this won’t work for any sysuser files that are in the tarball. So there is still the need to manually apply those?
You are absolutely right, if we do not want to use a downstream or self written sysusers file, because the project vendor added one into their source tarballs. In this case of course the macro from above cannot be used and the sysusers stuff has to be done by hand based on how the vendors have placed the files and handles them.
It would be less consistent and potentially confusing?
I do not think that this is confusing people. It may be more confusing to research how to code / do such a simple task like adding users/groups.
In such a case the macro would be an easy to use mechanism, which should do the job in a plenty of cases.
- Stefan
-Michael
On 30 Mar 2023, at 07:52, Stefan Schantl stefan.schantl@ipfire.org wrote:
This macro can be called inside a build file and easily allows to apply any kind of users/groups specified in a sysusers file.
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org
macros/systemd.macro | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/macros/systemd.macro b/macros/systemd.macro index 1453db95..27231094 100644 --- a/macros/systemd.macro +++ b/macros/systemd.macro @@ -2,6 +2,17 @@ SYSTEMD_TMPFILES_DIR = /usr/lib/tmpfiles.d SYSTEMD_SYSUSERS_DIR = /usr/lib/sysusers.d
+MACRO_APPLY_SYSTEMD_SYSUSERS
- mkdir -pv %{SYSTEMD_SYSUSERS_DIR}
- for file in %{DIR_SOURCE}/*.sysusers; do
- [ -e "${file}" ] || continue
- cat ${file} | \
- systemd-sysusers --replace=%{SYSTEMD_SYSUSERS_DIR}/$(basename
${file%*.sysusers}).conf -
- done
- unset file
+end
MACRO_INSTALL_SYSTEMD_FILES for file in %{DIR_SOURCE}/systemd/*; do [ -e "${file}" ] || continue -- 2.30.2
This macro can be called inside a build file and easily allows to apply any kind of users/groups specified in a sysusers file.
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- macros/systemd.macro | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/macros/systemd.macro b/macros/systemd.macro index 7a40cff6..0da90468 100644 --- a/macros/systemd.macro +++ b/macros/systemd.macro @@ -1,3 +1,14 @@ +MACRO_APPLY_SYSTEMD_SYSUSERS + mkdir -pv %{sysusersdir} + + for file in %{DIR_SOURCE}/*.sysusers; do + [ -e "${file}" ] || continue + cat ${file} | \ + systemd-sysusers --replace=%{sysusersdir}/$(basename ${file%*.sysusers}).conf - + done + unset file +end + MACRO_INSTALL_SYSTEMD_FILES for file in %{DIR_SOURCE}/systemd/*; do [ -e "${file}" ] || continue
Hello Stefan,
On 30 Mar 2023, at 07:52, Stefan Schantl stefan.schantl@ipfire.org wrote:
This macros works very similar than the tmpfiles one but handles sysusers files.
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org
macros/systemd.macro | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/macros/systemd.macro b/macros/systemd.macro index 9dc74ff0..1453db95 100644 --- a/macros/systemd.macro +++ b/macros/systemd.macro @@ -1,5 +1,6 @@
SYSTEMD_TMPFILES_DIR = /usr/lib/tmpfiles.d +SYSTEMD_SYSUSERS_DIR = /usr/lib/sysusers.d
Is there a particular reason you are not using %{sysusersdir} here?
MACRO_INSTALL_SYSTEMD_FILES for file in %{DIR_SOURCE}/systemd/*; do @@ -19,3 +20,12 @@ MACRO_INSTALL_SYSTEMD_TMPFILES done unset file end
+MACRO_INSTALL_SYSTEMD_SYSUSERS
- for file in %{DIR_SOURCE}/*.sysusers; do
- [ -e "${file}" ] || continue
- mkdir -p %{BUILDROOT}/%{SYSTEMD_SYSUSERS_DIR}
- cp -vf ${file} %{BUILDROOT}/%{SYSTEMD_SYSUSERS_DIR}/$(basename ${file%*.sysusers}).conf
- done
- unset file
+end
Should the command not be “install” with a specific file mode set? Probably 0644?
-- 2.30.2
Hello Michael,
a big thanks for your feedback and thoughts.
Hello Stefan,
On 30 Mar 2023, at 07:52, Stefan Schantl stefan.schantl@ipfire.org wrote:
This macros works very similar than the tmpfiles one but handles sysusers files.
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org
macros/systemd.macro | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/macros/systemd.macro b/macros/systemd.macro index 9dc74ff0..1453db95 100644 --- a/macros/systemd.macro +++ b/macros/systemd.macro @@ -1,5 +1,6 @@
SYSTEMD_TMPFILES_DIR = /usr/lib/tmpfiles.d +SYSTEMD_SYSUSERS_DIR = /usr/lib/sysusers.d
Is there a particular reason you are not using %{sysusersdir} here?
I was not aware about, I can use this here. So yes you are absolutely right in use %{sysusers} here again and avoid a dubble declaration of the same stuff.
Thought one step ahead, then it would also good to use %{tmpfiles} ?
MACRO_INSTALL_SYSTEMD_FILES for file in %{DIR_SOURCE}/systemd/*; do @@ -19,3 +20,12 @@ MACRO_INSTALL_SYSTEMD_TMPFILES done unset file end
+MACRO_INSTALL_SYSTEMD_SYSUSERS
- for file in %{DIR_SOURCE}/*.sysusers; do
- [ -e "${file}" ] || continue
- mkdir -p %{BUILDROOT}/%{SYSTEMD_SYSUSERS_DIR}
- cp -vf ${file} %{BUILDROOT}/%{SYSTEMD_SYSUSERS_DIR}/$(basename
${file%*.sysusers}).conf
- done
- unset file
+end
Should the command not be “install” with a specific file mode set? Probably 0644?
Yes, I'll switch that simple copy into an install command and specify the correct permissions.
-- 2.30.2
- Stefan
This macros works very similar than the tmpfiles one but handles sysusers files.
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- macros/build.macro | 1 + macros/systemd.macro | 9 +++++++++ 2 files changed, 10 insertions(+)
diff --git a/macros/build.macro b/macros/build.macro index 4eedd6a9..c19430a4 100644 --- a/macros/build.macro +++ b/macros/build.macro @@ -12,6 +12,7 @@ end def MACRO_INSTALL_FILES %{MACRO_INSTALL_DEFAULT_FILES} %{MACRO_INSTALL_SYSTEMD_FILES} + %{MACRO_INSTALL_SYSTEMD_SYSUSERS} %{MACRO_INSTALL_SYSTEMD_TMPFILES} %{MACRO_INSTALL_PAM_FILES} end diff --git a/macros/systemd.macro b/macros/systemd.macro index 085fabbd..7a40cff6 100644 --- a/macros/systemd.macro +++ b/macros/systemd.macro @@ -16,3 +16,12 @@ MACRO_INSTALL_SYSTEMD_TMPFILES done unset file end + +MACRO_INSTALL_SYSTEMD_SYSUSERS + for file in %{DIR_SOURCE}/*.sysusers; do + [ -e "${file}" ] || continue + mkdir -pv %{BUILDROOT}/%{sysusersdir} + install -v -m 0644 ${file} %{BUILDROOT}/%{sysusersdir}/$(basename ${file%*.sysusers}).conf + done + unset file +end