Improve run command to remove tomlq depedency
Some checks failed
/ build-artifacts (autoinstall) (push) Has been cancelled
/ build-artifacts (autostart-manage) (push) Has been cancelled
/ upload-release (push) Has been cancelled

This commit is contained in:
Tobias Reisinger 2024-05-13 13:58:40 +02:00
parent cadb8e01d0
commit e81f5ab4da
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
4 changed files with 53 additions and 17 deletions

View file

@ -1,6 +1,6 @@
name: autoinstall
help: Install files, repository and else
version: 0.1.2
version: 0.1.3
flags:
- long: --clean
@ -35,7 +35,7 @@ commands:
short: -f
help: File from which to read autoinstall-config
arg: file
default: $XDG_CONFIG_HOME/autoinstall.toml
default: $XDG_CONFIG_HOME/autoinstall.conf
- name: git
help: Install a git repository

View file

@ -16,7 +16,7 @@ then
fi
if [ ! -f "$target" ]
if [ ! -e "$target" ]
then
echo "Installing file $url to $target"

View file

@ -4,22 +4,16 @@ 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"
}
_handle_entry() {
type="$1"
source="$2"
target="$3"
hook="$4"
pipe="$5"
completions="$6"
_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
@ -45,4 +39,46 @@ _config_query ".[]" | while read -r entry; do
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

View file

@ -1,6 +1,6 @@
name: autostart-manage
help: Manage autostart
version: 0.1.2
version: 0.1.3
dependencies:
tomlq: please install yq (https://github.com/kislyuk/yq)