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
?
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