blob: f29a5b229149c4f2a511f65bd068a4ed1140c847 (
plain) (
blame)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
#!/usr/bin/env bash
set -eu
set -o pipefail
opened() {
test -e /dev/mapper/tozt-secrets
}
mounted() {
grep -q '^/dev/mapper/tozt-secrets /mnt' /proc/mounts
}
cmd_open() {
if ! opened; then
pass="$(rbw get luks tozt-secrets)"
echo -n "$pass" | sudo cryptsetup --key-file=- open ~/crypt/tozt-secrets.luks tozt-secrets
fi
if ! mounted; then
sudo mount /dev/mapper/tozt-secrets /mnt
fi
}
cmd_close() {
if mounted; then
sudo umount /dev/mapper/tozt-secrets
fi
if opened; then
sudo cryptsetup close tozt-secrets
fi
}
cmd_sync() {
if [ "${2:-}" = "--algo" ]; then
host="${3:-tozt}"
if [ "${host}" = "tozt" ]; then
hostname=tozt.algo
elif [ "${host}" = "mail" ]; then
hostname=mail.algo
elif [ "${host}" = "partofme" ]; then
hostname=partofme.algo
else
echo "unknown host ${host}" >&2
exit 1
fi
else
host="${2:-tozt}"
if [ "${host}" = "tozt" ]; then
hostname=tozt.net
elif [ "${host}" = "mail" ]; then
hostname=mail.tozt.net
elif [ "${host}" = "partofme" ]; then
hostname=partofme
else
echo "unknown host ${host}" >&2
exit 1
fi
fi
if mounted && opened; then
was_opened=1
else
cmd_open
was_opened=""
fi
rsync -avz --delete \
/mnt/puppet/"$host"/. \
root@"$hostname":/usr/local/share/puppet-tozt/modules/secret/files
if [ -z "$was_opened" ]; then
cmd_close
fi
}
case "$1" in
open)
cmd_open "$@"
;;
close)
cmd_close "$@"
;;
sync)
cmd_sync "$@"
;;
*)
echo "unknown subcommand $1" >&2
exit 1
;;
esac
|