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>
27 #include "repo_rpmdb.h"
29 #include "repo_pubkey.h"
31 #include "repo_products.h"
32 #include "repo_solv.h"
33 #include "common_write.h"
35 #include "repo_appdata.h"
38 #include "repo_autopattern.h"
45 fprintf(stderr, "\nUsage:\n"
46 "rpmdb2solv [-n] [-b <basefile>] [-p <productsdir>] [-r <root>]\n"
47 " -n : No packages, do not read rpmdb, useful to only parse products\n"
48 " -b <basefile> : Write .solv to <basefile>.solv instead of stdout\n"
49 " -p <productsdir> : Scan <productsdir> for .prod files, representing installed products\n"
50 " -r <root> : Prefix rpmdb path and <productsdir> with <root>\n"
51 " -o <solv> : Write .solv to file instead of stdout\n"
58 main(int argc, char **argv)
61 Pool *pool = pool_create();
67 const char *basefile = 0;
68 const char *refname = 0;
69 #ifdef ENABLE_SUSEREPO
87 while ((c = getopt(argc, argv, "APhnkxXb:r:p:o:")) >= 0)
106 #ifdef ENABLE_SUSEREPO
111 break; /* extrapool no longer supported */
118 #ifdef ENABLE_APPDATA
135 if (outfile && !freopen(outfile, "w", stdout))
142 * optional arg is old version of rpmdb solv file
143 * should make this a real option instead
147 refname = argv[optind];
149 if (refname && !nopacks)
151 if ((reffp = fopen(refname, "r")) == NULL)
156 * create 'installed' repository
163 pool_set_rootdir(pool, root);
165 repo = repo_create(pool, "installed");
166 data = repo_add_repodata(repo, 0);
170 if (repo_add_rpmdb_reffp(repo, reffp, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | (percent ? RPMDB_REPORT_PROGRESS : 0)))
172 fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
179 if (repo_add_rpmdb_pubkeys(repo, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | ADD_WITH_KEYSIGNATURES))
181 fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
187 #ifdef ENABLE_SUSEREPO
188 if (proddir && *proddir)
192 int rootlen = strlen(root);
193 if (!strncmp(root, proddir, rootlen))
196 if (*proddir != '/' && proddir[-1] == '/')
200 if (repo_add_products(repo, proddir, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
202 fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
208 #ifdef ENABLE_APPDATA
210 repo_add_appdata_dir(repo, "/usr/share/appdata", REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE);
212 repodata_internalize(data);
219 repo_add_autopattern(repo, ADD_NO_AUTOPRODUCTS);
222 tool_write(repo, basefile, 0);