summaryrefslogtreecommitdiff
path: root/scripts/update-trust
blob: 3485bdfaf54ea855fe74382822ff337d8e2c8209 (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
#!/bin/bash

export GNUPGHOME=/etc/metadata/gnupg
mkdir -p $GNUPGHOME
chmod 0700 $GNUPGHOME
if [ $(lsb_release -is) == 'Debian' ]; then
	export GPG=gpg
else
	export GPG=gpg2
fi

# Install new keys discovered in the keys directory
for k in keys/*.pub; do
   fp=`$GPG --with-colons --with-fingerprint < $k | awk -F: '$1 == "pub" {print $5}'`
   fp_in_db=`$GPG --with-colons --fingerprint | grep ":$fp:"`
   if [ "x`echo $fp_in_db | grep '^pub:e:'`" != "x" ]; then
       echo "$0: Key expired, will re-import it from $k"
       $GPG --fingerprint $fp
   fi
   # The removal of any ^pub:e: entrys means to ignore expired keys - thereby importing them again.
   echo $fp_in_db | grep -v "^pub:e:" | grep -q ":$fp:" || $GPG --import < $k
done

# Delete keys no longer present in keys directory
for fp in `$GPG --with-colons --fingerprint | awk -F: '$1 == "pub" {print $5}'`; do
   seen="no"
   for k in keys/*.pub; do
      $GPG --with-colons --with-fingerprint < $k | grep -q ":$fp:" && seen="yes"
   done
   if [ "x$seen" = "xno" ]; then
      $GPG --yes --batch --delete-key $fp || true
   fi
done