Skip to contentSkip to conversation

systemd: allow add users to groups in rootfs postprocess

PATCH New Stephano Cetola 1 participant 1 message Jul 14, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 systemd: allow add users to groups in rootfs postprocess

Currently the functionality checks for the "u" and "g" flags to create users and groups, but not the "m" flag to add users to groups. This change first checks to be sure that the users and groups are created, creates them if necessary, then adds the user to the group.

---
 meta/classes/rootfs-postcommands.bbclass | 9 +++++++++
 1 file changed, 9 insertions(+)
meta/classes/rootfs-postcommands.bbclass +9 -0
index db8b551..b38b6a5 100644
@@ -45,6 +45,15 @@ systemd_create_users () {
 			[ "$id" != "-" ] && groupadd_params="$groupadd_params --gid $id"
 			groupadd_params="$groupadd_params --system $name"
 			eval groupadd --root ${IMAGE_ROOTFS} $groupadd_params || true
+		elif [ "$type" = "m" ]; then
+			group=$id
+			if [ ! `grep -q "^${group}:" ${IMAGE_ROOTFS}${sysconfdir}/group` ]; then
+				eval groupadd --root ${IMAGE_ROOTFS} --system $group
+			fi
+			if [ ! `grep -q "^${name}:" ${IMAGE_ROOTFS}${sysconfdir}/passwd` ]; then
+				eval useradd --root ${IMAGE_ROOTFS} --shell /sbin/nologin --system $name
+			fi
+			eval usermod --root ${IMAGE_ROOTFS} -a -G $group $name
 		fi
 		done
 	done
Signature · 1 line
2.9.0