tools/autoinstall/run_command.sh

49 lines
1 KiB
Bash

#!/usr/bin/env bash
group=${args[group]:?}
file=${args[--file]:-}
clean=${args[--clean]:-}
_config_query() {
tomlq -c --arg group "$group" \
'.autoinstall | map(select(.groups + ["all"] | contains([$group]))) | '"$1" \
"$file"
}
_config_query ".[]" | while read -r entry; do
install_args=()
type=$(echo "$entry" | jq -r '.type')
source=$(echo "$entry" | jq -r '.source')
target=$(echo "$entry" | jq -r '.target')
hook=$(echo "$entry" | jq -r '.hook // ""')
pipe=$(echo "$entry" | jq -r '.pipe // ""')
completions=$(echo "$entry" | jq -r '.completions // ""')
if [[ -n "$hook" ]]; then
install_args+=("--hook=$hook")
fi
if [[ -n "$clean" ]]; then
install_args+=("--clean")
fi
install_args+=("$type")
if [[ -n "$pipe" ]]; then
install_args+=("--pipe=$pipe")
fi
if [[ -n "$completions" ]]; then
install_args+=("--completions=$completions")
fi
if [[ $source = \$* ]]
then
source=$(eval "echo $source")
fi
install_args+=("$source")
install_args+=("$(eval "echo $target")")
"$0" "${install_args[@]}" || true # Continue on error
done