How to run a shell script while compiling a recipe in Yocto - yocto

I have created a bash shell script, and want this script to be executed while I build that recipe(under which script was created). So I want bitbake to run this script while building recipe. What should I add into .bb file?
Any help would really be appreciated.

If you want to run a script in a recipe you can define a task and add a dependency to it
This is in my uboot.bb file. With this the uboot image is copied to a directory every time uboot is compiled
The before do_build means that this script is executed every time you run bitbake <recipe>
The after do deploy means that every time uboot is compiled this script is executed.
PACKET_OUTDIR ?= "${DEPLOY_DIR_IMAGE}/out"
UBOOT_OUTFILE ?= "${MACHINE}.uboot"
# Copy bin after compile
addtask bin after do_deploy before do_build
# redo task if vardeps variables changed from last execution
do_bin[vardeps] = "UBOOT_OUTFILE PACKET_OUTDIR"
do_bin() {
# create directory
install -d ${PACKET_OUTDIR}
# copy uboot bin to the out directory and print output on display
bbplain $(cp -vH ${DEPLOY_DIR_IMAGE}/${UBOOT_MAKE_TARGET}-${UBOOT_CONFIG} ${PACKET_OUTDIR}/${UBOOT_OUTFILE})
# run an external script in home
~/external_script.sh
}
If you want to run the script before the compiling just use before do_compile

Related

Scala: IOException during execute sh file

I'm trying to execute sh-file from resources.
Executed file is located at the root of resources: src/main/resources/hiveCommand.sh
import sys.process._
"./hiveCommand.sh" !!
But receive IOException: not such file or directory
What am I doing wrong?
Scala's Process integration does not know how to handle shell scripts. It can only start programs. To run a shell script you need start a shell (e.g. bash) and give it the file to run as an argument.
There is a complication however. Since the script is a resource (located at src/main/resources/hiveCommand.sh during compile time), it is located in a jar at run time.
So in short:
First extract the shell script (use getClass.getResourceAsStream("/hiveCommand.sh") to read the resource) and store it on disk.
Then start with something like:
"bash /tmp/hiveCommand.sh".!!

How to execute custom fish scripts in custom path folder

I'm having trouble executing a fish shell script I created. I added it to a custom path I added using fish_add_path. The folder appears just fine in $fish_user_paths and $PATH, and i've CHMOD +x the file, but when I type the name of the file, (which is pickc ath the moment), it can't find the command. How do I add fish scripts to the path and execute them like any other cli command (e.g. pickc)?
The content of the script is:
#!usr/bin/fish
colorpicker --short --one-shot --preview | sed -z 's/\n//g' | xclip -selection c
pkill picom
picom -b
I can execute the script just fine with the fish -c pickc command, but I can't execute with ./pickc, which gives me the error
Failed to execute process './pickc'. Reason: The file './pickc' does not exist or could not be executed.
I have doubly confirmed that the path in the $PATH and $fish_user_variable variable does lead to the folder containing the script.
Edit: I noticed that my paths were all really messed up somehow. The below answer does fix the issue of not being able to execute it, so thanks
You have mistyped your shebang. Switch
#!usr/bin/fish
to
#!/usr/bin/fish
or whatever path which fish shows.

Building Artifactory fails for Build Stage in Delivery Pipeline

