5 #if defined(IAM_RPM) || defined(__LCLINT__)
16 #define POPT_NODEPS 1025
17 #define POPT_FORCE 1026
18 #define POPT_NOMD5 1027
19 #define POPT_NOSCRIPTS 1028
23 #define GETOPT_REBUILD 1003
24 #define GETOPT_RECOMPILE 1004
27 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
28 #include "signature.h"
33 #define GETOPT_DBPATH 1010
34 #define GETOPT_SHOWRC 1018
35 #define GETOPT_DEFINEMACRO 1020
36 #define GETOPT_EVALMACRO 1021
38 #define GETOPT_RCFILE 1022
43 MODE_QUERY = (1 << 0),
44 MODE_VERIFY = (1 << 3),
45 MODE_QUERYTAGS = (1 << 9),
46 #define MODES_QV (MODE_QUERY | MODE_VERIFY)
48 MODE_INSTALL = (1 << 1),
49 MODE_ERASE = (1 << 2),
50 MODE_ROLLBACK = (1 << 14),
51 #define MODES_IE (MODE_INSTALL | MODE_ERASE | MODE_ROLLBACK)
53 MODE_BUILD = (1 << 4),
54 MODE_REBUILD = (1 << 5),
55 MODE_RECOMPILE = (1 << 8),
56 MODE_TARBUILD = (1 << 11),
57 #define MODES_BT (MODE_BUILD | MODE_TARBUILD | MODE_REBUILD | MODE_RECOMPILE)
59 MODE_CHECKSIG = (1 << 6),
60 MODE_RESIGN = (1 << 7),
61 #define MODES_K (MODE_CHECKSIG | MODE_RESIGN)
63 MODE_INITDB = (1 << 10),
64 MODE_REBUILDDB = (1 << 12),
65 MODE_VERIFYDB = (1 << 13),
66 #define MODES_DB (MODE_INITDB | MODE_REBUILDDB | MODE_VERIFYDB)
72 #define MODES_FOR_DBPATH (MODES_BT | MODES_IE | MODES_QV | MODES_DB)
73 #define MODES_FOR_NODEPS (MODES_BT | MODES_IE | MODE_VERIFY)
74 #define MODES_FOR_TEST (MODES_BT | MODES_IE)
75 #define MODES_FOR_ROOT (MODES_BT | MODES_IE | MODES_QV | MODES_DB)
77 /*@-exportheadervar@*/
78 extern int _ftp_debug;
80 extern int _rpmio_debug;
81 extern int _url_debug;
84 /*@observer@*/ extern const char * rpmNAME;
86 /*@observer@*/ extern const char * rpmEVR;
91 extern struct MacroContext_s rpmCLIMacroContext;
92 /*@=exportheadervar@*/
94 /* options for all executables */
97 static int noUsageMsg = 0;
98 /*@observer@*/ /*@null@*/ static const char * pipeOutput = NULL;
100 /*@observer@*/ /*@null@*/ static const char * rcfile = NULL;
101 /*@observer@*/ /*@null@*/ static char * rootdir = "/";
102 static int showrc = 0;
103 static int showVersion = 0;
105 static struct poptOption rpmAllPoptTable[] = {
106 { "version", '\0', 0, &showVersion, 0,
107 N_("print the version of rpm being used"),
109 { "quiet", '\0', 0, &quiet, 0,
110 N_("provide less detailed output"), NULL},
111 { "verbose", 'v', 0, 0, 'v',
112 N_("provide more detailed output"), NULL},
113 { "define", '\0', POPT_ARG_STRING, 0, GETOPT_DEFINEMACRO,
114 N_("define macro <name> with value <body>"),
115 N_("'<name> <body>'") },
116 { "eval", '\0', POPT_ARG_STRING, 0, GETOPT_EVALMACRO,
117 N_("print macro expansion of <expr>+"),
119 { "pipe", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, &pipeOutput, 0,
120 N_("send stdout to <cmd>"),
122 { "root", 'r', POPT_ARG_STRING | POPT_ARGFLAG_SHOW_DEFAULT, &rootdir, 0,
123 N_("use <dir> as the top level directory"),
125 { "macros", '\0', POPT_ARG_STRING, ¯ofiles, 0,
126 N_("read <file:...> instead of default macro file(s)"),
128 #if !defined(GETOPT_RCFILE)
129 { "rcfile", '\0', POPT_ARG_STRING, &rcfile, 0,
130 N_("read <file:...> instead of default rpmrc file(s)"),
133 { "rcfile", '\0', 0, 0, GETOPT_RCFILE,
134 N_("read <file:...> instead of default rpmrc file(s)"),
137 { "showrc", '\0', 0, &showrc, GETOPT_SHOWRC,
138 N_("display final rpmrc and macro configuration"),
141 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
142 { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
143 N_("disable use of libio(3) API"), NULL},
145 { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
146 N_("debug protocol data stream"), NULL},
147 { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
148 N_("debug rpmio I/O"), NULL},
149 { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
150 N_("debug URL cache handling"), NULL},
155 /* the structure describing the options we take and the defaults */
156 static struct poptOption optionsTable[] = {
158 /* XXX colliding options */
159 #if defined(IAM_RPMQV) || defined(IAM_RPMEIU) || defined(IAM_RPMBT)
160 { NULL, 'i', POPT_ARGFLAG_DOC_HIDDEN, 0, 'i', NULL, NULL},
161 { "nodeps", 0, POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_NODEPS, NULL, NULL},
162 { "noscripts", 0, POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_NOSCRIPTS, NULL, NULL},
163 { "nomd5", 0, POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_NOMD5, NULL, NULL},
164 { "force", 0, POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_FORCE, NULL, NULL},
168 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQueryPoptTable, 0,
169 N_("Query options (with -q or --query):"),
171 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmVerifyPoptTable, 0,
172 N_("Verify options (with -V or --verify):"),
174 #endif /* IAM_RPMQV */
177 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmSignPoptTable, 0,
178 N_("Signature options:"),
180 #endif /* IAM_RPMK */
183 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmDatabasePoptTable, 0,
184 N_("Database options:"),
186 #endif /* IAM_RPMDB */
189 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmBuildPoptTable, 0,
190 N_("Build options with [ <specfile> | <tarball> | <source package> ]:"),
192 #endif /* IAM_RPMBT */
195 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmInstallPoptTable, 0,
196 N_("Install/Upgrade/Erase options:"),
198 #endif /* IAM_RPMEIU */
200 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmAllPoptTable, 0,
201 N_("Common options for all rpm modes:"),
210 /* MiNT cannot dynamically increase the stack. */
211 long _stksize = 64 * 1024L;
214 /*@exits@*/ static void argerror(const char * desc)
215 /*@modifies fileSystem @*/
217 fprintf(stderr, _("%s: %s\n"), __progname, desc);
221 static void printVersion(void)
222 /*@modifies fileSystem @*/
224 fprintf(stdout, _("RPM version %s\n"), rpmEVR);
227 static void printBanner(void)
228 /*@modifies fileSystem @*/
230 (void) puts(_("Copyright (C) 1998-2000 - Red Hat, Inc."));
231 (void) puts(_("This program may be freely redistributed under the terms of the GNU GPL"));
234 static void printUsage(void)
235 /*@modifies fileSystem @*/
242 fprintf(fp, _("Usage: %s {--help}\n"), __progname);
243 fprintf(fp, " %s {--version}\n" , __progname);
249 --force alias for --replacepkgs --replacefiles
250 --includedocs handle as option in table
251 --erase forbids many options
253 #endif /* IAM_RPMEIU */
256 #ifdef DYING /* XXX popt glue needing --help doco. */
270 #endif /* IAM_RPMQV */
274 int main(int argc, const char ** argv)
276 enum modes bigMode = MODE_UNKNOWN;
279 QVA_t qva = &rpmQVArgs;
283 BTA_t ba = &rpmBTArgs;
287 struct rpmInstallArguments_s * ia = &rpmIArgs;
290 #if defined(IAM_RPMDB)
291 struct rpmDatabaseArguments_s * da = &rpmDBArgs;
294 #if defined(IAM_RPMK)
295 struct rpmSignArguments_s * ka = &rpmKArgs;
298 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
299 char * passPhrase = "";
312 #if HAVE_MCHECK_H && HAVE_MTRACE
313 mtrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
315 setprogname(argv[0]); /* Retrofit glibc __progname */
317 /* XXX glibc churn sanity */
318 if (__progname == NULL) {
319 if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
320 else __progname = argv[0];
323 /* Set the major mode based on argv[0] */
326 if (!strcmp(__progname, "rpmb")) bigMode = MODE_BUILD;
327 if (!strcmp(__progname, "rpmt")) bigMode = MODE_TARBUILD;
328 if (!strcmp(__progname, "rpmbuild")) bigMode = MODE_BUILD;
331 if (!strcmp(__progname, "rpmq")) bigMode = MODE_QUERY;
332 if (!strcmp(__progname, "rpmv")) bigMode = MODE_VERIFY;
333 if (!strcmp(__progname, "rpmquery")) bigMode = MODE_QUERY;
334 if (!strcmp(__progname, "rpmverify")) bigMode = MODE_VERIFY;
337 if (!strcmp(__progname, "rpme")) bigMode = MODE_ERASE;
338 if (!strcmp(__progname, "rpmi")) bigMode = MODE_INSTALL;
339 if (!strcmp(__progname, "rpmu")) bigMode = MODE_INSTALL;
343 /* set the defaults for the various command line options */
346 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
354 /* XXX Eliminate query linkage loop */
356 parseSpecVec = parseSpec;
357 freeSpecVec = freeSpec;
359 /* set up the correct locale */
360 (void) setlocale(LC_ALL, "" );
363 #define LOCALEDIR "/usr/share/locale"
365 bindtextdomain(PACKAGE, LOCALEDIR);
368 rpmSetVerbosity(RPMMESS_NORMAL); /* XXX silly use by showrc */
370 /* Make a first pass through the arguments, looking for --rcfile */
371 /* We need to handle that before dealing with the rest of the arguments. */
372 /*@-nullpass -temptrans@*/
373 optCon = poptGetContext(__progname, argc, argv, optionsTable, 0);
374 /*@=nullpass =temptrans@*/
375 (void) poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
376 (void) poptReadDefaultConfig(optCon, 1);
377 poptSetExecPath(optCon, RPMCONFIGDIR, 1);
379 /* reading rcfile early makes it easy to override */
380 /* XXX only --rcfile (and --showrc) need this pre-parse */
382 while ((arg = poptGetNextOpt(optCon)) > 0) {
385 rpmIncreaseVerbosity(); /* XXX silly use by showrc */
392 if (rpmReadConfigFiles(rcfile, NULL))
396 (void) rpmShowRC(stdout);
400 rpmSetVerbosity(RPMMESS_NORMAL); /* XXX silly use by showrc */
402 poptResetContext(optCon);
405 qva->qva_queryFormat = _free(qva->qva_queryFormat);
406 memset(qva, 0, sizeof(*qva));
407 qva->qva_source = RPMQV_PACKAGE;
408 qva->qva_fflags = RPMFILE_ALL;
414 ba->buildRootOverride = _free(ba->buildRootOverride);
415 ba->targets = _free(ba->targets);
416 memset(ba, 0, sizeof(*ba));
422 memset(da, 0, sizeof(*da));
426 memset(ka, 0, sizeof(*ka));
427 ka->addSign = RESIGN_NONE;
428 ka->checksigFlags = CHECKSIG_ALL;
432 ia->relocations = _free(ia->relocations);
433 memset(ia, 0, sizeof(*ia));
434 ia->transFlags = RPMTRANS_FLAG_NONE;
435 ia->probFilter = RPMPROB_FILTER_NONE;
436 ia->installInterfaceFlags = INSTALL_NONE;
437 ia->eraseInterfaceFlags = UNINSTALL_NONE;
440 while ((arg = poptGetNextOpt(optCon)) > 0) {
441 optArg = poptGetOptArg(optCon);
446 rpmIncreaseVerbosity();
449 /* XXX options used in multiple rpm modes */
450 #if defined(IAM_RPMQV) || defined(IAM_RPMK)
453 if (bigMode == MODE_VERIFY || qva->qva_mode == 'V')
454 qva->qva_flags |= VERIFY_MD5;
458 if (bigMode & MODES_K)
459 ka->checksigFlags &= ~CHECKSIG_MD5;
464 #endif /* IAM_RPMQV || IAM_RPMK */
466 #if defined(IAM_RPMQV) || defined(IAM_RPMEIU) || defined(IAM_RPMBT)
469 if (bigMode == MODE_VERIFY || qva->qva_mode == 'V')
470 qva->qva_flags |= VERIFY_DEPS;
474 if ((bigMode & MODES_IE) ||
475 (ia->installInterfaceFlags &
476 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE)))
481 if ((bigMode & MODES_BT) || ba->buildMode != ' ')
490 if ((bigMode & MODES_IE) ||
491 (ia->installInterfaceFlags &
492 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE)))
494 ( RPMPROB_FILTER_REPLACEPKG
495 | RPMPROB_FILTER_REPLACEOLDFILES
496 | RPMPROB_FILTER_REPLACENEWFILES
497 | RPMPROB_FILTER_OLDPACKAGE);
501 if ((bigMode & MODES_BT) || ba->buildMode != ' ')
510 if (bigMode == MODE_QUERY || qva->qva_mode == 'q') {
511 /*@-nullassign -readonlytrans@*/
512 const char * infoCommand[] = { "--info", NULL };
513 /*@=nullassign =readonlytrans@*/
514 (void) poptStuffArgs(optCon, infoCommand);
518 if (bigMode == MODE_INSTALL ||
519 (ia->installInterfaceFlags &
520 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL)))
522 else if (bigMode == MODE_UNKNOWN) {
523 /*@-nullassign -readonlytrans@*/
524 const char * installCommand[] = { "--install", NULL };
525 /*@=nullassign =readonlytrans@*/
526 (void) poptStuffArgs(optCon, installCommand);
534 if (bigMode == MODE_VERIFY || qva->qva_mode == 'V')
535 qva->qva_flags |= VERIFY_SCRIPT;
539 if ((bigMode & MODES_IE) ||
540 (ia->installInterfaceFlags &
541 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE)))
542 ia->transFlags |= (_noTransScripts | _noTransTriggers);
548 #endif /* IAM_RPMQV || IAM_RPMEIU || IAM_RPMBT */
550 case GETOPT_DEFINEMACRO:
552 (void) rpmDefineMacro(NULL, optArg, RMIL_CMDLINE);
553 (void) rpmDefineMacro(&rpmCLIMacroContext, optArg,RMIL_CMDLINE);
558 case GETOPT_EVALMACRO:
560 const char *val = rpmExpand(optArg, NULL);
561 fprintf(stdout, "%s\n", val);
567 #if defined(GETOPT_RCFILE)
569 fprintf(stderr, _("The --rcfile option has been eliminated.\n"));
570 fprintf(stderr, _("Use \"--macros <file:...>\" instead.\n"));
572 /*@notreached@*/ break;
576 fprintf(stderr, _("Internal error in argument processing (%d) :-(\n"), arg);
582 rpmSetVerbosity(RPMMESS_QUIET);
584 if (showVersion) printVersion();
587 fprintf(stderr, "%s: %s\n",
588 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
594 switch (ba->buildMode) {
595 case 'b': bigMode = MODE_BUILD; break;
596 case 't': bigMode = MODE_TARBUILD; break;
597 case 'B': bigMode = MODE_REBUILD; break;
598 case 'C': bigMode = MODE_RECOMPILE; break;
601 if ((ba->buildAmount & RPMBUILD_RMSOURCE) && bigMode == MODE_UNKNOWN)
602 bigMode = MODE_BUILD;
604 if ((ba->buildAmount & RPMBUILD_RMSPEC) && bigMode == MODE_UNKNOWN)
605 bigMode = MODE_BUILD;
607 if (ba->buildRootOverride && bigMode != MODE_BUILD &&
608 bigMode != MODE_REBUILD && bigMode != MODE_TARBUILD) {
609 argerror("--buildroot may only be used during package builds");
611 #endif /* IAM_RPMBT */
614 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_DB)) {
616 if (bigMode != MODE_UNKNOWN)
617 argerror(_("only one major mode may be specified"));
619 bigMode = MODE_INITDB;
622 if (bigMode != MODE_UNKNOWN)
623 argerror(_("only one major mode may be specified"));
625 bigMode = MODE_REBUILDDB;
628 if (bigMode != MODE_UNKNOWN)
629 argerror(_("only one major mode may be specified"));
631 bigMode = MODE_VERIFYDB;
634 #endif /* IAM_RPMDB */
637 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_QV)) {
638 switch (qva->qva_mode) {
639 case 'q': bigMode = MODE_QUERY; break;
640 case 'V': bigMode = MODE_VERIFY; break;
641 case 'Q': bigMode = MODE_QUERYTAGS; break;
644 if (qva->qva_sourceCount) {
645 if (qva->qva_sourceCount > 2)
646 argerror(_("one type of query/verify may be performed at a "
649 if (qva->qva_flags && (bigMode & ~MODES_QV))
650 argerror(_("unexpected query flags"));
652 if (qva->qva_queryFormat && (bigMode & ~MODES_QV))
653 argerror(_("unexpected query format"));
655 if (qva->qva_source != RPMQV_PACKAGE && (bigMode & ~MODES_QV))
656 argerror(_("unexpected query source"));
658 #endif /* IAM_RPMQV */
661 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_IE))
662 { int iflags = (ia->installInterfaceFlags &
663 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL));
664 int eflags = (ia->installInterfaceFlags & INSTALL_ERASE);
667 argerror(_("only one major mode may be specified"));
669 bigMode = MODE_INSTALL;
671 bigMode = MODE_ERASE;
673 #endif /* IAM_RPMQV */
676 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_K)) {
677 switch (ka->addSign) {
680 case RESIGN_CHK_SIGNATURE:
681 bigMode = MODE_CHECKSIG;
683 case RESIGN_ADD_SIGNATURE:
684 case RESIGN_NEW_SIGNATURE:
685 bigMode = MODE_RESIGN;
690 #endif /* IAM_RPMK */
692 /* XXX TODO: never happens. */
693 if (gotDbpath && (bigMode & ~MODES_FOR_DBPATH))
694 argerror(_("--dbpath given for operation that does not use a "
697 #if defined(IAM_RPMEIU)
698 if (!( bigMode == MODE_INSTALL ) &&
699 (ia->probFilter & (RPMPROB_FILTER_REPLACEPKG | RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES | RPMPROB_FILTER_OLDPACKAGE)))
700 argerror(_("only installation, upgrading, rmsource and rmspec may be forced"));
701 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_FORCERELOCATE))
702 argerror(_("files may only be relocated during package installation"));
704 if (ia->relocations && ia->prefix)
705 argerror(_("only one of --prefix or --relocate may be used"));
707 if (bigMode != MODE_INSTALL && ia->relocations)
708 argerror(_("--relocate and --excludepath may only be used when installing new packages"));
710 if (bigMode != MODE_INSTALL && ia->prefix)
711 argerror(_("--prefix may only be used when installing new packages"));
713 if (ia->prefix && ia->prefix[0] != '/')
714 argerror(_("arguments to --prefix must begin with a /"));
716 if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_HASH))
717 argerror(_("--hash (-h) may only be specified during package "
720 if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_PERCENT))
721 argerror(_("--percent may only be specified during package "
724 if (bigMode != MODE_INSTALL &&
725 (ia->probFilter & (RPMPROB_FILTER_REPLACEOLDFILES|RPMPROB_FILTER_REPLACENEWFILES)))
726 argerror(_("--replacefiles may only be specified during package "
729 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_REPLACEPKG))
730 argerror(_("--replacepkgs may only be specified during package "
733 if (bigMode != MODE_INSTALL && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
734 argerror(_("--excludedocs may only be specified during package "
737 if (bigMode != MODE_INSTALL && ia->incldocs)
738 argerror(_("--includedocs may only be specified during package "
741 if (ia->incldocs && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
742 argerror(_("only one of --excludedocs and --includedocs may be "
745 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREARCH))
746 argerror(_("--ignorearch may only be specified during package "
749 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREOS))
750 argerror(_("--ignoreos may only be specified during package "
753 if (bigMode != MODE_INSTALL &&
754 (ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES)))
755 argerror(_("--ignoresize may only be specified during package "
758 if ((ia->eraseInterfaceFlags & UNINSTALL_ALLMATCHES) && bigMode != MODE_ERASE)
759 argerror(_("--allmatches may only be specified during package "
762 if ((ia->transFlags & RPMTRANS_FLAG_ALLFILES) && bigMode != MODE_INSTALL)
763 argerror(_("--allfiles may only be specified during package "
766 if ((ia->transFlags & RPMTRANS_FLAG_JUSTDB) &&
767 bigMode != MODE_INSTALL && bigMode != MODE_ERASE)
768 argerror(_("--justdb may only be specified during package "
769 "installation and erasure"));
771 if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
772 (ia->transFlags & (RPMTRANS_FLAG_NOSCRIPTS | _noTransScripts | _noTransTriggers)))
773 argerror(_("script disabling options may only be specified during "
774 "package installation and erasure"));
776 if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
777 (ia->transFlags & (RPMTRANS_FLAG_NOTRIGGERS | _noTransTriggers)))
778 argerror(_("trigger disabling options may only be specified during "
779 "package installation and erasure"));
781 if (ia->noDeps & (bigMode & ~MODES_FOR_NODEPS))
782 argerror(_("--nodeps may only be specified during package "
783 "building, rebuilding, recompilation, installation,"
784 "erasure, and verification"));
786 if ((ia->transFlags & RPMTRANS_FLAG_TEST) && (bigMode & ~MODES_FOR_TEST))
787 argerror(_("--test may only be specified during package installation, "
788 "erasure, and building"));
789 #endif /* IAM_RPMEIU */
791 if (rootdir && rootdir[1] && (bigMode & ~MODES_FOR_ROOT))
792 argerror(_("--root (-r) may only be specified during "
793 "installation, erasure, querying, and "
794 "database rebuilds"));
797 switch (urlIsURL(rootdir)) {
799 if (bigMode & MODES_FOR_ROOT)
803 if (rootdir[0] != '/')
804 argerror(_("arguments to --root (-r) must begin with a /"));
809 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
811 #if defined(IAM_RPMBT)
814 #if defined(IAM_RPMK)
818 if (bigMode == MODE_REBUILD || bigMode == MODE_BUILD ||
819 bigMode == MODE_RESIGN || bigMode == MODE_TARBUILD) {
824 if ((av = poptGetArgs(optCon)) == NULL) {
825 fprintf(stderr, _("no files to sign\n"));
829 if (stat(*av, &sb)) {
830 fprintf(stderr, _("cannot access file %s\n"), *av);
841 if (poptPeekArg(optCon)) {
843 switch (sigTag = rpmLookupSignatureType(RPMLOOKUPSIG_QUERY)) {
847 if ((sigTag == RPMSIGTAG_PGP || sigTag == RPMSIGTAG_PGP5) &&
848 !rpmDetectPGPVersion(NULL)) {
849 fprintf(stderr, _("pgp not found: "));
854 passPhrase = rpmGetPassPhrase(_("Enter pass phrase: "), sigTag);
855 if (passPhrase == NULL) {
856 fprintf(stderr, _("Pass phrase check failed\n"));
860 fprintf(stderr, _("Pass phrase is good.\n"));
861 passPhrase = xstrdup(passPhrase);
865 _("Invalid %%_signature spec in macro file.\n"));
868 /*@notreached@*/ break;
872 argerror(_("--sign may only be used during package building"));
875 /* Make rpmLookupSignatureType() return 0 ("none") from now on */
876 (void) rpmLookupSignatureType(RPMLOOKUPSIG_DISABLE);
878 #endif /* IAM_RPMBT || IAM_RPMK */
883 if (!(pipeChild = fork())) {
885 (void) dup2(p[0], STDIN_FILENO);
887 (void) execl("/bin/sh", "/bin/sh", "-c", pipeOutput, NULL);
888 fprintf(stderr, _("exec failed\n"));
892 (void) dup2(p[1], STDOUT_FILENO);
899 (void) rpmdbInit(rootdir, 0644);
903 ec = rpmdbRebuild(rootdir);
906 ec = rpmdbVerify(rootdir);
908 #endif /* IAM_RPMDB */
914 while (!rpmIsVerbose())
915 rpmIncreaseVerbosity();
917 if (!poptPeekArg(optCon))
918 argerror(_("no packages files given for rebuild"));
920 ba->buildAmount = RPMBUILD_PREP | RPMBUILD_BUILD | RPMBUILD_INSTALL;
921 if (bigMode == MODE_REBUILD) {
922 ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
923 ba->buildAmount |= RPMBUILD_RMSOURCE;
924 ba->buildAmount |= RPMBUILD_RMSPEC;
925 ba->buildAmount |= RPMBUILD_CLEAN;
926 ba->buildAmount |= RPMBUILD_RMBUILD;
929 while ((pkg = poptGetArg(optCon))) {
930 const char * specFile = NULL;
931 char * cookie = NULL;
933 ec = rpmInstallSource("", pkg, &specFile, &cookie);
935 /*@loopbreak@*/ break;
937 ba->rootdir = rootdir;
938 ec = build(specFile, ba, passPhrase, cookie, rcfile);
941 free((void *)specFile);
945 /*@loopbreak@*/ break;
952 while (!rpmIsVerbose())
953 rpmIncreaseVerbosity();
955 switch (ba->buildChar) {
957 ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
960 ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
961 ba->buildAmount |= RPMBUILD_CLEAN;
964 ba->buildAmount |= RPMBUILD_INSTALL;
965 if ((ba->buildChar == 'i') && ba->shortCircuit)
966 /*@innerbreak@*/ break;
969 ba->buildAmount |= RPMBUILD_BUILD;
970 if ((ba->buildChar == 'c') && ba->shortCircuit)
971 /*@innerbreak@*/ break;
974 ba->buildAmount |= RPMBUILD_PREP;
975 /*@innerbreak@*/ break;
978 ba->buildAmount |= RPMBUILD_FILECHECK;
979 /*@innerbreak@*/ break;
981 ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
982 /*@innerbreak@*/ break;
985 if (!poptPeekArg(optCon)) {
986 if (bigMode == MODE_BUILD)
987 argerror(_("no spec files given for build"));
989 argerror(_("no tar files given for build"));
992 while ((pkg = poptGetArg(optCon))) {
993 ba->rootdir = rootdir;
994 ec = build(pkg, ba, passPhrase, NULL, rcfile);
996 /*@loopbreak@*/ break;
998 (void) rpmReadConfigFiles(rcfile, NULL);
1001 #endif /* IAM_RPMBT */
1005 if (!poptPeekArg(optCon))
1006 argerror(_("no packages given for uninstall"));
1008 if (ia->noDeps) ia->eraseInterfaceFlags |= UNINSTALL_NODEPS;
1010 ec = rpmErase(rootdir, (const char **)poptGetArgs(optCon),
1011 ia->transFlags, ia->eraseInterfaceFlags);
1016 if (!poptPeekArg(optCon))
1017 argerror(_("no packages given for install"));
1019 /* RPMTRANS_FLAG_BUILD_PROBS */
1020 /* RPMTRANS_FLAG_KEEPOBSOLETE */
1022 if (!ia->incldocs) {
1023 if (ia->transFlags & RPMTRANS_FLAG_NODOCS)
1025 else if (rpmExpandNumeric("%{_excludedocs}"))
1026 ia->transFlags |= RPMTRANS_FLAG_NODOCS;
1029 if (ia->noDeps) ia->installInterfaceFlags |= INSTALL_NODEPS;
1031 /* we've already ensured !(!ia->prefix && !ia->relocations) */
1033 ia->relocations = xmalloc(2 * sizeof(*ia->relocations));
1034 ia->relocations[0].oldPath = NULL; /* special case magic */
1035 ia->relocations[0].newPath = ia->prefix;
1036 ia->relocations[1].oldPath = NULL;
1037 ia->relocations[1].newPath = NULL;
1038 } else if (ia->relocations) {
1039 ia->relocations = xrealloc(ia->relocations,
1040 sizeof(*ia->relocations) * (ia->numRelocations + 1));
1041 ia->relocations[ia->numRelocations].oldPath = NULL;
1042 ia->relocations[ia->numRelocations].newPath = NULL;
1045 /*@-compdef@*/ /* FIX: ia->relocations[0].newPath undefined */
1046 ec += rpmInstall(rootdir, (const char **)poptGetArgs(optCon),
1047 ia->transFlags, ia->installInterfaceFlags, ia->probFilter,
1053 ia->rootdir = rootdir;
1054 ec += rpmRollback(ia, (const char **)poptGetArgs(optCon));
1057 #endif /* IAM_RPMEIU */
1063 qva->qva_prefix = rootdir;
1064 if (qva->qva_source == RPMQV_ALL) {
1066 if (poptPeekArg(optCon))
1067 argerror(_("extra arguments given for query of all packages"));
1069 const char ** av = poptGetArgs(optCon);
1071 /*@-nullpass@*/ /* FIX: av can be NULL */
1072 ec = rpmQuery(qva, RPMQV_ALL, (const char *) av);
1075 if (!poptPeekArg(optCon))
1076 argerror(_("no arguments given for query"));
1077 while ((pkg = poptGetArg(optCon)))
1078 ec += rpmQuery(qva, qva->qva_source, pkg);
1084 rpmVerifyFlags verifyFlags = VERIFY_ALL;
1086 verifyFlags &= ~qva->qva_flags;
1087 qva->qva_flags = (rpmQueryFlags) verifyFlags;
1088 qva->qva_prefix = rootdir;
1090 if (qva->qva_source == RPMQV_ALL) {
1091 if (poptPeekArg(optCon))
1092 argerror(_("extra arguments given for verify of all packages"));
1093 ec = rpmVerify(qva, RPMQV_ALL, NULL);
1095 if (!poptPeekArg(optCon))
1096 argerror(_("no arguments given for verify"));
1097 while ((pkg = poptGetArg(optCon)))
1098 ec += rpmVerify(qva, qva->qva_source, pkg);
1102 case MODE_QUERYTAGS:
1104 argerror(_("unexpected arguments to --querytags "));
1106 rpmDisplayQueryTags(stdout);
1108 #endif /* IAM_RPMQV */
1112 if (!poptPeekArg(optCon))
1113 argerror(_("no packages given for signature check"));
1114 ec = rpmCheckSig(ka->checksigFlags,
1115 (const char **)poptGetArgs(optCon));
1116 /* XXX don't overflow single byte exit status */
1117 if (ec > 255) ec = 255;
1121 if (!poptPeekArg(optCon))
1122 argerror(_("no packages given for signing"));
1123 ec = rpmReSign(ka->addSign, passPhrase,
1124 (const char **)poptGetArgs(optCon));
1125 /* XXX don't overflow single byte exit status */
1126 if (ec > 255) ec = 255;
1128 #endif /* IAM_RPMK */
1130 #if !defined(IAM_RPMQV)
1133 case MODE_QUERYTAGS:
1135 #if !defined(IAM_RPMK)
1139 #if !defined(IAM_RPMDB)
1141 case MODE_REBUILDDB:
1144 #if !defined(IAM_RPMBT)
1147 case MODE_RECOMPILE:
1150 #if !defined(IAM_RPMEIU)
1156 if (!showVersion && !help && !noUsageMsg) printUsage();
1160 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
1162 #endif /* IAM_RPMBT || IAM_RPMK */
1163 optCon = poptFreeContext(optCon);
1164 rpmFreeMacros(NULL);
1165 rpmFreeMacros(&rpmCLIMacroContext);
1169 (void) fclose(stdout);
1170 (void) waitpid(pipeChild, &status, 0);
1173 /* keeps memory leak checkers quiet */
1178 dbiTags = _free(dbiTags);
1181 qva->qva_queryFormat = _free(qva->qva_queryFormat);
1185 ba->buildRootOverride = _free(ba->buildRootOverride);
1186 ba->targets = _free(ba->targets);
1190 ia->relocations = _free(ia->relocations);
1193 #if HAVE_MCHECK_H && HAVE_MTRACE
1194 muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */