diff --git a/modules/script/legacy-compatibility-placeholder.md b/modules/script/legacy-compatibility-placeholder.md new file mode 100644 index 00000000..c47b3bc5 --- /dev/null +++ b/modules/script/legacy-compatibility-placeholder.md @@ -0,0 +1,3 @@ +`script.sh` should mimic `scripts.sh` code, in order to retain compatibility with existing custom image users which use `script` as a module name instead of new `scripts` module name. + +This is done in order to standardize module naming convention better. \ No newline at end of file diff --git a/modules/script/README.md b/modules/scripts/README.md similarity index 83% rename from modules/script/README.md rename to modules/scripts/README.md index 05d5945d..885aa91f 100644 --- a/modules/script/README.md +++ b/modules/scripts/README.md @@ -1,6 +1,6 @@ -# `script` +# `scripts` -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 `scripts` 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 `files/scripts/` directory, are declared under `scripts:`. diff --git a/modules/script/module.yml b/modules/scripts/module.yml similarity index 71% rename from modules/script/module.yml rename to modules/scripts/module.yml index dc298ecd..15cab8ea 100644 --- a/modules/script/module.yml +++ b/modules/scripts/module.yml @@ -1,7 +1,7 @@ -name: script -shortdesc: The script module can be used to run arbitrary bash snippets and scripts at image build time. +name: scripts +shortdesc: The scripts module can be used to run arbitrary bash snippets and scripts at image build time. example: | - type: script + type: scripts 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 diff --git a/modules/scripts/scripts.sh b/modules/scripts/scripts.sh new file mode 100644 index 00000000..b962bce9 --- /dev/null +++ b/modules/scripts/scripts.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# Tell build process to exit if there are any errors. +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" + "$PWD/$SCRIPT" +done + +for SNIPPET in "${SNIPPETS[@]}"; do + echo "Running snippet $SNIPPET" + bash -c "$SNIPPET" +done \ No newline at end of file diff --git a/modules/script/script.tsp b/modules/scripts/scripts.tsp similarity index 51% rename from modules/script/script.tsp rename to modules/scripts/scripts.tsp index 222ab355..39dc52cd 100644 --- a/modules/script/script.tsp +++ b/modules/scripts/scripts.tsp @@ -1,12 +1,12 @@ import "@typespec/json-schema"; using TypeSpec.JsonSchema; -@jsonSchema("/modules/script.json") +@jsonSchema("/modules/scripts.json") model ScriptModule { - /** The script module can be used to run arbitrary bash snippets and scripts at image build time. - * https://blue-build.org/reference/modules/script/ + /** The scripts module can be used to run arbitrary bash snippets and scripts at image build time. + * https://blue-build.org/reference/modules/scripts/ */ - type: "script"; + type: "scripts"; /** List of bash one-liners to run. */ snippets?: Array;