From cbb51fef2b568fdd2d6342db05d05603b56ebffb Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Sun, 27 Oct 2024 18:07:54 +0100 Subject: [PATCH] Update ansible-vault-manager to use .tar --- .bin/ansible-vault-manager | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/.bin/ansible-vault-manager b/.bin/ansible-vault-manager index 6621670..8477af8 100755 --- a/.bin/ansible-vault-manager +++ b/.bin/ansible-vault-manager @@ -1,11 +1,19 @@ #!/usr/bin/env bash project_dir="$(git rev-parse --show-toplevel)" +action="${1:-show}" +target="${2:-}" + +if [ "$action" = "save" ]; then + target="" # Save all files +fi if [ -z "$project_dir" ]; then exit 1 fi +cd "$project_dir" || exit 1 + url="$(git remote get-url origin)" re="^(https|git)(:\/\/|@)([^\/:]+)[\/:]([^\/:]+)\/(.+)(.git)*$" @@ -26,24 +34,32 @@ if ! pass "ansible/$project" >/dev/null 2>&1; then fi pass_content=$(pass "ansible/$project") -pass_path=$project_dir/$(echo "$pass_content" | grep "path:" | cut -d' ' -f2-) +pass_paths=() + +grep_filter="^path:" +if [ -n "$target" ]; then + grep_filter="^path: $target$" +fi +while read -r pass_path; do + pass_paths+=("$pass_path") +done <<< "$(echo "$pass_content" | grep "$grep_filter" | cut -d' ' -f2-)" + -action="${1:-show}" case "$action" in show) echo "$pass_content" | head -n 1 exit 0 ;; view) - ansible-vault view "$pass_path" + ansible-vault view "${pass_paths[@]}" exit 0 ;; edit) - ansible-vault edit "$pass_path" + ansible-vault edit "${pass_paths[@]}" exit 0 ;; deploy) - pass show "ansible/$project.file" > "$pass_path" + pass show "ansible/$project.tar" | tar x exit 0 ;; save) - pass insert -m "ansible/$project.file" < "$pass_path" + tar c "${pass_paths[@]}" | pass insert -m "ansible/$project.tar" exit 0 ;; pass-edit) pass edit "ansible/$project"