-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpgkey_el7
executable file
·50 lines (44 loc) · 1.43 KB
/
gpgkey_el7
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
#!/bin/bash
# This script requires GnuPG 2.2 or higher, this is only available on EL7
# with the following package: https://copr.fedorainfracloud.org/coprs/icon/lfit/package/gnupg22-static
# After installing the package, create the following symlink as well
# ln -s /usr/bin/pinentry /opt/gnupg22/bin/pinentry
#
# Set the following line in any user that should use these binaries:
# export PATH=/opt/gnupg22/bin:$PATH
# 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/.* = //')
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
/opt/gnupg22/libexec/gpg-preset-passphrase -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
/opt/gnupg22/libexec/gpg-preset-passphrase -f $kg
done
}
case "$1" in
"-c")
check
;;
"-l")
lock
;;
"-u")
unlock
;;
esac