Search code examples
embeddedembedded-linuxyocto

How to add a script (bash script) to my linux image developed in yocto?


I am developing a script to install packages in a linux image developed using yocto. Currently, I send the .sh script by scp to my device with the linux image, but I want to install this script directly in the linux image, and when for the device to have the .sh file when it boots. How can I do this in yocto? Do I need to create a recipe for this script?


Solution

  • You should create a recipe and a systemd services to enable it a boot time if you want to. The architecture should be like this:

    my_script/
    ├── files
    │   ├── my_script.service
    │   └── my_script.sh
    └── my_recipe.bb
    

    Your recipe should look like this,

    my_recipe.bb:

    LICENSE = "CLOSED"
    
    LIC_FILES_CHKSUM = ""
    
    SRC_URI = "file://myscript.service"
    
    SRC_URI += "file://myscript.sh"
    
      
    inherit systemd
    
    do_install() {
    
    install -Dm0755 ${WORKDIR}/my_script.sh ${D}/usr/bin/my_script.sh
    install -Dm0644 ${WORKDIR}/my_script.service ${D}${systemd_system_unitdir}/my_script.service
    
    }
    
    
    SYSTEMD_SERVICE_${PN} = "my_script.service"
    

    Of course, this should be in a meta-layer that is already in your conf/bblayers.conf Otherwise create it and add it manually.