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