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>
25 #include "repo_rpmdb.h"
27 #include "repo_pubkey.h"
29 #include "repo_products.h"
30 #include "repo_solv.h"
31 #include "common_write.h"
33 #include "repo_appdata.h"
36 #include "repo_autopattern.h"
43 fprintf(stderr, "\nUsage:\n"
44 "rpmdb2solv [-n] [-b <basefile>] [-p <productsdir>] [-r <root>]\n"
45 " -n : No packages, do not read rpmdb, useful to only parse products\n"
46 " -b <basefile> : Write .solv to <basefile>.solv instead of stdout\n"
47 " -p <productsdir> : Scan <productsdir> for .prod files, representing installed products\n"
48 " -r <root> : Prefix rpmdb path and <productsdir> with <root>\n"
49 " -o <solv> : Write .solv to file instead of stdout\n"
56 main(int argc, char **argv)
59 Pool *pool = pool_create();
65 const char *basefile = 0;
66 const char *refname = 0;
67 #ifdef ENABLE_SUSEREPO
85 while ((c = getopt(argc, argv, "APhnkxXb:r:p:o:")) >= 0)
104 #ifdef ENABLE_SUSEREPO
109 break; /* extrapool no longer supported */
116 #ifdef ENABLE_APPDATA
133 if (outfile && !freopen(outfile, "w", stdout))
140 * optional arg is old version of rpmdb solv file
141 * should make this a real option instead
145 refname = argv[optind];
147 if (refname && !nopacks)
149 if ((reffp = fopen(refname, "r")) == NULL)
154 * create 'installed' repository
161 pool_set_rootdir(pool, root);
163 repo = repo_create(pool, "installed");
164 data = repo_add_repodata(repo, 0);
168 if (repo_add_rpmdb_reffp(repo, reffp, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | (percent ? RPMDB_REPORT_PROGRESS : 0)))
170 fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
177 if (repo_add_rpmdb_pubkeys(repo, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | ADD_WITH_KEYSIGNATURES))
179 fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
185 #ifdef ENABLE_SUSEREPO
186 if (proddir && *proddir)
190 int rootlen = strlen(root);
191 if (!strncmp(root, proddir, rootlen))
194 if (*proddir != '/' && proddir[-1] == '/')
198 if (repo_add_products(repo, proddir, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
200 fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
206 #ifdef ENABLE_APPDATA
209 repo_add_appdata_dir(repo, "/usr/share/metainfo", REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | APPDATA_SEARCH_UNINTERNALIZED_FILELIST);
210 repo_add_appdata_dir(repo, "/usr/share/appdata", REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | APPDATA_SEARCH_UNINTERNALIZED_FILELIST);
213 repodata_internalize(data);
220 repo_add_autopattern(repo, ADD_NO_AUTOPRODUCTS);
223 tool_write(repo, basefile, 0);