forked from toringe/multi-pass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpass-common-func.sh
39 lines (36 loc) · 1.53 KB
/
pass-common-func.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
########################## Multi-user password-store ###########################
# #
# Common functions #
# #
# Author: Tor Inge Skaar #
# #
################################################################################
# Print message ($2) if exit code ($1) is not zero.
function check {
if [ $1 -ne 0 ]; then
echo "$2" 1>&2
exit 1
fi
}
# Check if password-store is encrypted with current user public key
# Which means user is authorized to accept and delete other users and sync
function authorized {
DEBUG=false
if [ "$2" = true ]; then
DEBUG=true
fi
if $DEBUG; then echo "Authorization check"; fi
prefix="Not authorized to $1"
myid=`gpg --list-secret-keys | grep ssb | cut -d/ -f2 | cut -d" " -f1`
if $DEBUG; then echo "My ID: $myid"; fi
test -n "$myid"
check $? "$prefix (Couldn't determine your key id)"
test -d $HOME/.password-store
check $? "$prefix (No password store found)"
afile=`find $HOME/.password-store/ -name *.gpg | head -1`
test -r $afile
check $? "$prefix (Unable to read file: $afile)"
gpg --batch $afile 2>&1 | grep "encrypted with" | grep -q $myid
check $? "$prefix (Store doesn't contain your key)"
if $DEBUG; then echo "Authorization OK"; fi
}