From 7a2647519eec1f9f9aebb5084994ecbf59293264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=BCller?= Date: Sun, 4 Nov 2018 21:12:26 +0100 Subject: [PATCH] Add user-with-full-skel.bbclass to fix uncomplete /etc/skel population MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andreas Müller --- README | 2 +- classes/user-with-full-skel.bbclass | 43 +++++++++++++++++++ .../users/unpriv-user_1.2.bb | 2 +- recipes-image/include/x11-base.inc | 2 + recipes-image/weston/weston-base-image.bb | 2 + 5 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 classes/user-with-full-skel.bbclass diff --git a/README b/README index fdf6577..31f106c 100644 --- a/README +++ b/README @@ -43,7 +43,7 @@ appends: for the layer is ignored (see conf/layer.conf). classes: - Currently instant-remote.bbclass only. + Currently instant-remote.bbclass and user-with-full-skel.bbclass. conf: layer.conf / and distro configurations diff --git a/classes/user-with-full-skel.bbclass b/classes/user-with-full-skel.bbclass new file mode 100644 index 0000000..9d804d0 --- /dev/null +++ b/classes/user-with-full-skel.bbclass @@ -0,0 +1,43 @@ +# Problem with copying /etc/skel to home forder by useradd only is that +# user-recipe must RDEPEND on all recipes installing files to /etc/skel. +# Otherwise content found in home folder is unpredictable. +# +# To get around, this class was created. It is dual role and can be inherited +# by: +# +# * recipes creating a user whose home folder shall be populated by /etc/skel. +# The only action performed is dropping a file +# /home/${USERNAME}/${SKEL_INIT_MARKER} to mark the folder for later +# population. +# * images which get a postprocess command copying /etc/skel for those home +# folders marked. + +SKEL_INIT_MARKER = "force-skel-full-init" + +# user recipe part +pkg_postinst_${PN}() { + if [ -n "$D" ]; then + touch $D/home/${USERNAME}/${SKEL_INIT_MARKER} + fi +} + +# image recipe part +ROOTFS_POSTPROCESS_COMMAND += "postinst_copy_skel; " + +postinst_copy_skel () { + if [ -d "${IMAGE_ROOTFS}/home" -a -d "${IMAGE_ROOTFS}/${sysconfdir}/skel" ]; then + for home_target in `find "${IMAGE_ROOTFS}/home" -name ${SKEL_INIT_MARKER}`; do + # remove marker + rm "$home_target" + homedir=`dirname "$home_target"` + user=`basename "$homedir"` + # 1. copy -> /home/user/skel + cp -rf --preserve=mode,ownership,timestamps,links ${IMAGE_ROOTFS}${sysconfdir}/skel "$homedir" + chown -R "$user:$user" "$homedir/skel" + # 2. copy -> /home/user - TBD mv? + cp -rfT --preserve=mode,ownership,timestamps,links "$homedir/skel" "$homedir" + # 3. remove /home/user/skel + rm -rf "$homedir/skel" + done + fi +} diff --git a/recipes-defaultconfig/users/unpriv-user_1.2.bb b/recipes-defaultconfig/users/unpriv-user_1.2.bb index c822c4f..e71af40 100644 --- a/recipes-defaultconfig/users/unpriv-user_1.2.bb +++ b/recipes-defaultconfig/users/unpriv-user_1.2.bb @@ -2,7 +2,7 @@ DESCRIPTION = "This recipe adds a user 'morona' without password" LICENSE = "MIT" LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" -inherit useradd +inherit useradd user-with-full-skel USERNAME = "morona" # groups user shall be member of (NO WHITESPACES ALLOWED) diff --git a/recipes-image/include/x11-base.inc b/recipes-image/include/x11-base.inc index 4db5e53..074b7c4 100644 --- a/recipes-image/include/x11-base.inc +++ b/recipes-image/include/x11-base.inc @@ -1,3 +1,5 @@ +inherit user-with-full-skel + X11_BASE_INSTALL += " \ ${DISTRO_GUI_USER} \ packagegroup-core-x11-xserver \ diff --git a/recipes-image/weston/weston-base-image.bb b/recipes-image/weston/weston-base-image.bb index 7c94c96..2508ba5 100644 --- a/recipes-image/weston/weston-base-image.bb +++ b/recipes-image/weston/weston-base-image.bb @@ -2,6 +2,8 @@ require recipes-image/console/console-net-image.bb export IMAGE_BASENAME = "weston-base-image" +inherit user-with-full-skel + IMAGE_INSTALL += " \ ${DISTRO_GUI_USER} \ \