feat(script): add snippet support for script module (#124)

This commit is contained in:
xynydev 2024-03-17 12:14:23 +02:00
parent 29649646e3
commit a97326fb98
3 changed files with 15 additions and 6 deletions

View file

@ -1,6 +1,8 @@
# `script`
The `script` module can be used to run arbitrary scripts at image build time that take no or minimal external configuration (in the form of command line arguments).
The `script` module can be used to run arbitrary bash snippets and scripts at image build time. This is intended for running commands that need no YAML configuration.
The snippets, which are run in a bash subshell, are declared under `snippets:`.
The scripts, which are run from the `config/scripts` directory, are declared under `scripts:`.
## Creating a Script

View file

@ -1,7 +1,10 @@
name: script
shortdesc: The script module can be used to run arbitrary scripts at image build time.
shortdesc: The script module can be used to run arbitrary bash snippets and scripts at image build time.
readme: https://raw.githubusercontent.com/blue-build/modules/main/modules/script/README.md
example: |
type: script
snippets:
- "curl https://example.com/examplebinary > /usr/bin/examplebinary" # example: download binary
- "ln -sf /usr/bin/ld.bfd /etc/alternatives/ld && ln -sf /etc/alternatives/ld /usr/bin/ld" # example: ld alternatives symlink workaround
scripts:
- myscript.sh # will run config/scripts/myscript.sh
- myscript.sh # example: run config/scripts/myscript.sh

View file

@ -4,13 +4,17 @@
set -euo pipefail
get_yaml_array SCRIPTS '.scripts[]' "$1"
get_yaml_array SNIPPETS '.snippets[]' "$1"
cd "$CONFIG_DIRECTORY/scripts"
# Make every script executable
find "$PWD" -type f -exec chmod +x {} \;
for SCRIPT in "${SCRIPTS[@]}"; do
echo "Running script $SCRIPT"
eval "$PWD/$SCRIPT"
"$PWD/$SCRIPT"
done
for SNIPPET in "${SNIPPETS[@]}"; do
echo "Running snippet $SNIPPET"
bash -c "$SNIPPET"
done