- initial import of revision 374 from cnc
[apt.git] / contrib / gpg-check / gpg-import.lua
1
2 -- don't bother if no write access to rpmdb
3 if not posix.access("/var/lib/rpm", "w") then
4         return
5 end
6
7 if confget("RPM::GPG-Import", "true") == "false" then
8         return
9 end
10
11
12 keypath = confget("Dir::Etc/f").."gpg/"
13 keys = posix.dir(keypath)
14
15 if not keys then
16         return
17 end
18
19 first = 1
20 for i, key in ipairs(keys) do
21         if string.sub(key, 1, 10) == "gpg-pubkey" then
22                 ret = os.execute("LANG=C rpm -q `basename "..key.."` > /dev/null 2>&1")
23                 if ret > 0 then
24                         if first then
25                                 print(_("You don't seem to have one or more of the needed GPG keys in your RPM database."))
26                                 print(_("Importing them now..."))
27                                 first = nil
28                         end
29                         ret = os.execute("LANG=C rpm --import "..keypath..key.." > /dev/null 2>&1")
30                         if ret > 0 then
31                                 print(_("Error importing GPG keys"))
32                                 return
33                         end
34                 end
35         end
36 end
37
38 -- vim:ts=4