-
Notifications
You must be signed in to change notification settings - Fork 10
/
ansible-vault-merge.sh
executable file
·62 lines (50 loc) · 1.13 KB
/
ansible-vault-merge.sh
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
#!/bin/sh
#
# ansible-vault-merge: helper script for merging changes in ansible-vault file
#
PROGNAME=$(basename $0)
usage() {
cat <<EOF
usage: ${PROGNAME} [OPTION]... [--] BASE CURRENT OTHER [LOCATION]
-h, --help Display this help
EOF
}
while test $# -gt 0; do
case $1 in
--help|-h)
usage
exit 0
;;
--)
shift 1
break
;;
-*)
echo "${PROGNAME}: unknown option $1" >&2
usage >&2
exit 1
;;
*)
# probably the first positional argument
break
esac
done
if test $# -lt 3; then
echo "${PROGNAME}: not enough arguments" >&2
usage >&2
exit 1
fi
BASE=$1
CURRENT=$2
OTHER=$3
LOCATION=$4
set -e
echo "ansible-vault-merge ${LOCATION}"
ansible-vault decrypt $BASE > /dev/null
ansible-vault decrypt $CURRENT > /dev/null
ansible-vault decrypt $OTHER > /dev/null
if ! git merge-file -L CURRENT -L BASE -L OTHER $CURRENT $BASE $OTHER; then
echo "Merge conflict; opening editor to resolve." >&2
${EDITOR:-vi} $CURRENT
fi
ansible-vault encrypt $CURRENT