setup: Use systemd sysusers mechanism to create users/groups
Commit Message
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@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
new file mode 100644
@@ -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
new file mode 100755
@@ -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
@@ -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