diff --git a/autoinstall/bashly.yml b/autoinstall/bashly.yml index 7a9cedc..bd7fb0f 100644 --- a/autoinstall/bashly.yml +++ b/autoinstall/bashly.yml @@ -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 diff --git a/autoinstall/file_command.sh b/autoinstall/file_command.sh index bfea98f..08e9519 100644 --- a/autoinstall/file_command.sh +++ b/autoinstall/file_command.sh @@ -16,7 +16,7 @@ then fi -if [ ! -f "$target" ] +if [ ! -e "$target" ] then echo "Installing file $url to $target" diff --git a/autoinstall/run_command.sh b/autoinstall/run_command.sh index a45399c..e60be67 100644 --- a/autoinstall/run_command.sh +++ b/autoinstall/run_command.sh @@ -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 diff --git a/autostart-manage/bashly.yml b/autostart-manage/bashly.yml index d042782..3327140 100644 --- a/autostart-manage/bashly.yml +++ b/autostart-manage/bashly.yml @@ -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)