feat: Add support for NuShell scripts

This commit is contained in:
Gerald Pinder 2024-12-24 13:23:54 -05:00
parent 1889bd9984
commit 74bd05643f
13 changed files with 115 additions and 16 deletions

View file

@ -19,16 +19,54 @@ print_banner() {
printf '%*.*s%s%*.*s\n' 0 "$padlen" "$padding" "$text" 0 "$padlen" "$padding"
}
get_script_path() {
local script_name="$1"
local extensions=("nu" "sh" "bash")
local base_script_path="/tmp/modules/${script_name}/${script_name}"
local tried_scripts=()
# See if
if [[ -f "${base_script_path}" ]]; then
echo "${base_script_path}"
return 0
fi
tried_scripts+=("${script_name}")
# Iterate through each extension and check if the file exists
for ext in "${extensions[@]}"; do
local script_path="${base_script_path}.${ext}"
tried_scripts+=("${script_name}.${ext}")
if [[ -f "$script_path" ]]; then
# Output only the script path without extra information
echo "$script_path"
return 0 # Exit the function when the first matching file is found
fi
done
# If no matching file was found
echo "Failed to find scripts matching: ${tried_scripts[*]}" >&2
return 1
}
module="$1"
params="$2"
script_path="/tmp/modules/${module}/${module}.sh"
script_path="$(get_script_path "$module")"
nushell_version="$(echo "${params}" | jq '.["nushell-version"] // empty')"
export PATH="/usr/libexec/bluebuild/nu/:$PATH"
color_string "$(print_banner "Start '${module}' Module")" "33"
chmod +x ${script_path}
chmod +x "${script_path}"
if ${script_path} "${params}"; then
if "${script_path}" "${params}"; then
color_string "$(print_banner "End '${module}' Module")" "32"
else
color_string "$(print_banner "Failed '${module}' Module")" "31"
exit 1
fi
if command -v ostree > /dev/null; then
ostree container commit
fi