I have created a toolchain, which downloads the code from the bitbucket repository and builds the docker image in IBM Cloud.
After the code builds the image, the build stage fails while building the artifactory.
Error:
Preparing the build artifacts...
Customer script does not exist for the job, exitting
I have specified the Build archive directory as the folder name. Do I need to write any scripts for archiving?
That particular error occurs when one of our checks -- the existence of /home/pipeline/$TASK_ID/_customer_script.sh -- fails.
Archiving happens automatically but that file needs to be present as we use it as part of the traceability around how the artifact was created. Is it possible that file is getting removed? (Also will look into removing or making the check non-fatal however that will take time)
This issue appears to be caused by setting a working directory for the job. _customer_script.sh gets dropped into the working directory, but the script Simon is referring to (/opt/IBM/pipeline/bin/ids-buildables-notify.sh) only checks the top-level directory the code input is at (/home/pipeline/$TASK_ID/).
Three options to fix this, assuming you're doing a container registry job:
Run cp _customer_script.sh /home/pipeline/$TASK_ID in your script. The ids-buildables-notify.sh script does some grepping for your bx cr build call, so make sure that's still in there.
touch /home/pipeline/$TASK_ID/_customer_script.sh and export PIPELINE_IMAGE_URL=<your image url>. If PIPELINE_IMAGE_URL is set, the notify script doesn't bother with being clever, which I prefer.
Don't change the working directory.
A script which works for me:
#!/bin/bash
echo -e "Build environment variables:"
echo "REGISTRY_URL=${REGISTRY_URL}"
echo "REGISTRY_NAMESPACE=${REGISTRY_NAMESPACE}"
echo "IMAGE_NAME=${IMAGE_NAME}"
echo "BUILD_NUMBER=${BUILD_NUMBER}"
echo -e "Building container image"
set -x
export PIPELINE_IMAGE_URL=$REGISTRY_URL/$REGISTRY_NAMESPACE/$IMAGE_NAME:$BUILD_NUMBER
bx cr build -t $PIPELINE_IMAGE_URL .
set +x
touch /home/pipeline/$TASK_ID/_customer_script.sh

Compiling powershell scripts using PowerGUI

In my power shell script(task_scheduler.ps1) when runs in a system, it creates a daily task in task scheduler. This daily task is to run another power shell file (action.ps1) in the system.
Now I would like to convert task_scheduler.ps1 into an exe file. Since this file accesses action.ps1 file, I tried giving the same as "dependency" in Power GUI (while compiling script).
Now, the task is getting scheduled. But the task is not running the action.ps1 file. As the file is not present in the specified path.
How shall I get the path whether the dependency ps1 files get saved?

How to run perl script from any where (any directory)

I have a perl script exist in the follwoing path (/home/Leen/Desktop/Tools/bin/tool.pl)
Every time I want to run this tool I go to the terminal
>
and then change the directory to
..../bin>
Then I run the perl by writing
..../bin> perl tool.pl file= whatever config= whatever
The problem is that I want to run this perl script without the need to go to the bin folder where it exist . so I can run perl script from any directory and as soon as I enter shell
I went to the etc/environment and I wrote the follwoing
export PERL5LIB=$PERL5LIB:/home/Leen/Desktop/Tools/bin
But when I go to terminal and write the follwoing straight ahead without going to bin folder where tool.pl exist
>perl tool.pl file=... config=...
it says the file "tool.pl" does not exist???
The first argument to the perl program is the path to an executable file. These calls are equivalent:
:~$ perl /home/Leen/Desktop/Tools/bin/tool.pl
:~$ perl ~/Desktop/Tools/bin/tool.pl
:~$ perl ./Desktop/Tools/bin/tool.pl
:~/Desktop/Tools/bin$ perl tool.pl
:~/Desktop/Tools/bin$ perl ./tool.pl
etc.
In the shell the tilde ~ expands to your home directory, and ./ symbolizes the current directory. On *nix shells (including the various terminal emulators on ubuntu), the command prompt ususally is $ in nomal mode, # as root user and seldom %. > Is a secondary command prompt, e.g. when continuing a multiline argument, unlike cmd.exe on Windows.
The PERL5LIB variable determines where Perl looks for modules, not for executable files.
You can set a script as executable via chmod +x FILENAME. You can then call the script without specifying the perl program:
:~/Desktop/Tools/bin$ ./tool.pl
You can modify the PATH variable to change where the shell looks for executables. The PATH usually contains /usr/bin/ and other directories. You can add a directory of your own via
PATH=$PATH:/home/Leen/Desktop/Tools/bin
Add your directory at the end of the PATHes, so you don't overrule other programs.
If you want to set this permanently, you can add this line to the file ~/.bashrc (only for your user and only for the bash shell).
Then you can call your script from anywhere, without a full path name:
:~/foo/bar$ tool.pl
You should consider using a more specific command name in this case, to prevent name clashes.