Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

One can import a key with:

rpm --import /path/to/key

But how can you tell later if you have already imported this key? Trying to reimport it will fail with an error and I am trying to avoid this as I am using Puppet to install the key.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

You can double check if a key is already imported using rpm -qi gpg-pubkey-<version>-<release>. If it is installed, rpm will give you all the information about it, if not, it'll just exit with a return value of 1, so you could add to your puppet recipe an unless parameter:

exec { "rpm --import /path/to/package":
  # ...
  unless => "rpm -qi gpg-pubkey-<version>-<release> > /dev/null 2>&1"
}
share|improve this answer
1  
Better way through some code I found: KEYFILE=/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release; KEYID=$(echo $(gpg --throw-keyids < $KEYFILE)|cut -c11-18|tr [A-Z] [a-z]); rpm -q gpg-pubkey-$KEYID –  lsd Feb 6 '13 at 13:43

Every key imported adds a rpmdb entry of gpg-pubkey-<left(hex(fingerprint), 8)>-<encoded import date>. Just check for that name (gpg-pubkey) and the appropriate version (the first 8 characters of the key fingerprint in hex) in the rpmdb.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.