aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/pass/install.sh
blob: 2ab3f9e1db49182917530389b9598fb97de68a3a (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
#!/bin/sh

pkgname=pass

if ! command -v "$pkgname" >/dev/null; then
	printf '%s: %s not found, skipping...\n' "$0" "$pkgname"
	exit 0
fi

store=${PASSWORD_STORE_DIR:-$XDG_DATA_HOME/pass}

if [ ! -d "$store" ]; then
	printf "%s: Cloning password-store\n" "$0"

	git clone git@git.sr.ht:~tobyvin/.password-store "$store"
else
	printf "%s: Syncing password-store\n" "$0"

	git remote update

	LOCAL=$(git rev-parse @)
	REMOTE=$(git rev-parse '@{u}')
	BASE=$(git merge-base @ '@{u}')

	if [ "$BASE" != "$REMOTE" ]; then
		git -C "$store" pull
	fi

	if [ "$BASE" != "$LOCAL" ]; then
		git -C "$store" push
	fi
fi