Improve error handling in autoinstall run

This commit is contained in:
Tobias Reisinger 2024-05-13 15:01:21 +02:00
parent e81f5ab4da
commit aed681d0b0
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE

View file

@ -4,7 +4,7 @@ group=${args[group]:?}
file=${args[--file]:-} file=${args[--file]:-}
clean=${args[--clean]:-} clean=${args[--clean]:-}
_handle_entry() { _install_entry() {
type="$1" type="$1"
source="$2" source="$2"
target="$3" target="$3"
@ -30,19 +30,49 @@ _handle_entry() {
install_args+=("--completions=$completions") install_args+=("--completions=$completions")
fi fi
if [[ $source = \$* ]]
then
source=$(eval "echo $source")
fi
install_args+=("$source") 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") file_lines=$(wc -l < "$file")
line=0 line=129
while [[ $line -lt $file_lines ]]; do while [[ $line -lt $file_lines ]]; do
entry=$(tail -n +$line "$file" | awk '/^$/{exit} {print} ') entry=$(tail -n +$line "$file" | awk '/^$/{exit} {print} ')
entry_len=$(echo "$entry" | wc -l) entry_len=$(echo "$entry" | wc -l)
@ -52,33 +82,5 @@ while [[ $line -lt $file_lines ]]; do
continue continue
fi fi
unset AUTOINSTALL_ITEM_TYPE \ _handle_entry "$entry" || true # ignore errors
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 done