5 #if defined(IAM_RPM) || defined(__LCLINT__)
16 #define POPT_NODEPS 1025
17 #define POPT_FORCE 1026
18 #define POPT_NOMD5 1027
22 #define GETOPT_REBUILD 1003
23 #define GETOPT_RECOMPILE 1004
26 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
27 #include "signature.h"
32 #define GETOPT_DBPATH 1010
33 #define GETOPT_SHOWRC 1018
34 #define GETOPT_DEFINEMACRO 1020
35 #define GETOPT_EVALMACRO 1021
37 #define GETOPT_RCFILE 1022
42 MODE_QUERY = (1 << 0),
43 MODE_VERIFY = (1 << 3),
44 MODE_QUERYTAGS = (1 << 9),
45 #define MODES_QV (MODE_QUERY | MODE_VERIFY)
47 MODE_INSTALL = (1 << 1),
48 MODE_ERASE = (1 << 2),
49 MODE_ROLLBACK = (1 << 14),
50 #define MODES_IE (MODE_INSTALL | MODE_ERASE | MODE_ROLLBACK)
52 MODE_BUILD = (1 << 4),
53 MODE_REBUILD = (1 << 5),
54 MODE_RECOMPILE = (1 << 8),
55 MODE_TARBUILD = (1 << 11),
56 #define MODES_BT (MODE_BUILD | MODE_TARBUILD | MODE_REBUILD | MODE_RECOMPILE)
58 MODE_CHECKSIG = (1 << 6),
59 MODE_RESIGN = (1 << 7),
60 #define MODES_K (MODE_CHECKSIG | MODE_RESIGN)
62 MODE_INITDB = (1 << 10),
63 MODE_REBUILDDB = (1 << 12),
64 MODE_VERIFYDB = (1 << 13),
65 #define MODES_DB (MODE_INITDB | MODE_REBUILDDB | MODE_VERIFYDB)
71 #define MODES_FOR_DBPATH (MODES_BT | MODES_IE | MODES_QV | MODES_DB)
72 #define MODES_FOR_NODEPS (MODES_BT | MODES_IE | MODE_VERIFY)
73 #define MODES_FOR_TEST (MODES_BT | MODES_IE)
74 #define MODES_FOR_ROOT (MODES_BT | MODES_IE | MODES_QV | MODES_DB)
76 /*@-exportheadervar@*/
77 extern int _ftp_debug;
79 extern int _rpmio_debug;
80 extern int _url_debug;
83 /*@observer@*/ extern const char * rpmNAME;
85 /*@observer@*/ extern const char * rpmEVR;
90 extern struct MacroContext_s rpmCLIMacroContext;
91 /*@=exportheadervar@*/
93 /* options for all executables */
96 static int noUsageMsg = 0;
97 /*@observer@*/ /*@null@*/ static const char * pipeOutput = NULL;
99 /*@observer@*/ /*@null@*/ static const char * rcfile = NULL;
100 /*@observer@*/ /*@null@*/ static char * rootdir = "/";
101 static int showrc = 0;
102 static int showVersion = 0;
104 static struct poptOption rpmAllPoptTable[] = {
105 { "version", '\0', 0, &showVersion, 0,
106 N_("print the version of rpm being used"),
108 { "quiet", '\0', 0, &quiet, 0,
109 N_("provide less detailed output"), NULL},
110 { "verbose", 'v', 0, 0, 'v',
111 N_("provide more detailed output"), NULL},
112 { "define", '\0', POPT_ARG_STRING, 0, GETOPT_DEFINEMACRO,
113 N_("define macro <name> with value <body>"),
114 N_("'<name> <body>'") },
115 { "eval", '\0', POPT_ARG_STRING, 0, GETOPT_EVALMACRO,
116 N_("print macro expansion of <expr>+"),
118 { "pipe", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, &pipeOutput, 0,
119 N_("send stdout to <cmd>"),
121 { "root", 'r', POPT_ARG_STRING | POPT_ARGFLAG_SHOW_DEFAULT, &rootdir, 0,
122 N_("use <dir> as the top level directory"),
124 { "macros", '\0', POPT_ARG_STRING, ¯ofiles, 0,
125 N_("read <file:...> instead of default macro file(s)"),
127 #if !defined(GETOPT_RCFILE)
128 { "rcfile", '\0', POPT_ARG_STRING, &rcfile, 0,
129 N_("read <file:...> instead of default rpmrc file(s)"),
132 { "rcfile", '\0', 0, 0, GETOPT_RCFILE,
133 N_("read <file:...> instead of default rpmrc file(s)"),
136 { "showrc", '\0', 0, &showrc, GETOPT_SHOWRC,
137 N_("display final rpmrc and macro configuration"),
140 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
141 { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
142 N_("disable use of libio(3) API"), NULL},
144 { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
145 N_("debug protocol data stream"), NULL},
146 { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
147 N_("debug rpmio I/O"), NULL},
148 { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
149 N_("debug URL cache handling"), NULL},
154 /* the structure describing the options we take and the defaults */
155 static struct poptOption optionsTable[] = {
157 /* XXX colliding options */
158 #if defined(IAM_RPMQV) || defined(IAM_RPMEIU) || defined(IAM_RPMBT)
159 { NULL, 'i', POPT_ARGFLAG_DOC_HIDDEN, 0, 'i', NULL, NULL},
160 { "nodeps", 0, POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_NODEPS, NULL, NULL},
161 { "nomd5", 0, POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_NOMD5, NULL, NULL},
162 { "force", 0, POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_FORCE, NULL, NULL},
166 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQueryPoptTable, 0,
167 N_("Query options (with -q or --query):"),
169 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmVerifyPoptTable, 0,
170 N_("Verify options (with -V or --verify):"),
172 #endif /* IAM_RPMQV */
175 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmSignPoptTable, 0,
176 N_("Signature options:"),
178 #endif /* IAM_RPMK */
181 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmDatabasePoptTable, 0,
182 N_("Database options:"),
184 #endif /* IAM_RPMDB */
187 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmBuildPoptTable, 0,
188 N_("Build options with [ <specfile> | <tarball> | <source package> ]:"),
190 #endif /* IAM_RPMBT */
193 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmInstallPoptTable, 0,
194 N_("Install/Upgrade/Erase options:"),
196 #endif /* IAM_RPMEIU */
198 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmAllPoptTable, 0,
199 N_("Common options for all rpm modes:"),
208 /* MiNT cannot dynamically increase the stack. */
209 long _stksize = 64 * 1024L;
212 /*@exits@*/ static void argerror(const char * desc)
213 /*@modifies fileSystem @*/
215 fprintf(stderr, _("%s: %s\n"), __progname, desc);
219 static void printVersion(void)
220 /*@modifies fileSystem @*/
222 fprintf(stdout, _("RPM version %s\n"), rpmEVR);
225 static void printBanner(void)
226 /*@modifies fileSystem @*/
228 (void) puts(_("Copyright (C) 1998-2000 - Red Hat, Inc."));
229 (void) puts(_("This program may be freely redistributed under the terms of the GNU GPL"));
232 static void printUsage(void)
233 /*@modifies fileSystem @*/
240 fprintf(fp, _("Usage: %s {--help}\n"), __progname);
241 fprintf(fp, (" %s {--version}\n"), __progname);
247 --force alias for --replacepkgs --replacefiles
248 --includedocs handle as option in table
249 --erase forbids many options
251 #endif /* IAM_RPMEIU */
254 #ifdef DYING /* XXX popt glue needing --help doco. */
268 #endif /* IAM_RPMQV */
272 int main(int argc, const char ** argv)
274 enum modes bigMode = MODE_UNKNOWN;
277 QVA_t qva = &rpmQVArgs;
281 BTA_t ba = &rpmBTArgs;
285 struct rpmInstallArguments_s * ia = &rpmIArgs;
288 #if defined(IAM_RPMDB)
289 struct rpmDatabaseArguments_s * da = &rpmDBArgs;
292 #if defined(IAM_RPMK)
293 struct rpmSignArguments_s * ka = &rpmKArgs;
296 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
297 char * passPhrase = "";
310 #if HAVE_MCHECK_H && HAVE_MTRACE
311 mtrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
313 setprogname(argv[0]); /* Retrofit glibc __progname */
315 /* XXX glibc churn sanity */
316 if (__progname == NULL) {
317 if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
318 else __progname = argv[0];
321 /* Set the major mode based on argv[0] */
324 if (!strcmp(__progname, "rpmb")) bigMode = MODE_BUILD;
325 if (!strcmp(__progname, "rpmt")) bigMode = MODE_TARBUILD;
326 if (!strcmp(__progname, "rpmbuild")) bigMode = MODE_BUILD;
329 if (!strcmp(__progname, "rpmq")) bigMode = MODE_QUERY;
330 if (!strcmp(__progname, "rpmv")) bigMode = MODE_VERIFY;
331 if (!strcmp(__progname, "rpmquery")) bigMode = MODE_QUERY;
332 if (!strcmp(__progname, "rpmverify")) bigMode = MODE_VERIFY;
335 if (!strcmp(__progname, "rpme")) bigMode = MODE_ERASE;
336 if (!strcmp(__progname, "rpmi")) bigMode = MODE_INSTALL;
337 if (!strcmp(__progname, "rpmu")) bigMode = MODE_INSTALL;
341 /* set the defaults for the various command line options */
344 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
352 /* XXX Eliminate query linkage loop */
354 parseSpecVec = parseSpec;
355 freeSpecVec = freeSpec;
357 /* set up the correct locale */
358 (void) setlocale(LC_ALL, "" );
361 #define LOCALEDIR "/usr/share/locale"
363 bindtextdomain(PACKAGE, LOCALEDIR);
366 rpmSetVerbosity(RPMMESS_NORMAL); /* XXX silly use by showrc */
368 /* Make a first pass through the arguments, looking for --rcfile */
369 /* We need to handle that before dealing with the rest of the arguments. */
370 /*@-nullpass -temptrans@*/
371 optCon = poptGetContext(__progname, argc, argv, optionsTable, 0);
372 /*@=nullpass =temptrans@*/
373 (void) poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
374 (void) poptReadDefaultConfig(optCon, 1);
375 poptSetExecPath(optCon, RPMCONFIGDIR, 1);
377 /* reading rcfile early makes it easy to override */
378 /* XXX only --rcfile (and --showrc) need this pre-parse */
380 while ((arg = poptGetNextOpt(optCon)) > 0) {
383 rpmIncreaseVerbosity(); /* XXX silly use by showrc */
390 if (rpmReadConfigFiles(rcfile, NULL))
394 (void) rpmShowRC(stdout);
398 rpmSetVerbosity(RPMMESS_NORMAL); /* XXX silly use by showrc */
400 poptResetContext(optCon);
403 qva->qva_queryFormat = _free(qva->qva_queryFormat);
404 memset(qva, 0, sizeof(*qva));
405 qva->qva_source = RPMQV_PACKAGE;
406 qva->qva_fflags = RPMFILE_ALL;
412 ba->buildRootOverride = _free(ba->buildRootOverride);
413 ba->targets = _free(ba->targets);
414 memset(ba, 0, sizeof(*ba));
420 memset(da, 0, sizeof(*da));
424 memset(ka, 0, sizeof(*ka));
425 ka->addSign = RESIGN_NONE;
426 ka->checksigFlags = CHECKSIG_ALL;
430 ia->relocations = _free(ia->relocations);
431 memset(ia, 0, sizeof(*ia));
432 ia->transFlags = RPMTRANS_FLAG_NONE;
433 ia->probFilter = RPMPROB_FILTER_NONE;
434 ia->installInterfaceFlags = INSTALL_NONE;
435 ia->eraseInterfaceFlags = UNINSTALL_NONE;
438 while ((arg = poptGetNextOpt(optCon)) > 0) {
439 optArg = poptGetOptArg(optCon);
444 rpmIncreaseVerbosity();
447 /* XXX options used in multiple rpm modes */
448 #if defined(IAM_RPMQV) || defined(IAM_RPMK)
451 if (bigMode == MODE_VERIFY || qva->qva_mode == 'V')
452 qva->qva_flags |= VERIFY_MD5;
456 if (bigMode & MODES_K)
457 ka->checksigFlags &= ~CHECKSIG_MD5;
462 #endif /* IAM_RPMQV || IAM_RPMK */
464 #if defined(IAM_RPMQV) || defined(IAM_RPMEIU) || defined(IAM_RPMBT)
467 if (bigMode == MODE_VERIFY || qva->qva_mode == 'V')
468 qva->qva_flags |= VERIFY_DEPS;
472 if ((bigMode & MODES_IE) ||
473 (ia->installInterfaceFlags &
474 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE)))
479 if ((bigMode & MODES_BT) || ba->buildMode != ' ')
488 if ((bigMode & MODES_IE) ||
489 (ia->installInterfaceFlags &
490 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE)))
492 ( RPMPROB_FILTER_REPLACEPKG
493 | RPMPROB_FILTER_REPLACEOLDFILES
494 | RPMPROB_FILTER_REPLACENEWFILES
495 | RPMPROB_FILTER_OLDPACKAGE);
499 if ((bigMode & MODES_BT) || ba->buildMode != ' ')
508 if (bigMode == MODE_QUERY || qva->qva_mode == 'q') {
509 /*@-nullassign -readonlytrans@*/
510 const char * infoCommand[] = { "--info", NULL };
511 /*@=nullassign =readonlytrans@*/
512 (void) poptStuffArgs(optCon, infoCommand);
516 if (bigMode == MODE_INSTALL ||
517 (ia->installInterfaceFlags &
518 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL)))
520 else if (bigMode == MODE_UNKNOWN) {
521 /*@-nullassign -readonlytrans@*/
522 const char * installCommand[] = { "--install", NULL };
523 /*@=nullassign =readonlytrans@*/
524 (void) poptStuffArgs(optCon, installCommand);
529 #endif /* IAM_RPMQV || IAM_RPMEIU || IAM_RPMBT */
531 case GETOPT_DEFINEMACRO:
533 (void) rpmDefineMacro(NULL, optArg, RMIL_CMDLINE);
534 (void) rpmDefineMacro(&rpmCLIMacroContext, optArg,RMIL_CMDLINE);
539 case GETOPT_EVALMACRO:
541 const char *val = rpmExpand(optArg, NULL);
542 fprintf(stdout, "%s\n", val);
548 #if defined(GETOPT_RCFILE)
550 fprintf(stderr, _("The --rcfile option has been eliminated.\n"));
551 fprintf(stderr, _("Use \"--macros <file:...>\" instead.\n"));
553 /*@notreached@*/ break;
557 fprintf(stderr, _("Internal error in argument processing (%d) :-(\n"), arg);
563 rpmSetVerbosity(RPMMESS_QUIET);
565 if (showVersion) printVersion();
568 fprintf(stderr, "%s: %s\n",
569 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
575 switch (ba->buildMode) {
576 case 'b': bigMode = MODE_BUILD; break;
577 case 't': bigMode = MODE_TARBUILD; break;
578 case 'B': bigMode = MODE_REBUILD; break;
579 case 'C': bigMode = MODE_RECOMPILE; break;
582 if ((ba->buildAmount & RPMBUILD_RMSOURCE) && bigMode == MODE_UNKNOWN)
583 bigMode = MODE_BUILD;
585 if ((ba->buildAmount & RPMBUILD_RMSPEC) && bigMode == MODE_UNKNOWN)
586 bigMode = MODE_BUILD;
588 if (ba->buildRootOverride && bigMode != MODE_BUILD &&
589 bigMode != MODE_REBUILD && bigMode != MODE_TARBUILD) {
590 argerror("--buildroot may only be used during package builds");
592 #endif /* IAM_RPMBT */
595 if (bigMode == MODE_UNKNOWN) {
597 if (bigMode != MODE_UNKNOWN)
598 argerror(_("only one major mode may be specified"));
600 bigMode = MODE_INITDB;
603 if (bigMode != MODE_UNKNOWN)
604 argerror(_("only one major mode may be specified"));
606 bigMode = MODE_REBUILDDB;
609 if (bigMode != MODE_UNKNOWN)
610 argerror(_("only one major mode may be specified"));
612 bigMode = MODE_VERIFYDB;
615 #endif /* IAM_RPMDB */
618 if (bigMode == MODE_UNKNOWN) {
619 switch (qva->qva_mode) {
620 case 'q': bigMode = MODE_QUERY; break;
621 case 'V': bigMode = MODE_VERIFY; break;
622 case 'Q': bigMode = MODE_QUERYTAGS; break;
625 if (qva->qva_sourceCount) {
626 if (qva->qva_sourceCount > 2)
627 argerror(_("one type of query/verify may be performed at a "
630 if (qva->qva_flags && (bigMode & ~MODES_QV))
631 argerror(_("unexpected query flags"));
633 if (qva->qva_queryFormat && (bigMode & ~MODES_QV))
634 argerror(_("unexpected query format"));
636 if (qva->qva_source != RPMQV_PACKAGE && (bigMode & ~MODES_QV))
637 argerror(_("unexpected query source"));
639 #endif /* IAM_RPMQV */
642 if (bigMode == MODE_UNKNOWN)
643 { int iflags = (ia->installInterfaceFlags &
644 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL));
645 int eflags = (ia->installInterfaceFlags & INSTALL_ERASE);
648 argerror(_("only one major mode may be specified"));
650 bigMode = MODE_INSTALL;
652 bigMode = MODE_ERASE;
654 #endif /* IAM_RPMQV */
657 if (bigMode == MODE_UNKNOWN) {
658 switch (ka->addSign) {
661 case RESIGN_CHK_SIGNATURE:
662 bigMode = MODE_CHECKSIG;
664 case RESIGN_ADD_SIGNATURE:
665 case RESIGN_NEW_SIGNATURE:
666 bigMode = MODE_RESIGN;
671 #endif /* IAM_RPMK */
673 /* XXX TODO: never happens. */
674 if (gotDbpath && (bigMode & ~MODES_FOR_DBPATH))
675 argerror(_("--dbpath given for operation that does not use a "
678 #if defined(IAM_RPMEIU)
679 if (!( bigMode == MODE_INSTALL ) &&
680 (ia->probFilter & (RPMPROB_FILTER_REPLACEPKG | RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES | RPMPROB_FILTER_OLDPACKAGE)))
681 argerror(_("only installation, upgrading, rmsource and rmspec may be forced"));
682 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_FORCERELOCATE))
683 argerror(_("files may only be relocated during package installation"));
685 if (ia->relocations && ia->prefix)
686 argerror(_("only one of --prefix or --relocate may be used"));
688 if (bigMode != MODE_INSTALL && ia->relocations)
689 argerror(_("--relocate and --excludepath may only be used when installing new packages"));
691 if (bigMode != MODE_INSTALL && ia->prefix)
692 argerror(_("--prefix may only be used when installing new packages"));
694 if (ia->prefix && ia->prefix[0] != '/')
695 argerror(_("arguments to --prefix must begin with a /"));
697 if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_HASH))
698 argerror(_("--hash (-h) may only be specified during package "
701 if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_PERCENT))
702 argerror(_("--percent may only be specified during package "
705 if (bigMode != MODE_INSTALL &&
706 (ia->probFilter & (RPMPROB_FILTER_REPLACEOLDFILES|RPMPROB_FILTER_REPLACENEWFILES)))
707 argerror(_("--replacefiles may only be specified during package "
710 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_REPLACEPKG))
711 argerror(_("--replacepkgs may only be specified during package "
714 if (bigMode != MODE_INSTALL && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
715 argerror(_("--excludedocs may only be specified during package "
718 if (bigMode != MODE_INSTALL && ia->incldocs)
719 argerror(_("--includedocs may only be specified during package "
722 if (ia->incldocs && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
723 argerror(_("only one of --excludedocs and --includedocs may be "
726 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREARCH))
727 argerror(_("--ignorearch may only be specified during package "
730 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREOS))
731 argerror(_("--ignoreos may only be specified during package "
734 if (bigMode != MODE_INSTALL &&
735 (ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES)))
736 argerror(_("--ignoresize may only be specified during package "
739 if ((ia->eraseInterfaceFlags & UNINSTALL_ALLMATCHES) && bigMode != MODE_ERASE)
740 argerror(_("--allmatches may only be specified during package "
743 if ((ia->transFlags & RPMTRANS_FLAG_ALLFILES) && bigMode != MODE_INSTALL)
744 argerror(_("--allfiles may only be specified during package "
747 if ((ia->transFlags & RPMTRANS_FLAG_JUSTDB) &&
748 bigMode != MODE_INSTALL && bigMode != MODE_ERASE)
749 argerror(_("--justdb may only be specified during package "
750 "installation and erasure"));
752 if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
753 (ia->transFlags & (RPMTRANS_FLAG_NOSCRIPTS | _noTransScripts | _noTransTriggers)))
754 argerror(_("script disabling options may only be specified during "
755 "package installation and erasure"));
757 if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
758 (ia->transFlags & (RPMTRANS_FLAG_NOTRIGGERS | _noTransTriggers)))
759 argerror(_("trigger disabling options may only be specified during "
760 "package installation and erasure"));
762 if (ia->noDeps & (bigMode & ~MODES_FOR_NODEPS))
763 argerror(_("--nodeps may only be specified during package "
764 "building, rebuilding, recompilation, installation,"
765 "erasure, and verification"));
767 if ((ia->transFlags & RPMTRANS_FLAG_TEST) && (bigMode & ~MODES_FOR_TEST))
768 argerror(_("--test may only be specified during package installation, "
769 "erasure, and building"));
770 #endif /* IAM_RPMEIU */
772 if (rootdir && rootdir[1] && (bigMode & ~MODES_FOR_ROOT))
773 argerror(_("--root (-r) may only be specified during "
774 "installation, erasure, querying, and "
775 "database rebuilds"));
778 switch (urlIsURL(rootdir)) {
780 if (bigMode & MODES_FOR_ROOT)
784 if (rootdir[0] != '/')
785 argerror(_("arguments to --root (-r) must begin with a /"));
790 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
792 #if defined(IAM_RPMBT)
795 #if defined(IAM_RPMK)
799 if (bigMode == MODE_REBUILD || bigMode == MODE_BUILD ||
800 bigMode == MODE_RESIGN || bigMode == MODE_TARBUILD) {
805 if ((av = poptGetArgs(optCon)) == NULL) {
806 fprintf(stderr, _("no files to sign\n"));
810 if (stat(*av, &sb)) {
811 fprintf(stderr, _("cannot access file %s\n"), *av);
822 if (poptPeekArg(optCon)) {
824 switch (sigTag = rpmLookupSignatureType(RPMLOOKUPSIG_QUERY)) {
828 if ((sigTag == RPMSIGTAG_PGP || sigTag == RPMSIGTAG_PGP5) &&
829 !rpmDetectPGPVersion(NULL)) {
830 fprintf(stderr, _("pgp not found: "));
835 passPhrase = rpmGetPassPhrase(_("Enter pass phrase: "), sigTag);
836 if (passPhrase == NULL) {
837 fprintf(stderr, _("Pass phrase check failed\n"));
841 fprintf(stderr, _("Pass phrase is good.\n"));
842 passPhrase = xstrdup(passPhrase);
846 _("Invalid %%_signature spec in macro file.\n"));
849 /*@notreached@*/ break;
853 argerror(_("--sign may only be used during package building"));
856 /* Make rpmLookupSignatureType() return 0 ("none") from now on */
857 (void) rpmLookupSignatureType(RPMLOOKUPSIG_DISABLE);
859 #endif /* IAM_RPMBT || IAM_RPMK */
864 if (!(pipeChild = fork())) {
866 (void) dup2(p[0], STDIN_FILENO);
868 (void) execl("/bin/sh", "/bin/sh", "-c", pipeOutput, NULL);
869 fprintf(stderr, _("exec failed\n"));
873 (void) dup2(p[1], STDOUT_FILENO);
880 (void) rpmdbInit(rootdir, 0644);
884 ec = rpmdbRebuild(rootdir);
887 ec = rpmdbVerify(rootdir);
889 #endif /* IAM_RPMDB */
895 while (!rpmIsVerbose())
896 rpmIncreaseVerbosity();
898 if (!poptPeekArg(optCon))
899 argerror(_("no packages files given for rebuild"));
901 ba->buildAmount = RPMBUILD_PREP | RPMBUILD_BUILD | RPMBUILD_INSTALL;
902 if (bigMode == MODE_REBUILD) {
903 ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
904 ba->buildAmount |= RPMBUILD_RMSOURCE;
905 ba->buildAmount |= RPMBUILD_RMSPEC;
906 ba->buildAmount |= RPMBUILD_CLEAN;
907 ba->buildAmount |= RPMBUILD_RMBUILD;
910 while ((pkg = poptGetArg(optCon))) {
911 const char * specFile = NULL;
912 char * cookie = NULL;
914 ec = rpmInstallSource("", pkg, &specFile, &cookie);
916 /*@loopbreak@*/ break;
918 ba->rootdir = rootdir;
919 ec = build(specFile, ba, passPhrase, cookie, rcfile);
922 free((void *)specFile);
926 /*@loopbreak@*/ break;
933 while (!rpmIsVerbose())
934 rpmIncreaseVerbosity();
936 switch (ba->buildChar) {
938 ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
941 ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
942 ba->buildAmount |= RPMBUILD_CLEAN;
945 ba->buildAmount |= RPMBUILD_INSTALL;
946 if ((ba->buildChar == 'i') && ba->shortCircuit)
950 ba->buildAmount |= RPMBUILD_BUILD;
951 if ((ba->buildChar == 'c') && ba->shortCircuit)
955 ba->buildAmount |= RPMBUILD_PREP;
959 ba->buildAmount |= RPMBUILD_FILECHECK;
962 ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
966 if (!poptPeekArg(optCon)) {
967 if (bigMode == MODE_BUILD)
968 argerror(_("no spec files given for build"));
970 argerror(_("no tar files given for build"));
973 while ((pkg = poptGetArg(optCon))) {
974 ba->rootdir = rootdir;
975 ec = build(pkg, ba, passPhrase, NULL, rcfile);
977 /*@loopbreak@*/ break;
979 (void) rpmReadConfigFiles(rcfile, NULL);
982 #endif /* IAM_RPMBT */
986 if (!poptPeekArg(optCon))
987 argerror(_("no packages given for uninstall"));
989 if (ia->noDeps) ia->eraseInterfaceFlags |= UNINSTALL_NODEPS;
991 ec = rpmErase(rootdir, (const char **)poptGetArgs(optCon),
992 ia->transFlags, ia->eraseInterfaceFlags);
997 if (!poptPeekArg(optCon))
998 argerror(_("no packages given for install"));
1000 /* RPMTRANS_FLAG_BUILD_PROBS */
1001 /* RPMTRANS_FLAG_KEEPOBSOLETE */
1003 if (!ia->incldocs) {
1004 if (ia->transFlags & RPMTRANS_FLAG_NODOCS)
1006 else if (rpmExpandNumeric("%{_excludedocs}"))
1007 ia->transFlags |= RPMTRANS_FLAG_NODOCS;
1010 if (ia->noDeps) ia->installInterfaceFlags |= INSTALL_NODEPS;
1012 /* we've already ensured !(!ia->prefix && !ia->relocations) */
1014 ia->relocations = xmalloc(2 * sizeof(*ia->relocations));
1015 ia->relocations[0].oldPath = NULL; /* special case magic */
1016 ia->relocations[0].newPath = ia->prefix;
1017 ia->relocations[1].oldPath = ia->relocations[1].newPath = NULL;
1018 } else if (ia->relocations) {
1019 ia->relocations = xrealloc(ia->relocations,
1020 sizeof(*ia->relocations) * (ia->numRelocations + 1));
1021 ia->relocations[ia->numRelocations].oldPath = NULL;
1022 ia->relocations[ia->numRelocations].newPath = NULL;
1025 ec += rpmInstall(rootdir, (const char **)poptGetArgs(optCon),
1026 ia->transFlags, ia->installInterfaceFlags, ia->probFilter,
1031 ia->rootdir = rootdir;
1032 ec += rpmRollback(ia, (const char **)poptGetArgs(optCon));
1035 #endif /* IAM_RPMEIU */
1041 qva->qva_prefix = rootdir;
1042 if (qva->qva_source == RPMQV_ALL) {
1044 if (poptPeekArg(optCon))
1045 argerror(_("extra arguments given for query of all packages"));
1047 const char ** av = poptGetArgs(optCon);
1049 /*@-nullpass@*/ /* FIX: av can be NULL */
1050 ec = rpmQuery(qva, RPMQV_ALL, (const char *) av);
1053 if (!poptPeekArg(optCon))
1054 argerror(_("no arguments given for query"));
1055 while ((pkg = poptGetArg(optCon)))
1056 ec += rpmQuery(qva, qva->qva_source, pkg);
1062 rpmVerifyFlags verifyFlags = VERIFY_ALL;
1064 verifyFlags &= ~qva->qva_flags;
1065 qva->qva_flags = (rpmQueryFlags) verifyFlags;
1066 qva->qva_prefix = rootdir;
1068 if (qva->qva_source == RPMQV_ALL) {
1069 if (poptPeekArg(optCon))
1070 argerror(_("extra arguments given for verify of all packages"));
1071 ec = rpmVerify(qva, RPMQV_ALL, NULL);
1073 if (!poptPeekArg(optCon))
1074 argerror(_("no arguments given for verify"));
1075 while ((pkg = poptGetArg(optCon)))
1076 ec += rpmVerify(qva, qva->qva_source, pkg);
1080 case MODE_QUERYTAGS:
1082 argerror(_("unexpected arguments to --querytags "));
1084 rpmDisplayQueryTags(stdout);
1086 #endif /* IAM_RPMQV */
1090 if (!poptPeekArg(optCon))
1091 argerror(_("no packages given for signature check"));
1092 ec = rpmCheckSig(ka->checksigFlags,
1093 (const char **)poptGetArgs(optCon));
1094 /* XXX don't overflow single byte exit status */
1095 if (ec > 255) ec = 255;
1099 if (!poptPeekArg(optCon))
1100 argerror(_("no packages given for signing"));
1101 ec = rpmReSign(ka->addSign, passPhrase,
1102 (const char **)poptGetArgs(optCon));
1103 /* XXX don't overflow single byte exit status */
1104 if (ec > 255) ec = 255;
1106 #endif /* IAM_RPMK */
1108 #if !defined(IAM_RPMQV)
1111 case MODE_QUERYTAGS:
1113 #if !defined(IAM_RPMK)
1117 #if !defined(IAM_RPMDB)
1119 case MODE_REBUILDDB:
1122 #if !defined(IAM_RPMBT)
1125 case MODE_RECOMPILE:
1128 #if !defined(IAM_RPMEIU)
1134 if (!showVersion && !help && !noUsageMsg) printUsage();
1138 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
1140 #endif /* IAM_RPMBT || IAM_RPMK */
1141 optCon = poptFreeContext(optCon);
1142 rpmFreeMacros(NULL);
1143 rpmFreeMacros(&rpmCLIMacroContext);
1147 (void) fclose(stdout);
1148 (void) waitpid(pipeChild, &status, 0);
1151 /* keeps memory leak checkers quiet */
1157 qva->qva_queryFormat = _free(qva->qva_queryFormat);
1161 ba->buildRootOverride = _free(ba->buildRootOverride);
1162 ba->targets = _free(ba->targets);
1166 ia->relocations = _free(ia->relocations);
1169 #if HAVE_MCHECK_H && HAVE_MTRACE
1170 muntrace(); /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */