summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2017-12-15 03:25:34 +0100
committertv <tv@krebsco.de>2017-12-15 03:25:34 +0100
commit6605d590c87e6d9f3e8e1a86807d2bbad9ff7c52 (patch)
treed255a0979385db8c44bfa964253aa2276a371b7e /bin
parent05534c806db2883e28f9905bffae9bd30c73b838 (diff)
pass: initv2.1.0
Diffstat (limited to 'bin')
-rwxr-xr-xbin/populate50
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 "$@"