00001 #include "system.h"
00002
00003 #define _AUTOHELP
00004
00005 #if defined(IAM_RPM) || defined(__LCLINT__)
00006 #define IAM_RPMBT
00007 #define IAM_RPMDB
00008 #define IAM_RPMEIU
00009 #define IAM_RPMQV
00010 #define IAM_RPMK
00011 #endif
00012
00013 #include "rpmcli.h"
00014 #include "rpmbuild.h"
00015
00016 #define POPT_NODEPS 1025
00017 #define POPT_FORCE 1026
00018 #define POPT_NOMD5 1027
00019 #define POPT_NOSCRIPTS 1028
00020
00021 #ifdef IAM_RPMBT
00022 #include "build.h"
00023 #define GETOPT_REBUILD 1003
00024 #define GETOPT_RECOMPILE 1004
00025 #endif
00026
00027 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
00028 #include "signature.h"
00029 #endif
00030
00031 #include "debug.h"
00032
00033 #define GETOPT_DBPATH 1010
00034 #define GETOPT_SHOWRC 1018
00035 #define GETOPT_DEFINEMACRO 1020
00036 #define GETOPT_EVALMACRO 1021
00037 #ifdef NOTYET
00038 #define GETOPT_RCFILE 1022
00039 #endif
00040
00041 enum modes {
00042
00043 MODE_QUERY = (1 << 0),
00044 MODE_VERIFY = (1 << 3),
00045 MODE_QUERYTAGS = (1 << 9),
00046 #define MODES_QV (MODE_QUERY | MODE_VERIFY)
00047
00048 MODE_INSTALL = (1 << 1),
00049 MODE_ERASE = (1 << 2),
00050 #define MODES_IE (MODE_INSTALL | MODE_ERASE)
00051
00052 MODE_BUILD = (1 << 4),
00053 MODE_REBUILD = (1 << 5),
00054 MODE_RECOMPILE = (1 << 8),
00055 MODE_TARBUILD = (1 << 11),
00056 #define MODES_BT (MODE_BUILD | MODE_TARBUILD | MODE_REBUILD | MODE_RECOMPILE)
00057
00058 MODE_CHECKSIG = (1 << 6),
00059 MODE_RESIGN = (1 << 7),
00060 #define MODES_K (MODE_CHECKSIG | MODE_RESIGN)
00061
00062 MODE_INITDB = (1 << 10),
00063 MODE_REBUILDDB = (1 << 12),
00064 MODE_VERIFYDB = (1 << 13),
00065 #define MODES_DB (MODE_INITDB | MODE_REBUILDDB | MODE_VERIFYDB)
00066
00067
00068 MODE_UNKNOWN = 0
00069 };
00070
00071 #define MODES_FOR_DBPATH (MODES_BT | MODES_IE | MODES_QV | MODES_DB)
00072 #define MODES_FOR_NODEPS (MODES_BT | MODES_IE | MODE_VERIFY)
00073 #define MODES_FOR_TEST (MODES_BT | MODES_IE)
00074 #define MODES_FOR_ROOT (MODES_BT | MODES_IE | MODES_QV | MODES_DB)
00075
00076
00077
00078 extern int _ftp_debug;
00079
00080 extern int noLibio;
00081
00082 extern int _rpmio_debug;
00083
00084
00085 extern int _url_debug;
00086
00087
00088
00089
00090
00091
00092
00093 static int help = 0;
00094
00095 static int noUsageMsg = 0;
00096
00097 static const char * pipeOutput = NULL;
00098
00099 static int quiet = 0;
00100
00101 static const char * rcfile = NULL;
00102
00103 static char * rootdir = "/";
00104
00105 static int showrc = 0;
00106
00107 static int showVersion = 0;
00108
00109
00110 static struct poptOption rpmAllPoptTable[] = {
00111 { "version", '\0', 0, &showVersion, 0,
00112 N_("print the version of rpm being used"),
00113 NULL },
00114 { "quiet", '\0', 0, &quiet, 0,
00115 N_("provide less detailed output"), NULL},
00116 { "verbose", 'v', 0, 0, 'v',
00117 N_("provide more detailed output"), NULL},
00118 { "define", '\0', POPT_ARG_STRING, 0, GETOPT_DEFINEMACRO,
00119 N_("define macro <name> with value <body>"),
00120 N_("'<name> <body>'") },
00121 { "eval", '\0', POPT_ARG_STRING, 0, GETOPT_EVALMACRO,
00122 N_("print macro expansion of <expr>+"),
00123 N_("<expr>+") },
00124 { "pipe", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, &pipeOutput, 0,
00125 N_("send stdout to <cmd>"),
00126 N_("<cmd>") },
00127 { "root", 'r', POPT_ARG_STRING | POPT_ARGFLAG_SHOW_DEFAULT, &rootdir, 0,
00128 N_("use <dir> as the top level directory"),
00129 N_("<dir>") },
00130 { "macros", '\0', POPT_ARG_STRING, ¯ofiles, 0,
00131 N_("read <file:...> instead of default macro file(s)"),
00132 N_("<file:...>") },
00133 #if !defined(GETOPT_RCFILE)
00134 { "rcfile", '\0', POPT_ARG_STRING, &rcfile, 0,
00135 N_("read <file:...> instead of default rpmrc file(s)"),
00136 N_("<file:...>") },
00137 #else
00138 { "rcfile", '\0', 0, 0, GETOPT_RCFILE,
00139 N_("read <file:...> instead of default rpmrc file(s)"),
00140 N_("<file:...>") },
00141 #endif
00142 { "showrc", '\0', 0, &showrc, GETOPT_SHOWRC,
00143 N_("display final rpmrc and macro configuration"),
00144 NULL },
00145
00146 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
00147 { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
00148 N_("disable use of libio(3) API"), NULL},
00149 #endif
00150 { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
00151 N_("debug protocol data stream"), NULL},
00152 { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
00153 N_("debug rpmio I/O"), NULL},
00154 { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
00155 N_("debug URL cache handling"), NULL},
00156
00157 POPT_TABLEEND
00158 };
00159
00160
00161
00162 static struct poptOption optionsTable[] = {
00163
00164
00165 #if defined(IAM_RPMQV) || defined(IAM_RPMEIU) || defined(IAM_RPMBT)
00166 { NULL, 'i', POPT_ARGFLAG_DOC_HIDDEN, 0, 'i', NULL, NULL},
00167 { "nodeps", 0, POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_NODEPS, NULL, NULL},
00168 { "noscripts", 0, POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_NOSCRIPTS, NULL, NULL},
00169 { "nomd5", 0, POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_NOMD5, NULL, NULL},
00170 { "force", 0, POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_FORCE, NULL, NULL},
00171 #endif
00172
00173 #ifdef IAM_RPMQV
00174 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQueryPoptTable, 0,
00175 N_("Query options (with -q or --query):"),
00176 NULL },
00177 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmVerifyPoptTable, 0,
00178 N_("Verify options (with -V or --verify):"),
00179 NULL },
00180 #endif
00181
00182 #ifdef IAM_RPMK
00183 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmSignPoptTable, 0,
00184 N_("Signature options:"),
00185 NULL },
00186 #endif
00187
00188 #ifdef IAM_RPMDB
00189 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmDatabasePoptTable, 0,
00190 N_("Database options:"),
00191 NULL },
00192 #endif
00193
00194 #ifdef IAM_RPMBT
00195 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmBuildPoptTable, 0,
00196 N_("Build options with [ <specfile> | <tarball> | <source package> ]:"),
00197 NULL },
00198 #endif
00199
00200 #ifdef IAM_RPMEIU
00201 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmInstallPoptTable, 0,
00202 N_("Install/Upgrade/Erase options:"),
00203 NULL },
00204 #endif
00205
00206 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmAllPoptTable, 0,
00207 N_("Common options for all rpm modes:"),
00208 NULL },
00209
00210 POPT_AUTOALIAS
00211 POPT_AUTOHELP
00212 POPT_TABLEEND
00213 };
00214
00215 #ifdef __MINT__
00216
00217 long _stksize = 64 * 1024L;
00218 #endif
00219
00220 static void argerror(const char * desc)
00221
00222
00223 {
00224 fprintf(stderr, _("%s: %s\n"), __progname, desc);
00225 exit(EXIT_FAILURE);
00226 }
00227
00228 static void printVersion(void)
00229
00230
00231 {
00232 fprintf(stdout, _("RPM version %s\n"), rpmEVR);
00233 }
00234
00235 static void printBanner(void)
00236
00237
00238 {
00239 (void) puts(_("Copyright (C) 1998-2000 - Red Hat, Inc."));
00240 (void) puts(_("This program may be freely redistributed under the terms of the GNU GPL"));
00241 }
00242
00243 static void printUsage(void)
00244
00245
00246 {
00247 FILE * fp = stdout;
00248 printVersion();
00249 printBanner();
00250 (void) puts("");
00251
00252 fprintf(fp, _("Usage: %s {--help}\n"), __progname);
00253 fprintf(fp, " %s {--version}\n" , __progname);
00254
00255 #ifdef IAM_RPMEIU
00256 #ifdef DYING
00257 --dbpath all
00258 --ftpproxy etc all
00259 --force alias for --replacepkgs --replacefiles
00260 --includedocs handle as option in table
00261 --erase forbids many options
00262 #endif
00263 #endif
00264
00265 #ifdef IAM_RPMQV
00266 #ifdef DYING
00267 --dbpath all
00268 --ftpproxy etc all
00269 -i,--info Q
00270 -R,--requires Q
00271 -P,--provides Q
00272 --scripts Q
00273 --triggeredby Q
00274 --changelog Q
00275 --triggers Q
00276 --querytags !V
00277 --setperms V
00278 --setugids V
00279 #endif
00280 #endif
00281
00282 }
00283
00284 int main(int argc, const char ** argv)
00285 {
00286 enum modes bigMode = MODE_UNKNOWN;
00287
00288 #ifdef IAM_RPMQV
00289 QVA_t qva = &rpmQVArgs;
00290 #endif
00291
00292 #ifdef IAM_RPMBT
00293 BTA_t ba = &rpmBTArgs;
00294 #endif
00295
00296 #ifdef IAM_RPMEIU
00297 struct rpmInstallArguments_s * ia = &rpmIArgs;
00298 #endif
00299
00300 #if defined(IAM_RPMDB)
00301 struct rpmDatabaseArguments_s * da = &rpmDBArgs;
00302 #endif
00303
00304 #if defined(IAM_RPMK)
00305 struct rpmSignArguments_s * ka = &rpmKArgs;
00306 #endif
00307
00308 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
00309 char * passPhrase = "";
00310 #endif
00311
00312 int arg;
00313 int gotDbpath = 0;
00314
00315 const char * optArg;
00316 pid_t pipeChild = 0;
00317 poptContext optCon;
00318 int ec = 0;
00319 int status;
00320 int p[2];
00321
00322 #if HAVE_MCHECK_H && HAVE_MTRACE
00323 mtrace();
00324 #endif
00325 setprogname(argv[0]);
00326
00327 #if HAVE_SYSLOG_H
00328
00329 openlog( __progname, 0, LOG_USER );
00330 #endif
00331
00332
00333
00334 #ifdef IAM_RPMBT
00335 if (!strcmp(__progname, "rpmb")) bigMode = MODE_BUILD;
00336 if (!strcmp(__progname, "rpmt")) bigMode = MODE_TARBUILD;
00337 if (!strcmp(__progname, "rpmbuild")) bigMode = MODE_BUILD;
00338 #endif
00339 #ifdef IAM_RPMQV
00340 if (!strcmp(__progname, "rpmq")) bigMode = MODE_QUERY;
00341 if (!strcmp(__progname, "rpmv")) bigMode = MODE_VERIFY;
00342 if (!strcmp(__progname, "rpmquery")) bigMode = MODE_QUERY;
00343 if (!strcmp(__progname, "rpmverify")) bigMode = MODE_VERIFY;
00344 #endif
00345 #ifdef RPMEIU
00346 if (!strcmp(__progname, "rpme")) bigMode = MODE_ERASE;
00347 if (!strcmp(__progname, "rpmi")) bigMode = MODE_INSTALL;
00348 if (!strcmp(__progname, "rpmu")) bigMode = MODE_INSTALL;
00349 #endif
00350
00351
00352
00353 _ftp_debug = 0;
00354
00355 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
00356 noLibio = 0;
00357 #else
00358 noLibio = 1;
00359 #endif
00360 _rpmio_debug = 0;
00361 _url_debug = 0;
00362
00363
00364 specedit = 0;
00365 parseSpecVec = parseSpec;
00366 freeSpecVec = freeSpec;
00367
00368
00369 (void) setlocale(LC_ALL, "" );
00370
00371 #ifdef __LCLINT__
00372 #define LOCALEDIR "/usr/share/locale"
00373 #endif
00374 bindtextdomain(PACKAGE, LOCALEDIR);
00375 textdomain(PACKAGE);
00376
00377 rpmSetVerbosity(RPMMESS_NORMAL);
00378
00379
00380
00381
00382 optCon = poptGetContext(__progname, argc, argv, optionsTable, 0);
00383
00384 (void) poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
00385 (void) poptReadDefaultConfig(optCon, 1);
00386 poptSetExecPath(optCon, RPMCONFIGDIR, 1);
00387
00388
00389
00390
00391 while ((arg = poptGetNextOpt(optCon)) > 0) {
00392 switch(arg) {
00393 case 'v':
00394 rpmIncreaseVerbosity();
00395 break;
00396 default:
00397 break;
00398 }
00399 }
00400
00401 if (rpmReadConfigFiles(rcfile, NULL))
00402 exit(EXIT_FAILURE);
00403
00404 if (showrc) {
00405 (void) rpmShowRC(stdout);
00406 exit(EXIT_SUCCESS);
00407 }
00408
00409 rpmSetVerbosity(RPMMESS_NORMAL);
00410
00411 poptResetContext(optCon);
00412
00413 #ifdef IAM_RPMQV
00414 qva->qva_queryFormat = _free(qva->qva_queryFormat);
00415 memset(qva, 0, sizeof(*qva));
00416 qva->qva_source = RPMQV_PACKAGE;
00417 qva->qva_fflags = RPMFILE_ALL;
00418 qva->qva_mode = ' ';
00419 qva->qva_char = ' ';
00420 #endif
00421
00422 #ifdef IAM_RPMBT
00423 ba->buildRootOverride = _free(ba->buildRootOverride);
00424 ba->targets = _free(ba->targets);
00425 memset(ba, 0, sizeof(*ba));
00426 ba->buildMode = ' ';
00427 ba->buildChar = ' ';
00428 #endif
00429
00430 #ifdef IAM_RPMDB
00431 memset(da, 0, sizeof(*da));
00432 #endif
00433
00434 #ifdef IAM_RPMK
00435 memset(ka, 0, sizeof(*ka));
00436 ka->addSign = RESIGN_NONE;
00437 ka->checksigFlags = CHECKSIG_ALL;
00438 #endif
00439
00440 #ifdef IAM_RPMEIU
00441 ia->relocations = _free(ia->relocations);
00442 memset(ia, 0, sizeof(*ia));
00443 ia->transFlags = RPMTRANS_FLAG_NONE;
00444 ia->probFilter = RPMPROB_FILTER_NONE;
00445 ia->installInterfaceFlags = INSTALL_NONE;
00446 ia->eraseInterfaceFlags = UNINSTALL_NONE;
00447 #endif
00448
00449 while ((arg = poptGetNextOpt(optCon)) > 0) {
00450 optArg = poptGetOptArg(optCon);
00451
00452 switch (arg) {
00453
00454 case 'v':
00455 rpmIncreaseVerbosity();
00456 break;
00457
00458
00459 #if defined(IAM_RPMQV) || defined(IAM_RPMK)
00460 case POPT_NOMD5:
00461 #ifdef IAM_RPMQV
00462 if (bigMode == MODE_VERIFY || qva->qva_mode == 'V')
00463 qva->qva_flags |= VERIFY_MD5;
00464 else
00465 #endif
00466 #ifdef IAM_RPMK
00467 if (bigMode & MODES_K)
00468 ka->checksigFlags &= ~CHECKSIG_MD5;
00469 else
00470 #endif
00471 #ifdef IAM_RPMEIU
00472 if (bigMode & MODES_IE)
00473 ia->transFlags |= RPMTRANS_FLAG_NOMD5;
00474 else
00475 #endif
00476 {};
00477 break;
00478 #endif
00479
00480 #if defined(IAM_RPMQV) || defined(IAM_RPMEIU) || defined(IAM_RPMBT)
00481 case POPT_NODEPS:
00482 #ifdef IAM_RPMQV
00483 if (bigMode == MODE_VERIFY || qva->qva_mode == 'V')
00484 qva->qva_flags |= VERIFY_DEPS;
00485 else
00486 #endif
00487 #ifdef IAM_RPMEIU
00488 if ((bigMode & MODES_IE) ||
00489 (ia->installInterfaceFlags &
00490 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE)))
00491 ia->noDeps = 1;
00492 else
00493 #endif
00494 #ifdef IAM_RPMBT
00495 if ((bigMode & MODES_BT) || ba->buildMode != ' ')
00496 ba->noDeps = 1;
00497 else
00498 #endif
00499 ;
00500 break;
00501
00502 case POPT_FORCE:
00503 #ifdef IAM_RPMEIU
00504 if ((bigMode & MODES_IE) ||
00505 (ia->installInterfaceFlags &
00506 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE)))
00507 ia->probFilter |=
00508 ( RPMPROB_FILTER_REPLACEPKG
00509 | RPMPROB_FILTER_REPLACEOLDFILES
00510 | RPMPROB_FILTER_REPLACENEWFILES
00511 | RPMPROB_FILTER_OLDPACKAGE);
00512 else
00513 #endif
00514 #ifdef IAM_RPMBT
00515 if ((bigMode & MODES_BT) || ba->buildMode != ' ')
00516 ba->force = 1;
00517 else
00518 #endif
00519 ;
00520 break;
00521
00522 case 'i':
00523 #ifdef IAM_RPMQV
00524 if (bigMode == MODE_QUERY || qva->qva_mode == 'q') {
00525
00526 const char * infoCommand[] = { "--info", NULL };
00527
00528 (void) poptStuffArgs(optCon, infoCommand);
00529 } else
00530 #endif
00531 #ifdef IAM_RPMEIU
00532 if (bigMode == MODE_INSTALL ||
00533 (ia->installInterfaceFlags &
00534 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL)))
00535 ;
00536 else if (bigMode == MODE_UNKNOWN) {
00537
00538 const char * installCommand[] = { "--install", NULL };
00539
00540 (void) poptStuffArgs(optCon, installCommand);
00541 } else
00542 #endif
00543 ;
00544 break;
00545
00546 case POPT_NOSCRIPTS:
00547 #ifdef IAM_RPMQV
00548 if (bigMode == MODE_VERIFY || qva->qva_mode == 'V')
00549 qva->qva_flags |= VERIFY_SCRIPT;
00550 else
00551 #endif
00552 #ifdef IAM_RPMEIU
00553 if ((bigMode & MODES_IE) ||
00554 (ia->installInterfaceFlags &
00555 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL|INSTALL_ERASE)))
00556 ia->transFlags |= (_noTransScripts | _noTransTriggers);
00557 else
00558 #endif
00559 ;
00560 break;
00561
00562 #endif
00563
00564 case GETOPT_DEFINEMACRO:
00565 if (optArg) {
00566 (void) rpmDefineMacro(NULL, optArg, RMIL_CMDLINE);
00567 (void) rpmDefineMacro(rpmCLIMacroContext, optArg,RMIL_CMDLINE);
00568 }
00569 noUsageMsg = 1;
00570 break;
00571
00572 case GETOPT_EVALMACRO:
00573 if (optArg) {
00574 const char *val = rpmExpand(optArg, NULL);
00575 fprintf(stdout, "%s\n", val);
00576 val = _free(val);
00577 }
00578 noUsageMsg = 1;
00579 break;
00580
00581 #if defined(GETOPT_RCFILE)
00582 case GETOPT_RCFILE:
00583 fprintf(stderr, _("The --rcfile option has been eliminated.\n"));
00584 fprintf(stderr, _("Use \"--macros <file:...>\" instead.\n"));
00585 exit(EXIT_FAILURE);
00586 break;
00587 #endif
00588
00589 default:
00590 fprintf(stderr, _("Internal error in argument processing (%d) :-(\n"), arg);
00591 exit(EXIT_FAILURE);
00592 }
00593 }
00594
00595 if (quiet)
00596 rpmSetVerbosity(RPMMESS_QUIET);
00597
00598 if (showVersion) printVersion();
00599
00600 if (arg < -1) {
00601 fprintf(stderr, "%s: %s\n",
00602 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
00603 poptStrerror(arg));
00604 exit(EXIT_FAILURE);
00605 }
00606
00607 #ifdef IAM_RPMBT
00608 if ( !(geteuid() || rpmExpandNumeric( "%_allow_root_build" )) )
00609 argerror( _("current site policy disallows root to build packages") );
00610
00611 nice(10);
00612
00613 switch (ba->buildMode) {
00614 case 'b': bigMode = MODE_BUILD; break;
00615 case 't': bigMode = MODE_TARBUILD; break;
00616 case 'B': bigMode = MODE_REBUILD; break;
00617 case 'C': bigMode = MODE_RECOMPILE; break;
00618 }
00619
00620 if ((ba->buildAmount & RPMBUILD_RMSOURCE) && bigMode == MODE_UNKNOWN)
00621 bigMode = MODE_BUILD;
00622
00623 if ((ba->buildAmount & RPMBUILD_RMSPEC) && bigMode == MODE_UNKNOWN)
00624 bigMode = MODE_BUILD;
00625
00626 if (ba->buildRootOverride && bigMode != MODE_BUILD &&
00627 bigMode != MODE_REBUILD && bigMode != MODE_TARBUILD) {
00628 argerror("--buildroot may only be used during package builds");
00629 }
00630 #endif
00631
00632 #ifdef IAM_RPMDB
00633 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_DB)) {
00634 if (da->init) {
00635 if (bigMode != MODE_UNKNOWN)
00636 argerror(_("only one major mode may be specified"));
00637 else
00638 bigMode = MODE_INITDB;
00639 } else
00640 if (da->rebuild) {
00641 if (bigMode != MODE_UNKNOWN)
00642 argerror(_("only one major mode may be specified"));
00643 else
00644 bigMode = MODE_REBUILDDB;
00645 } else
00646 if (da->verify) {
00647 if (bigMode != MODE_UNKNOWN)
00648 argerror(_("only one major mode may be specified"));
00649 else
00650 bigMode = MODE_VERIFYDB;
00651 }
00652 }
00653 #endif
00654
00655 #ifdef IAM_RPMQV
00656 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_QV)) {
00657 switch (qva->qva_mode) {
00658 case 'q': bigMode = MODE_QUERY; break;
00659 case 'V': bigMode = MODE_VERIFY; break;
00660 case 'Q': bigMode = MODE_QUERYTAGS; break;
00661 }
00662
00663 if (qva->qva_sourceCount) {
00664 if (qva->qva_sourceCount > 2)
00665 argerror(_("one type of query/verify may be performed at a "
00666 "time"));
00667 }
00668 if (qva->qva_flags && (bigMode & ~MODES_QV))
00669 argerror(_("unexpected query flags"));
00670
00671 if (qva->qva_queryFormat && (bigMode & ~MODES_QV))
00672 argerror(_("unexpected query format"));
00673
00674 if (qva->qva_source != RPMQV_PACKAGE && (bigMode & ~MODES_QV))
00675 argerror(_("unexpected query source"));
00676 }
00677 #endif
00678
00679 #ifdef IAM_RPMEIU
00680 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_IE))
00681 { int iflags = (ia->installInterfaceFlags &
00682 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL));
00683 int eflags = (ia->installInterfaceFlags & INSTALL_ERASE);
00684
00685 if (iflags & eflags)
00686 argerror(_("only one major mode may be specified"));
00687 else if (iflags)
00688 bigMode = MODE_INSTALL;
00689 else if (eflags)
00690 bigMode = MODE_ERASE;
00691 }
00692 #endif
00693
00694 #ifdef IAM_RPMK
00695 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_K)) {
00696 switch (ka->addSign) {
00697 case RESIGN_NONE:
00698 break;
00699 case RESIGN_CHK_SIGNATURE:
00700 bigMode = MODE_CHECKSIG;
00701 break;
00702 case RESIGN_ADD_SIGNATURE:
00703 case RESIGN_NEW_SIGNATURE:
00704 bigMode = MODE_RESIGN;
00705 break;
00706
00707 }
00708 }
00709 #endif
00710
00711
00712 if (gotDbpath && (bigMode & ~MODES_FOR_DBPATH))
00713 argerror(_("--dbpath given for operation that does not use a "
00714 "database"));
00715
00716 #if defined(IAM_RPMEIU)
00717 if (!( bigMode == MODE_INSTALL ) &&
00718 (ia->probFilter & (RPMPROB_FILTER_REPLACEPKG | RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES | RPMPROB_FILTER_OLDPACKAGE)))
00719 argerror(_("only installation, upgrading, rmsource and rmspec may be forced"));
00720 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_FORCERELOCATE))
00721 argerror(_("files may only be relocated during package installation"));
00722
00723 if (ia->relocations && ia->prefix)
00724 argerror(_("only one of --prefix or --relocate may be used"));
00725
00726 if (bigMode != MODE_INSTALL && ia->relocations)
00727 argerror(_("--relocate and --excludepath may only be used when installing new packages"));
00728
00729 if (bigMode != MODE_INSTALL && ia->prefix)
00730 argerror(_("--prefix may only be used when installing new packages"));
00731
00732 if (ia->prefix && ia->prefix[0] != '/')
00733 argerror(_("arguments to --prefix must begin with a /"));
00734
00735 if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_HASH))
00736 argerror(_("--hash (-h) may only be specified during package "
00737 "installation"));
00738
00739 if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_PERCENT))
00740 argerror(_("--percent may only be specified during package "
00741 "installation"));
00742
00743 if (bigMode != MODE_INSTALL &&
00744 (ia->probFilter & (RPMPROB_FILTER_REPLACEOLDFILES|RPMPROB_FILTER_REPLACENEWFILES)))
00745 argerror(_("--replacefiles may only be specified during package "
00746 "installation"));
00747
00748 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_REPLACEPKG))
00749 argerror(_("--replacepkgs may only be specified during package "
00750 "installation"));
00751
00752 if (bigMode != MODE_INSTALL && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
00753 argerror(_("--excludedocs may only be specified during package "
00754 "installation"));
00755
00756 if (bigMode != MODE_INSTALL && ia->incldocs)
00757 argerror(_("--includedocs may only be specified during package "
00758 "installation"));
00759
00760 if (ia->incldocs && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
00761 argerror(_("only one of --excludedocs and --includedocs may be "
00762 "specified"));
00763
00764 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREARCH))
00765 argerror(_("--ignorearch may only be specified during package "
00766 "installation"));
00767
00768 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREOS))
00769 argerror(_("--ignoreos may only be specified during package "
00770 "installation"));
00771
00772 if (bigMode != MODE_INSTALL &&
00773 (ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES)))
00774 argerror(_("--ignoresize may only be specified during package "
00775 "installation"));
00776
00777 if ((ia->eraseInterfaceFlags & UNINSTALL_ALLMATCHES) && bigMode != MODE_ERASE)
00778 argerror(_("--allmatches may only be specified during package "
00779 "erasure"));
00780
00781 if ((ia->transFlags & RPMTRANS_FLAG_ALLFILES) && bigMode != MODE_INSTALL)
00782 argerror(_("--allfiles may only be specified during package "
00783 "installation"));
00784
00785 if ((ia->transFlags & RPMTRANS_FLAG_JUSTDB) &&
00786 bigMode != MODE_INSTALL && bigMode != MODE_ERASE)
00787 argerror(_("--justdb may only be specified during package "
00788 "installation and erasure"));
00789
00790 if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
00791 (ia->transFlags & (RPMTRANS_FLAG_NOSCRIPTS | _noTransScripts | _noTransTriggers)))
00792 argerror(_("script disabling options may only be specified during "
00793 "package installation and erasure"));
00794
00795 if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
00796 (ia->transFlags & (RPMTRANS_FLAG_NOTRIGGERS | _noTransTriggers)))
00797 argerror(_("trigger disabling options may only be specified during "
00798 "package installation and erasure"));
00799
00800 if (ia->noDeps & (bigMode & ~MODES_FOR_NODEPS))
00801 argerror(_("--nodeps may only be specified during package "
00802 "building, rebuilding, recompilation, installation,"
00803 "erasure, and verification"));
00804
00805 if ((ia->transFlags & RPMTRANS_FLAG_TEST) && (bigMode & ~MODES_FOR_TEST))
00806 argerror(_("--test may only be specified during package installation, "
00807 "erasure, and building"));
00808 #endif
00809
00810 if (rootdir && rootdir[1] && (bigMode & ~MODES_FOR_ROOT))
00811 argerror(_("--root (-r) may only be specified during "
00812 "installation, erasure, querying, and "
00813 "database rebuilds"));
00814
00815 if (rootdir) {
00816 switch (urlIsURL(rootdir)) {
00817 default:
00818 if (bigMode & MODES_FOR_ROOT)
00819 break;
00820
00821 case URL_IS_UNKNOWN:
00822 if (rootdir[0] != '/')
00823 argerror(_("arguments to --root (-r) must begin with a /"));
00824 break;
00825 }
00826 }
00827
00828 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
00829 if (0
00830 #if defined(IAM_RPMBT)
00831 || ba->sign
00832 #endif
00833 #if defined(IAM_RPMK)
00834 || ka->sign
00835 #endif
00836 ) {
00837 if (bigMode == MODE_REBUILD || bigMode == MODE_BUILD ||
00838 bigMode == MODE_RESIGN || bigMode == MODE_TARBUILD) {
00839 const char ** av;
00840 struct stat sb;
00841 int errors = 0;
00842
00843 if ((av = poptGetArgs(optCon)) == NULL) {
00844 fprintf(stderr, _("no files to sign\n"));
00845 errors++;
00846 } else
00847 while (*av) {
00848 if (stat(*av, &sb)) {
00849 fprintf(stderr, _("cannot access file %s\n"), *av);
00850 errors++;
00851 }
00852 av++;
00853 }
00854
00855 if (errors) {
00856 ec = errors;
00857 goto exit;
00858 }
00859
00860 if (poptPeekArg(optCon)) {
00861 int sigTag;
00862 switch (sigTag = rpmLookupSignatureType(RPMLOOKUPSIG_QUERY)) {
00863 case 0:
00864 break;
00865 case RPMSIGTAG_PGP:
00866 if ((sigTag == RPMSIGTAG_PGP || sigTag == RPMSIGTAG_PGP5) &&
00867 !rpmDetectPGPVersion(NULL)) {
00868 fprintf(stderr, _("pgp not found: "));
00869 ec = EXIT_FAILURE;
00870 goto exit;
00871 }
00872 case RPMSIGTAG_GPG:
00873 passPhrase = rpmGetPassPhrase(_("Enter pass phrase: "), sigTag);
00874 if (passPhrase == NULL) {
00875 fprintf(stderr, _("Pass phrase check failed\n"));
00876 ec = EXIT_FAILURE;
00877 goto exit;
00878 }
00879 fprintf(stderr, _("Pass phrase is good.\n"));
00880 passPhrase = xstrdup(passPhrase);
00881 break;
00882 default:
00883 fprintf(stderr,
00884 _("Invalid %%_signature spec in macro file.\n"));
00885 ec = EXIT_FAILURE;
00886 goto exit;
00887 break;
00888 }
00889 }
00890 } else {
00891 argerror(_("--sign may only be used during package building"));
00892 }
00893 } else {
00894
00895 (void) rpmLookupSignatureType(RPMLOOKUPSIG_DISABLE);
00896 }
00897 #endif
00898
00899 if (pipeOutput) {
00900 (void) pipe(p);
00901
00902 if (!(pipeChild = fork())) {
00903 (void) close(p[1]);
00904 (void) dup2(p[0], STDIN_FILENO);
00905 (void) close(p[0]);
00906
00907 if ( rpm_close_all() ) {
00908 perror( "rpm_close_all" );
00909 _exit( -1 );
00910 }
00911
00912 (void) execl("/bin/sh", "/bin/sh", "-c", pipeOutput, NULL);
00913 fprintf(stderr, _("exec failed\n"));
00914 exit( EXIT_FAILURE );
00915 }
00916
00917 (void) close(p[0]);
00918 (void) dup2(p[1], STDOUT_FILENO);
00919 (void) close(p[1]);
00920 }
00921
00922 switch (bigMode) {
00923 #ifdef IAM_RPMDB
00924 case MODE_INITDB:
00925 (void) rpmdbInit(rootdir, 0644);
00926 break;
00927
00928 case MODE_REBUILDDB:
00929 ec = rpmdbRebuild(rootdir);
00930 break;
00931 case MODE_VERIFYDB:
00932 ec = rpmdbVerify(rootdir);
00933 break;
00934 #endif
00935
00936 #ifdef IAM_RPMBT
00937 case MODE_REBUILD:
00938 case MODE_RECOMPILE:
00939 { const char * pkg;
00940 while (!rpmIsVerbose())
00941 rpmIncreaseVerbosity();
00942
00943 if (!poptPeekArg(optCon))
00944 argerror(_("no packages files given for rebuild"));
00945
00946 ba->buildAmount = RPMBUILD_PREP | RPMBUILD_BUILD | RPMBUILD_INSTALL;
00947 if (bigMode == MODE_REBUILD) {
00948 ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
00949 ba->buildAmount |= RPMBUILD_RMSOURCE;
00950 ba->buildAmount |= RPMBUILD_RMSPEC;
00951 ba->buildAmount |= RPMBUILD_CLEAN;
00952 ba->buildAmount |= RPMBUILD_RMBUILD;
00953 }
00954
00955 while ((pkg = poptGetArg(optCon))) {
00956 const char * specFile = NULL;
00957 char * cookie = NULL;
00958
00959 ec = rpmInstallSource("", pkg, &specFile, &cookie);
00960 if (ec)
00961 break;
00962
00963 ba->rootdir = rootdir;
00964 ec = build(specFile, ba, passPhrase, cookie, rcfile);
00965 free(cookie);
00966 cookie = NULL;
00967 free((void *)specFile);
00968 specFile = NULL;
00969
00970 if (ec)
00971 break;
00972 }
00973 } break;
00974
00975 case MODE_BUILD:
00976 case MODE_TARBUILD:
00977 { const char * pkg;
00978 while (!rpmIsVerbose())
00979 rpmIncreaseVerbosity();
00980
00981 switch (ba->buildChar) {
00982 case 'E':
00983 ba->buildAmount |= RPMBUILD_PREPROCESS;
00984
00985 case 'a':
00986 ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
00987
00988 case 'b':
00989 ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
00990 ba->buildAmount |= RPMBUILD_CLEAN;
00991 if (ba->shortCircuit) break;
00992
00993 case 'i':
00994 ba->buildAmount |= RPMBUILD_INSTALL;
00995 if (ba->shortCircuit) break;
00996
00997 case 'c':
00998 ba->buildAmount |= RPMBUILD_BUILD;
00999 if (ba->shortCircuit) break;
01000
01001 case 'p':
01002 ba->buildAmount |= RPMBUILD_PREP;
01003 break;
01004
01005 case 'l':
01006 ba->buildAmount |= RPMBUILD_FILECHECK;
01007 break;
01008 case 's':
01009 ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
01010 break;
01011 }
01012
01013 if (!poptPeekArg(optCon)) {
01014 if (bigMode == MODE_BUILD)
01015 argerror(_("no spec files given for build"));
01016 else
01017 argerror(_("no tar files given for build"));
01018 }
01019
01020 while ((pkg = poptGetArg(optCon))) {
01021 ba->rootdir = rootdir;
01022 ec = build(pkg, ba, passPhrase, NULL, rcfile);
01023 if (ec)
01024 break;
01025 rpmFreeMacros(NULL);
01026 (void) rpmReadConfigFiles(rcfile, NULL);
01027 }
01028 } break;
01029 #endif
01030
01031 #ifdef IAM_RPMEIU
01032 case MODE_ERASE:
01033 ia->rootdir = rootdir;
01034 if (ia->noDeps) ia->eraseInterfaceFlags |= UNINSTALL_NODEPS;
01035
01036 if (!poptPeekArg(optCon)) {
01037 if (ia->rbtid == 0)
01038 argerror(_("no packages given for erase"));
01039 ia->transFlags |= RPMTRANS_FLAG_NOMD5;
01040 ia->probFilter |= RPMPROB_FILTER_OLDPACKAGE;
01041 ec += rpmRollback(ia, NULL);
01042 } else {
01043 ec += rpmErase(rootdir, (const char **)poptGetArgs(optCon),
01044 ia->transFlags, ia->eraseInterfaceFlags);
01045 }
01046 break;
01047
01048 case MODE_INSTALL:
01049
01050
01051 ia->rootdir = rootdir;
01052 if (!ia->incldocs) {
01053 if (ia->transFlags & RPMTRANS_FLAG_NODOCS)
01054 ;
01055 else if (rpmExpandNumeric("%{_excludedocs}"))
01056 ia->transFlags |= RPMTRANS_FLAG_NODOCS;
01057 }
01058
01059 if (ia->noDeps) ia->installInterfaceFlags |= INSTALL_NODEPS;
01060
01061
01062 if (ia->prefix) {
01063 ia->relocations = xmalloc(2 * sizeof(*ia->relocations));
01064 ia->relocations[0].oldPath = NULL;
01065 ia->relocations[0].newPath = ia->prefix;
01066 ia->relocations[1].oldPath = ia->relocations[1].newPath = NULL;
01067 } else if (ia->relocations) {
01068 ia->relocations = xrealloc(ia->relocations,
01069 sizeof(*ia->relocations) * (ia->numRelocations + 1));
01070 ia->relocations[ia->numRelocations].oldPath = NULL;
01071 ia->relocations[ia->numRelocations].newPath = NULL;
01072 }
01073
01074 if (!poptPeekArg(optCon)) {
01075 if (ia->rbtid == 0)
01076 argerror(_("no packages given for install"));
01077 ia->transFlags |= RPMTRANS_FLAG_NOMD5;
01078 ia->probFilter |= RPMPROB_FILTER_OLDPACKAGE;
01079 ec += rpmRollback(ia, NULL);
01080 } else {
01081
01082
01083 ec += rpmInstall(rootdir, (const char **)poptGetArgs(optCon),
01084 ia->transFlags, ia->installInterfaceFlags,
01085 ia->probFilter, ia->relocations);
01086 }
01087
01088 break;
01089 #endif
01090
01091 #ifdef IAM_RPMQV
01092 case MODE_QUERY:
01093 { const char * pkg;
01094
01095 qva->qva_prefix = rootdir;
01096 if (qva->qva_source == RPMQV_ALL) {
01097 #ifdef DYING
01098 if (poptPeekArg(optCon))
01099 argerror(_("extra arguments given for query of all packages"));
01100 #else
01101 const char ** av = poptGetArgs(optCon);
01102 #endif
01103
01104 ec = rpmQuery(qva, RPMQV_ALL, (const char *) av);
01105
01106 } else {
01107 if (!poptPeekArg(optCon))
01108 argerror(_("no arguments given for query"));
01109 while ((pkg = poptGetArg(optCon)))
01110 ec += rpmQuery(qva, qva->qva_source, pkg);
01111 }
01112 } break;
01113
01114 case MODE_VERIFY:
01115 { const char * pkg;
01116 rpmVerifyFlags verifyFlags = VERIFY_ALL;
01117
01118 verifyFlags &= ~qva->qva_flags;
01119 qva->qva_flags = (rpmQueryFlags) verifyFlags;
01120 qva->qva_prefix = rootdir;
01121
01122 if (qva->qva_source == RPMQV_ALL) {
01123 if (poptPeekArg(optCon))
01124 argerror(_("extra arguments given for verify of all packages"));
01125 ec = rpmVerify(qva, RPMQV_ALL, NULL);
01126 } else {
01127 if (!poptPeekArg(optCon))
01128 argerror(_("no arguments given for verify"));
01129 while ((pkg = poptGetArg(optCon)))
01130 ec += rpmVerify(qva, qva->qva_source, pkg);
01131 }
01132 } break;
01133
01134 case MODE_QUERYTAGS:
01135 if (argc != 2)
01136 argerror(_("unexpected arguments to --querytags "));
01137
01138 rpmDisplayQueryTags(stdout);
01139 break;
01140 #endif
01141
01142 #ifdef IAM_RPMK
01143 case MODE_CHECKSIG:
01144 if (!poptPeekArg(optCon))
01145 argerror(_("no packages given for signature check"));
01146 ec = rpmCheckSig(ka->checksigFlags,
01147 (const char **)poptGetArgs(optCon));
01148
01149 if (ec > 255) ec = 255;
01150 break;
01151
01152 case MODE_RESIGN:
01153 if (!poptPeekArg(optCon))
01154 argerror(_("no packages given for signing"));
01155 ec = rpmReSign(ka->addSign, passPhrase,
01156 (const char **)poptGetArgs(optCon));
01157
01158 if (ec > 255) ec = 255;
01159 break;
01160 #endif
01161
01162 #if !defined(IAM_RPMQV)
01163 case MODE_QUERY:
01164 case MODE_VERIFY:
01165 case MODE_QUERYTAGS:
01166 #endif
01167 #if !defined(IAM_RPMK)
01168 case MODE_CHECKSIG:
01169 case MODE_RESIGN:
01170 #endif
01171 #if !defined(IAM_RPMDB)
01172 case MODE_INITDB:
01173 case MODE_REBUILDDB:
01174 case MODE_VERIFYDB:
01175 #endif
01176 #if !defined(IAM_RPMBT)
01177 case MODE_BUILD:
01178 case MODE_REBUILD:
01179 case MODE_RECOMPILE:
01180 case MODE_TARBUILD:
01181 #endif
01182 #if !defined(IAM_RPMEIU)
01183 case MODE_INSTALL:
01184 case MODE_ERASE:
01185 #endif
01186 case MODE_UNKNOWN:
01187 if (!showVersion && !help && !noUsageMsg) printUsage();
01188 break;
01189 }
01190
01191 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
01192 exit:
01193 #endif
01194 optCon = poptFreeContext(optCon);
01195 rpmFreeMacros(NULL);
01196 rpmFreeMacros(rpmCLIMacroContext);
01197 rpmFreeRpmrc();
01198
01199 if (pipeChild) {
01200 (void) fclose(stdout);
01201 (void) waitpid(pipeChild, &status, 0);
01202 }
01203
01204
01205 freeNames();
01206 freeFilesystems();
01207 urlFreeCache();
01208 rpmlogClose();
01209 dbiTags = _free(dbiTags);
01210
01211 #ifdef IAM_RPMQV
01212 qva->qva_queryFormat = _free(qva->qva_queryFormat);
01213 #endif
01214
01215 #ifdef IAM_RPMBT
01216 ba->buildRootOverride = _free(ba->buildRootOverride);
01217 ba->targets = _free(ba->targets);
01218 #endif
01219
01220 #ifdef IAM_RPMEIU
01221 ia->relocations = _free(ia->relocations);
01222 #endif
01223
01224 #if HAVE_MCHECK_H && HAVE_MTRACE
01225 muntrace();
01226 #endif
01227
01228 return ec;
01229
01230 }