5 #if defined(IAM_RPM) || defined(__LCLINT__)
18 #define GETOPT_REBUILD 1003
19 #define GETOPT_RECOMPILE 1004
22 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
23 #include "signature.h"
28 #define GETOPT_DBPATH 1010
29 #define GETOPT_SHOWRC 1018
30 #define GETOPT_DEFINEMACRO 1020
31 #define GETOPT_EVALMACRO 1021
33 #define GETOPT_RCFILE 1022
38 MODE_QUERY = (1 << 0),
39 MODE_VERIFY = (1 << 3),
40 MODE_QUERYTAGS = (1 << 9),
41 #define MODES_QV (MODE_QUERY | MODE_VERIFY)
43 MODE_INSTALL = (1 << 1),
44 MODE_ERASE = (1 << 2),
45 #define MODES_IE (MODE_INSTALL | MODE_ERASE)
47 MODE_BUILD = (1 << 4),
48 MODE_REBUILD = (1 << 5),
49 MODE_RECOMPILE = (1 << 8),
50 MODE_TARBUILD = (1 << 11),
51 #define MODES_BT (MODE_BUILD | MODE_TARBUILD | MODE_REBUILD | MODE_RECOMPILE)
53 MODE_CHECKSIG = (1 << 6),
54 MODE_RESIGN = (1 << 7),
55 #define MODES_K (MODE_CHECKSIG | MODES_RESIGN)
57 MODE_INITDB = (1 << 10),
58 MODE_REBUILDDB = (1 << 12),
59 MODE_VERIFYDB = (1 << 13),
60 #define MODES_DB (MODE_INITDB | MODE_REBUILDDB | MODE_VERIFYDB)
65 #define MODES_FOR_DBPATH (MODES_BT | MODES_IE | MODES_QV | MODES_DB)
66 #define MODES_FOR_NODEPS (MODES_BT | MODES_IE | MODE_VERIFY)
67 #define MODES_FOR_TEST (MODES_BT | MODES_IE)
68 #define MODES_FOR_ROOT (MODES_BT | MODES_IE | MODES_QV | MODES_DB)
70 /*@-exportheadervar@*/
71 extern int _ftp_debug;
73 extern int _rpmio_debug;
74 extern int _url_debug;
77 /*@observer@*/ extern const char * rpmNAME;
79 /*@observer@*/ extern const char * rpmEVR;
84 extern struct MacroContext_s rpmCLIMacroContext;
85 /*@=exportheadervar@*/
87 /* options for all executables */
90 static int noUsageMsg = 0;
91 /*@observer@*/ /*@null@*/ static const char * pipeOutput = NULL;
93 /*@observer@*/ /*@null@*/ static const char * rcfile = NULL;
94 /*@observer@*/ /*@null@*/ static char * rootdir = "/";
95 static int showrc = 0;
96 static int showVersion = 0;
98 static struct poptOption rpmAllPoptTable[] = {
99 { "version", '\0', 0, &showVersion, 0,
100 N_("print the version of rpm being used"),
102 { "quiet", '\0', 0, &quiet, 0,
103 N_("provide less detailed output"), NULL},
104 { "verbose", 'v', 0, 0, 'v',
105 N_("provide more detailed output"), NULL},
106 { "define", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, 0, GETOPT_DEFINEMACRO,
107 N_("define macro <name> with value <body>"),
108 N_("'<name> <body>'") },
109 { "eval", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, 0, GETOPT_EVALMACRO,
110 N_("print macro expansion of <expr>+"),
112 { "pipe", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, &pipeOutput, 0,
113 N_("send stdout to <cmd>"),
115 { "root", 'r', POPT_ARG_STRING, &rootdir, 0,
116 N_("use <dir> as the top level directory"),
118 { "macros", '\0', POPT_ARG_STRING, ¯ofiles, 0,
119 N_("read <file:...> instead of default macro file(s)"),
121 #if !defined(GETOPT_RCFILE)
122 { "rcfile", '\0', POPT_ARG_STRING, &rcfile, 0,
123 N_("read <file:...> instead of default rpmrc file(s)"),
126 { "rcfile", '\0', 0, 0, GETOPT_RCFILE,
127 N_("read <file:...> instead of default rpmrc file(s)"),
130 { "showrc", '\0', 0, &showrc, GETOPT_SHOWRC,
131 N_("display final rpmrc and macro configuration"),
134 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
135 { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
136 N_("disable use of libio(3) API"), NULL},
138 { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
139 N_("debug protocol data stream"), NULL},
140 { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
141 N_("debug rpmio I/O"), NULL},
142 { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
143 N_("debug URL cache handling"), NULL},
148 /* the structure describing the options we take and the defaults */
149 static struct poptOption optionsTable[] = {
150 #if !defined(_AUTOHELP)
151 { "help", '\0', 0, &help, 0, NULL, NULL},
154 /* XXX colliding options */
155 #if defined(IAM_RPMQV) || defined(IAM_RPMEIU) || defined(IAM_RPMBT)
156 { NULL, 'i', POPT_ARGFLAG_DOC_HIDDEN, 0, 'i', NULL, NULL},
160 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQueryPoptTable, 0,
161 N_("Query options (with -q or --query):"),
163 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmVerifyPoptTable, 0,
164 N_("Verify options (with -V or --verify):"),
166 #endif /* IAM_RPMQV */
169 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmSignPoptTable, 0,
170 N_("Signature options:"),
172 #endif /* IAM_RPMK */
175 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmDatabasePoptTable, 0,
176 N_("Database options:"),
178 #endif /* IAM_RPMDB */
181 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmBuildPoptTable, 0,
182 N_("Build options with [ <specfile> | <tarball> | <source package> ]:"),
184 #endif /* IAM_RPMBT */
187 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmInstallPoptTable, 0,
188 N_("Install/Upgrade/Erase options:"),
190 #endif /* IAM_RPMEIU */
192 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmAllPoptTable, 0,
193 N_("Common options for all rpm modes:"),
201 /* MiNT cannot dynamically increase the stack. */
202 long _stksize = 64 * 1024L;
205 /*@exits@*/ static void argerror(const char * desc)
206 /*@modifies fileSystem @*/
208 fprintf(stderr, _("%s: %s\n"), __progname, desc);
212 static void printVersion(void)
213 /*@modifies fileSystem @*/
215 fprintf(stdout, _("RPM version %s\n"), rpmEVR);
218 static void printBanner(void)
219 /*@modifies fileSystem @*/
221 (void) puts(_("Copyright (C) 1998-2000 - Red Hat, Inc."));
222 (void) puts(_("This program may be freely redistributed under the terms of the GNU GPL"));
225 static void printUsage(void)
226 /*@modifies fileSystem @*/
233 fprintf(fp, _("Usage: %s {--help}\n"), __progname);
234 fprintf(fp, (" %s {--version}\n"), __progname);
240 --force alias for --replacepkgs --replacefiles
241 --includedocs handle as option in table
242 --erase forbids many options
244 #endif /* IAM_RPMEIU */
247 #ifdef DYING /* XXX popt glue needing --help doco. */
261 #endif /* IAM_RPMQV */
265 int main(int argc, const char ** argv)
267 enum modes bigMode = MODE_UNKNOWN;
270 QVA_t qva = &rpmQVArgs;
274 BTA_t ba = &rpmBTArgs;
278 struct rpmInstallArguments_s * ia = &rpmIArgs;
281 #if defined(IAM_RPMDB)
282 struct rpmDatabaseArguments_s * da = &rpmDBArgs;
285 #if defined(IAM_RPMK)
286 struct rpmSignArguments_s * ka = &rpmKArgs;
289 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
290 char * passPhrase = "";
303 #if HAVE_MCHECK_H && HAVE_MTRACE
304 mtrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
306 setprogname(argv[0]); /* Retrofit glibc __progname */
308 /* XXX glibc churn sanity */
309 if (__progname == NULL) {
310 if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
311 else __progname = argv[0];
314 /* Set the major mode based on argv[0] */
317 if (!strcmp(__progname, "rpmb")) bigMode = MODE_BUILD;
318 if (!strcmp(__progname, "rpmt")) bigMode = MODE_TARBUILD;
319 if (!strcmp(__progname, "rpmbuild")) bigMode = MODE_BUILD;
322 if (!strcmp(__progname, "rpmq")) bigMode = MODE_QUERY;
323 if (!strcmp(__progname, "rpmv")) bigMode = MODE_VERIFY;
324 if (!strcmp(__progname, "rpmquery")) bigMode = MODE_QUERY;
325 if (!strcmp(__progname, "rpmverify")) bigMode = MODE_VERIFY;
328 if (!strcmp(__progname, "rpme")) bigMode = MODE_ERASE;
329 if (!strcmp(__progname, "rpmi")) bigMode = MODE_INSTALL;
330 if (!strcmp(__progname, "rpmu")) bigMode = MODE_INSTALL;
334 /* set the defaults for the various command line options */
337 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
345 /* XXX Eliminate query linkage loop */
347 parseSpecVec = parseSpec;
348 freeSpecVec = freeSpec;
350 /* set up the correct locale */
351 (void) setlocale(LC_ALL, "" );
354 #define LOCALEDIR "/usr/share/locale"
356 bindtextdomain(PACKAGE, LOCALEDIR);
359 rpmSetVerbosity(RPMMESS_NORMAL); /* XXX silly use by showrc */
361 /* Make a first pass through the arguments, looking for --rcfile */
362 /* We need to handle that before dealing with the rest of the arguments. */
363 /*@-nullpass -temptrans@*/
364 optCon = poptGetContext(__progname, argc, argv, optionsTable, 0);
365 /*@=nullpass =temptrans@*/
366 (void) poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
367 (void) poptReadDefaultConfig(optCon, 1);
368 poptSetExecPath(optCon, RPMCONFIGDIR, 1);
370 /* reading rcfile early makes it easy to override */
371 /* XXX only --rcfile (and --showrc) need this pre-parse */
373 while ((arg = poptGetNextOpt(optCon)) > 0) {
376 rpmIncreaseVerbosity(); /* XXX silly use by showrc */
383 if (rpmReadConfigFiles(rcfile, NULL))
387 (void) rpmShowRC(stdout);
391 rpmSetVerbosity(RPMMESS_NORMAL); /* XXX silly use by showrc */
393 poptResetContext(optCon);
396 qva->qva_queryFormat = _free(qva->qva_queryFormat);
397 memset(qva, 0, sizeof(*qva));
398 qva->qva_source = RPMQV_PACKAGE;
404 ba->buildRootOverride = _free(ba->buildRootOverride);
405 ba->targets = _free(ba->targets);
406 memset(ba, 0, sizeof(*ba));
412 memset(da, 0, sizeof(*da));
416 memset(ka, 0, sizeof(*ka));
417 ka->addSign = RESIGN_CHK_SIGNATURE;
418 ka->checksigFlags = CHECKSIG_ALL;
422 ia->relocations = _free(ia->relocations);
423 memset(ia, 0, sizeof(*ia));
424 ia->transFlags = RPMTRANS_FLAG_NONE;
425 ia->probFilter = RPMPROB_FILTER_NONE;
426 ia->installInterfaceFlags = INSTALL_NONE;
427 ia->eraseInterfaceFlags = UNINSTALL_NONE;
430 while ((arg = poptGetNextOpt(optCon)) > 0) {
431 optArg = poptGetOptArg(optCon);
436 rpmIncreaseVerbosity();
439 #if defined(IAM_RPMQV) || defined(IAM_RPMEIU) || defined(IAM_RPMBT)
442 if (bigMode == MODE_QUERY) {
443 /*@-nullassign -readonlytrans@*/
444 const char * infoCommand[] = { "--info", NULL };
445 /*@=nullassign =readonlytrans@*/
446 (void) poptStuffArgs(optCon, infoCommand);
450 if (bigMode == MODE_INSTALL)
452 if (bigMode == MODE_UNKNOWN) {
453 /*@-nullassign -readonlytrans@*/
454 const char * installCommand[] = { "--install", NULL };
455 /*@=nullassign =readonlytrans@*/
456 (void) poptStuffArgs(optCon, installCommand);
460 #endif /* IAM_RPMQV || IAM_RPMEIU || IAM_RPMBT */
462 case GETOPT_DEFINEMACRO:
464 (void) rpmDefineMacro(NULL, optArg, RMIL_CMDLINE);
465 (void) rpmDefineMacro(&rpmCLIMacroContext, optArg,RMIL_CMDLINE);
470 case GETOPT_EVALMACRO:
472 const char *val = rpmExpand(optArg, NULL);
473 fprintf(stdout, "%s\n", val);
479 #if defined(GETOPT_RCFILE)
481 fprintf(stderr, _("The --rcfile option has been eliminated.\n"));
482 fprintf(stderr, _("Use \"--macros <file:...>\" instead.\n"));
484 /*@notreached@*/ break;
488 fprintf(stderr, _("Internal error in argument processing (%d) :-(\n"), arg);
494 rpmSetVerbosity(RPMMESS_QUIET);
496 if (showVersion) printVersion();
499 fprintf(stderr, "%s: %s\n",
500 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
506 switch (ba->buildMode) {
507 case 'b': bigMode = MODE_BUILD; break;
508 case 't': bigMode = MODE_TARBUILD; break;
509 case 'B': bigMode = MODE_REBUILD; break;
510 case 'C': bigMode = MODE_RECOMPILE; break;
513 if ((ba->buildAmount & RPMBUILD_RMSOURCE) && bigMode == MODE_UNKNOWN)
514 bigMode = MODE_BUILD;
516 if ((ba->buildAmount & RPMBUILD_RMSPEC) && bigMode == MODE_UNKNOWN)
517 bigMode = MODE_BUILD;
519 if (ba->buildRootOverride && bigMode != MODE_BUILD &&
520 bigMode != MODE_REBUILD && bigMode != MODE_TARBUILD) {
521 argerror("--buildroot may only be used during package builds");
523 #endif /* IAM_RPMBT */
527 if (bigMode != MODE_UNKNOWN)
528 argerror(_("only one major mode may be specified"));
530 bigMode = MODE_INITDB;
533 if (bigMode != MODE_UNKNOWN)
534 argerror(_("only one major mode may be specified"));
536 bigMode = MODE_REBUILDDB;
539 if (bigMode != MODE_UNKNOWN)
540 argerror(_("only one major mode may be specified"));
542 bigMode = MODE_VERIFYDB;
544 #endif /* IAM_RPMDB */
547 switch (qva->qva_mode) {
548 case 'q': bigMode = MODE_QUERY; break;
549 case 'V': bigMode = MODE_VERIFY; break;
550 case 'Q': bigMode = MODE_QUERYTAGS; break;
553 if (qva->qva_sourceCount) {
554 if (qva->qva_sourceCount > 2)
555 argerror(_("one type of query/verify may be performed at a "
558 if (qva->qva_flags && (bigMode & ~MODES_QV))
559 argerror(_("unexpected query flags"));
561 if (qva->qva_queryFormat && (bigMode & ~MODES_QV))
562 argerror(_("unexpected query format"));
564 if (qva->qva_source != RPMQV_PACKAGE && (bigMode & ~MODES_QV))
565 argerror(_("unexpected query source"));
566 #endif /* IAM_RPMQV */
569 { int iflags = (ia->installInterfaceFlags &
570 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_NOERASE));
571 int eflags = (ia->installInterfaceFlags & INSTALL_UPGRADE);
574 argerror(_("only one major mode may be specified"));
576 bigMode = MODE_INSTALL;
578 bigMode = MODE_ERASE;
580 #endif /* IAM_RPMQV */
582 /* XXX TODO: never happens. */
583 if (gotDbpath && (bigMode & ~MODES_FOR_DBPATH))
584 argerror(_("--dbpath given for operation that does not use a "
587 #if defined(IAM_RPMEIU)
588 if (!( bigMode == MODE_INSTALL ) &&
589 (ia->probFilter & (RPMPROB_FILTER_REPLACEPKG | RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES | RPMPROB_FILTER_OLDPACKAGE)))
590 argerror(_("only installation, upgrading, rmsource and rmspec may be forced"));
591 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_FORCERELOCATE))
592 argerror(_("files may only be relocated during package installation"));
594 if (ia->relocations && ia->prefix)
595 argerror(_("only one of --prefix or --relocate may be used"));
597 if (bigMode != MODE_INSTALL && ia->relocations)
598 argerror(_("--relocate and --excludepath may only be used when installing new packages"));
600 if (bigMode != MODE_INSTALL && ia->prefix)
601 argerror(_("--prefix may only be used when installing new packages"));
603 if (ia->prefix && ia->prefix[0] != '/')
604 argerror(_("arguments to --prefix must begin with a /"));
606 if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_HASH))
607 argerror(_("--hash (-h) may only be specified during package "
610 if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_PERCENT))
611 argerror(_("--percent may only be specified during package "
614 if (bigMode != MODE_INSTALL &&
615 (ia->probFilter & (RPMPROB_FILTER_REPLACEOLDFILES|RPMPROB_FILTER_REPLACENEWFILES)))
616 argerror(_("--replacefiles may only be specified during package "
619 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_REPLACEPKG))
620 argerror(_("--replacepkgs may only be specified during package "
623 if (bigMode != MODE_INSTALL && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
624 argerror(_("--excludedocs may only be specified during package "
627 if (bigMode != MODE_INSTALL && ia->incldocs)
628 argerror(_("--includedocs may only be specified during package "
631 if (ia->incldocs && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
632 argerror(_("only one of --excludedocs and --includedocs may be "
635 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREARCH))
636 argerror(_("--ignorearch may only be specified during package "
639 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREOS))
640 argerror(_("--ignoreos may only be specified during package "
643 if (bigMode != MODE_INSTALL &&
644 (ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES)))
645 argerror(_("--ignoresize may only be specified during package "
648 if ((ia->eraseInterfaceFlags & UNINSTALL_ALLMATCHES) && bigMode != MODE_ERASE)
649 argerror(_("--allmatches may only be specified during package "
652 if ((ia->transFlags & RPMTRANS_FLAG_ALLFILES) && bigMode != MODE_INSTALL)
653 argerror(_("--allfiles may only be specified during package "
656 if ((ia->transFlags & RPMTRANS_FLAG_JUSTDB) &&
657 bigMode != MODE_INSTALL && bigMode != MODE_ERASE)
658 argerror(_("--justdb may only be specified during package "
659 "installation and erasure"));
661 if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
662 (ia->transFlags & (RPMTRANS_FLAG_NOSCRIPTS | _noTransScripts | _noTransTriggers)))
663 argerror(_("script disabling options may only be specified during "
664 "package installation and erasure"));
666 if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
667 (ia->transFlags & (RPMTRANS_FLAG_NOTRIGGERS | _noTransTriggers)))
668 argerror(_("trigger disabling options may only be specified during "
669 "package installation and erasure"));
671 if (ia->noDeps & (bigMode & ~MODES_FOR_NODEPS))
672 argerror(_("--nodeps may only be specified during package "
673 "building, rebuilding, recompilation, installation,"
674 "erasure, and verification"));
676 if ((ia->transFlags & RPMTRANS_FLAG_TEST) && (bigMode & ~MODES_FOR_TEST))
677 argerror(_("--test may only be specified during package installation, "
678 "erasure, and building"));
679 #endif /* IAM_RPMEIU */
681 if (rootdir && rootdir[1] && (bigMode & ~MODES_FOR_ROOT))
682 argerror(_("--root (-r) may only be specified during "
683 "installation, erasure, querying, and "
684 "database rebuilds"));
687 switch (urlIsURL(rootdir)) {
689 if (bigMode & MODES_FOR_ROOT)
693 if (rootdir[0] != '/')
694 argerror(_("arguments to --root (-r) must begin with a /"));
699 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
701 #if defined(IAM_RPMBT)
704 #if defined(IAM_RPMK)
708 if (bigMode == MODE_REBUILD || bigMode == MODE_BUILD ||
709 bigMode == MODE_RESIGN || bigMode == MODE_TARBUILD) {
714 if ((av = poptGetArgs(optCon)) == NULL) {
715 fprintf(stderr, _("no files to sign\n"));
719 if (stat(*av, &sb)) {
720 fprintf(stderr, _("cannot access file %s\n"), *av);
731 if (poptPeekArg(optCon)) {
733 switch (sigTag = rpmLookupSignatureType(RPMLOOKUPSIG_QUERY)) {
737 if ((sigTag == RPMSIGTAG_PGP || sigTag == RPMSIGTAG_PGP5) &&
738 !rpmDetectPGPVersion(NULL)) {
739 fprintf(stderr, _("pgp not found: "));
744 passPhrase = rpmGetPassPhrase(_("Enter pass phrase: "), sigTag);
745 if (passPhrase == NULL) {
746 fprintf(stderr, _("Pass phrase check failed\n"));
750 fprintf(stderr, _("Pass phrase is good.\n"));
751 passPhrase = xstrdup(passPhrase);
755 _("Invalid %%_signature spec in macro file.\n"));
758 /*@notreached@*/ break;
762 argerror(_("--sign may only be used during package building"));
765 /* Make rpmLookupSignatureType() return 0 ("none") from now on */
766 (void) rpmLookupSignatureType(RPMLOOKUPSIG_DISABLE);
768 #endif /* IAM_RPMBT || IAM_RPMK */
773 if (!(pipeChild = fork())) {
775 (void) dup2(p[0], STDIN_FILENO);
777 (void) execl("/bin/sh", "/bin/sh", "-c", pipeOutput, NULL);
778 fprintf(stderr, _("exec failed\n"));
782 (void) dup2(p[1], STDOUT_FILENO);
789 (void) rpmdbInit(rootdir, 0644);
793 ec = rpmdbRebuild(rootdir);
796 ec = rpmdbVerify(rootdir);
798 #endif /* IAM_RPMDB */
804 while (!rpmIsVerbose())
805 rpmIncreaseVerbosity();
807 if (!poptPeekArg(optCon))
808 argerror(_("no packages files given for rebuild"));
810 ba->buildAmount = RPMBUILD_PREP | RPMBUILD_BUILD | RPMBUILD_INSTALL;
811 if (bigMode == MODE_REBUILD) {
812 ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
813 ba->buildAmount |= RPMBUILD_RMSOURCE;
814 ba->buildAmount |= RPMBUILD_RMSPEC;
815 ba->buildAmount |= RPMBUILD_CLEAN;
816 ba->buildAmount |= RPMBUILD_RMBUILD;
819 while ((pkg = poptGetArg(optCon))) {
820 const char * specFile = NULL;
821 char * cookie = NULL;
823 ec = rpmInstallSource("", pkg, &specFile, &cookie);
825 /*@loopbreak@*/ break;
827 ba->rootdir = rootdir;
828 ec = build(specFile, ba, passPhrase, cookie, rcfile);
831 free((void *)specFile);
835 /*@loopbreak@*/ break;
842 while (!rpmIsVerbose())
843 rpmIncreaseVerbosity();
845 switch (ba->buildChar) {
847 ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
850 ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
851 ba->buildAmount |= RPMBUILD_CLEAN;
854 ba->buildAmount |= RPMBUILD_INSTALL;
855 if ((ba->buildChar == 'i') && ba->shortCircuit)
859 ba->buildAmount |= RPMBUILD_BUILD;
860 if ((ba->buildChar == 'c') && ba->shortCircuit)
864 ba->buildAmount |= RPMBUILD_PREP;
868 ba->buildAmount |= RPMBUILD_FILECHECK;
871 ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
875 if (!poptPeekArg(optCon)) {
876 if (bigMode == MODE_BUILD)
877 argerror(_("no spec files given for build"));
879 argerror(_("no tar files given for build"));
882 while ((pkg = poptGetArg(optCon))) {
883 ba->rootdir = rootdir;
884 ec = build(pkg, ba, passPhrase, NULL, rcfile);
886 /*@loopbreak@*/ break;
888 (void) rpmReadConfigFiles(rcfile, NULL);
891 #endif /* IAM_RPMBT */
895 if (!poptPeekArg(optCon))
896 argerror(_("no packages given for uninstall"));
898 if (ia->noDeps) ia->eraseInterfaceFlags |= UNINSTALL_NODEPS;
900 ec = rpmErase(rootdir, (const char **)poptGetArgs(optCon),
901 ia->transFlags, ia->eraseInterfaceFlags);
906 /* RPMTRANS_FLAG_BUILD_PROBS */
907 /* RPMTRANS_FLAG_KEEPOBSOLETE */
910 if (ia->transFlags & RPMTRANS_FLAG_NODOCS)
912 else if (rpmExpandNumeric("%{_excludedocs}"))
913 ia->transFlags |= RPMTRANS_FLAG_NODOCS;
916 if (ia->noDeps) ia->installInterfaceFlags |= INSTALL_NODEPS;
918 if (!poptPeekArg(optCon))
919 argerror(_("no packages given for install"));
921 /* we've already ensured !(!ia->prefix && !ia->relocations) */
923 ia->relocations = xmalloc(2 * sizeof(*ia->relocations));
924 ia->relocations[0].oldPath = NULL; /* special case magic */
925 ia->relocations[0].newPath = ia->prefix;
926 ia->relocations[1].oldPath = ia->relocations[1].newPath = NULL;
927 } else if (ia->relocations) {
928 ia->relocations = xrealloc(ia->relocations,
929 sizeof(*ia->relocations) * (ia->numRelocations + 1));
930 ia->relocations[ia->numRelocations].oldPath = NULL;
931 ia->relocations[ia->numRelocations].newPath = NULL;
934 ec += rpmInstall(rootdir, (const char **)poptGetArgs(optCon),
935 ia->transFlags, ia->installInterfaceFlags, ia->probFilter,
938 #endif /* IAM_RPMEIU */
944 qva->qva_prefix = rootdir;
945 if (qva->qva_source == RPMQV_ALL) {
947 if (poptPeekArg(optCon))
948 argerror(_("extra arguments given for query of all packages"));
950 const char ** av = poptGetArgs(optCon);
952 /*@-nullpass@*/ /* FIX: av can be NULL */
953 ec = rpmQuery(qva, RPMQV_ALL, (const char *) av);
956 if (!poptPeekArg(optCon))
957 argerror(_("no arguments given for query"));
958 while ((pkg = poptGetArg(optCon)))
959 ec += rpmQuery(qva, qva->qva_source, pkg);
965 rpmVerifyFlags verifyFlags = VERIFY_ALL;
967 verifyFlags &= ~qva->qva_flags;
968 qva->qva_flags = (rpmQueryFlags) verifyFlags;
969 qva->qva_prefix = rootdir;
971 if (qva->qva_source == RPMQV_ALL) {
972 if (poptPeekArg(optCon))
973 argerror(_("extra arguments given for verify of all packages"));
974 ec = rpmVerify(qva, RPMQV_ALL, NULL);
976 if (!poptPeekArg(optCon))
977 argerror(_("no arguments given for verify"));
978 while ((pkg = poptGetArg(optCon)))
979 ec += rpmVerify(qva, qva->qva_source, pkg);
985 argerror(_("unexpected arguments to --querytags "));
987 rpmDisplayQueryTags(stdout);
989 #endif /* IAM_RPMQV */
993 if (!poptPeekArg(optCon))
994 argerror(_("no packages given for signature check"));
995 ec = rpmCheckSig(ka->checksigFlags,
996 (const char **)poptGetArgs(optCon));
997 /* XXX don't overflow single byte exit status */
998 if (ec > 255) ec = 255;
1002 if (!poptPeekArg(optCon))
1003 argerror(_("no packages given for signing"));
1004 ec = rpmReSign(ka->addSign, passPhrase,
1005 (const char **)poptGetArgs(optCon));
1006 /* XXX don't overflow single byte exit status */
1007 if (ec > 255) ec = 255;
1009 #endif /* IAM_RPMK */
1011 #if !defined(IAM_RPMQV)
1014 case MODE_QUERYTAGS:
1016 #if !defined(IAM_RPMK)
1020 #if !defined(IAM_RPMDB)
1022 case MODE_REBUILDDB:
1025 #if !defined(IAM_RPMBT)
1028 case MODE_RECOMPILE:
1031 #if !defined(IAM_RPMEIU)
1036 if (!showVersion && !help && !noUsageMsg) printUsage();
1040 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
1042 #endif /* IAM_RPMBT || IAM_RPMK */
1043 optCon = poptFreeContext(optCon);
1044 rpmFreeMacros(NULL);
1045 rpmFreeMacros(&rpmCLIMacroContext);
1049 (void) fclose(stdout);
1050 (void) waitpid(pipeChild, &status, 0);
1053 /* keeps memory leak checkers quiet */
1059 qva->qva_queryFormat = _free(qva->qva_queryFormat);
1063 ba->buildRootOverride = _free(ba->buildRootOverride);
1064 ba->targets = _free(ba->targets);
1068 ia->relocations = _free(ia->relocations);
1071 #if HAVE_MCHECK_H && HAVE_MTRACE
1072 muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */