diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/populate | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/bin/populate b/bin/populate index ab7dce5..78d4b78 100755 --- a/bin/populate +++ b/bin/populate @@ -88,6 +88,11 @@ main() {( git_ref=$(echo "$source" | jq -r .value.git.ref) populate_git "$key" "$git_url" "$git_ref" ;; + pass) + pass_dir=$(echo "$source" | jq -r .value.pass.dir) + pass_name_root=$(echo "$source" | jq -r .value.pass.name) + populate_pass "$key" "$pass_dir" "$pass_name_root" + ;; symlink) symlink_target=$(echo "$source" | jq -r .value.symlink.target) populate_symlink "$key" "$symlink_target" @@ -199,6 +204,51 @@ populate_git() {( target_shell )} +populate_pass() {( + print_info populate_pass "$@" + + pass_target_name=$1 + pass_dir=$2 + pass_name_root=$3 + + if is_local_target; then + pass_target=$target_path/$pass_target_name + else + pass_target=$target_user@$target_host:$target_path/$pass_target_name + fi + + umask 0077 + + tmp_dir=$(mktemp -dt populate-pass.XXXXXXXX) + trap cleanup EXIT + cleanup() { + rm -fR "$tmp_dir" + } + + pass_prefix=$pass_dir/$pass_name_root/ + + find "$pass_prefix" -type f | + while read -r pass_gpg_file_path; do + + rel_name=${pass_gpg_file_path:${#pass_prefix}} + rel_name=${rel_name%.gpg} + + pass_name=$pass_name_root/$rel_name + tmp_path=$tmp_dir/$rel_name + + mkdir -p "$(dirname "$tmp_path")" + PASSWORD_STORE_DIR=$pass_dir pass show "$pass_name" > "$tmp_path" + done + + rsync \ + --checksum \ + -vFrlptD \ + --delete-excluded \ + "$tmp_dir"/ \ + -e "ssh -o ControlPersist=no -p $target_port" \ + "$pass_target" +)} + populate_symlink() {( print_info populate_symlink "$@" |