2024-01-09 15:48:11 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
group=${args[group]:?}
|
2024-03-22 21:14:13 +00:00
|
|
|
file=${args[--file]:-}
|
2024-01-12 01:40:58 +00:00
|
|
|
clean=${args[--clean]:-}
|
2024-01-09 15:48:11 +00:00
|
|
|
|
2024-05-13 13:01:21 +00:00
|
|
|
_install_entry() {
|
2024-05-13 11:58:40 +00:00
|
|
|
type="$1"
|
|
|
|
source="$2"
|
|
|
|
target="$3"
|
|
|
|
hook="$4"
|
|
|
|
pipe="$5"
|
|
|
|
completions="$6"
|
2024-01-09 15:48:11 +00:00
|
|
|
|
|
|
|
install_args=()
|
|
|
|
|
|
|
|
if [[ -n "$hook" ]]; then
|
|
|
|
install_args+=("--hook=$hook")
|
|
|
|
fi
|
2024-01-12 01:40:58 +00:00
|
|
|
if [[ -n "$clean" ]]; then
|
|
|
|
install_args+=("--clean")
|
|
|
|
fi
|
2024-01-09 15:48:11 +00:00
|
|
|
|
|
|
|
install_args+=("$type")
|
|
|
|
|
|
|
|
if [[ -n "$pipe" ]]; then
|
|
|
|
install_args+=("--pipe=$pipe")
|
|
|
|
fi
|
2024-01-12 01:40:58 +00:00
|
|
|
if [[ -n "$completions" ]]; then
|
|
|
|
install_args+=("--completions=$completions")
|
|
|
|
fi
|
2024-01-09 15:48:11 +00:00
|
|
|
|
2024-05-14 10:20:10 +00:00
|
|
|
if [[ $source = \$* ]]
|
|
|
|
then
|
|
|
|
source=$(eval "echo $source")
|
|
|
|
fi
|
2024-01-09 15:48:11 +00:00
|
|
|
install_args+=("$source")
|
|
|
|
|
2024-05-14 10:20:10 +00:00
|
|
|
install_args+=("$(eval "echo $target")")
|
2024-01-09 15:48:11 +00:00
|
|
|
|
2024-05-13 13:01:21 +00:00
|
|
|
"$0" "${install_args[@]}"
|
2024-05-13 11:58:40 +00:00
|
|
|
}
|
|
|
|
|
2024-05-13 13:01:21 +00:00
|
|
|
_handle_entry() {
|
2024-05-13 11:58:40 +00:00
|
|
|
unset AUTOINSTALL_ITEM_TYPE \
|
|
|
|
AUTOINSTALL_ITEM_SOURCE \
|
|
|
|
AUTOINSTALL_ITEM_TARGET \
|
|
|
|
AUTOINSTALL_ITEM_HOOK \
|
|
|
|
AUTOINSTALL_ITEM_PIPE \
|
2024-06-21 20:35:59 +00:00
|
|
|
AUTOINSTALL_ITEM_COMPLETIONS
|
2024-05-13 13:01:21 +00:00
|
|
|
|
|
|
|
eval "$1"
|
2024-05-13 11:58:40 +00:00
|
|
|
|
|
|
|
# check if we have the required vars
|
|
|
|
if [[ -z "${AUTOINSTALL_ITEM_TYPE:-}" \
|
|
|
|
|| -z "${AUTOINSTALL_ITEM_SOURCE:-}" \
|
2024-06-21 20:35:59 +00:00
|
|
|
|| -z "${AUTOINSTALL_ITEM_TARGET:-}" ]]
|
2024-05-13 11:58:40 +00:00
|
|
|
then
|
2024-05-13 13:01:21 +00:00
|
|
|
return
|
2024-05-13 11:58:40 +00:00
|
|
|
fi
|
|
|
|
|
2024-05-13 13:01:21 +00:00
|
|
|
_install_entry "$AUTOINSTALL_ITEM_TYPE" "$AUTOINSTALL_ITEM_SOURCE" \
|
2024-05-13 11:58:40 +00:00
|
|
|
"$AUTOINSTALL_ITEM_TARGET" "${AUTOINSTALL_ITEM_HOOK:-}" "${AUTOINSTALL_ITEM_PIPE:-}" "${AUTOINSTALL_ITEM_COMPLETIONS:-}"
|
2024-05-13 13:01:21 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
file_lines=$(wc -l < "$file")
|
2024-05-23 16:28:10 +00:00
|
|
|
line=0
|
2024-05-13 13:01:21 +00:00
|
|
|
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
|
|
|
|
|
2024-06-21 20:35:59 +00:00
|
|
|
if [[ "$group" != "all" ]]
|
|
|
|
then
|
|
|
|
# check if group is in groups
|
|
|
|
if ! echo "$entry" | grep -qE "^AUTOINSTALL_ITEM_GROUPS=\"(.*,)?$group(,.*)?\"$"
|
|
|
|
then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2024-05-13 13:01:21 +00:00
|
|
|
_handle_entry "$entry" || true # ignore errors
|
2024-01-09 15:48:11 +00:00
|
|
|
done
|