-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpgkey
executable file
·47 lines (40 loc) · 1.29 KB
/
gpgkey
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
#!/bin/bash
# Get keygrips
keygrip_sign=$(gpg --list-secret-keys --with-keygrip | grep -A 2 "^sec" | grep Keygrip | sed 's/.* = //')
keygrip_enc=$(gpg --list-secret-keys --with-keygrip | grep -A 1 "\[E\]" | grep Keygrip | sed 's/.* = //')
keygrip_ssh=$(gpg --list-secret-keys --with-keygrip | grep -A 1 "\[A\]" | grep Keygrip | sed 's/.* = //')
test -f /usr/lib/gnupg2/gpg-preset-passphrase && gpgpresetpassphrase=/usr/lib/gnupg2/gpg-preset-passphrase
test -f /usr/libexec/gpg-preset-passphrase && gpgpresetpassphrase=/usr/libexec/gpg-preset-passphrase
test "$gpgpresetpassphrase" == "" && echo "ERROR: no gpg-preset-passphrase found!" && exit 1
function check() {
for kg in $keygrip_sign $keygrip_enc $keygrip_ssh
do
gpg-connect-agent "keyinfo --list" /bye | grep $kg | grep " 1 " > /dev/null 2>&1
test $? -ne 0 && echo "$kg is not loaded"
done
}
function unlock() {
read -sp "Enter Passphrase: " passphrase
for kg in $keygrip_sign $keygrip_enc $keygrip_ssh
do
$gpgpresetpassphrase -c $kg <<< $passphrase
done
}
function lock() {
for kg in $keygrip_sign $keygrip_enc $keygrip_ssh
do
gpg-connect-agent "clear_passphrase --mode=normal $kg" /bye
$gpgpresetpassphrase -f $kg
done
}
case "$1" in
"-c")
check
;;
"-l")
lock
;;
"-u")
unlock
;;
esac