Search code examples
yocto

yocto recipe do_install file name with spaces


I am trying to install a file name with spaces in rootfs and having problems to overcome it. I tried escape characters before the space, single quote start + end of the file name without success.

See below the bbappend recipe. I am trying to set default address with NetworkManager.

SRC_URI += " \
    file://Wired connection 1.nmconnection \
    file://Wired connection 2.nmconnection \
"

FILES:${PN} += " \
    ${sysconfdir}/NetworkManager/system-connections/Wired connection 1.nmconnection  \
    ${sysconfdir}/NetworkManager/system-connections/Wired connection 2.nmconnection \
"

do_install:append() {
    install -d ${D}${sysconfdir}/NetworkManager/system-connections
    install -m 0644 ${WORKDIR}/Wired connection 1.nmconnection ${D}${sysconfdir}/NetworkManager/system-connections
    install -m 0644 ${WORKDIR}/Wired connection 2.nmconnection ${D}${sysconfdir}/NetworkManager/system-connections

Solution

  • The manual specifies:

    The OpenEmbedded build system does not support file or directory names that contain spaces. Be sure that the Source Directory you use does not contain these types of names.

    In the FAQ, they add this.

    But with some additional work, you can use a trick by replacing the spaces by a special character (e.g '_'). For example, rename "Wired connection 1.nmconnection" into "Wired_connection_1.nmconnection". Then, you write a shell function (e.g. named my_install()) which restores the original names at installation time with the tr command. Call this function from the install task in your recipe:

    
    SRC_URI += " \
        file://Wired_connection_1.nmconnection \
        file://Wired_connection_2.nmconnection \
    "
    
    my_install () {
        install -d ${D}${sysconfdir}/NetworkManager/system-connections
        file=Wired_connection_1.nmconnection
        install -m 0644 "${WORKDIR}/$file" ${D}${sysconfdir}/NetworkManager/system-connections
        mv "${D}${sysconfdir}/NetworkManager/system-connections/$file" "${D}${sysconfdir}/NetworkManager/system-connections/`echo $file | tr _ ' '`
        file=Wired_connection_2.nmconnection
        install -m 0644 "${WORKDIR}/$file" ${D}${sysconfdir}/NetworkManager/system-connections
        mv "${D}${sysconfdir}/NetworkManager/system-connections/$file" "${D}${sysconfdir}/NetworkManager/system-connections/`echo $file | tr _ ' '`
    }
    
    do_install:append() {
        my_install
    }