2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * Reads rpm database (and evtl. more, like product metadata) to build
12 * a .solv file of 'installed' solvables.
13 * Writes .solv to stdout
17 #include <sys/types.h>
23 #ifdef ENABLE_RPMDB_LIBRPM
24 #include <rpm/rpmmacro.h>
30 #include "repo_rpmdb.h"
32 #include "repo_pubkey.h"
34 #include "repo_products.h"
35 #include "repo_solv.h"
36 #include "common_write.h"
38 #include "repo_appdata.h"
41 #include "repo_autopattern.h"
48 fprintf(stderr, "\nUsage:\n"
49 "rpmdb2solv [-P] [-C] [-n] [-b <basefile>] [-p <productsdir>] [-r <root>]\n"
50 " -n : No packages, do not read rpmdb, useful to only parse products\n"
51 " -p <productsdir> : Scan <productsdir> for .prod files, representing installed products\n"
52 " -r <root> : Prefix rpmdb path and <productsdir> with <root>\n"
53 " -o <solv> : Write .solv to file instead of stdout\n"
54 " -P : print percentage done\n"
55 " -C : include the changelog\n"
62 main(int argc, char **argv)
65 Pool *pool = pool_create();
70 int add_changelog = 0;
72 const char *dbpath = 0;
73 const char *refname = 0;
74 #ifdef ENABLE_SUSEREPO
92 while ((c = getopt(argc, argv, "ACD:PhnkxXr:p:o:")) >= 0)
111 #ifdef ENABLE_SUSEREPO
116 break; /* extrapool no longer supported */
123 #ifdef ENABLE_APPDATA
143 if (outfile && !freopen(outfile, "w", stdout))
150 * optional arg is old version of rpmdb solv file
151 * should make this a real option instead
155 refname = argv[optind];
157 if (refname && !nopacks)
159 if ((reffp = fopen(refname, "r")) == NULL)
164 * create 'installed' repository
171 pool_set_rootdir(pool, root);
173 if (dbpath && *dbpath && (!nopacks || pubkeys))
175 if (dbpath && *dbpath && !nopacks)
178 #ifdef ENABLE_RPMDB_LIBRPM
179 char *macro = solv_dupjoin("_dbpath ", dbpath, 0);
180 rpmDefineMacro(NULL, macro, 0);
183 fprintf(stderr, "cannot set dbpath without librpm\n");
188 repo = repo_create(pool, "installed");
189 data = repo_add_repodata(repo, 0);
193 int flags = REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE;
195 flags |= RPMDB_REPORT_PROGRESS;
197 flags |= RPM_ADD_WITH_CHANGELOG;
198 if (repo_add_rpmdb_reffp(repo, reffp, flags))
200 fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
207 if (repo_add_rpmdb_pubkeys(repo, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | ADD_WITH_KEYSIGNATURES))
209 fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
215 #ifdef ENABLE_SUSEREPO
216 if (proddir && *proddir)
220 int rootlen = strlen(root);
221 if (!strncmp(root, proddir, rootlen))
224 if (*proddir != '/' && proddir[-1] == '/')
228 if (repo_add_products(repo, proddir, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
230 fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
236 #ifdef ENABLE_APPDATA
239 repo_add_appdata_dir(repo, "/usr/share/metainfo", REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | APPDATA_SEARCH_UNINTERNALIZED_FILELIST);
240 repo_add_appdata_dir(repo, "/usr/share/appdata", REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | APPDATA_SEARCH_UNINTERNALIZED_FILELIST);
243 repodata_internalize(data);
250 repo_add_autopattern(repo, ADD_NO_AUTOPRODUCTS);
253 tool_write(repo, stdout);