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