简体   繁体   中英

How should I sed files on the Yocto-generated rootfs?

I would like to find a way to run sed scripts on files within a Yocto-generated OS from a .bbappend file. My OS has a read-only rootfs, which seems to stop any possibility of a post-installation script. Specifically, I need to make these changes to /etc/default/ssh (as run after booting the generated OS):

sed -i 's/var\/run/etc/' /etc/default/ssh 
sed -i 's/_readonly//' /etc/default/ssh

Here's my openssh_7.1p1.bbappend which I've created in an attempt to solve these problems:

FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI += " \
    file://ssh_host_dsa_key.pub  \
    file://ssh_host_rsa_key.pub  \
    ...
    "

do_install_append() {
    sed -i 's/var\/run/etc/' ${D}${sysconfdir}/default/ssh
    sed -i 's/_readonly//' ${D}${sysconfdir}/default/ssh

    # these lines work fine
    install -m 0755 ${WORKDIR}/ssh_host_dsa_key          ${D}/etc/ssh
    install -m 0755 ${WORKDIR}/ssh_host_dsa_key.pub      ${D}/etc/ssh
    ...
}
FILES_${PN} += "${sysconfdir}/default/ssh"

#these lines work
FILES_${PN} += "${sysconfdir}/ssh/ssh_host_dsa_key"
FILES_${PN} += "${sysconfdir}/ssh/ssh_host_dsa_key.pub"
...

BitBake fails during the execution of do_install_append() with this error:

sed: can't read ${TMPDIR}/work/x86-poky-linux/openssh/image/etc/default/ssh: No such file or directory

(where TMPDIR is my actual tmp directory) Obviously this file doesn't exist because the proper copy is created in a separate MULTIMACH_TARGET_SYS directory (ie not x86-poky-linux ) by image.bbclass.

Is this sort of thing possible to do from within a .bbappend file (or some other compartmentalized way)? I have found a way to do it within a .inc file with ROOTFS_POSTPROCESS_COMMAND within my core-image, but this method is leading to a poor organizational structure.

Maybe moving the operations to a post-installation function in your .bbappend is appropriate for your circumstance?

pkg_postinst_${PN} () {
    #!/bin/sh
    if [ x"$D" = "x" ]; then
        sed -i 's/var\/run/etc/' /etc/default/ssh 
        sed -i 's/_readonly//' /etc/default/ssh
    else
        exit 1
    fi
}

The function above will cause the sed operations to execute on first boot, rather than during the build.

在SRC_URI变量中包含您尝试sed的文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM