]> git.ipfire.org Git - people/stevee/ipfire-3.x.git/commitdiff
setup: Use systemd sysusers mechanism to create users/groups
authorStefan Schantl <stefan.schantl@ipfire.org>
Tue, 11 Apr 2023 13:46:07 +0000 (15:46 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Tue, 11 Apr 2023 13:46:07 +0000 (15:46 +0200)
The sysusers files will be generated by the corresponding script file,
based on the passwd and group file in the source directory.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
setup/generate-sysusers-fragments.sh [new file with mode: 0755]
setup/setup.nm

diff --git a/setup/generate-sysusers-fragments.sh b/setup/generate-sysusers-fragments.sh
new file mode 100755 (executable)
index 0000000..194c720
--- /dev/null
@@ -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
index cee66fab47e2f19a0638824927f397b4ebdd1fad..d4fd041ec003367b5ee7ff77450bc380ce9e4479 100644 (file)
@@ -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