主目录不是由 useradd-example.bb 创建的

Home directory not created by useradd-example.bb

我正在使用 useradd-example.bb 的修改版本来仅创建 user1USERADD_PARAMS 建议在 /home/user1.

下创建主目录

构建映像时,user1 会按预期添加,目录 /usr/share/user 也会按预期添加,并具有正确的权限。但是,不会创建 /home/user1 目录。实际上,我已经很惊讶 USERADD_PARAMS.

中不需要指定 -d ${D}/home/user1 等路径

我是否必须使用适当的权限在 do_install 中手动添加路径?我是否从导致主目录丢失的原始示例中删除了某些内容,或者我是否必须在 USERADD_PARAM 中指定完整路径,例如 -d ${D}/home/user1?

这是被 user2user3 部分删除的示例(我发现这使示例过于复杂)。

SUMMARY = "Example recipe for using inherit useradd"
DESCRIPTION = "This recipe serves as an example for using features from useradd.bbclass"
SECTION = "examples"
PR = "r1"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"

S = "${WORKDIR}"

inherit useradd

# You must set USERADD_PACKAGES when you inherit useradd. This
# lists which output packages will include the user/group
# creation code.
USERADD_PACKAGES = "${PN}"

# You must also set USERADD_PARAM and/or GROUPADD_PARAM when
# you inherit useradd.

# USERADD_PARAM specifies command line options to pass to the
# useradd command. Multiple users can be created by separating
# the commands with a semicolon. Here we'll create two users,
# user1 and user2:
USERADD_PARAM:${PN} = "-u 1210 -d /home/user1 -r -s /bin/bash user1"

# GROUPADD_PARAM works the same way, which you set to the options
# you'd normally pass to the groupadd command. This will create
# groups group1 and group2:
GROUPADD_PARAM:${PN} = "-g 880 group1"

do_install () {
    install -d -m 755 ${D}${datadir}/user1

    # The new users and groups are created before the do_install
    # step, so you are now free to make use of them:
    chown -R user1 ${D}${datadir}/user1

    chgrp -R group1 ${D}${datadir}/user1
}

FILES:${PN} = "${datadir}/user1 /usr/share/user1"

# Prevents do_package failures with:
# debugsources.list: No such file or directory:
INHIBIT_PACKAGE_DEBUG_SPLIT = "1"

我不确定这是否是一种干净的方法,但我最终创建了如下主目录:

do_install () {
    install -d -m 711 ${D}/home/user1
    chown -R user1 ${D}/home/user1
    chgrp -R user1 ${D}/home/user1
}

重要的经验教训:如果您打算将文件从另一个配方移动到创建的主目录中,请确保您在那里创建的目录与此处设置的权限相匹配。否则你会得到一个错误,说有冲突的目录。