-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport-from-pass-to-pago
executable file
·57 lines (49 loc) · 1.11 KB
/
import-from-pass-to-pago
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#! /usr/bin/env bash
# A tool for importing the password repository from pass to pago.
#
# License: MIT.
# See the file `LICENSE`.
set -euo pipefail
shopt -s nullglob
src=${1:-}
dest=${2:-}
if [[ ! -d $src || ! -d $dest ]]; then
cat <<EOF
usage: $(basename "$0") <pass-dir> <pago-dir>
Requirements:
- git(1)
- A pago directory initialized *without Git* (\`pago init --no-git\`)
- The pago agent running
EOF
exit 2
fi
git_src=0
[[ -d $src/.git/ ]] && git_src=1
recips=.age-recipients
cd "$dest/store/"
if [[ $git_src -eq 1 ]]; then
mv "$recips" ..
git clone "$src" "$dest/store"
mv ../"$recips" .
else
printf "no '%s/.git/' - not cloning to '%s'\n" "$src" "$dest"
git init
fi
cd "$src"
for file in ./*.gpg ./**/*.gpg; do
no_ext=${file%*.gpg}
name=${no_ext#./*}
${PASS:-pass} show "$name" | ${PAGO:-pago} add "$name" \
--dir "$dest" \
--multiline \
--no-confirm \
--no-git \
;
done
cd "$dest/store/"
if [[ $git_src -eq 1 ]]; then
rm -f ./*.gpg ./**/*.gpg ./.gpg-id
fi
git add "$recips"
git add ./*.age ./**/*.age
git commit -m 'Migrate to pago'