tools/autoinstall/run_command.sh
Tobias Reisinger e81f5ab4da
All checks were successful
/ build-artifacts (autoinstall) (push) Successful in 25s
/ build-artifacts (autostart-manage) (push) Successful in 15s
/ upload-release (push) Successful in 19s
Improve run command to remove tomlq depedency
2024-05-13 13:58:40 +02:00

85 lines
1.7 KiB
Bash

#!/usr/bin/env bash
group=${args[group]:?}
file=${args[--file]:-}
clean=${args[--clean]:-}
_handle_entry() {
type="$1"
source="$2"
target="$3"
hook="$4"
pipe="$5"
completions="$6"
install_args=()
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
}
file_lines=$(wc -l < "$file")
line=0
while [[ $line -lt $file_lines ]]; do
entry=$(tail -n +$line "$file" | awk '/^$/{exit} {print} ')
entry_len=$(echo "$entry" | wc -l)
line=$((line + entry_len))
if [[ $entry_len -le 1 ]]; then
continue
fi
unset AUTOINSTALL_ITEM_TYPE \
AUTOINSTALL_ITEM_SOURCE \
AUTOINSTALL_ITEM_TARGET \
AUTOINSTALL_ITEM_HOOK \
AUTOINSTALL_ITEM_PIPE \
AUTOINSTALL_ITEM_COMPLETIONS \
AUTOINSTALL_ITEM_GROUPS
eval "$entry"
# check if we have the required vars
if [[ -z "${AUTOINSTALL_ITEM_TYPE:-}" \
|| -z "${AUTOINSTALL_ITEM_SOURCE:-}" \
|| -z "${AUTOINSTALL_ITEM_TARGET:-}" \
|| -z "${AUTOINSTALL_ITEM_GROUPS:-}" ]]
then
continue
fi
if [[ "$group" != "all" ]]
then
# check if group is in groups
if [[ ! "${AUTOINSTALL_ITEM_GROUPS}" =~ (^|,)$group(,|$) ]]
then
continue
fi
fi
_handle_entry "$AUTOINSTALL_ITEM_TYPE" "$AUTOINSTALL_ITEM_SOURCE" \
"$AUTOINSTALL_ITEM_TARGET" "${AUTOINSTALL_ITEM_HOOK:-}" "${AUTOINSTALL_ITEM_PIPE:-}" "${AUTOINSTALL_ITEM_COMPLETIONS:-}"
done