summaryrefslogtreecommitdiff
path: root/examples/git-metapull
blob: 8842b11547c4f1d678f1656e85046cec0ebc1fd8 (plain)
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
#!/bin/sh
#
# This script can be used instead of git-pull when updating a remote
# repo to make sure the metadata matches what is stored in the repo.
# It will do a git-pull, show a list of changes to be made to the metadata,
# and after getting confirmation, apply the changes.

DO_MTIME=yes
MSFILE=".metadata"
umask 0077

[ "$DO_MTIME" = "yes" ] && MSFLAGS="-m"

exit_on_fail() {
	"$@"
	if [ $? -ne 0 ]; then
		echo "Failed to execute: $@" >&2
		exit 1
	fi
}

exit_on_fail \
	git-pull

if [ ! -e "$MSFILE" ]; then
	echo "\"$MSFILE\" missing" >&2
	exit 1
fi

echo "Going to apply the following metadata changes" >&2

metastore -c $MSFLAGS -f "$MSFILE" >&2

printf "%s" "Ok to apply? (y/n): " >&2
read REPLY
echo ""

if [ "$REPLY" != "y" ]; then
	echo "Aborted" >&2
	exit 1
fi

exit_on_fail \
	metastore -a $MSFLAGS -f "$MSFILE"

exit 0