I'm creating an RPM package (let's call it Foo) that contains a gpg key that will be used to sign other RPMs. During the postinstall script for Foo, I execute 'rpm --import [keyfile]' to import the key into the RPM system. That works fine.

In an effort to clean up after myself, I would like to undo this import when Foo is uninstalled. I see from other forums that a way to undo the import is to do "rpm -e gpg-pubkey-[keyid]". However, when I try to do that in the Foo's postuninstall script, the RPM uninstall hangs because the rpm command to remove the key cannot grab the transaction lock (since it's already in use to remove Foo).

So... is there a way for me to cleanly remove that gpg key when the original Foo RPM package is removed?


Yes the transaction lock will prevent rpm -e.

You can rename the lock (it's in /var/lib/rpm) in %preun, then erase the gpg-pubkey, and then rename the lock back into place. Renaming has the advantage of being a KISS and expedient hack and will "work".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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