10 #define GETOPT_REBUILD 1003
11 #define GETOPT_RECOMPILE 1004
12 #define GETOPT_ADDSIGN 1005
13 #define GETOPT_RESIGN 1006
14 #define GETOPT_DBPATH 1010
15 #define GETOPT_TIMECHECK 1012
16 #define GETOPT_REBUILDDB 1013
17 #define GETOPT_INSTALL 1014
18 #define GETOPT_RELOCATE 1016
19 #define GETOPT_SHOWRC 1018
20 #define GETOPT_EXCLUDEPATH 1019
21 #define GETOPT_DEFINEMACRO 1020
22 #define GETOPT_EVALMACRO 1021
26 MODE_QUERY = (1 << 0),
27 MODE_INSTALL = (1 << 1),
28 MODE_UNINSTALL = (1 << 2),
29 MODE_VERIFY = (1 << 3),
30 MODE_BUILD = (1 << 4),
31 MODE_REBUILD = (1 << 5),
32 MODE_CHECKSIG = (1 << 6),
33 MODE_RESIGN = (1 << 7),
34 MODE_RECOMPILE = (1 << 8),
35 MODE_QUERYTAGS = (1 << 9),
36 MODE_INITDB = (1 << 10),
37 MODE_TARBUILD = (1 << 11),
38 MODE_REBUILDDB = (1 << 12)
41 #define MODES_QV (MODE_QUERY | MODE_VERIFY)
42 #define MODES_BT (MODE_BUILD | MODE_TARBUILD | MODE_REBUILD | MODE_RECOMPILE)
43 #define MODES_IE (MODE_INSTALL | MODE_UNINSTALL)
44 #define MODES_DB (MODE_INITDB | MODE_REBUILDDB)
45 #define MODES_K (MODE_CHECKSIG | MODES_RESIGN)
47 #define MODES_FOR_DBPATH (MODES_BT | MODES_IE | MODES_QV | MODES_DB)
48 #define MODES_FOR_TIMECHECK (MODES_BT)
49 #define MODES_FOR_NODEPS (MODES_BT | MODES_IE | MODE_VERIFY)
50 #define MODES_FOR_TEST (MODES_BT | MODES_IE)
51 #define MODES_FOR_ROOT (MODES_BT | MODES_IE | MODES_QV | MODES_DB)
53 /* the flags for the various options */
55 static int allMatches;
59 extern int _ftp_debug;
60 static char * ftpPort;
61 static char * ftpProxy;
62 static char * httpPort;
63 static char * httpProxy;
66 static int ignoreArch;
68 static int ignoreSize;
79 static int noTriggers;
80 static int noUsageMsg;
81 static int oldPackage;
82 static char * pipeOutput;
87 static int replaceFiles;
88 static int replacePackages;
89 static char * rootdir;
90 extern int _rpmio_debug;
91 static int showPercents;
95 extern int _url_debug;
96 extern int _noDirTokens;
98 static int showVersion;
99 extern const char * rpmNAME;
100 extern const char * rpmEVR;
103 extern MacroContext rpmCLIMacroContext;
105 static struct rpmQVArguments rpmQVArgs;
106 static struct rpmBuildArguments rpmBArgs;
108 /* the structure describing the options we take and the defaults */
109 static struct poptOption optionsTable[] = {
110 { "addsign", '\0', 0, 0, GETOPT_ADDSIGN, NULL, NULL},
111 /* all and allmatches both using 'a' is dumb */
112 { "all", 'a', 0, 0, 'a', NULL, NULL},
113 { "allfiles", '\0', 0, &allFiles, 0, NULL, NULL},
114 { "allmatches", '\0', 0, &allMatches, 0, NULL, NULL},
115 { "badreloc", '\0', 0, &badReloc, 0, NULL, NULL},
116 { "build", 'b', POPT_ARG_STRING, 0, 'b', NULL, NULL},
117 { "checksig", 'K', 0, 0, 'K', NULL, NULL},
118 { "dbpath", '\0', POPT_ARG_STRING, 0, GETOPT_DBPATH, NULL, NULL},
119 { "define", '\0', POPT_ARG_STRING, &noUsageMsg, GETOPT_DEFINEMACRO,NULL, NULL},
120 { "dirtokens", '\0', POPT_ARG_VAL, &_noDirTokens, 0, NULL, NULL},
121 { "erase", 'e', 0, 0, 'e', NULL, NULL},
122 { "eval", '\0', POPT_ARG_STRING, &noUsageMsg, GETOPT_EVALMACRO, NULL, NULL},
123 { "excludedocs", '\0', 0, &excldocs, 0, NULL, NULL},
124 { "excludepath", '\0', POPT_ARG_STRING, 0, GETOPT_EXCLUDEPATH, NULL, NULL},
125 { "force", '\0', 0, &force, 0, NULL, NULL},
126 { "ftpdebug", '\0', POPT_ARG_VAL, &_ftp_debug, -1, NULL, NULL},
127 { "ftpport", '\0', POPT_ARG_STRING, &ftpPort, 0, NULL, NULL},
128 { "ftpproxy", '\0', POPT_ARG_STRING, &ftpProxy, 0, NULL, NULL},
129 { "hash", 'h', 0, &showHash, 0, NULL, NULL},
130 { "help", '\0', 0, &help, 0, NULL, NULL},
131 { "httpport", '\0', POPT_ARG_STRING, &httpPort, 0, NULL, NULL},
132 { "httpproxy", '\0', POPT_ARG_STRING, &httpProxy, 0, NULL, NULL},
133 { NULL, 'i', 0, 0, 'i', NULL, NULL},
134 { "ignorearch", '\0', 0, &ignoreArch, 0, NULL, NULL},
135 { "ignoreos", '\0', 0, &ignoreOs, 0, NULL, NULL},
136 { "ignoresize", '\0', 0, &ignoreSize, 0, NULL, NULL},
137 { "includedocs", '\0', 0, &incldocs, 0, NULL, NULL},
138 { "initdb", '\0', 0, &initdb, 0, NULL, NULL},
139 /* info and install both using 'i' is dumb */
140 { "install", '\0', 0, 0, GETOPT_INSTALL, NULL, NULL},
141 { "justdb", '\0', 0, &justdb, 0, NULL, NULL},
142 { "nodeps", '\0', 0, &noDeps, 0, NULL, NULL},
143 { "nodirtokens", '\0', POPT_ARG_VAL, &_noDirTokens, 1, NULL, NULL},
144 { "nogpg", '\0', 0, &noGpg, 0, NULL, NULL},
145 { "nolibio", '\0', 0, &noLibio, 0, NULL, NULL},
146 { "nomd5", '\0', 0, &noMd5, 0, NULL, NULL},
147 { "noorder", '\0', 0, &noOrder, 0, NULL, NULL},
148 { "nopgp", '\0', 0, &noPgp, 0, NULL, NULL},
149 { "noscripts", '\0', 0, &noScripts, 0, NULL, NULL},
150 { "notriggers", '\0', 0, &noTriggers, 0, NULL, NULL},
151 { "oldpackage", '\0', 0, &oldPackage, 0, NULL, NULL},
152 { "percent", '\0', 0, &showPercents, 0, NULL, NULL},
153 { "pipe", '\0', POPT_ARG_STRING, &pipeOutput, 0, NULL, NULL},
154 { "prefix", '\0', POPT_ARG_STRING, &prefix, 0, NULL, NULL},
155 { "query", 'q', 0, NULL, 'q', NULL, NULL},
156 { "querytags", '\0', 0, &queryTags, 0, NULL, NULL},
157 { "quiet", '\0', 0, &quiet, 0, NULL, NULL},
158 { "rcfile", '\0', POPT_ARG_STRING, &rcfile, 0, NULL, NULL},
159 { "rebuild", '\0', 0, 0, GETOPT_REBUILD, NULL, NULL},
160 { "rebuilddb", '\0', 0, 0, GETOPT_REBUILDDB, NULL, NULL},
161 { "recompile", '\0', 0, 0, GETOPT_RECOMPILE, NULL, NULL},
162 { "relocate", '\0', POPT_ARG_STRING, 0, GETOPT_RELOCATE, NULL, NULL},
163 { "replacefiles", '\0', 0, &replaceFiles, 0, NULL, NULL},
164 { "replacepkgs", '\0', 0, &replacePackages, 0, NULL, NULL},
165 { "resign", '\0', 0, 0, GETOPT_RESIGN, NULL, NULL},
166 { "root", 'r', POPT_ARG_STRING, &rootdir, 0, NULL, NULL},
167 { "rpmiodebug", '\0', POPT_ARG_VAL, &_rpmio_debug, -1, NULL, NULL},
168 { "showrc", '\0', 0, &showrc, GETOPT_SHOWRC, NULL, NULL},
169 { "sign", '\0', 0, &signIt, 0, NULL, NULL},
170 { "tarbuild", 't', POPT_ARG_STRING, 0, 't', NULL, NULL},
171 { "test", '\0', 0, &test, 0, NULL, NULL},
172 { "timecheck", '\0', POPT_ARG_STRING, 0, GETOPT_TIMECHECK, NULL, NULL},
173 { "upgrade", 'U', 0, 0, 'U', NULL, NULL},
174 { "urldebug", '\0', POPT_ARG_VAL, &_url_debug, -1, NULL, NULL},
175 { "uninstall", 'u', 0, 0, 'u', NULL, NULL},
176 { "verbose", 'v', 0, 0, 'v', NULL, NULL},
177 { "verify", 'V', 0, 0, 'V', NULL, NULL},
178 { NULL, 'y', 0, 0, 'V', NULL, NULL},
179 { "version", '\0', 0, &showVersion, 0, NULL, NULL},
180 { NULL, '\0', POPT_ARG_INCLUDE_TABLE,
181 rpmQVSourcePoptTable, 0, (void *) &rpmQVArgs, NULL },
182 { NULL, '\0', POPT_ARG_INCLUDE_TABLE,
183 rpmQueryPoptTable, 0, (void *) &rpmQVArgs, NULL },
184 { NULL, '\0', POPT_ARG_INCLUDE_TABLE,
185 rpmVerifyPoptTable, 0, (void *) &rpmQVArgs, NULL },
186 { NULL, '\0', POPT_ARG_INCLUDE_TABLE,
187 rpmBuildPoptTable, 0, (void *) &rpmBArgs, NULL },
188 { 0, 0, 0, 0, 0, NULL, NULL }
192 /* MiNT cannot dynamically increase the stack. */
193 long _stksize = 64 * 1024L;
196 static void argerror(char * desc) {
197 fprintf(stderr, _("rpm: %s\n"), desc);
201 static void printHelp(void);
202 static void printVersion(void);
203 static void printBanner(void);
204 static void printUsage(void);
205 static void printHelpLine(char * prefix, char * help);
207 static void printVersion(void) {
208 fprintf(stdout, _("RPM version %s\n"), rpmEVR);
211 static void printBanner(void) {
212 puts(_("Copyright (C) 1998 - Red Hat Software"));
213 puts(_("This may be freely redistributed under the terms of the GNU GPL"));
216 static void printUsage(void) {
221 puts(_("usage: rpm {--help}"));
222 puts(_(" rpm {--version}"));
223 puts(_(" rpm {--initdb} [--dbpath <dir>]"));
224 puts(_(" rpm {--install -i} [-v] [--hash -h] [--percent] [--force] [--test]"));
225 puts(_(" [--replacepkgs] [--replacefiles] [--root <dir>]"));
226 puts(_(" [--excludedocs] [--includedocs] [--noscripts]"));
227 puts(_(" [--rcfile <file>] [--ignorearch] [--dbpath <dir>]"));
228 puts(_(" [--prefix <dir>] [--ignoreos] [--nodeps] [--allfiles]"));
229 puts(_(" [--ftpproxy <host>] [--ftpport <port>] [--justdb]"));
230 puts(_(" [--httpproxy <host>] [--httpport <port>] "));
231 puts(_(" [--noorder] [--relocate oldpath=newpath]"));
232 puts(_(" [--badreloc] [--notriggers] [--excludepath <path>]"));
233 puts(_(" [--ignoresize] file1.rpm ... fileN.rpm"));
234 puts(_(" rpm {--upgrade -U} [-v] [--hash -h] [--percent] [--force] [--test]"));
235 puts(_(" [--oldpackage] [--root <dir>] [--noscripts]"));
236 puts(_(" [--excludedocs] [--includedocs] [--rcfile <file>]"));
237 puts(_(" [--ignorearch] [--dbpath <dir>] [--prefix <dir>] "));
238 puts(_(" [--ftpproxy <host>] [--ftpport <port>]"));
239 puts(_(" [--httpproxy <host>] [--httpport <port>] "));
240 puts(_(" [--ignoreos] [--nodeps] [--allfiles] [--justdb]"));
241 puts(_(" [--noorder] [--relocate oldpath=newpath]"));
242 puts(_(" [--badreloc] [--excludepath <path>] [--ignoresize]"));
243 puts(_(" file1.rpm ... fileN.rpm"));
244 puts(_(" rpm {--query -q} [-afpg] [-i] [-l] [-s] [-d] [-c] [-v] [-R]"));
245 puts(_(" [--scripts] [--root <dir>] [--rcfile <file>]"));
246 puts(_(" [--whatprovides] [--whatrequires] [--requires]"));
247 puts(_(" [--triggeredby] [--ftpuseport] [--ftpproxy <host>]"));
248 puts(_(" [--httpproxy <host>] [--httpport <port>] "));
249 puts(_(" [--ftpport <port>] [--provides] [--triggers] [--dump]"));
250 puts(_(" [--changelog] [--dbpath <dir>] [targets]"));
251 puts(_(" rpm {--verify -V -y} [-afpg] [--root <dir>] [--rcfile <file>]"));
252 puts(_(" [--dbpath <dir>] [--nodeps] [--nofiles] [--noscripts]"));
253 puts(_(" [--nomd5] [targets]"));
254 puts(_(" rpm {--setperms} [-afpg] [target]"));
255 puts(_(" rpm {--setugids} [-afpg] [target]"));
256 puts(_(" rpm {--freshen -F} file1.rpm ... fileN.rpm"));
257 puts(_(" rpm {--erase -e} [--root <dir>] [--noscripts] [--rcfile <file>]"));
258 puts(_(" [--dbpath <dir>] [--nodeps] [--allmatches]"));
259 puts(_(" [--justdb] [--notriggers] rpackage1 ... packageN"));
260 puts(_(" rpm {-b|t}[plciba] [-v] [--short-circuit] [--clean] [--rcfile <file>]"));
261 puts(_(" [--sign] [--nobuild] [--timecheck <s>] ]"));
262 puts(_(" [--target=platform1[,platform2...]]"));
263 puts(_(" [--rmsource] [--rmspec] specfile"));
264 puts(_(" rpm {--rmsource} [--rcfile <file>] [-v] specfile"));
265 puts(_(" rpm {--rebuild} [--rcfile <file>] [-v] source1.rpm ... sourceN.rpm"));
266 puts(_(" rpm {--recompile} [--rcfile <file>] [-v] source1.rpm ... sourceN.rpm"));
267 puts(_(" rpm {--resign} [--rcfile <file>] package1 package2 ... packageN"));
268 puts(_(" rpm {--addsign} [--rcfile <file>] package1 package2 ... packageN"));
269 puts(_(" rpm {--checksig -K} [--nopgp] [--nogpg] [--nomd5] [--rcfile <file>]"));
270 puts(_(" package1 ... packageN"));
271 puts(_(" rpm {--rebuilddb} [--rcfile <file>] [--dbpath <dir>]"));
272 puts(_(" rpm {--querytags}"));
275 static void printHelpLine(char * prefix, char * help) {
276 int indentLength = strlen(prefix) + 3;
277 int lineLength = 79 - indentLength;
278 int helpLength = strlen(help);
282 fprintf(stdout, "%s - ", prefix);
284 while (helpLength > lineLength) {
285 ch = help + lineLength - 1;
286 while (ch > help && !isspace(*ch)) ch--;
287 if (ch == help) break; /* give up */
288 while (ch > (help + 1) && isspace(*ch)) ch--;
291 sprintf(format, "%%.%ds\n%%%ds", (int) (ch - help), indentLength);
292 fprintf(stdout, format, help, " ");
294 while (isspace(*help) && *help) help++;
295 helpLength = strlen(help);
298 if (helpLength) puts(help);
301 static void printHelp(void) {
307 printHelpLine( " --help ",
308 _("print this message"));
309 printHelpLine( " --version ",
310 _("print the version of rpm being used"));
311 puts( _(" all modes support the following arguments:"));
312 printHelpLine(_(" --rcfile <file> "),
313 _("use <file> instead of /etc/rpmrc and $HOME/.rpmrc"));
314 printHelpLine( " -v ",
315 _("be a little more verbose"));
316 printHelpLine( " -vv ",
317 _("be incredibly verbose (for debugging)"));
318 printHelpLine( " -q ",
320 printHelpLine(_(" --root <dir> "),
321 _("use <dir> as the top level directory"));
322 printHelpLine(_(" --dbpath <dir> "),
323 _("use <dir> as the directory for the database"));
324 printHelpLine(_(" --queryformat <qfmt>"),
325 _("use <qfmt> as the header format (implies -i)"));
326 puts( _(" install, upgrade and query (with -p) allow ftp URL's to be used in place"));
327 puts( _(" of file names as well as the following options:"));
328 printHelpLine(_(" --ftpproxy <host> "),
329 _("hostname or IP of ftp proxy"));
330 printHelpLine(_(" --ftpport <port> "),
331 _("port number of ftp server (or proxy)"));
332 printHelpLine(_(" --httpproxy <host> "),
333 _("hostname or IP of http proxy"));
334 printHelpLine(_(" --httpport <port> "),
335 _("port number of http server (or proxy)"));
336 puts( _(" Package specification options:"));
337 printHelpLine( " -a ",
338 _("query all packages"));
339 printHelpLine(_(" -f <file>+ "),
340 _("query package owning <file>"));
341 printHelpLine(_(" -p <packagefile>+ "),
342 _("query (uninstalled) package <packagefile>"));
343 printHelpLine(_(" --triggeredby <pkg>"),
344 _("query packages triggered by <pkg>"));
345 printHelpLine(_(" --whatprovides <cap>"),
346 _("query packages which provide <cap> capability"));
347 printHelpLine(_(" --whatrequires <cap>"),
348 _("query packages which require <cap> capability"));
349 puts( _(" Information selection options:"));
350 printHelpLine( " -i ",
351 _("display package information"));
352 printHelpLine( " --changelog ",
353 _("display the package's change log"));
354 printHelpLine( " -l ",
355 _("display package file list"));
356 printHelpLine( " -s ",
357 _("show file states (implies -l)"));
358 printHelpLine( " -d ",
359 _("list only documentation files (implies -l)"));
360 printHelpLine( " -c ",
361 _("list only configuration files (implies -l)"));
362 printHelpLine( " --dump ",
363 _("show all verifiable information for each file (must be used with -l, -c, or -d)"));
364 printHelpLine( " --provides ",
365 _("list capabilities package provides"));
366 puts( _(" --requires"));
367 printHelpLine( " -R ",
368 _("list package dependencies"));
369 printHelpLine( " --scripts ",
370 _("print the various [un]install scripts"));
371 printHelpLine(" --triggers ",
372 _("show the trigger scripts contained in the package"));
376 printHelpLine(_(" --pipe <cmd> "),
377 _("send stdout to <cmd>"));
378 printHelpLine( " --verify ",
379 _("verify a package installation using the same same package specification options as -q"));
380 printHelpLine(_(" --dbpath <dir> "),
381 _("use <dir> as the directory for the database"));
382 printHelpLine(_(" --root <dir> "),
383 _("use <dir> as the top level directory"));
384 printHelpLine( " --nodeps ",
385 _("do not verify package dependencies"));
386 printHelpLine( " --nomd5 ",
387 _("do not verify file md5 checksums"));
388 printHelpLine( " --nofiles ",
389 _("do not verify file attributes"));
391 printHelpLine( " --setperms ",
392 _("set the file permissions to those in the package database"
393 " using the same package specification options as -q"));
394 printHelpLine( " --setugids ",
395 _("set the file owner and group to those in the package "
396 "database using the same package specification options as "
399 puts( _(" --install <packagefile>"));
400 printHelpLine(_(" -i <packagefile> "),
401 _("install package"));
402 printHelpLine(_(" --excludepath <path>"),
403 _("skip files in path <path>"));
404 printHelpLine(_(" --relocate <oldpath>=<newpath>"),
405 _("relocate files from <oldpath> to <newpath>"));
406 printHelpLine( " --badreloc",
407 _("relocate files even though the package doesn't allow it"));
408 printHelpLine(_(" --prefix <dir> "),
409 _("relocate the package to <dir>, if relocatable"));
410 printHelpLine(_(" --dbpath <dir> "),
411 _("use <dir> as the directory for the database"));
412 printHelpLine( " --excludedocs ",
413 _("do not install documentation"));
414 printHelpLine( " --force ",
415 _("short hand for --replacepkgs --replacefiles"));
417 printHelpLine( " --hash ",
418 _("print hash marks as package installs (good with -v)"));
419 printHelpLine( " --allfiles ",
420 _("install all files, even configurations which might "
421 "otherwise be skipped"));
422 printHelpLine( " --ignorearch ",
423 _("don't verify package architecture"));
424 printHelpLine( " --ignoresize ",
425 _("don't check disk space before installing"));
426 printHelpLine( " --ignoreos ",
427 _("don't verify package operating system"));
428 printHelpLine( " --includedocs ",
429 _("install documentation"));
430 printHelpLine( " --justdb ",
431 _("update the database, but do not modify the filesystem"));
432 printHelpLine( " --nodeps ",
433 _("do not verify package dependencies"));
434 printHelpLine( " --noorder ",
435 _("do not reorder package installation to satisfy dependencies"));
436 printHelpLine( " --noscripts ",
437 _("don't execute any installation scripts"));
438 printHelpLine( " --notriggers ",
439 _("don't execute any scripts triggered by this package"));
440 printHelpLine( " --percent ",
441 _("print percentages as package installs"));
442 printHelpLine( " --replacefiles ",
443 _("install even if the package replaces installed files"));
444 printHelpLine( " --replacepkgs ",
445 _("reinstall if the package is already present"));
446 printHelpLine(_(" --root <dir> "),
447 _("use <dir> as the top level directory"));
448 printHelpLine( " --test ",
449 _("don't install, but tell if it would work or not"));
451 puts( _(" --upgrade <packagefile>"));
452 printHelpLine(_(" -U <packagefile> "),
453 _("upgrade package (same options as --install, plus)"));
454 printHelpLine( " --oldpackage ",
455 _("upgrade to an old version of the package (--force on upgrades does this automatically)"));
457 puts( _(" --erase <package>"));
458 printHelpLine( " -e <package> ",
459 _("erase (uninstall) package"));
460 printHelpLine( " --allmatches ",
461 _("remove all packages which match <package> (normally an error is generated if <package> specified multiple packages)"));
462 printHelpLine(_(" --dbpath <dir> "),
463 _("use <dir> as the directory for the database"));
464 printHelpLine( " --justdb ",
465 _("update the database, but do not modify the filesystem"));
466 printHelpLine( " --nodeps ",
467 _("do not verify package dependencies"));
468 printHelpLine( " --noorder ",
469 _("do not reorder package installation to satisfy dependencies"));
470 printHelpLine( " --noscripts ",
471 _("do not execute any package specific scripts"));
472 printHelpLine( " --notriggers ",
473 _("don't execute any scripts triggered by this package"));
474 printHelpLine(_(" --root <dir> "),
475 _("use <dir> as the top level directory"));
477 puts( _(" -b<stage> <spec> "));
478 printHelpLine(_(" -t<stage> <tarball> "),
479 _("build package, where <stage> is one of:"));
480 printHelpLine( " p ",
481 _("prep (unpack sources and apply patches)"));
482 printHelpLine( " l ",
483 _("list check (do some cursory checks on %files)"));
484 printHelpLine( " c ",
485 _("compile (prep and compile)"));
486 printHelpLine( " i ",
487 _("install (prep, compile, install)"));
488 printHelpLine( " b ",
489 _("binary package (prep, compile, install, package)"));
490 printHelpLine( " a ",
491 _("bin/src package (prep, compile, install, package)"));
492 printHelpLine( " --short-circuit ",
493 _("skip straight to specified stage (only for c,i)"));
494 printHelpLine( " --clean ",
495 _("remove build tree when done"));
496 printHelpLine( " --rmsource ",
497 _("remove sources and spec file when done"));
498 printHelpLine( " --sign ",
499 _("generate PGP/GPG signature"));
500 printHelpLine(_(" --buildroot <dir> "),
501 _("use <dir> as the build root"));
502 printHelpLine(_(" --target=<platform>+"),
503 _("build the packages for the build targets platform1...platformN."));
504 printHelpLine( " --nobuild ",
505 _("do not execute any stages"));
506 printHelpLine(_(" --timecheck <secs> "),
507 _("set the time check to <secs> seconds (0 disables)"));
509 printHelpLine(_(" --rebuild <src_pkg> "),
510 _("install source package, build binary package and remove spec file, sources, patches, and icons."));
511 printHelpLine(_(" --rmsource <spec> "),
512 _("remove sources and spec file"));
513 printHelpLine(_(" --recompile <src_pkg> "),
514 _("like --rebuild, but don't build any package"));
515 printHelpLine(_(" --resign <pkg>+ "),
516 _("sign a package (discard current signature)"));
517 printHelpLine(_(" --addsign <pkg>+ "),
518 _("add a signature to a package"));
520 printHelpLine(_(" --checksig <pkg>+ "),
521 _("verify package signature"));
522 printHelpLine( " --nopgp ",
523 _("skip any PGP signatures"));
524 printHelpLine( " --nogpg ",
525 _("skip any GPG signatures"));
526 printHelpLine( " --nomd5 ",
527 _("skip any MD5 signatures"));
528 printHelpLine( " --querytags ",
529 _("list the tags that can be used in a query format"));
530 printHelpLine( " --initdb ",
531 _("make sure a valid database exists"));
532 printHelpLine( " --rebuilddb ",
533 _("rebuild database from existing database"));
534 printHelpLine(_(" --dbpath <dir> "),
535 _("use <dir> as the directory for the database"));
536 printHelpLine( " --root <dir> ",
537 _("use <dir> as the top level directory"));
540 int main(int argc, const char ** argv)
542 enum modes bigMode = MODE_UNKNOWN;
543 QVA_t *qva = &rpmQVArgs;
544 struct rpmBuildArguments *ba = &rpmBArgs;
545 enum rpmQVSources QVSource = RPMQV_PACKAGE;
547 int installFlags = 0, uninstallFlags = 0, interfaceFlags = 0;
548 int gotDbpath = 0, verifyFlags;
549 int checksigFlags = 0;
550 unsigned long int timeCheck = 0L;
551 int addSign = NEW_SIGNATURE;
552 const char * specFile;
554 char * passPhrase = "";
555 char * cookie = NULL;
559 char * errString = NULL;
561 const char * infoCommand[] = { "--info", NULL };
562 const char * installCommand[] = { "--install", NULL };
566 rpmRelocation * relocations = NULL;
567 int numRelocations = 0;
572 #if HAVE_MCHECK_H && HAVE_MTRACE
573 mtrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
575 setprogname(argv[0]); /* Retrofit glibc __progname */
577 /* set the defaults for the various command line options */
622 /* XXX Eliminate query linkage loop */
623 parseSpecVec = parseSpec;
624 freeSpecVec = freeSpec;
626 /* set up the correct locale */
627 setlocale(LC_ALL, "" );
630 #define LOCALEDIR "/usr/share/locale"
632 bindtextdomain(PACKAGE, LOCALEDIR);
635 rpmSetVerbosity(RPMMESS_NORMAL); /* XXX silly use by showrc */
637 /* Make a first pass through the arguments, looking for --rcfile */
638 /* We need to handle that before dealing with the rest of the arguments. */
639 optCon = poptGetContext("rpm", argc, argv, optionsTable, 0);
640 poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
641 poptReadDefaultConfig(optCon, 1);
642 poptSetExecPath(optCon, RPMCONFIGDIR, 1);
644 /* reading rcfile early makes it easy to override */
645 /* XXX only --rcfile (and --showrc) need this pre-parse */
647 while ((arg = poptGetNextOpt(optCon)) > 0) {
650 rpmIncreaseVerbosity(); /* XXX silly use by showrc */
657 if (rpmReadConfigFiles(rcfile, NULL))
665 rpmSetVerbosity(RPMMESS_NORMAL); /* XXX silly use by showrc */
667 poptResetContext(optCon);
669 if (qva->qva_queryFormat) xfree(qva->qva_queryFormat);
670 memset(qva, 0, sizeof(*qva));
671 if (ba->buildRootOverride) xfree(ba->buildRootOverride);
672 if (ba->targets) free(ba->targets);
673 memset(ba, 0, sizeof(*ba));
676 while ((arg = poptGetNextOpt(optCon)) > 0) {
677 optArg = poptGetOptArg(optCon);
681 if (bigMode != MODE_UNKNOWN && bigMode != MODE_CHECKSIG)
682 argerror(_("only one major mode may be specified"));
683 bigMode = MODE_CHECKSIG;
687 if (bigMode != MODE_UNKNOWN && bigMode != MODE_QUERY)
688 argerror(_("only one major mode may be specified"));
689 bigMode = MODE_QUERY;
694 if (bigMode != MODE_UNKNOWN && bigMode != MODE_VERIFY)
695 argerror(_("only one major mode may be specified"));
696 bigMode = MODE_VERIFY;
700 if (bigMode != MODE_UNKNOWN && bigMode != MODE_UNINSTALL)
701 argerror(_("only one major mode may be specified"));
702 bigMode = MODE_UNINSTALL;
703 rpmMessage(RPMMESS_ERROR, _("-u and --uninstall are deprecated and no"
705 rpmMessage(RPMMESS_ERROR, _("Use -e or --erase instead.\n"));
709 if (bigMode != MODE_UNKNOWN && bigMode != MODE_UNINSTALL)
710 argerror(_("only one major mode may be specified"));
711 bigMode = MODE_UNINSTALL;
716 if (bigMode != MODE_UNKNOWN && bigMode != MODE_BUILD)
717 argerror(_("only one major mode may be specified"));
720 bigMode = MODE_BUILD;
721 errString = _("--build (-b) requires one of a,b,i,c,p,l as "
722 "its sole argument");
724 bigMode = MODE_TARBUILD;
725 errString = _("--tarbuild (-t) requires one of a,b,i,c,p,l as "
726 "its sole argument");
729 if (strlen(optArg) > 1)
732 ba->buildChar = optArg[0];
733 switch (ba->buildChar) {
750 rpmIncreaseVerbosity();
754 if (bigMode == MODE_QUERY)
755 poptStuffArgs(optCon, infoCommand);
756 else if (bigMode == MODE_INSTALL)
758 else if (bigMode == MODE_UNKNOWN)
759 poptStuffArgs(optCon, installCommand);
763 if (bigMode != MODE_UNKNOWN && bigMode != MODE_INSTALL)
764 argerror(_("only one major mode may be specified"));
765 bigMode = MODE_INSTALL;
769 if (bigMode != MODE_UNKNOWN && bigMode != MODE_INSTALL)
770 argerror(_("only one major mode may be specified"));
771 bigMode = MODE_INSTALL;
776 if (QVSource != RPMQV_PACKAGE && QVSource != RPMQV_RPM)
777 argerror(_("one type of query/verify may be performed at a " "time"));
778 QVSource = RPMQV_RPM;
782 if (QVSource != RPMQV_PACKAGE && QVSource != RPMQV_GROUP)
783 argerror(_("one type of query/verify may be performed at a "
785 QVSource = RPMQV_GROUP;
789 if (QVSource != RPMQV_PACKAGE && QVSource != RPMQV_PATH)
790 argerror(_("one type of query/verify may be performed at a "
792 QVSource = RPMQV_PATH;
796 if (QVSource != RPMQV_PACKAGE && QVSource != RPMQV_ALL)
797 argerror(_("one type of query/verify may be performed at a "
799 QVSource = RPMQV_ALL;
803 if (bigMode != MODE_UNKNOWN && bigMode != MODE_REBUILD)
804 argerror(_("only one major mode may be specified"));
805 bigMode = MODE_REBUILD;
808 case GETOPT_RECOMPILE:
809 if (bigMode != MODE_UNKNOWN && bigMode != MODE_RECOMPILE)
810 argerror(_("only one major mode may be specified"));
811 bigMode = MODE_RECOMPILE;
815 if (bigMode != MODE_UNKNOWN && bigMode != MODE_RESIGN)
816 argerror(_("only one major mode may be specified"));
817 bigMode = MODE_RESIGN;
818 addSign = NEW_SIGNATURE;
823 if (bigMode != MODE_UNKNOWN && bigMode != MODE_RESIGN)
824 argerror(_("only one major mode may be specified"));
825 bigMode = MODE_RESIGN;
826 addSign = ADD_SIGNATURE;
831 switch (urlIsURL(optArg)) {
833 if (optArg[0] != '/')
834 argerror(_("arguments to --dbpath must begin with a /"));
839 addMacro(NULL, "_dbpath", NULL, optArg, RMIL_CMDLINE);
840 addMacro(&rpmCLIMacroContext, "_dbpath", NULL, optArg, RMIL_CMDLINE);
844 case GETOPT_DEFINEMACRO:
845 rpmDefineMacro(NULL, optArg, RMIL_CMDLINE);
846 rpmDefineMacro(&rpmCLIMacroContext, optArg, RMIL_CMDLINE);
849 case GETOPT_EVALMACRO:
850 { const char *val = rpmExpand(optArg, NULL);
851 fprintf(stdout, "%s\n", val);
855 case GETOPT_TIMECHECK:
857 timeCheck = strtoul(optArg, &tce, 10);
858 if ((*tce) || (tce == optArg) || (timeCheck == ULONG_MAX)) {
859 argerror("Argument to --timecheck must be integer");
861 addMacro(NULL, "_timecheck", NULL, optArg, RMIL_CMDLINE);
862 addMacro(&rpmCLIMacroContext, "_timecheck", NULL, optArg, RMIL_CMDLINE);
866 case GETOPT_REBUILDDB:
867 if (bigMode != MODE_UNKNOWN && bigMode != MODE_REBUILDDB)
868 argerror(_("only one major mode may be specified"));
869 bigMode = MODE_REBUILDDB;
872 case GETOPT_RELOCATE:
874 argerror(_("relocations must begin with a /"));
875 if (!(errString = strchr(optArg, '=')))
876 argerror(_("relocations must contain a ="));
878 if (*errString != '/')
879 argerror(_("relocations must have a / following the ="));
880 relocations = xrealloc(relocations,
881 sizeof(*relocations) * (numRelocations + 1));
882 relocations[numRelocations].oldPath = optArg;
883 relocations[numRelocations++].newPath = errString;
886 case GETOPT_EXCLUDEPATH:
888 argerror(_("exclude paths must begin with a /"));
890 relocations = xrealloc(relocations,
891 sizeof(*relocations) * (numRelocations + 1));
892 relocations[numRelocations].oldPath = optArg;
893 relocations[numRelocations++].newPath = NULL;
897 fprintf(stderr, _("Internal error in argument processing (%d) :-(\n"), arg);
903 rpmSetVerbosity(RPMMESS_QUIET);
905 if (showVersion) printVersion();
906 if (help) printHelp();
909 fprintf(stderr, "%s: %s\n",
910 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
915 if ((ba->buildAmount & RPMBUILD_RMSOURCE) && bigMode == MODE_UNKNOWN)
916 bigMode = MODE_BUILD;
918 if ((ba->buildAmount & RPMBUILD_RMSPEC) && bigMode == MODE_UNKNOWN)
919 bigMode = MODE_BUILD;
922 if (bigMode != MODE_UNKNOWN)
923 argerror(_("only one major mode may be specified"));
925 bigMode = MODE_INITDB;
929 if (bigMode != MODE_UNKNOWN)
930 argerror(_("only one major mode may be specified"));
932 bigMode = MODE_QUERYTAGS;
935 if (qva->qva_sourceCount) {
936 if (QVSource != RPMQV_PACKAGE || qva->qva_sourceCount > 1)
937 argerror(_("one type of query/verify may be performed at a "
939 QVSource = qva->qva_source;
942 if (ba->buildRootOverride && bigMode != MODE_BUILD &&
943 bigMode != MODE_REBUILD && bigMode != MODE_TARBUILD) {
944 argerror("--buildroot may only be used during package builds");
947 if (gotDbpath && (bigMode & ~MODES_FOR_DBPATH))
948 argerror(_("--dbpath given for operation that does not use a "
951 if (timeCheck && (bigMode & ~MODES_FOR_TIMECHECK))
952 argerror(_("--timecheck may only be used during package builds"));
954 if (qva->qva_flags && (bigMode & ~MODES_QV))
955 argerror(_("unexpected query flags"));
957 if (qva->qva_queryFormat && (bigMode & ~MODES_QV))
958 argerror(_("unexpected query format"));
960 if (QVSource != RPMQV_PACKAGE && (bigMode & ~MODES_QV))
961 argerror(_("unexpected query source"));
963 if (!(bigMode == MODE_INSTALL ||
964 (bigMode==MODE_BUILD && (ba->buildAmount & RPMBUILD_RMSOURCE))||
965 (bigMode==MODE_BUILD && (ba->buildAmount & RPMBUILD_RMSPEC)))
967 argerror(_("only installation, upgrading, rmsource and rmspec may be forced"));
969 if (bigMode != MODE_INSTALL && badReloc)
970 argerror(_("files may only be relocated during package installation"));
972 if (relocations && prefix)
973 argerror(_("only one of --prefix or --relocate may be used"));
975 if (bigMode != MODE_INSTALL && relocations)
976 argerror(_("--relocate and --excludepath may only be used when installing new packages"));
978 if (bigMode != MODE_INSTALL && prefix)
979 argerror(_("--prefix may only be used when installing new packages"));
981 if (prefix && prefix[0] != '/')
982 argerror(_("arguments to --prefix must begin with a /"));
984 if (bigMode != MODE_INSTALL && showHash)
985 argerror(_("--hash (-h) may only be specified during package "
988 if (bigMode != MODE_INSTALL && showPercents)
989 argerror(_("--percent may only be specified during package "
992 if (bigMode != MODE_INSTALL && replaceFiles)
993 argerror(_("--replacefiles may only be specified during package "
996 if (bigMode != MODE_INSTALL && replacePackages)
997 argerror(_("--replacepkgs may only be specified during package "
1000 if (bigMode != MODE_INSTALL && excldocs)
1001 argerror(_("--excludedocs may only be specified during package "
1004 if (bigMode != MODE_INSTALL && incldocs)
1005 argerror(_("--includedocs may only be specified during package "
1008 if (excldocs && incldocs)
1009 argerror(_("only one of --excludedocs and --includedocs may be "
1012 if (bigMode != MODE_INSTALL && ignoreArch)
1013 argerror(_("--ignorearch may only be specified during package "
1016 if (bigMode != MODE_INSTALL && ignoreOs)
1017 argerror(_("--ignoreos may only be specified during package "
1020 if (bigMode != MODE_INSTALL && ignoreSize)
1021 argerror(_("--ignoresize may only be specified during package "
1024 if (allMatches && bigMode != MODE_UNINSTALL)
1025 argerror(_("--allmatches may only be specified during package "
1028 if (allFiles && bigMode != MODE_INSTALL)
1029 argerror(_("--allfiles may only be specified during package "
1032 if (justdb && bigMode != MODE_INSTALL && bigMode != MODE_UNINSTALL)
1033 argerror(_("--justdb may only be specified during package "
1034 "installation and erasure"));
1036 if (bigMode != MODE_INSTALL && bigMode != MODE_UNINSTALL &&
1037 bigMode != MODE_VERIFY && noScripts)
1038 argerror(_("--noscripts may only be specified during package "
1039 "installation, erasure, and verification"));
1041 if (bigMode != MODE_INSTALL && bigMode != MODE_UNINSTALL && noTriggers)
1042 argerror(_("--notriggers may only be specified during package "
1043 "installation, erasure, and verification"));
1045 if (noDeps & (bigMode & ~MODES_FOR_NODEPS))
1046 argerror(_("--nodeps may only be specified during package "
1047 "building, rebuilding, recompilation, installation,"
1048 "erasure, and verification"));
1050 if (test && (bigMode & ~MODES_FOR_TEST))
1051 argerror(_("--test may only be specified during package installation, "
1052 "erasure, and building"));
1054 if (rootdir[1] && (bigMode & ~MODES_FOR_ROOT))
1055 argerror(_("--root (-r) may only be specified during "
1056 "installation, erasure, querying, and "
1057 "database rebuilds"));
1060 switch (urlIsURL(rootdir)) {
1062 if (bigMode & MODES_FOR_ROOT)
1065 case URL_IS_UNKNOWN:
1066 if (rootdir[0] != '/')
1067 argerror(_("arguments to --root (-r) must begin with a /"));
1072 if (oldPackage && !upgrade)
1073 argerror(_("--oldpackage may only be used during upgrades"));
1075 if ((ftpProxy || ftpPort) && !(bigMode == MODE_INSTALL ||
1076 ((bigMode == MODE_QUERY && QVSource == RPMQV_RPM)) ||
1077 ((bigMode == MODE_VERIFY && QVSource == RPMQV_RPM))))
1078 argerror(_("ftp options can only be used during package queries, "
1079 "installs, and upgrades"));
1081 if ((httpProxy || httpPort) && !(bigMode == MODE_INSTALL ||
1082 ((bigMode == MODE_QUERY && QVSource == RPMQV_RPM)) ||
1083 ((bigMode == MODE_VERIFY && QVSource == RPMQV_RPM))))
1084 argerror(_("http options can only be used during package queries, "
1085 "installs, and upgrades"));
1087 if (noPgp && bigMode != MODE_CHECKSIG)
1088 argerror(_("--nopgp may only be used during signature checking"));
1090 if (noGpg && bigMode != MODE_CHECKSIG)
1091 argerror(_("--nogpg may only be used during signature checking"));
1093 if (noMd5 && bigMode != MODE_CHECKSIG && bigMode != MODE_VERIFY)
1094 argerror(_("--nomd5 may only be used during signature checking and "
1095 "package verification"));
1098 addMacro(NULL, "_ftpproxy", NULL, ftpProxy, RMIL_CMDLINE);
1099 addMacro(&rpmCLIMacroContext, "_ftpproxy", NULL, ftpProxy, RMIL_CMDLINE);
1102 addMacro(NULL, "_ftpport", NULL, ftpPort, RMIL_CMDLINE);
1103 addMacro(&rpmCLIMacroContext, "_ftpport", NULL, ftpPort, RMIL_CMDLINE);
1106 addMacro(NULL, "_httpproxy", NULL, httpProxy, RMIL_CMDLINE);
1107 addMacro(&rpmCLIMacroContext, "_httpproxy", NULL, httpProxy, RMIL_CMDLINE);
1110 addMacro(NULL, "_httpport", NULL, httpPort, RMIL_CMDLINE);
1111 addMacro(&rpmCLIMacroContext, "_httpport", NULL, httpPort, RMIL_CMDLINE);
1115 if (bigMode == MODE_REBUILD || bigMode == MODE_BUILD ||
1116 bigMode == MODE_RESIGN || bigMode == MODE_TARBUILD) {
1121 if ((argv = poptGetArgs(optCon)) == NULL) {
1122 fprintf(stderr, _("no files to sign\n"));
1126 if (stat(*argv, &sb)) {
1127 fprintf(stderr, _("cannot access file %s\n"), *argv);
1133 if (errors) return errors;
1135 if (poptPeekArg(optCon)) {
1136 switch (sigTag = rpmLookupSignatureType(RPMLOOKUPSIG_QUERY)) {
1140 if ((sigTag == RPMSIGTAG_PGP || sigTag == RPMSIGTAG_PGP5) &&
1141 !rpmDetectPGPVersion(NULL)) {
1142 fprintf(stderr, _("pgp not found: "));
1146 passPhrase = rpmGetPassPhrase(_("Enter pass phrase: "), sigTag);
1147 if (passPhrase == NULL) {
1148 fprintf(stderr, _("Pass phrase check failed\n"));
1151 fprintf(stderr, _("Pass phrase is good.\n"));
1152 passPhrase = xstrdup(passPhrase);
1156 _("Invalid %%_signature spec in macro file.\n"));
1158 /*@notreached@*/ break;
1162 argerror(_("--sign may only be used during package building"));
1165 /* Make rpmLookupSignatureType() return 0 ("none") from now on */
1166 rpmLookupSignatureType(RPMLOOKUPSIG_DISABLE);
1172 if (!(pipeChild = fork())) {
1174 dup2(p[0], STDIN_FILENO);
1176 execl("/bin/sh", "/bin/sh", "-c", pipeOutput, NULL);
1177 fprintf(stderr, _("exec failed\n"));
1181 dup2(p[1], STDOUT_FILENO);
1187 if (!showVersion && !help && !noUsageMsg) printUsage();
1190 case MODE_REBUILDDB:
1191 ec = rpmdbRebuild(rootdir);
1194 case MODE_QUERYTAGS:
1196 argerror(_("unexpected arguments to --querytags "));
1198 rpmDisplayQueryTags(stdout);
1202 rpmdbInit(rootdir, 0644);
1206 if (!poptPeekArg(optCon))
1207 argerror(_("no packages given for signature check"));
1208 if (!noPgp) checksigFlags |= CHECKSIG_PGP;
1209 if (!noGpg) checksigFlags |= CHECKSIG_GPG;
1210 if (!noMd5) checksigFlags |= CHECKSIG_MD5;
1211 ec = rpmCheckSig(checksigFlags, (const char **)poptGetArgs(optCon));
1212 /* XXX don't overflow single byte exit status */
1213 if (ec > 255) ec = 255;
1217 if (!poptPeekArg(optCon))
1218 argerror(_("no packages given for signing"));
1219 ec = rpmReSign(addSign, passPhrase, (const char **)poptGetArgs(optCon));
1220 /* XXX don't overflow single byte exit status */
1221 if (ec > 255) ec = 255;
1225 case MODE_RECOMPILE:
1226 if (rpmGetVerbosity() == RPMMESS_NORMAL)
1227 rpmSetVerbosity(RPMMESS_VERBOSE);
1229 if (!poptPeekArg(optCon))
1230 argerror(_("no packages files given for rebuild"));
1232 ba->buildAmount = RPMBUILD_PREP | RPMBUILD_BUILD | RPMBUILD_INSTALL;
1233 if (bigMode == MODE_REBUILD) {
1234 ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
1235 ba->buildAmount |= RPMBUILD_RMSOURCE;
1236 ba->buildAmount |= RPMBUILD_RMSPEC;
1237 ba->buildAmount |= RPMBUILD_CLEAN;
1238 ba->buildAmount |= RPMBUILD_RMBUILD;
1241 while ((pkg = poptGetArg(optCon))) {
1242 ec = rpmInstallSource("", pkg, &specFile, &cookie);
1246 ba->rootdir = rootdir;
1247 ec = build(specFile, ba, passPhrase, 0, cookie, rcfile, force, noDeps);
1257 if (rpmGetVerbosity() == RPMMESS_NORMAL)
1258 rpmSetVerbosity(RPMMESS_VERBOSE);
1260 switch (ba->buildChar) {
1261 /* these fallthroughs are intentional */
1263 ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
1266 ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
1267 ba->buildAmount |= RPMBUILD_CLEAN;
1270 ba->buildAmount |= RPMBUILD_INSTALL;
1271 if ((ba->buildChar == 'i') && ba->shortCircuit)
1275 ba->buildAmount |= RPMBUILD_BUILD;
1276 if ((ba->buildChar == 'c') && ba->shortCircuit)
1280 ba->buildAmount |= RPMBUILD_PREP;
1284 ba->buildAmount |= RPMBUILD_FILECHECK;
1287 ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
1291 if (!poptPeekArg(optCon)) {
1292 if (bigMode == MODE_BUILD)
1293 argerror(_("no spec files given for build"));
1295 argerror(_("no tar files given for build"));
1298 while ((pkg = poptGetArg(optCon))) {
1299 ba->rootdir = rootdir;
1300 ec = build(pkg, ba, passPhrase, bigMode == MODE_TARBUILD,
1301 NULL, rcfile, force, noDeps);
1304 rpmFreeMacros(NULL);
1305 rpmReadConfigFiles(rcfile, NULL);
1309 case MODE_UNINSTALL:
1310 if (!poptPeekArg(optCon))
1311 argerror(_("no packages given for uninstall"));
1313 if (noScripts) uninstallFlags |= RPMTRANS_FLAG_NOSCRIPTS;
1314 if (noTriggers) uninstallFlags |= RPMTRANS_FLAG_NOTRIGGERS;
1315 if (test) uninstallFlags |= RPMTRANS_FLAG_TEST;
1316 if (justdb) uninstallFlags |= RPMTRANS_FLAG_JUSTDB;
1317 if (noDeps) interfaceFlags |= UNINSTALL_NODEPS;
1318 if (allMatches) interfaceFlags |= UNINSTALL_ALLMATCHES;
1320 ec = rpmErase(rootdir, (const char **)poptGetArgs(optCon),
1321 uninstallFlags, interfaceFlags);
1326 probFilter |= RPMPROB_FILTER_REPLACEPKG |
1327 RPMPROB_FILTER_REPLACEOLDFILES |
1328 RPMPROB_FILTER_REPLACENEWFILES |
1329 RPMPROB_FILTER_OLDPACKAGE;
1331 if (replaceFiles) probFilter |= RPMPROB_FILTER_REPLACEOLDFILES |
1332 RPMPROB_FILTER_REPLACENEWFILES;
1333 if (badReloc) probFilter |= RPMPROB_FILTER_FORCERELOCATE;
1334 if (replacePackages) probFilter |= RPMPROB_FILTER_REPLACEPKG;
1335 if (oldPackage) probFilter |= RPMPROB_FILTER_OLDPACKAGE;
1336 if (ignoreArch) probFilter |= RPMPROB_FILTER_IGNOREARCH;
1337 if (ignoreOs) probFilter |= RPMPROB_FILTER_IGNOREOS;
1338 if (ignoreSize) probFilter |= RPMPROB_FILTER_DISKSPACE;
1340 if (test) installFlags |= RPMTRANS_FLAG_TEST;
1341 /* RPMTRANS_FLAG_BUILD_PROBS */
1342 if (noScripts) installFlags |= RPMTRANS_FLAG_NOSCRIPTS;
1343 if (justdb) installFlags |= RPMTRANS_FLAG_JUSTDB;
1344 if (noTriggers) installFlags |= RPMTRANS_FLAG_NOTRIGGERS;
1347 installFlags |= RPMTRANS_FLAG_NODOCS;
1348 else if (rpmExpandNumeric("%{_excludedocs}"))
1349 installFlags |= RPMTRANS_FLAG_NODOCS;
1351 if (allFiles) installFlags |= RPMTRANS_FLAG_ALLFILES;
1352 /* RPMTRANS_FLAG_KEEPOBSOLETE */
1354 if (showPercents) interfaceFlags |= INSTALL_PERCENT;
1355 if (showHash) interfaceFlags |= INSTALL_HASH;
1356 if (noDeps) interfaceFlags |= INSTALL_NODEPS;
1357 if (noOrder) interfaceFlags |= INSTALL_NOORDER;
1358 if (upgrade) interfaceFlags |= INSTALL_UPGRADE;
1360 if (!poptPeekArg(optCon))
1361 argerror(_("no packages given for install"));
1363 /* we've already ensured !(!prefix && !relocations) */
1365 relocations = alloca(2 * sizeof(*relocations));
1366 relocations[0].oldPath = NULL; /* special case magic */
1367 relocations[0].newPath = prefix;
1368 relocations[1].oldPath = relocations[1].newPath = NULL;
1369 } else if (relocations) {
1370 relocations = xrealloc(relocations,
1371 sizeof(*relocations) * (numRelocations + 1));
1372 relocations[numRelocations].oldPath = NULL;
1373 relocations[numRelocations].newPath = NULL;
1376 ec += rpmInstall(rootdir, (const char **)poptGetArgs(optCon),
1377 installFlags, interfaceFlags, probFilter, relocations);
1381 qva->qva_prefix = rootdir;
1382 if (QVSource == RPMQV_ALL) {
1383 if (poptPeekArg(optCon))
1384 argerror(_("extra arguments given for query of all packages"));
1386 ec = rpmQuery(qva, RPMQV_ALL, NULL);
1388 if (!poptPeekArg(optCon))
1389 argerror(_("no arguments given for query"));
1390 while ((pkg = poptGetArg(optCon)))
1391 ec += rpmQuery(qva, QVSource, pkg);
1396 verifyFlags = (VERIFY_FILES|VERIFY_DEPS|VERIFY_SCRIPT|VERIFY_MD5);
1397 verifyFlags &= ~qva->qva_flags;
1398 if (noDeps) verifyFlags &= ~VERIFY_DEPS;
1399 if (noScripts) verifyFlags &= ~VERIFY_SCRIPT;
1400 if (noMd5) verifyFlags &= ~VERIFY_MD5;
1402 qva->qva_prefix = rootdir;
1403 qva->qva_flags = verifyFlags;
1404 if (QVSource == RPMQV_ALL) {
1405 if (poptPeekArg(optCon))
1406 argerror(_("extra arguments given for verify of all packages"));
1407 ec = rpmVerify(qva, RPMQV_ALL, NULL);
1409 if (!poptPeekArg(optCon))
1410 argerror(_("no arguments given for verify"));
1411 while ((pkg = poptGetArg(optCon)))
1412 ec += rpmVerify(qva, QVSource, pkg);
1417 poptFreeContext(optCon);
1418 rpmFreeMacros(NULL);
1419 rpmFreeMacros(&rpmCLIMacroContext);
1424 (void)waitpid(pipeChild, &status, 0);
1427 /* keeps memory leak checkers quiet */
1431 if (qva->qva_queryFormat) xfree(qva->qva_queryFormat);
1432 if (ba->buildRootOverride) xfree(ba->buildRootOverride);
1433 if (ba->targets) free(ba->targets);
1435 #if HAVE_MCHECK_H && HAVE_MTRACE
1436 muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */