From aed681d0b0c18cc2966c9c687434cf6b4b8f90e0 Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Mon, 13 May 2024 15:01:21 +0200 Subject: [PATCH] Improve error handling in autoinstall run --- autoinstall/run_command.sh | 76 +++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/autoinstall/run_command.sh b/autoinstall/run_command.sh index e60be67..f82eb34 100644 --- a/autoinstall/run_command.sh +++ b/autoinstall/run_command.sh @@ -4,7 +4,7 @@ group=${args[group]:?} file=${args[--file]:-} clean=${args[--clean]:-} -_handle_entry() { +_install_entry() { type="$1" source="$2" target="$3" @@ -30,19 +30,49 @@ _handle_entry() { install_args+=("--completions=$completions") fi - if [[ $source = \$* ]] - then - source=$(eval "echo $source") - fi install_args+=("$source") - install_args+=("$(eval "echo $target")") + install_args+=("$target") + + "$0" "${install_args[@]}" +} + +_handle_entry() { + unset AUTOINSTALL_ITEM_TYPE \ + AUTOINSTALL_ITEM_SOURCE \ + AUTOINSTALL_ITEM_TARGET \ + AUTOINSTALL_ITEM_HOOK \ + AUTOINSTALL_ITEM_PIPE \ + AUTOINSTALL_ITEM_COMPLETIONS \ + AUTOINSTALL_ITEM_GROUPS + + eval "$1" + + # 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 + return + fi + + if [[ "$group" != "all" ]] + then + # check if group is in groups + if [[ ! "${AUTOINSTALL_ITEM_GROUPS}" =~ (^|,)$group(,|$) ]] + then + return + fi + fi + + _install_entry "$AUTOINSTALL_ITEM_TYPE" "$AUTOINSTALL_ITEM_SOURCE" \ + "$AUTOINSTALL_ITEM_TARGET" "${AUTOINSTALL_ITEM_HOOK:-}" "${AUTOINSTALL_ITEM_PIPE:-}" "${AUTOINSTALL_ITEM_COMPLETIONS:-}" - "$0" "${install_args[@]}" || true # Continue on error } file_lines=$(wc -l < "$file") -line=0 +line=129 while [[ $line -lt $file_lines ]]; do entry=$(tail -n +$line "$file" | awk '/^$/{exit} {print} ') entry_len=$(echo "$entry" | wc -l) @@ -52,33 +82,5 @@ while [[ $line -lt $file_lines ]]; do 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:-}" + _handle_entry "$entry" || true # ignore errors done