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