From: Stefan Schantl <stefan.schantl@ipfire.org>
To: development@lists.ipfire.org
Subject: [PATCH] setup: Use systemd sysusers mechanism to create users/groups
Date: Wed, 29 Mar 2023 17:06:31 +0200 [thread overview]
Message-ID: <20230329150631.2890261-1-stefan.schantl@ipfire.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 2914 bytes --]
The sysusers files will be generated by the corresponding script file,
based on the passwd and group file in the source directory.
So we easily can edit the files stored in git and the changes will be
taken.
Signed-off-by: Stefan Schantl <stefan.schantl(a)ipfire.org>
---
dbus/dbus.sysusers | 7 +++++++
setup/generate-sysusers-fragments.sh | 31 ++++++++++++++++++++++++++++
setup/setup.nm | 7 ++++++-
3 files changed, 44 insertions(+), 1 deletion(-)
create mode 100644 dbus/dbus.sysusers
create mode 100755 setup/generate-sysusers-fragments.sh
diff --git a/dbus/dbus.sysusers b/dbus/dbus.sysusers
new file mode 100644
index 000000000..2ed994442
--- /dev/null
+++ b/dbus/dbus.sysusers
@@ -0,0 +1,7 @@
+#Type Name ID REMARK Home directory Shell
+
+# Dbus group
+g dbus 61
+
+# Dbus user
+u dbus 61 "User for dbus service" / /usr/sbin/nologin
diff --git a/setup/generate-sysusers-fragments.sh b/setup/generate-sysusers-fragments.sh
new file mode 100755
index 000000000..194c7204b
--- /dev/null
+++ b/setup/generate-sysusers-fragments.sh
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+#SPDX-License-Identifier: 0BSD
+
+set -euo pipefail
+
+test -f group
+test -f passwd
+
+mkdir -p sysusers.d
+
+while read -r line; do
+ groupname=$(echo "${line}" | cut -d: -f1)
+ gid=$(echo "${line}" | cut -d: -f3)
+ echo "g ${groupname} ${gid}"
+done <group >sysusers.d/20-setup-groups.conf
+
+while read -r line; do
+ username=$(echo "${line}" | cut -d: -f1)
+ uid=$(echo "${line}" | cut -d: -f3)
+ gid=$(echo "${line}" | cut -d: -f4)
+ gecos=$(echo "${line}" | cut -d: -f5)
+ homedir=$(echo "${line}" | cut -d: -f6)
+ if [ "${homedir}" == "/" ]; then
+ homedir="-"
+ fi
+ shell=$(echo "${line}" | cut -d: -f7)
+ if [ "${shell}" == "/usr/sbin/nologin" ]; then
+ shell="-"
+ fi
+ echo "u ${username} ${uid}:${gid} \"${gecos}\" ${homedir} ${shell}"
+done <passwd >sysusers.d/20-setup-users.conf
diff --git a/setup/setup.nm b/setup/setup.nm
index cee66fab4..d4fd041ec 100644
--- a/setup/setup.nm
+++ b/setup/setup.nm
@@ -5,7 +5,7 @@
name = setup
version = 3.0
-release = 18
+release = 19
arch = noarch
groups = Base Build System/Base
@@ -29,6 +29,7 @@ build
end
build
+ bash ./generate-sysusers-fragments.sh
bash ./shadowconvert.sh
end
@@ -69,6 +70,10 @@ build
echo "d /run/motd.d 0755 root root -" >> %{BUILDROOT}%{tmpfilesdir}/%{name}.conf
chmod 0644 %{BUILDROOT}%{tmpfilesdir}/%{name}.conf
+ # Install generated sysusers files.
+ mkdir -pv %{BUILDROOT}%{sysusersdir}
+ install -v -m 0644 %{DIR_APP}/sysusers.d/*.conf %{BUILDROOT}%{sysusersdir}
+
mkdir -pv %{BUILDROOT}%{sysconfdir}/sysctl.d
install -m 644 %{DIR_APP}/sysctl/printk.conf \
%{BUILDROOT}%{sysconfdir}/sysctl.d/printk.conf
--
2.30.2
reply other threads:[~2023-03-29 15:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230329150631.2890261-1-stefan.schantl@ipfire.org \
--to=stefan.schantl@ipfire.org \
--cc=development@lists.ipfire.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox