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 HAVE_MCHECK_H && HAVE_MTRACE
00207
00208 mtrace();
00209
00210 #endif
00211 setprogname(argv[0]);
00212
00213 #if !defined(__GLIBC__) && !defined(__LCLINT__)
00214 environ = envp;
00215 #endif
00216
00217
00218 if (__progname == NULL) {
00219 if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
00220 else __progname = argv[0];
00221 }
00222
00223
00224
00225 #ifdef IAM_RPMBT
00226 if (!strcmp(__progname, "rpmb")) bigMode = MODE_BUILD;
00227 if (!strcmp(__progname, "lt-rpmb")) bigMode = MODE_BUILD;
00228 if (!strcmp(__progname, "rpmt")) bigMode = MODE_TARBUILD;
00229 if (!strcmp(__progname, "rpmbuild")) bigMode = MODE_BUILD;
00230 #endif
00231 #ifdef IAM_RPMQV
00232 if (!strcmp(__progname, "rpmq")) bigMode = MODE_QUERY;
00233 if (!strcmp(__progname, "lt-rpmq")) bigMode = MODE_QUERY;
00234 if (!strcmp(__progname, "rpmv")) bigMode = MODE_VERIFY;
00235 if (!strcmp(__progname, "rpmquery")) bigMode = MODE_QUERY;
00236 if (!strcmp(__progname, "rpmverify")) bigMode = MODE_VERIFY;
00237 #endif
00238 #ifdef RPMEIU
00239 if (!strcmp(__progname, "rpme")) bigMode = MODE_ERASE;
00240 if (!strcmp(__progname, "rpmi")) bigMode = MODE_INSTALL;
00241 if (!strcmp(__progname, "lt-rpmi")) bigMode = MODE_INSTALL;
00242 if (!strcmp(__progname, "rpmu")) bigMode = MODE_INSTALL;
00243 #endif
00244
00245
00246 #if defined(IAM_RPMQV)
00247
00248 switch (bigMode) {
00249 case MODE_QUERY: qva->qva_mode = 'q'; break;
00250 case MODE_VERIFY: qva->qva_mode = 'V'; break;
00251 case MODE_CHECKSIG: qva->qva_mode = 'K'; break;
00252 case MODE_RESIGN: qva->qva_mode = 'R'; break;
00253 case MODE_INSTALL:
00254 case MODE_ERASE:
00255 case MODE_BUILD:
00256 case MODE_REBUILD:
00257 case MODE_RECOMPILE:
00258 case MODE_TARBUILD:
00259 case MODE_INITDB:
00260 case MODE_REBUILDDB:
00261 case MODE_VERIFYDB:
00262 case MODE_UNKNOWN:
00263 default:
00264 break;
00265 }
00266 #endif
00267
00268 #if defined(ENABLE_NLS)
00269
00270 (void) setlocale(LC_ALL, "" );
00271
00272 #ifdef __LCLINT__
00273 #define LOCALEDIR "/usr/share/locale"
00274 #endif
00275 bindtextdomain(PACKAGE, LOCALEDIR);
00276 textdomain(PACKAGE);
00277 #endif
00278
00279 if (getenv("RPM_FORCE_NPTL") != NULL) {
00280 char *threadimpl;
00281 size_t n;
00282
00283 n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, (size_t)0);
00284 if ((threadimpl = malloc(n)) == NULL) {
00285 fprintf(stderr, "unable to allocate memory\n");
00286 exit(EXIT_FAILURE);
00287 }
00288 confstr(_CS_GNU_LIBPTHREAD_VERSION, threadimpl, n);
00289
00290 if (strncasecmp(threadimpl, "nptl", 4)) {
00291 if (getenv("LD_ASSUME_KERNEL") != NULL) {
00292 setenv("OLD_LD_ASSUME_KERNEL", getenv("LD_ASSUME_KERNEL"), 1);
00293 unsetenv("LD_ASSUME_KERNEL");
00294
00295 execvp(argv[0], (char ** const) argv);
00296
00297 fprintf(stderr, "error executing %s in attempt to "
00298 "switch to NPTL: %s\n", argv[0], strerror(errno));
00299 exit(EXIT_FAILURE);
00300 } else {
00301
00302
00303 fprintf(stderr, "error: RPM_FORCE_NPTL is set, "
00304 "LD_ASSUME_KERNEL is not set, but the thread "
00305 "environment is still not NPTL\n");
00306 exit(EXIT_FAILURE);
00307 }
00308 }
00309 }
00310
00311 rpmSetVerbosity(RPMMESS_NORMAL);
00312
00313
00314
00315
00316 optCon = poptGetContext(__progname, argc, argv, optionsTable, 0);
00317
00318 (void) poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
00319 (void) poptReadDefaultConfig(optCon, 1);
00320 poptSetExecPath(optCon, RPMCONFIGDIR, 1);
00321
00322 while ((arg = poptGetNextOpt(optCon)) > 0) {
00323 optArg = poptGetOptArg(optCon);
00324
00325 switch (arg) {
00326 default:
00327 fprintf(stderr, _("Internal error in argument processing (%d) :-(\n"), arg);
00328 exit(EXIT_FAILURE);
00329 }
00330 }
00331
00332 if (arg < -1) {
00333 fprintf(stderr, "%s: %s\n",
00334 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
00335 poptStrerror(arg));
00336 exit(EXIT_FAILURE);
00337 }
00338
00339 rpmcliConfigured();
00340
00341 #ifdef IAM_RPMBT
00342 switch (ba->buildMode) {
00343 case 'b': bigMode = MODE_BUILD; break;
00344 case 't': bigMode = MODE_TARBUILD; break;
00345 case 'B': bigMode = MODE_REBUILD; break;
00346 case 'C': bigMode = MODE_RECOMPILE; break;
00347 }
00348
00349 if ((ba->buildAmount & RPMBUILD_RMSOURCE) && bigMode == MODE_UNKNOWN)
00350 bigMode = MODE_BUILD;
00351
00352 if ((ba->buildAmount & RPMBUILD_RMSPEC) && bigMode == MODE_UNKNOWN)
00353 bigMode = MODE_BUILD;
00354
00355 if (ba->buildRootOverride && bigMode != MODE_BUILD &&
00356 bigMode != MODE_REBUILD && bigMode != MODE_TARBUILD) {
00357 argerror("--buildroot may only be used during package builds");
00358 }
00359 #endif
00360
00361 #ifdef IAM_RPMDB
00362 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_DB)) {
00363 if (da->init) {
00364 if (bigMode != MODE_UNKNOWN)
00365 argerror(_("only one major mode may be specified"));
00366 else
00367 bigMode = MODE_INITDB;
00368 } else
00369 if (da->rebuild) {
00370 if (bigMode != MODE_UNKNOWN)
00371 argerror(_("only one major mode may be specified"));
00372 else
00373 bigMode = MODE_REBUILDDB;
00374 } else
00375 if (da->verify) {
00376 if (bigMode != MODE_UNKNOWN)
00377 argerror(_("only one major mode may be specified"));
00378 else
00379 bigMode = MODE_VERIFYDB;
00380 }
00381 }
00382 #endif
00383
00384 #ifdef IAM_RPMQV
00385 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_QV)) {
00386 switch (qva->qva_mode) {
00387 case 'q': bigMode = MODE_QUERY; break;
00388 case 'V': bigMode = MODE_VERIFY; break;
00389 }
00390
00391 if (qva->qva_sourceCount) {
00392 if (qva->qva_sourceCount > 2)
00393 argerror(_("one type of query/verify may be performed at a "
00394 "time"));
00395 }
00396 if (qva->qva_flags && (bigMode & ~MODES_QV))
00397 argerror(_("unexpected query flags"));
00398
00399 if (qva->qva_queryFormat && (bigMode & ~MODES_QV))
00400 argerror(_("unexpected query format"));
00401
00402 if (qva->qva_source != RPMQV_PACKAGE && (bigMode & ~MODES_QV))
00403 argerror(_("unexpected query source"));
00404 }
00405 #endif
00406
00407 #ifdef IAM_RPMEIU
00408 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_IE))
00409 { int iflags = (ia->installInterfaceFlags &
00410 (INSTALL_UPGRADE|INSTALL_FRESHEN|INSTALL_INSTALL));
00411 int eflags = (ia->installInterfaceFlags & INSTALL_ERASE);
00412
00413 if (iflags & eflags)
00414 argerror(_("only one major mode may be specified"));
00415 else if (iflags)
00416 bigMode = MODE_INSTALL;
00417 else if (eflags)
00418 bigMode = MODE_ERASE;
00419 }
00420 #endif
00421
00422 #ifdef IAM_RPMK
00423 if (bigMode == MODE_UNKNOWN || (bigMode & MODES_K)) {
00424 switch (ka->qva_mode) {
00425 case RPMSIGN_NONE:
00426 ka->sign = 0;
00427 break;
00428 case RPMSIGN_IMPORT_PUBKEY:
00429 case RPMSIGN_CHK_SIGNATURE:
00430 bigMode = MODE_CHECKSIG;
00431 ka->sign = 0;
00432 break;
00433 case RPMSIGN_ADD_SIGNATURE:
00434 case RPMSIGN_NEW_SIGNATURE:
00435 bigMode = MODE_RESIGN;
00436 ka->sign = 1;
00437 break;
00438 }
00439 }
00440 #endif
00441
00442 #if defined(IAM_RPMEIU)
00443 if (!( bigMode == MODE_INSTALL ) &&
00444 (ia->probFilter & (RPMPROB_FILTER_REPLACEPKG | RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES | RPMPROB_FILTER_OLDPACKAGE)))
00445 argerror(_("only installation, upgrading, rmsource and rmspec may be forced"));
00446 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_FORCERELOCATE))
00447 argerror(_("files may only be relocated during package installation"));
00448
00449 if (ia->relocations && ia->prefix)
00450 argerror(_("cannot use --prefix with --relocate or --excludepath"));
00451
00452 if (bigMode != MODE_INSTALL && ia->relocations)
00453 argerror(_("--relocate and --excludepath may only be used when installing new packages"));
00454
00455 if (bigMode != MODE_INSTALL && ia->prefix)
00456 argerror(_("--prefix may only be used when installing new packages"));
00457
00458 if (ia->prefix && ia->prefix[0] != '/')
00459 argerror(_("arguments to --prefix must begin with a /"));
00460
00461 if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_HASH))
00462 argerror(_("--hash (-h) may only be specified during package "
00463 "installation"));
00464
00465 if (bigMode != MODE_INSTALL && (ia->installInterfaceFlags & INSTALL_PERCENT))
00466 argerror(_("--percent may only be specified during package "
00467 "installation"));
00468
00469 if (bigMode != MODE_INSTALL &&
00470 (ia->probFilter & (RPMPROB_FILTER_REPLACEOLDFILES|RPMPROB_FILTER_REPLACENEWFILES)))
00471 argerror(_("--replacefiles may only be specified during package "
00472 "installation"));
00473
00474 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_REPLACEPKG))
00475 argerror(_("--replacepkgs may only be specified during package "
00476 "installation"));
00477
00478 if (bigMode != MODE_INSTALL && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
00479 argerror(_("--excludedocs may only be specified during package "
00480 "installation"));
00481
00482 if (bigMode != MODE_INSTALL && ia->incldocs)
00483 argerror(_("--includedocs may only be specified during package "
00484 "installation"));
00485
00486 if (ia->incldocs && (ia->transFlags & RPMTRANS_FLAG_NODOCS))
00487 argerror(_("only one of --excludedocs and --includedocs may be "
00488 "specified"));
00489
00490 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREARCH))
00491 argerror(_("--ignorearch may only be specified during package "
00492 "installation"));
00493
00494 if (bigMode != MODE_INSTALL && (ia->probFilter & RPMPROB_FILTER_IGNOREOS))
00495 argerror(_("--ignoreos may only be specified during package "
00496 "installation"));
00497
00498 if (bigMode != MODE_INSTALL &&
00499 (ia->probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES)))
00500 argerror(_("--ignoresize may only be specified during package "
00501 "installation"));
00502
00503 if ((ia->eraseInterfaceFlags & UNINSTALL_ALLMATCHES) && bigMode != MODE_ERASE)
00504 argerror(_("--allmatches may only be specified during package "
00505 "erasure"));
00506
00507 if ((ia->transFlags & RPMTRANS_FLAG_ALLFILES) && bigMode != MODE_INSTALL)
00508 argerror(_("--allfiles may only be specified during package "
00509 "installation"));
00510
00511 if ((ia->transFlags & RPMTRANS_FLAG_JUSTDB) &&
00512 bigMode != MODE_INSTALL && bigMode != MODE_ERASE)
00513 argerror(_("--justdb may only be specified during package "
00514 "installation and erasure"));
00515
00516 if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
00517 (ia->transFlags & (RPMTRANS_FLAG_NOSCRIPTS | _noTransScripts | _noTransTriggers)))
00518 argerror(_("script disabling options may only be specified during "
00519 "package installation and erasure"));
00520
00521 if (bigMode != MODE_INSTALL && bigMode != MODE_ERASE &&
00522 (ia->transFlags & (RPMTRANS_FLAG_NOTRIGGERS | _noTransTriggers)))
00523 argerror(_("trigger disabling options may only be specified during "
00524 "package installation and erasure"));
00525
00526 if (ia->noDeps & (bigMode & ~MODES_FOR_NODEPS))
00527 argerror(_("--nodeps may only be specified during package "
00528 "building, rebuilding, recompilation, installation,"
00529 "erasure, and verification"));
00530
00531 if ((ia->transFlags & RPMTRANS_FLAG_TEST) && (bigMode & ~MODES_FOR_TEST))
00532 argerror(_("--test may only be specified during package installation, "
00533 "erasure, and building"));
00534 #endif
00535
00536 if (rpmcliRootDir && rpmcliRootDir[1] && (bigMode & ~MODES_FOR_ROOT))
00537 argerror(_("--root (-r) may only be specified during "
00538 "installation, erasure, querying, and "
00539 "database rebuilds"));
00540
00541 if (rpmcliRootDir) {
00542 switch (urlIsURL(rpmcliRootDir)) {
00543 default:
00544 if (bigMode & MODES_FOR_ROOT)
00545 break;
00546
00547 case URL_IS_UNKNOWN:
00548 if (rpmcliRootDir[0] != '/')
00549 argerror(_("arguments to --root (-r) must begin with a /"));
00550 break;
00551 }
00552 }
00553
00554 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
00555 if (0
00556 #if defined(IAM_RPMBT)
00557 || ba->sign
00558 #endif
00559 #if defined(IAM_RPMK)
00560 || ka->sign
00561 #endif
00562 )
00563
00564 {
00565 if (bigMode == MODE_REBUILD || bigMode == MODE_BUILD ||
00566 bigMode == MODE_RESIGN || bigMode == MODE_TARBUILD)
00567 {
00568 const char ** av;
00569 struct stat sb;
00570 int errors = 0;
00571
00572 if ((av = poptGetArgs(optCon)) == NULL) {
00573 fprintf(stderr, _("no files to sign\n"));
00574 errors++;
00575 } else
00576 while (*av) {
00577 if (stat(*av, &sb)) {
00578 fprintf(stderr, _("cannot access file %s\n"), *av);
00579 errors++;
00580 }
00581 av++;
00582 }
00583
00584 if (errors) {
00585 ec = errors;
00586 goto exit;
00587 }
00588
00589 if (poptPeekArg(optCon)) {
00590 int sigTag;
00591 switch (sigTag = rpmLookupSignatureType(RPMLOOKUPSIG_QUERY)) {
00592 case 0:
00593 break;
00594 case RPMSIGTAG_PGP:
00595 if ((sigTag == RPMSIGTAG_PGP || sigTag == RPMSIGTAG_PGP5) &&
00596 !rpmDetectPGPVersion(NULL)) {
00597 fprintf(stderr, _("pgp not found: "));
00598 ec = EXIT_FAILURE;
00599 goto exit;
00600 }
00601 case RPMSIGTAG_GPG:
00602 passPhrase = rpmGetPassPhrase(_("Enter pass phrase: "), sigTag);
00603 if (passPhrase == NULL) {
00604 fprintf(stderr, _("Pass phrase check failed\n"));
00605 ec = EXIT_FAILURE;
00606 goto exit;
00607 }
00608 fprintf(stderr, _("Pass phrase is good.\n"));
00609 passPhrase = xstrdup(passPhrase);
00610 break;
00611 default:
00612 fprintf(stderr,
00613 _("Invalid %%_signature spec in macro file.\n"));
00614 ec = EXIT_FAILURE;
00615 goto exit;
00616 break;
00617 }
00618 }
00619 } else {
00620 argerror(_("--sign may only be used during package building"));
00621 }
00622 } else {
00623
00624 (void) rpmLookupSignatureType(RPMLOOKUPSIG_DISABLE);
00625 }
00626
00627 #endif
00628
00629 if (rpmcliPipeOutput) {
00630 (void) pipe(p);
00631
00632 if (!(pipeChild = fork())) {
00633 (void) close(p[1]);
00634 (void) dup2(p[0], STDIN_FILENO);
00635 (void) close(p[0]);
00636 (void) execl("/bin/sh", "/bin/sh", "-c", rpmcliPipeOutput, NULL);
00637 fprintf(stderr, _("exec failed\n"));
00638 }
00639
00640 (void) close(p[0]);
00641 (void) dup2(p[1], STDOUT_FILENO);
00642 (void) close(p[1]);
00643 }
00644
00645 ts = rpmtsCreate();
00646 (void) rpmtsSetRootDir(ts, rpmcliRootDir);
00647 switch (bigMode) {
00648 #ifdef IAM_RPMDB
00649 case MODE_INITDB:
00650 (void) rpmtsInitDB(ts, 0644);
00651 break;
00652
00653 case MODE_REBUILDDB:
00654 { rpmVSFlags vsflags = rpmExpandNumeric("%{_vsflags_rebuilddb}");
00655 rpmVSFlags ovsflags = rpmtsSetVSFlags(ts, vsflags);
00656 ec = rpmtsRebuildDB(ts);
00657 vsflags = rpmtsSetVSFlags(ts, ovsflags);
00658 } break;
00659 case MODE_VERIFYDB:
00660 ec = rpmtsVerifyDB(ts);
00661 break;
00662 #endif
00663
00664 #ifdef IAM_RPMBT
00665 case MODE_REBUILD:
00666 case MODE_RECOMPILE:
00667 { const char * pkg;
00668
00669 while (!rpmIsVerbose())
00670 rpmIncreaseVerbosity();
00671
00672 if (!poptPeekArg(optCon))
00673 argerror(_("no packages files given for rebuild"));
00674
00675 ba->buildAmount =
00676 RPMBUILD_PREP | RPMBUILD_BUILD | RPMBUILD_INSTALL | RPMBUILD_CHECK;
00677 if (bigMode == MODE_REBUILD) {
00678 ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
00679 ba->buildAmount |= RPMBUILD_RMSOURCE;
00680 ba->buildAmount |= RPMBUILD_RMSPEC;
00681 ba->buildAmount |= RPMBUILD_CLEAN;
00682 ba->buildAmount |= RPMBUILD_RMBUILD;
00683 }
00684
00685 while ((pkg = poptGetArg(optCon))) {
00686 const char * specFile = NULL;
00687
00688 ba->cookie = NULL;
00689 ec = rpmInstallSource(ts, pkg, &specFile, &ba->cookie);
00690 if (ec == 0) {
00691 ba->rootdir = rpmcliRootDir;
00692 ba->passPhrase = passPhrase;
00693 ec = build(ts, specFile, ba, rpmcliRcfile);
00694 }
00695 ba->cookie = _free(ba->cookie);
00696 specFile = _free(specFile);
00697
00698 if (ec)
00699 break;
00700 }
00701
00702 } break;
00703
00704 case MODE_BUILD:
00705 case MODE_TARBUILD:
00706 { const char * pkg;
00707 while (!rpmIsVerbose())
00708 rpmIncreaseVerbosity();
00709
00710 switch (ba->buildChar) {
00711 case 'a':
00712 ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
00713
00714 case 'b':
00715 ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
00716 ba->buildAmount |= RPMBUILD_CLEAN;
00717
00718 case 'i':
00719 ba->buildAmount |= RPMBUILD_INSTALL;
00720 ba->buildAmount |= RPMBUILD_CHECK;
00721 if ((ba->buildChar == 'i') && ba->shortCircuit)
00722 break;
00723
00724 case 'c':
00725 ba->buildAmount |= RPMBUILD_BUILD;
00726 if ((ba->buildChar == 'c') && ba->shortCircuit)
00727 break;
00728
00729 case 'p':
00730 ba->buildAmount |= RPMBUILD_PREP;
00731 break;
00732
00733 case 'l':
00734 ba->buildAmount |= RPMBUILD_FILECHECK;
00735 break;
00736 case 's':
00737 ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
00738 break;
00739 }
00740
00741 if (!poptPeekArg(optCon)) {
00742 if (bigMode == MODE_BUILD)
00743 argerror(_("no spec files given for build"));
00744 else
00745 argerror(_("no tar files given for build"));
00746 }
00747
00748 while ((pkg = poptGetArg(optCon))) {
00749 ba->rootdir = rpmcliRootDir;
00750 ba->passPhrase = passPhrase;
00751 ba->cookie = NULL;
00752 ec = build(ts, pkg, ba, rpmcliRcfile);
00753 if (ec)
00754 break;
00755 rpmFreeMacros(NULL);
00756 (void) rpmReadConfigFiles(rpmcliRcfile, NULL);
00757 }
00758 } break;
00759 #endif
00760
00761 #ifdef IAM_RPMEIU
00762 case MODE_ERASE:
00763 if (ia->noDeps) ia->eraseInterfaceFlags |= UNINSTALL_NODEPS;
00764
00765 if (!poptPeekArg(optCon)) {
00766 if (ia->rbtid == 0)
00767 argerror(_("no packages given for erase"));
00768 ia->transFlags |= RPMTRANS_FLAG_NOMD5;
00769 ia->probFilter |= RPMPROB_FILTER_OLDPACKAGE;
00770 ec += rpmRollback(ts, ia, NULL);
00771 } else {
00772 ec += rpmErase(ts, ia, (const char **) poptGetArgs(optCon));
00773 }
00774 break;
00775
00776 case MODE_INSTALL:
00777
00778
00779
00780 if (!ia->incldocs) {
00781 if (ia->transFlags & RPMTRANS_FLAG_NODOCS) {
00782 ;
00783 } else if (rpmExpandNumeric("%{_excludedocs}"))
00784 ia->transFlags |= RPMTRANS_FLAG_NODOCS;
00785 }
00786
00787 if (ia->noDeps) ia->installInterfaceFlags |= INSTALL_NODEPS;
00788
00789
00790
00791 if (ia->prefix) {
00792 ia->relocations = xmalloc(2 * sizeof(*ia->relocations));
00793 ia->relocations[0].oldPath = NULL;
00794 ia->relocations[0].newPath = ia->prefix;
00795 ia->relocations[1].oldPath = NULL;
00796 ia->relocations[1].newPath = NULL;
00797 } else if (ia->relocations) {
00798 ia->relocations = xrealloc(ia->relocations,
00799 sizeof(*ia->relocations) * (ia->numRelocations + 1));
00800 ia->relocations[ia->numRelocations].oldPath = NULL;
00801 ia->relocations[ia->numRelocations].newPath = NULL;
00802 }
00803
00804
00805 if (!poptPeekArg(optCon)) {
00806 if (ia->rbtid == 0)
00807 argerror(_("no packages given for install"));
00808 ia->transFlags |= RPMTRANS_FLAG_NOMD5;
00809 ia->probFilter |= RPMPROB_FILTER_OLDPACKAGE;
00810 ec += rpmRollback(ts, ia, NULL);
00811 } else {
00812
00813 ec += rpmInstall(ts, ia, (const char **)poptGetArgs(optCon));
00814
00815 }
00816 break;
00817
00818 #endif
00819
00820 #ifdef IAM_RPMQV
00821 case MODE_QUERY:
00822 if (qva->qva_source != RPMQV_ALL && !poptPeekArg(optCon))
00823 argerror(_("no arguments given for query"));
00824
00825 qva->qva_specQuery = rpmspecQuery;
00826 ec = rpmcliQuery(ts, qva, (const char **) poptGetArgs(optCon));
00827 qva->qva_specQuery = NULL;
00828 break;
00829
00830 case MODE_VERIFY:
00831 { rpmVerifyFlags verifyFlags = VERIFY_ALL;
00832
00833 verifyFlags &= ~qva->qva_flags;
00834 qva->qva_flags = (rpmQueryFlags) verifyFlags;
00835
00836 if (qva->qva_source != RPMQV_ALL && !poptPeekArg(optCon))
00837 argerror(_("no arguments given for verify"));
00838 ec = rpmcliVerify(ts, qva, (const char **) poptGetArgs(optCon));
00839 } break;
00840 #endif
00841
00842 #ifdef IAM_RPMK
00843 case MODE_CHECKSIG:
00844 { rpmVerifyFlags verifyFlags =
00845 (VERIFY_MD5|VERIFY_DIGEST|VERIFY_SIGNATURE);
00846
00847 verifyFlags &= ~ka->qva_flags;
00848 ka->qva_flags = (rpmQueryFlags) verifyFlags;
00849 }
00850 case MODE_RESIGN:
00851 if (!poptPeekArg(optCon))
00852 argerror(_("no arguments given"));
00853 ka->passPhrase = passPhrase;
00854 ec = rpmcliSign(ts, ka, (const char **)poptGetArgs(optCon));
00855 break;
00856 #endif
00857
00858 #if !defined(IAM_RPMQV)
00859 case MODE_QUERY:
00860 case MODE_VERIFY:
00861 #endif
00862 #if !defined(IAM_RPMK)
00863 case MODE_CHECKSIG:
00864 case MODE_RESIGN:
00865 #endif
00866 #if !defined(IAM_RPMDB)
00867 case MODE_INITDB:
00868 case MODE_REBUILDDB:
00869 case MODE_VERIFYDB:
00870 #endif
00871 #if !defined(IAM_RPMBT)
00872 case MODE_BUILD:
00873 case MODE_REBUILD:
00874 case MODE_RECOMPILE:
00875 case MODE_TARBUILD:
00876 #endif
00877 #if !defined(IAM_RPMEIU)
00878 case MODE_INSTALL:
00879 case MODE_ERASE:
00880 #endif
00881 case MODE_UNKNOWN:
00882 if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) {
00883 printUsage(optCon, stdout, 0);
00884 ec = argc;
00885 }
00886 break;
00887 }
00888
00889 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
00890 exit:
00891 #endif
00892
00893 ts = rpmtsFree(ts);
00894
00895 optCon = poptFreeContext(optCon);
00896 rpmFreeMacros(NULL);
00897 rpmFreeMacros(rpmCLIMacroContext);
00898 rpmFreeRpmrc();
00899
00900 if (pipeChild) {
00901 (void) fclose(stdout);
00902 (void) waitpid(pipeChild, &status, 0);
00903 }
00904
00905
00906 freeFilesystems();
00907 urlFreeCache();
00908 rpmlogClose();
00909 dbiTags = _free(dbiTags);
00910
00911 #ifdef IAM_RPMQV
00912 qva->qva_queryFormat = _free(qva->qva_queryFormat);
00913 #endif
00914
00915 #ifdef IAM_RPMBT
00916 freeNames();
00917 ba->buildRootOverride = _free(ba->buildRootOverride);
00918 ba->targets = _free(ba->targets);
00919 #endif
00920
00921 #ifdef IAM_RPMEIU
00922 if (ia->relocations != NULL)
00923 for (i = 0; i < ia->numRelocations; i++)
00924 ia->relocations[i].oldPath = _free(ia->relocations[i].oldPath);
00925 ia->relocations = _free(ia->relocations);
00926 #endif
00927
00928 #if HAVE_MCHECK_H && HAVE_MTRACE
00929
00930 muntrace();
00931
00932 #endif
00933
00934
00935 if (ec > 255) ec = 255;
00936
00937
00938 return ec;
00939
00940 }
00941
00942