Yocto:更改 /usr /lib的所有权

发布于 2025-02-03 05:44:27 字数 351 浏览 5 评论 0原文

如何更改/usr/lib目录的所有权以及特定用户内部的所有库?

我试图在没有成功的情况下编写自定义BB食谱。

SUMMARY = "Change /usr/lib ownership."
LICENSE = "MIT"

FILES_${PN} = "${libdir}\*"

do_install () {
        chown user1:group1 ${D}${libdir}
}

我还尝试使用$ {libdir}而不是/usr/lib,但没有成功。如何正确访问/usr/lib

How can I change ownership of the /usr/lib directory and all libraries inside for a specific user?

I tried to write a custom bb recipe without success.

SUMMARY = "Change /usr/lib ownership."
LICENSE = "MIT"

FILES_${PN} = "${libdir}\*"

do_install () {
        chown user1:group1 ${D}${libdir}
}

I also tried to use ${libdir} instead of /usr/lib, but without success. How can I access correctly /usr/lib?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青柠芒果 2025-02-10 05:44:27

在YOCTO编译期间,不可能更改它,因为文件系统是在过程结束时构建的。有两种实现它的方法。首先是在系统图像安装脚本中添加 chmod
第二个是准备系统服务和bash脚本,该脚本可以检查所有者并在必要时设置当前的脚本。

所有者updater.service

[Unit]
Description=Directory Owner Updater
After=local-fs.target

[Service]
Type=oneshot
ExecStart=/opt/update-owner
StandardOutput=journal

[Install]
WantedBy=multi-user.target

更新所有者

#!/bin/bash

USER=user_name
DIR_PATH="/usr/lib"
DIR_OWNER="$(stat --format '%U' $DIR_PATH)"
DIR_GROUP="$(stat --format '%G' $DIR_PATH)"

if [ "$(id -u $DIR_OWNER)" -eq "$(id -u $USER)" ] &&
   [ "$(id -g $DIR_GROUP)" -eq "$(id -g $USER)" ]; then
    echo Correct owner
else
    echo Incorrect owner
fi
    chown -R [user_name/user_id]:[group_name/group_id] /usr/lib

It's impossible to change it during yocto compilation because the filesystem is built at the end of the process. There are two ways to achieve it. The first is to add chmod in the system image installation script.
The second one is to prepare a system service and bash script, which can check the owner and set the current one if necessary.

owner-updater.service

[Unit]
Description=Directory Owner Updater
After=local-fs.target

[Service]
Type=oneshot
ExecStart=/opt/update-owner
StandardOutput=journal

[Install]
WantedBy=multi-user.target

update-owner

#!/bin/bash

USER=user_name
DIR_PATH="/usr/lib"
DIR_OWNER="$(stat --format '%U' $DIR_PATH)"
DIR_GROUP="$(stat --format '%G' $DIR_PATH)"

if [ "$(id -u $DIR_OWNER)" -eq "$(id -u $USER)" ] &&
   [ "$(id -g $DIR_GROUP)" -eq "$(id -g $USER)" ]; then
    echo Correct owner
else
    echo Incorrect owner
fi
    chown -R [user_name/user_id]:[group_name/group_id] /usr/lib
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文