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