1 #define INCLUDE_TESTSETUP_WITHOUT_BOOST
2 #include "zypp/../tests/lib/TestSetup.h"
3 #undef INCLUDE_TESTSETUP_WITHOUT_BOOST
7 #include <boost/program_options.hpp>
8 namespace opt = boost::program_options;
10 #include <zypp/target/rpm/RpmDb.h>
12 static std::string appname( "unknown" );
14 int errexit( const std::string & msg_r = std::string(), int exit_r = 100 )
16 if ( ! msg_r.empty() )
18 cerr << endl << msg_r << endl << endl;
23 bool byTTL( const PublicKey & lhs, const PublicKey & rhs )
25 int cmp = lhs.gpgPubkeyVersion().compare( rhs.gpgPubkeyVersion() );
26 if ( cmp ) return cmp < 0;
27 return lhs.gpgPubkeyRelease() > rhs.gpgPubkeyRelease(); // intentionally reverse cdate
30 /******************************************************************
32 ** FUNCTION NAME : main
33 ** FUNCTION TYPE : int
35 int main( int argc, char * argv[] )
37 appname = Pathname::basename( argv[0] );
38 ///////////////////////////////////////////////////////////////////
40 opt::options_description options( "Options" );
42 ( "key-file", opt::value<std::vector<std::string> >(),
43 "ASCII ascii armored public key file")
44 ( "root", opt::value<std::string>()->default_value( "/" ),
45 "Use the rmp database from system rooted at ARG")
46 ( "help,?", "Produce this help message")
49 opt::positional_options_description positional;
50 positional.add( "key-file", -1 );
52 opt::variables_map vm;
53 opt::store( opt::command_line_parser( argc, argv ).options( options ).positional( positional ).run(), vm );
56 if ( vm.count( "help" ) )
58 cerr << "Usage: " << appname << " [OPTIONS] [key-files...]" << endl;
59 cerr << "If no key files are given, list info about all gpg-pubkeys in the rpm database." << endl;
60 cerr << "Otherwise print info about each key and wheter it is present in the rpm database. " << endl;
61 cerr << options << endl;
64 ///////////////////////////////////////////////////////////////////
66 if ( ! PathInfo( vm["root"].as<std::string>() ).isDir() )
67 return errexit("--root requires a directory");
69 target::rpm::RpmDb rpmdb;
70 rpmdb.initDatabase( vm["root"].as<std::string>() );
71 std::list<PublicKey> rpmpubkeys( rpmdb.pubkeys() );
72 rpmpubkeys.sort( byTTL );
74 if ( ! vm.count( "key-file" ) )
77 for_each_( it, rpmpubkeys )
79 if ( last == it->gpgPubkeyVersion() )
83 cout << dump( *it ) << endl;
84 last = it->gpgPubkeyVersion();
90 ///////////////////////////////////////////////////////////////////
92 for_each_( it, vm["key-file"].as< std::vector<std::string> >() )
94 cout << "=== " << PathInfo(*it) << endl;
95 PublicKey pubkey( *it );
96 cout << dump( pubkey ) << endl;
98 std::string pubkeyV( pubkey.gpgPubkeyVersion() );
99 std::string pubkeyR( pubkey.gpgPubkeyRelease() );
101 for_each_( rpmpub, rpmpubkeys )
103 if ( rpmpub->gpgPubkeyVersion() == pubkeyV )
105 int cmp = rpmpub->gpgPubkeyRelease().compare( pubkeyR );
115 cout << "gpg-pubkey-" << rpmpub->gpgPubkeyVersion() << "-" << rpmpub->gpgPubkeyRelease() << " " << rpmpub->daysToLive() << endl;
120 cout << "*** Not in rpm database." << endl;
125 ///////////////////////////////////////////////////////////////////