Improve run command to remove tomlq depedency
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

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

View file

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

View file

@ -4,22 +4,16 @@ group=${args[group]:?}
file=${args[--file]:-} file=${args[--file]:-}
clean=${args[--clean]:-} clean=${args[--clean]:-}
_config_query() { _handle_entry() {
tomlq -c --arg group "$group" \ type="$1"
'.autoinstall | map(select(.groups + ["all"] | contains([$group]))) | '"$1" \ source="$2"
"$file" target="$3"
} hook="$4"
pipe="$5"
completions="$6"
_config_query ".[]" | while read -r entry; do
install_args=() 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 if [[ -n "$hook" ]]; then
install_args+=("--hook=$hook") install_args+=("--hook=$hook")
fi fi
@ -45,4 +39,46 @@ _config_query ".[]" | while read -r entry; do
install_args+=("$(eval "echo $target")") install_args+=("$(eval "echo $target")")
"$0" "${install_args[@]}" || true # Continue on error "$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 done

View file

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