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 #include "rpmdb.h"
00017 #include "rpmps.h"
00018 #include "rpmts.h"
00019
00020 #ifdef IAM_RPMBT
00021 #include "build.h"
00022 #define GETOPT_REBUILD 1003
00023 #define GETOPT_RECOMPILE 1004
00024 #endif
00025
00026 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
00027 #include "signature.h"
00028 #endif
00029
00030 #include "debug.h"
00031
00032 enum modes {
00033
00034 MODE_QUERY = (1 << 0),
00035 MODE_VERIFY = (1 << 3),
00036 #define MODES_QV (MODE_QUERY | MODE_VERIFY)
00037
00038 MODE_INSTALL = (1 << 1),
00039 MODE_ERASE = (1 << 2),
00040 #define MODES_IE (MODE_INSTALL | MODE_ERASE)
00041
00042 MODE_BUILD = (1 << 4),
00043 MODE_REBUILD = (1 << 5),
00044 MODE_RECOMPILE = (1 << 8),
00045 MODE_TARBUILD = (1 << 11),
00046 #define MODES_BT (MODE_BUILD | MODE_TARBUILD | MODE_REBUILD | MODE_RECOMPILE)
00047
00048 MODE_CHECKSIG = (1 << 6),
00049 MODE_RESIGN = (1 << 7),
00050 #define MODES_K (MODE_CHECKSIG | MODE_RESIGN)
00051
00052 MODE_INITDB = (1 << 10),
00053 MODE_REBUILDDB = (1 << 12),
00054 MODE_VERIFYDB = (1 << 13),
00055 #define MODES_DB (MODE_INITDB | MODE_REBUILDDB | MODE_VERIFYDB)
00056
00057
00058 MODE_UNKNOWN = 0
00059 };
00060
00061 #define MODES_FOR_DBPATH (MODES_BT | MODES_IE | MODES_QV | MODES_DB)
00062 #define MODES_FOR_NODEPS (MODES_BT | MODES_IE | MODE_VERIFY)
00063 #define MODES_FOR_TEST (MODES_BT | MODES_IE)
00064 #define MODES_FOR_ROOT (MODES_BT | MODES_IE | MODES_QV | MODES_DB | MODES_K)
00065
00066
00067
00068 static struct poptOption optionsTable[] = {
00069
00070 #ifdef IAM_RPMQV
00071 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQueryPoptTable, 0,
00072 N_("Query options (with -q or --query):"),
00073 NULL },
00074 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmVerifyPoptTable, 0,
00075 N_("Verify options (with -V or --verify):"),
00076 NULL },
00077 #endif
00078
00079 #ifdef IAM_RPMK
00080 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmSignPoptTable, 0,
00081 N_("Signature options:"),
00082 NULL },
00083 #endif
00084
00085 #ifdef IAM_RPMDB
00086 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmDatabasePoptTable, 0,
00087 N_("Database options:"),
00088 NULL },
00089 #endif
00090
00091 #ifdef IAM_RPMBT
00092 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmBuildPoptTable, 0,
00093 N_("Build options with [ <specfile> | <tarball> | <source package> ]:"),
00094 NULL },
00095 #endif
00096
00097 #ifdef IAM_RPMEIU
00098 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmInstallPoptTable, 0,
00099 N_("Install/Upgrade/Erase options:"),
00100 NULL },
00101 #endif
00102
00103 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
00104 N_("Common options for all rpm modes:"),
00105 NULL },
00106
00107 POPT_AUTOALIAS
00108 POPT_AUTOHELP
00109 POPT_TABLEEND
00110 };
00111
00112 #ifdef __MINT__
00113
00114 long _stksize = 64 * 1024L;
00115 #endif
00116
00117 static void argerror(const char * desc)
00118
00119
00120 {
00121 fprintf(stderr, _("%s: %s\n"), __progname, desc);
00122 exit(EXIT_FAILURE);
00123 }
00124
00125 static void printVersion(FILE * fp)
00126
00127
00128 {
00129 fprintf(fp, _("RPM version %s\n"), rpmEVR);
00130 }
00131
00132 static void printBanner(FILE * fp)
00133
00134
00135 {
00136 fprintf(fp, _("Copyright (C) 1998-2002 - Red Hat, Inc.\n"));
00137 fprintf(fp, _("This program may be freely redistributed under the terms of the GNU GPL\n"));
00138 }
00139
00140 static void printUsage(poptContext con, FILE * fp, int flags)
00141
00142
00143 {
00144 printVersion(fp);
00145 printBanner(fp);
00146 fprintf(fp, "\n");
00147
00148 if (rpmIsVerbose())
00149 poptPrintHelp(con, fp, flags);
00150 else
00151 poptPrintUsage(con, fp, flags);
00152 }
00153
00154
00155
00156 #if !defined(__GLIBC__) && !defined(__LCLINT__)
00157 int main(int argc, const char ** argv, char ** envp)
00158 #else
00159 int main(int argc, const char ** argv)
00160 #endif
00161
00162
00163
00164
00165
00166 {
00167 rpmts ts = NULL;
00168 enum modes bigMode = MODE_UNKNOWN;
00169
00170 #if defined(IAM_RPMQV)
00171 QVA_t qva = &rpmQVKArgs;
00172 #endif
00173
00174 #ifdef IAM_RPMBT
00175 BTA_t ba = &rpmBTArgs;
00176 #endif
00177
00178 #ifdef IAM_RPMEIU
00179 struct rpmInstallArguments_s * ia = &rpmIArgs;
00180 #endif
00181
00182 #if defined(IAM_RPMDB)
00183 struct rpmDatabaseArguments_s * da = &rpmDBArgs;
00184 #endif
00185
00186 #if defined(IAM_RPMK)
00187 QVA_t ka = &rpmQVKArgs;
00188 #endif
00189
00190 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
00191 char * passPhrase = "";
00192 #endif
00193
00194 int arg;
00195
00196 const char * optArg;
00197 pid_t pipeChild = 0;
00198 poptContext optCon;
00199 int ec = 0;
00200 int status;
00201 int p[2];
00202 #ifdef IAM_RPMEIU
00203 int i;
00204 #endif
00205
00206 #if defined(__GLIBC__)
00207
00212 {
00213 if (getenv("LD_ASSUME_KERNEL") != NULL && getenv("RPM_ALLOW_LD_ASSUME_KERNEL") == NULL)
00214 {
00215 char* bypassVar = (char*)malloc(1024*sizeof(char));
00216 if (bypassVar != NULL)
00217 {
00218 rpmMessage(RPMMESS_DEBUG, _("Enabling bypass of LD_ASSUME_KERNEL.\n"));
00219 snprintf(bypassVar, 1024, "__PASSTHROUGH_LD_ASSUME_KERNEL_%d=%s", getpid(), getenv("LD_ASSUME_KERNEL"));
00220 bypassVar[1023] = '\0';
00221 unsetenv("LD_ASSUME_KERNEL");
00222 putenv(bypassVar);
00223 execvp(argv[0], argv);
00224 }
00225 }
00226 }
00227 #endif
00228
00229 #if HAVE_MCHECK_H && HAVE_MTRACE
00230
00231 mtrace();
00232
00233 #endif
00234 setprogname(argv[0]);
00235
00236 #if !defined(__GLIBC__) && !defined(__LCLINT__)
00237 environ = envp;
00238 #endif
00239
00240
00241 if (__progname == NULL) {
00242 if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
00243 else __progname = argv[0];
00244 }
00245
00246
00247
00248 #ifdef IAM_RPMBT
00249 if (!strcmp(__progname, "rpmb")) bigMode = MODE_BUILD;
00250 if (!strcmp(__progname, "lt-rpmb")) bigMode = MODE_BUILD;
00251 if (!strcmp(__progname, "rpmt")) bigMode = MODE_TARBUILD;
00252 if (!strcmp(__progname, "rpmbuild")) bigMode = MODE_BUILD;
00253 #endif
00254 #ifdef IAM_RPMQV
00255 if (!strcmp(__progname, "rpmq")) bigMode = MODE_QUERY;
00256 if (!strcmp(__progname, "lt-rpmq")) bigMode = MODE_QUERY;
00257 if (!strcmp(__progname, "rpmv")) bigMode = MODE_VERIFY;
00258 if (!strcmp(__progname, "rpmquery")) bigMode = MODE_QUERY;
00259 if (!strcmp(__progname, "rpmverify")) bigMode = MODE_VERIFY;
00260 #endif
00261 #ifdef RPMEIU
00262 if (!strcmp(__progname, "rpme")) bigMode = MODE_ERASE;
00263 if (!strcmp(__progname, "rpmi")) bigMode = MODE_INSTALL;
00264 if (!strcmp(__progname, "lt-rpmi")) bigMode = MODE_INSTALL;
00265 if (!strcmp(__progname, "rpmu")) bigMode = MODE_INSTALL;
00266 #endif
00267
00268
00269 #if defined(IAM_RPMQV)
00270
00271 switch (bigMode) {
00272 case MODE_QUERY: qva->qva_mode = 'q'; break;
00273 case MODE_VERIFY: qva->qva_mode = 'V'; break;
00274 case MODE_CHECKSIG: qva->qva_mode = 'K'; break;
00275 case MODE_RESIGN: qva->qva_mode = 'R'; break;
00276 case MODE_INSTALL:
00277 case MODE_ERASE:
00278 case MODE_BUILD:
00279 case MODE_REBUILD:
00280 case MODE_RECOMPILE:
00281 case MODE_TARBUILD:
00282 case MODE_INITDB:
00283 case MODE_REBUILDDB:
00284 case MODE_VERIFYDB:
00285 case MODE_UNKNOWN:
00286 default:
00287 break;
00288 }
00289 #endif
00290
00291 #if defined(ENABLE_NLS)
00292
00293 (void) setlocale(LC_ALL, "" );
00294
00295 #ifdef __LCLINT__
00296 #define LOCALEDIR "/usr/share/locale"
00297 #endif
00298 bindtextdomain(PACKAGE, LOCALEDIR);
00299 textdomain(PACKAGE);
00300 #endif
00301
00302 rpmSetVerbosity(RPMMESS_NORMAL);
00303
00304
00305
00306
00307 optCon = poptGetContext(__progname, argc, argv, optionsTable, 0);
00308
00309 (void) poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
00310 (void) poptReadDefaultConfig(optCon, 1);
00311 poptSetExecPath(optCon, RPMCONFIGDIR, 1);
00312
00313 while ((arg = poptGetNextOpt(optCon)) > 0) {
00314 optArg = poptGetOptArg(optCon);
00315
00316 switch (arg) {
00317 default:
00318 fprintf(stderr, _("Internal error in argument processing (%d) :-(\n"), arg);
00319 exit(EXIT_FAILURE);
00320 }
00321 }
00322
00323 if (arg < -1) {
00324 fprintf(stderr, "%s: %s\n",
00325 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
00326 poptStrerror(arg));
00327 exit(EXIT_FAILURE);
00328 }
00329
00330 rpmcliConfigured();
00331
00332 #ifdef IAM_RPMBT
00333 switch (ba->buildMode) {
00334 case 'b': bigMode = MODE_BUILD; break;
00335 case 't': bigMode = MODE_TARBUILD; break;
00336 case 'B': bigMode = MODE_REBUILD; break;
00337 case 'C': bigMode = MODE_RECOMPILE; break;
00338 }
00339
00340 if ((ba->buildAmount & RPMBUILD_RMSOURCE) && bigMode == MODE_UNKNOWN)
00341 bigMode = MODE_BUILD;
00342
00343 if ((ba->buildAmount & RPMBUILD_RMSPEC) && bigMode == MODE_UNKNOWN)
00344 bigMode = MODE_BUILD;
00345
00346 if (ba->buildRootOverride && bigMode != MODE_BUILD &&
00347 bigMode != MODE_REBUILD && bigMode != MODE_TARBUILD) {
00348 argerror("--buildroot may only be used during package builds");
00349 }
00350 #endif
00351
00352 #ifdef IAM_RPMDB
00353 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_DB)) {
00354 if (da->init) {
00355 if (bigMode != MODE_UNKNOWN)
00356 argerror(_("only one major mode may be specified"));
00357 else
00358 bigMode = MODE_INITDB;
00359 } else
00360 if (da->rebuild) {
00361 if (bigMode != MODE_UNKNOWN)
00362 argerror(_("only one major mode may be specified"));
00363 else
00364 bigMode = MODE_REBUILDDB;
00365 } else
00366 if (da->verify) {
00367 if (bigMode != MODE_UNKNOWN)
00368 argerror(_("only one major mode may be specified"));
00369 else
00370 bigMode = MODE_VERIFYDB;
00371 }
00372 }
00373 #endif
00374
00375 #ifdef IAM_RPMQV
00376 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_QV)) {
00377 switch (qva->qva_mode) {
00378 case 'q': bigMode = MODE_QUERY; break;
00379 case 'V': bigMode = MODE_VERIFY; break;
00380 }
00381
00382 if (qva->qva_sourceCount) {
00383 if (qva->qva_sourceCount > 2)
00384 argerror(_("one type of query/verify may be performed at a "
00385 "time"));
00386 }
00387 if (qva->qva_flags && (bigMode & ~MODES_QV))
00388 argerror(_("unexpected query flags"));
00389
00390 if (qva->qva_queryFormat && (bigMode & ~MODES_QV))
00391 argerror(_("unexpected query format"));
00392
00393 if (qva->qva_source != RPMQV_PACKAGE && (bigMode & ~MODES_QV))
00394 argerror(_("unexpected query source"));
00395 }
00396 #endif
00397
00398 #ifdef IAM_RPMEIU
00399 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_IE))
00400 { int iflags = (ia->installInterfaceFlags &
00401 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL));
00402 int eflags = (ia->installInterfaceFlags & INSTALL_ERASE);
00403
00404 if (iflags & eflags)
00405 argerror(_("only one major mode may be specified"));
00406 else if (iflags)
00407 bigMode = MODE_INSTALL;
00408 else if (eflags)
00409 bigMode = MODE_ERASE;
00410 }
00411 #endif
00412
00413 #ifdef IAM_RPMK
00414 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_K)) {
00415 switch (ka->qva_mode) {
00416 case RPMSIGN_NONE:
00417 ka->sign = 0;
00418 break;
00419 case RPMSIGN_IMPORT_PUBKEY:
00420 case RPMSIGN_CHK_SIGNATURE:
00421 bigMode = MODE_CHECKSIG;
00422 ka->sign = 0;
00423 break;
00424 case RPMSIGN_ADD_SIGNATURE:
00425 case RPMSIGN_NEW_SIGNATURE:
00426 bigMode = MODE_RESIGN;
00427 ka->sign = 1;
00428 break;
00429 }
00430 }
00431 #endif
00432
00433 #if defined(IAM_RPMEIU)
00434 if (!( bigMode == MODE_INSTALL ) &&
00435 (ia->probFilter & (RPMPROB_FILTER_REPLACEPKG | RPMPROB_FILTER_OLDPACKAGE)))
00436 argerror(_("only installation, upgrading, rmsource and rmspec may be forced"));
00437 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_FORCERELOCATE))
00438 argerror(_("files may only be relocated during package installation"));
00439
00440 if (ia->relocations && ia->prefix)
00441 argerror(_("cannot use --prefix with --relocate or --excludepath"));
00442
00443 if (bigMode != MODE_INSTALL && ia->relocations)
00444 argerror(_("--relocate and --excludepath may only be used when installing new packages"));
00445
00446 if (bigMode != MODE_INSTALL && ia->prefix)
00447 argerror(_("--prefix may only be used when installing new packages"));
00448
00449 if (ia->prefix && ia->prefix[0] != '/')
00450 argerror(_("arguments to --prefix must begin with a /"));
00451
00452 if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_HASH))
00453 argerror(_("--hash (-h) may only be specified during package "
00454 "installation"));
00455
00456 if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_PERCENT))
00457 argerror(_("--percent may only be specified during package "
00458 "installation"));
00459
00460 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_REPLACEPKG))
00461 argerror(_("--replacepkgs may only be specified during package "
00462 "installation"));
00463
00464 if (bigMode != MODE_INSTALL && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
00465 argerror(_("--excludedocs may only be specified during package "
00466 "installation"));
00467
00468 if (bigMode != MODE_INSTALL && ia->incldocs)
00469 argerror(_("--includedocs may only be specified during package "
00470 "installation"));
00471
00472 if (ia->incldocs && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
00473 argerror(_("only one of --excludedocs and --includedocs may be "
00474 "specified"));
00475
00476 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREARCH))
00477 argerror(_("--ignorearch may only be specified during package "
00478 "installation"));
00479
00480 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREOS))
00481 argerror(_("--ignoreos may only be specified during package "
00482 "installation"));
00483
00484 if ((ia->eraseInterfaceFlags & UNINSTALL_ALLMATCHES) && bigMode != MODE_ERASE)
00485 argerror(_("--allmatches may only be specified during package "
00486 "erasure"));
00487
00488 if ((ia->transFlags & RPMTRANS_FLAG_ALLFILES) && bigMode != MODE_INSTALL)
00489 argerror(_("--allfiles may only be specified during package "
00490 "installation"));
00491
00492 if ((ia->transFlags & RPMTRANS_FLAG_JUSTDB) &&
00493 bigMode != MODE_INSTALL && bigMode != MODE_ERASE)
00494 argerror(_("--justdb may only be specified during package "
00495 "installation and erasure"));
00496
00497 if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
00498 (ia->transFlags & (RPMTRANS_FLAG_NOSCRIPTS | _noTransScripts | _noTransTriggers)))
00499 argerror(_("script disabling options may only be specified during "
00500 "package installation and erasure"));
00501
00502 if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
00503 (ia->transFlags & (RPMTRANS_FLAG_NOTRIGGERS | _noTransTriggers)))
00504 argerror(_("trigger disabling options may only be specified during "
00505 "package installation and erasure"));
00506
00507 if (ia->noDeps & (bigMode & ~MODES_FOR_NODEPS))
00508 argerror(_("--nodeps may only be specified during package "
00509 "building, rebuilding, recompilation, installation,"
00510 "erasure, and verification"));
00511
00512 if ((ia->transFlags & RPMTRANS_FLAG_TEST) && (bigMode & ~MODES_FOR_TEST))
00513 argerror(_("--test may only be specified during package installation, "
00514 "erasure, and building"));
00515 #endif
00516
00517 if (rpmcliRootDir && rpmcliRootDir[1] && (bigMode & ~MODES_FOR_ROOT))
00518 argerror(_("--root (-r) may only be specified during "
00519 "installation, erasure, querying, and "
00520 "database rebuilds"));
00521
00522 if (rpmcliRootDir) {
00523 switch (urlIsURL(rpmcliRootDir)) {
00524 default:
00525 if (bigMode & MODES_FOR_ROOT)
00526 break;
00527
00528 case URL_IS_UNKNOWN:
00529 if (rpmcliRootDir[0] != '/')
00530 argerror(_("arguments to --root (-r) must begin with a /"));
00531 break;
00532 }
00533 }
00534
00535 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
00536 if (0
00537 #if defined(IAM_RPMBT)
00538 || ba->sign
00539 #endif
00540 #if defined(IAM_RPMK)
00541 || ka->sign
00542 #endif
00543 )
00544
00545 {
00546 if (bigMode == MODE_REBUILD || bigMode == MODE_BUILD ||
00547 bigMode == MODE_RESIGN || bigMode == MODE_TARBUILD)
00548 {
00549 const char ** av;
00550 struct stat sb;
00551 int errors = 0;
00552
00553 if ((av = poptGetArgs(optCon)) == NULL) {
00554 fprintf(stderr, _("no files to sign\n"));
00555 errors++;
00556 } else
00557 while (*av) {
00558 if (stat(*av, &sb)) {
00559 fprintf(stderr, _("cannot access file %s\n"), *av);
00560 errors++;
00561 }
00562 av++;
00563 }
00564
00565 if (errors) {
00566 ec = errors;
00567 goto exit;
00568 }
00569
00570 if (poptPeekArg(optCon)) {
00571 int sigTag;
00572 switch (sigTag = rpmLookupSignatureType(RPMLOOKUPSIG_QUERY)) {
00573 case 0:
00574 break;
00575 case RPMSIGTAG_PGP:
00576 if ((sigTag == RPMSIGTAG_PGP || sigTag == RPMSIGTAG_PGP5) &&
00577 !rpmDetectPGPVersion(NULL)) {
00578 fprintf(stderr, _("pgp not found: "));
00579 ec = EXIT_FAILURE;
00580 goto exit;
00581 }
00582 case RPMSIGTAG_GPG:
00583 passPhrase = rpmGetPassPhrase(_("Enter pass phrase: "), sigTag);
00584 if (passPhrase == NULL) {
00585 fprintf(stderr, _("Pass phrase check failed\n"));
00586 ec = EXIT_FAILURE;
00587 goto exit;
00588 }
00589 fprintf(stderr, _("Pass phrase is good.\n"));
00590 passPhrase = xstrdup(passPhrase);
00591 break;
00592 default:
00593 fprintf(stderr,
00594 _("Invalid %%_signature spec in macro file.\n"));
00595 ec = EXIT_FAILURE;
00596 goto exit;
00597 break;
00598 }
00599 }
00600 } else {
00601 argerror(_("--sign may only be used during package building"));
00602 }
00603 } else {
00604
00605 (void) rpmLookupSignatureType(RPMLOOKUPSIG_DISABLE);
00606 }
00607
00608 #endif
00609
00610 if (rpmcliPipeOutput) {
00611 (void) pipe(p);
00612
00613 if (!(pipeChild = fork())) {
00614 (void) close(p[1]);
00615 (void) dup2(p[0], STDIN_FILENO);
00616 (void) close(p[0]);
00617 (void) execl("/bin/sh", "/bin/sh", "-c", rpmcliPipeOutput, NULL);
00618 fprintf(stderr, _("exec failed\n"));
00619 }
00620
00621 (void) close(p[0]);
00622 (void) dup2(p[1], STDOUT_FILENO);
00623 (void) close(p[1]);
00624 }
00625
00626 ts = rpmtsCreate();
00627 (void) rpmtsSetRootDir(ts, rpmcliRootDir);
00628 switch (bigMode) {
00629 #ifdef IAM_RPMDB
00630 case MODE_INITDB:
00631 (void) rpmtsInitDB(ts, 0644);
00632 break;
00633
00634 case MODE_REBUILDDB:
00635 { rpmVSFlags vsflags = rpmExpandNumeric("%{_vsflags_rebuilddb}");
00636 rpmVSFlags ovsflags = rpmtsSetVSFlags(ts, vsflags);
00637 ec = rpmtsRebuildDB(ts);
00638 vsflags = rpmtsSetVSFlags(ts, ovsflags);
00639 } break;
00640 case MODE_VERIFYDB:
00641 ec = rpmtsVerifyDB(ts);
00642 break;
00643 #endif
00644
00645 #ifdef IAM_RPMBT
00646 case MODE_REBUILD:
00647 case MODE_RECOMPILE:
00648 { const char * pkg;
00649
00650 while (!rpmIsVerbose())
00651 rpmIncreaseVerbosity();
00652
00653 if (!poptPeekArg(optCon))
00654 argerror(_("no packages files given for rebuild"));
00655
00656 ba->buildAmount =
00657 RPMBUILD_PREP | RPMBUILD_BUILD | RPMBUILD_INSTALL | RPMBUILD_CHECK;
00658 if (bigMode == MODE_REBUILD) {
00659 ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
00660 ba->buildAmount |= RPMBUILD_RMSOURCE;
00661 ba->buildAmount |= RPMBUILD_RMSPEC;
00662 ba->buildAmount |= RPMBUILD_CLEAN;
00663 ba->buildAmount |= RPMBUILD_RMBUILD;
00664 }
00665
00666 while ((pkg = poptGetArg(optCon))) {
00667 const char * specFile = NULL;
00668
00669 ba->cookie = NULL;
00670 ec = rpmInstallSource(ts, pkg, &specFile, &ba->cookie);
00671 if (ec == 0) {
00672 ba->rootdir = rpmcliRootDir;
00673 ba->passPhrase = passPhrase;
00674 ec = build(ts, specFile, ba, rpmcliRcfile);
00675 }
00676 ba->cookie = _free(ba->cookie);
00677 specFile = _free(specFile);
00678
00679 if (ec)
00680 break;
00681 }
00682
00683 } break;
00684
00685 case MODE_BUILD:
00686 case MODE_TARBUILD:
00687 { const char * pkg;
00688 while (!rpmIsVerbose())
00689 rpmIncreaseVerbosity();
00690
00691 switch (ba->buildChar) {
00692 case 'a':
00693 ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
00694
00695 case 'b':
00696 ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
00697 ba->buildAmount |= RPMBUILD_CLEAN;
00698
00699 case 'i':
00700 ba->buildAmount |= RPMBUILD_INSTALL;
00701 ba->buildAmount |= RPMBUILD_CHECK;
00702 if ((ba->buildChar == 'i') && ba->shortCircuit)
00703 break;
00704
00705 case 'c':
00706 ba->buildAmount |= RPMBUILD_BUILD;
00707 if ((ba->buildChar == 'c') && ba->shortCircuit)
00708 break;
00709
00710 case 'p':
00711 ba->buildAmount |= RPMBUILD_PREP;
00712 break;
00713
00714 case 'l':
00715 ba->buildAmount |= RPMBUILD_FILECHECK;
00716 break;
00717 case 's':
00718 ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
00719 break;
00720 }
00721
00722 if (!poptPeekArg(optCon)) {
00723 if (bigMode == MODE_BUILD)
00724 argerror(_("no spec files given for build"));
00725 else
00726 argerror(_("no tar files given for build"));
00727 }
00728
00729 while ((pkg = poptGetArg(optCon))) {
00730 ba->rootdir = rpmcliRootDir;
00731 ba->passPhrase = passPhrase;
00732 ba->cookie = NULL;
00733 ec = build(ts, pkg, ba, rpmcliRcfile);
00734 if (ec)
00735 break;
00736 rpmFreeMacros(NULL);
00737 (void) rpmReadConfigFiles(rpmcliRcfile, NULL);
00738 }
00739 } break;
00740 #endif
00741
00742 #ifdef IAM_RPMEIU
00743 case MODE_ERASE:
00744 if (ia->noDeps) ia->eraseInterfaceFlags |= UNINSTALL_NODEPS;
00745
00746 if (!poptPeekArg(optCon)) {
00747 if (ia->rbtid == 0)
00748 argerror(_("no packages given for erase"));
00749 ia->transFlags |= RPMTRANS_FLAG_NOMD5;
00750 ia->probFilter |= RPMPROB_FILTER_OLDPACKAGE;
00751 ec += rpmRollback(ts, ia, NULL);
00752 } else {
00753 ec += rpmErase(ts, ia, (const char **) poptGetArgs(optCon));
00754 }
00755 break;
00756
00757 case MODE_INSTALL:
00758
00759
00760
00761 if (!ia->incldocs) {
00762 if (ia->transFlags & RPMTRANS_FLAG_NODOCS) {
00763 ;
00764 } else if (rpmExpandNumeric("%{_excludedocs}"))
00765 ia->transFlags |= RPMTRANS_FLAG_NODOCS;
00766 }
00767
00768 if (ia->noDeps) ia->installInterfaceFlags |= INSTALL_NODEPS;
00769
00770
00771
00772 if (ia->prefix) {
00773 ia->relocations = xmalloc(2 * sizeof(*ia->relocations));
00774 ia->relocations[0].oldPath = NULL;
00775 ia->relocations[0].newPath = ia->prefix;
00776 ia->relocations[1].oldPath = NULL;
00777 ia->relocations[1].newPath = NULL;
00778 } else if (ia->relocations) {
00779 ia->relocations = xrealloc(ia->relocations,
00780 sizeof(*ia->relocations) * (ia->numRelocations + 1));
00781 ia->relocations[ia->numRelocations].oldPath = NULL;
00782 ia->relocations[ia->numRelocations].newPath = NULL;
00783 }
00784
00785
00786 if (!poptPeekArg(optCon)) {
00787 if (ia->rbtid == 0)
00788 argerror(_("no packages given for install"));
00789 ia->transFlags |= RPMTRANS_FLAG_NOMD5;
00790 ia->probFilter |= RPMPROB_FILTER_OLDPACKAGE;
00791 ec += rpmRollback(ts, ia, NULL);
00792 } else {
00793
00794 ec += rpmInstall(ts, ia, (const char **)poptGetArgs(optCon));
00795
00796 }
00797 break;
00798
00799 #endif
00800
00801 #ifdef IAM_RPMQV
00802 case MODE_QUERY:
00803 if (qva->qva_source != RPMQV_ALL && !poptPeekArg(optCon))
00804 argerror(_("no arguments given for query"));
00805
00806 qva->qva_specQuery = rpmspecQuery;
00807 ec = rpmcliQuery(ts, qva, (const char **) poptGetArgs(optCon));
00808 qva->qva_specQuery = NULL;
00809 break;
00810
00811 case MODE_VERIFY:
00812 { rpmVerifyFlags verifyFlags = VERIFY_ALL;
00813
00814 verifyFlags &= ~qva->qva_flags;
00815 qva->qva_flags = (rpmQueryFlags) verifyFlags;
00816
00817 if (qva->qva_source != RPMQV_ALL && !poptPeekArg(optCon))
00818 argerror(_("no arguments given for verify"));
00819 ec = rpmcliVerify(ts, qva, (const char **) poptGetArgs(optCon));
00820 } break;
00821 #endif
00822
00823 #ifdef IAM_RPMK
00824 case MODE_CHECKSIG:
00825 { rpmVerifyFlags verifyFlags =
00826 (VERIFY_MD5|VERIFY_DIGEST|VERIFY_SIGNATURE);
00827
00828 verifyFlags &= ~ka->qva_flags;
00829 ka->qva_flags = (rpmQueryFlags) verifyFlags;
00830 }
00831 case MODE_RESIGN:
00832 if (!poptPeekArg(optCon))
00833 argerror(_("no arguments given"));
00834 ka->passPhrase = passPhrase;
00835 ec = rpmcliSign(ts, ka, (const char **)poptGetArgs(optCon));
00836 break;
00837 #endif
00838
00839 #if !defined(IAM_RPMQV)
00840 case MODE_QUERY:
00841 case MODE_VERIFY:
00842 #endif
00843 #if !defined(IAM_RPMK)
00844 case MODE_CHECKSIG:
00845 case MODE_RESIGN:
00846 #endif
00847 #if !defined(IAM_RPMDB)
00848 case MODE_INITDB:
00849 case MODE_REBUILDDB:
00850 case MODE_VERIFYDB:
00851 #endif
00852 #if !defined(IAM_RPMBT)
00853 case MODE_BUILD:
00854 case MODE_REBUILD:
00855 case MODE_RECOMPILE:
00856 case MODE_TARBUILD:
00857 #endif
00858 #if !defined(IAM_RPMEIU)
00859 case MODE_INSTALL:
00860 case MODE_ERASE:
00861 #endif
00862 case MODE_UNKNOWN:
00863 if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) {
00864 printUsage(optCon, stdout, 0);
00865 ec = argc;
00866 }
00867 break;
00868 }
00869
00870 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
00871 exit:
00872 #endif
00873
00874 ts = rpmtsFree(ts);
00875
00876 optCon = poptFreeContext(optCon);
00877 rpmFreeMacros(NULL);
00878 rpmFreeMacros(rpmCLIMacroContext);
00879 rpmFreeRpmrc();
00880
00881 if (pipeChild) {
00882 (void) fclose(stdout);
00883 (void) waitpid(pipeChild, &status, 0);
00884 }
00885
00886
00887 freeFilesystems();
00888 urlFreeCache();
00889 rpmlogClose();
00890 dbiTags = _free(dbiTags);
00891
00892 #ifdef IAM_RPMQV
00893 qva->qva_queryFormat = _free(qva->qva_queryFormat);
00894 #endif
00895
00896 #ifdef IAM_RPMBT
00897 freeNames();
00898 ba->buildRootOverride = _free(ba->buildRootOverride);
00899 ba->targets = _free(ba->targets);
00900 #endif
00901
00902 #ifdef IAM_RPMEIU
00903 if (ia->relocations != NULL)
00904 for (i = 0; i < ia->numRelocations; i++)
00905 ia->relocations[i].oldPath = _free(ia->relocations[i].oldPath);
00906 ia->relocations = _free(ia->relocations);
00907 #endif
00908
00909 #if HAVE_MCHECK_H && HAVE_MTRACE
00910
00911 muntrace();
00912
00913 #endif
00914
00915
00916 if (ec > 255) ec = 255;
00917
00918
00919 return ec;
00920
00921 }
00922
00923