Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

rpmqv.c

Go to the documentation of this file.
00001 #include "system.h"
00002 
00003 #define _AUTOHELP
00004 
00005 #if defined(IAM_RPM)
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 <rpmbuild.h>
00014 #include <rpmurl.h>
00015 
00016 #ifdef  IAM_RPMBT
00017 #include "build.h"
00018 #define GETOPT_REBUILD          1003
00019 #define GETOPT_RECOMPILE        1004
00020 #endif
00021 
00022 #ifdef  IAM_RPMDB
00023 #define GETOPT_REBUILDDB        1013
00024 static int initdb = 0;
00025 #endif
00026 
00027 #ifdef  IAM_RPMEIU
00028 #define GETOPT_INSTALL          1014
00029 #define GETOPT_RELOCATE         1016
00030 #define GETOPT_EXCLUDEPATH      1019
00031 static int incldocs = 0;
00032 static char * prefix = NULL;
00033 #endif  /* IAM_RPMEIU */
00034 
00035 #ifdef  IAM_RPMK
00036 #define GETOPT_ADDSIGN          1005
00037 #define GETOPT_RESIGN           1006
00038 static int noGpg = 0;
00039 static int noPgp = 0;
00040 #endif  /* IAM_RPMK */
00041 
00042 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
00043 #include "signature.h"
00044 #endif
00045 
00046 #include "debug.h"
00047 
00048 #define GETOPT_DBPATH           1010
00049 #define GETOPT_SHOWRC           1018
00050 #define GETOPT_DEFINEMACRO      1020
00051 #define GETOPT_EVALMACRO        1021
00052 #define GETOPT_RCFILE           1022
00053 
00054 enum modes {
00055 
00056     MODE_QUERY          = (1 <<  0),
00057     MODE_VERIFY         = (1 <<  3),
00058     MODE_QUERYTAGS      = (1 <<  9),
00059 #define MODES_QV (MODE_QUERY | MODE_VERIFY)
00060 
00061     MODE_INSTALL        = (1 <<  1),
00062     MODE_UNINSTALL      = (1 <<  2),
00063 #define MODES_IE (MODE_INSTALL | MODE_UNINSTALL)
00064 
00065     MODE_BUILD          = (1 <<  4),
00066     MODE_REBUILD        = (1 <<  5),
00067     MODE_RECOMPILE      = (1 <<  8),
00068     MODE_TARBUILD       = (1 << 11),
00069 #define MODES_BT (MODE_BUILD | MODE_TARBUILD | MODE_REBUILD | MODE_RECOMPILE)
00070 
00071     MODE_CHECKSIG       = (1 <<  6),
00072     MODE_RESIGN         = (1 <<  7),
00073 #define MODES_K  (MODE_CHECKSIG | MODES_RESIGN)
00074 
00075     MODE_INITDB         = (1 << 10),
00076     MODE_REBUILDDB      = (1 << 12),
00077 #define MODES_DB (MODE_INITDB | MODE_REBUILDDB)
00078 
00079     MODE_UNKNOWN        = 0
00080 };
00081 
00082 #define MODES_FOR_DBPATH        (MODES_BT | MODES_IE | MODES_QV | MODES_DB)
00083 #define MODES_FOR_NODEPS        (MODES_BT | MODES_IE | MODE_VERIFY)
00084 #define MODES_FOR_TEST          (MODES_BT | MODES_IE)
00085 #define MODES_FOR_ROOT          (MODES_BT | MODES_IE | MODES_QV | MODES_DB)
00086 
00087 extern int _ftp_debug;
00088 extern int noLibio;
00089 extern int _rpmio_debug;
00090 extern int _url_debug;
00091 extern int _noDirTokens;
00092 
00093 extern const char * rpmNAME;
00094 extern const char * rpmEVR;
00095 extern int rpmFLAGS;
00096 
00097 extern MacroContext rpmCLIMacroContext;
00098 
00099 /* options for all executables */
00100 
00101 static int help = 0;
00102 static int noUsageMsg = 0;
00103 static char * pipeOutput = NULL;
00104 static int quiet = 0;
00105 static char * rcfile = NULL;
00106 static char * rootdir = "/";
00107 static int showrc = 0;
00108 static int showVersion = 0;
00109 
00110 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
00111 static int signIt = 0;
00112 #endif  /* IAM_RPMBT || IAM_RPMK */
00113 
00114 #if defined(IAM_RPMQV) || defined(IAM_RPMK)
00115 static int noMd5 = 0;
00116 #endif
00117 
00118 #if defined(IAM_RPMEIU)
00119 static int noDeps = 0;
00120 #endif
00121 
00122 #if defined(IAM_RPMEIU)
00123 static int force = 0;
00124 #endif
00125 
00126 static struct poptOption rpmAllPoptTable[] = {
00127  { "version", '\0', 0, &showVersion, 0,
00128         N_("print the version of rpm being used"),
00129         NULL },
00130  { "quiet", '\0', 0, &quiet, 0,
00131         N_("provide less detailed output"), NULL},
00132  { "verbose", 'v', 0, 0, 'v',
00133         N_("provide more detailed output"), NULL},
00134  { "define", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, 0, GETOPT_DEFINEMACRO,
00135         N_("define macro <name> with value <body>"),
00136         N_("'<name> <body>'") },
00137  { "eval", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, 0, GETOPT_EVALMACRO,
00138         N_("print macro expansion of <expr>+"),
00139         N_("<expr>+") },
00140  { "pipe", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, &pipeOutput, 0,
00141         N_("send stdout to <cmd>"),
00142         N_("<cmd>") },
00143  { "root", 'r', POPT_ARG_STRING, &rootdir, 0,
00144         N_("use <dir> as the top level directory"),
00145         N_("<dir>") },
00146  { "macros", '\0', POPT_ARG_STRING, &macrofiles, 0,
00147         N_("read <file:...> instead of default macro file(s)"),
00148         N_("<file:...>") },
00149 #ifndef DYING
00150  { "rcfile", '\0', POPT_ARG_STRING, &rcfile, 0,
00151         N_("read <file:...> instead of default rpmrc file(s)"),
00152         N_("<file:...>") },
00153 #else
00154  { "rcfile", '\0', 0, 0, GETOPT_RCFILE, 
00155         N_("read <file:...> instead of default rpmrc file(s)"),
00156         N_("<file:...>") },
00157 #endif
00158  { "showrc", '\0', 0, &showrc, GETOPT_SHOWRC,
00159         N_("display final rpmrc and macro configuration"),
00160         NULL },
00161 
00162 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
00163  { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
00164         N_("disable use of libio(3) API"), NULL},
00165 #endif
00166  { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
00167         N_("debug protocol data stream"), NULL},
00168  { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
00169         N_("debug rpmio I/O"), NULL},
00170  { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
00171         N_("debug URL cache handling"), NULL},
00172 
00173    POPT_TABLEEND
00174 };
00175 
00176 #ifdef  IAM_RPMDB
00177 static struct poptOption rpmDatabasePoptTable[] = {
00178  { "initdb", '\0', 0, &initdb, 0,
00179         N_("initialize database"), NULL},
00180  { "rebuilddb", '\0', 0, 0, GETOPT_REBUILDDB,
00181         N_("rebuild database inverted lists from installed package headers"),
00182         NULL},
00183  { "nodirtokens", '\0', POPT_ARG_VAL, &_noDirTokens, 1,
00184         N_("generate headers compatible with (legacy) rpm[23] packaging"),
00185         NULL},
00186  { "dirtokens", '\0', POPT_ARG_VAL, &_noDirTokens, 0,
00187         N_("generate headers compatible with rpm4 packaging"), NULL},
00188 
00189    POPT_TABLEEND
00190 };
00191 #endif  /* IAM_RPMDB */
00192 
00193 #ifdef  IAM_RPMK
00194 static struct poptOption rpmSignPoptTable[] = {
00195  { "addsign", '\0', 0, 0, GETOPT_ADDSIGN,
00196         N_("add a signature to a package"), NULL },
00197  { "resign", '\0', 0, 0, GETOPT_RESIGN,
00198         N_("sign a package (discard current signature)"), NULL },
00199  { "sign", '\0', 0, &signIt, 0,
00200         N_("generate PGP/GPG signature"), NULL },
00201  { "checksig", 'K', 0, 0, 'K',
00202         N_("verify package signature"), NULL },
00203  { "nogpg", '\0', 0, &noGpg, 0,
00204         N_("skip any PGP signatures"), NULL },
00205  { "nopgp", '\0', 0, &noPgp, 0,
00206         N_("skip any GPG signatures"), NULL },
00207  { "nomd5", '\0', 0, &noMd5, 0,
00208         N_("do not verify file md5 checksums"), NULL },
00209 
00210    POPT_TABLEEND
00211 };
00212 #endif  /* IAM_RPMK */
00213 
00214 #ifdef  IAM_RPMEIU
00215 static rpmtransFlags transFlags = RPMTRANS_FLAG_NONE;
00216 static rpmprobFilterFlags probFilter = RPMPROB_FILTER_NONE;
00217 static rpmInstallInterfaceFlags installInterfaceFlags = INSTALL_NONE;
00218 static rpmEraseInterfaceFlags eraseInterfaceFlags = UNINSTALL_NONE;
00219 
00220 #define _POPT_SET_BIT   (POPT_ARG_VAL|POPT_ARGFLAG_OR)
00221 
00222 static struct poptOption rpmInstallPoptTable[] = {
00223  { "allfiles", '\0', _POPT_SET_BIT, &transFlags, RPMTRANS_FLAG_ALLFILES,
00224   N_("install all files, even configurations which might otherwise be skipped"),
00225         NULL},
00226  { "allmatches", '\0', _POPT_SET_BIT, &eraseInterfaceFlags, UNINSTALL_ALLMATCHES,
00227         N_("remove all packages which match <package> (normally an error is generated if <package> specified multiple packages)"),
00228         NULL},
00229 
00230  { "apply", '\0', _POPT_SET_BIT, &transFlags,
00231         (_noTransScripts|_noTransTriggers|
00232                 RPMTRANS_FLAG_APPLYONLY|RPMTRANS_FLAG_PKGCOMMIT),
00233         N_("do not execute package scriptlet(s)"), NULL },
00234 
00235  { "badreloc", '\0', _POPT_SET_BIT, &probFilter, RPMPROB_FILTER_FORCERELOCATE,
00236         N_("relocate files in non-relocateable package"), NULL},
00237  { "dirstash", '\0', _POPT_SET_BIT, &transFlags, RPMTRANS_FLAG_DIRSTASH,
00238         N_("save erased package files by renaming into sub-directory"), NULL},
00239  { "erase", 'e', 0, 0, 'e',
00240         N_("erase (uninstall) package"), N_("<package>+") },
00241  { "excludedocs", '\0', _POPT_SET_BIT, &transFlags, RPMTRANS_FLAG_NODOCS,
00242         N_("do not install documentation"), NULL},
00243  { "excludepath", '\0', POPT_ARG_STRING, 0, GETOPT_EXCLUDEPATH,
00244         N_("skip files with leading component <path> "),
00245         N_("<path>") },
00246  { "force", '\0', 0, &force, 0,
00247         N_("short hand for --replacepkgs --replacefiles"), NULL},
00248  { "freshen", 'F', _POPT_SET_BIT, &installInterfaceFlags,
00249         (INSTALL_UPGRADE|INSTALL_FRESHEN),
00250         N_("upgrade package(s) if already installed"),
00251         N_("<packagefile>+") },
00252  { "hash", 'h', _POPT_SET_BIT, &installInterfaceFlags, INSTALL_HASH,
00253         N_("print hash marks as package installs (good with -v)"), NULL},
00254  { "ignorearch", '\0', _POPT_SET_BIT, &probFilter, RPMPROB_FILTER_IGNOREARCH,
00255         N_("don't verify package architecture"), NULL},
00256  { "ignoreos", '\0', _POPT_SET_BIT, &probFilter, RPMPROB_FILTER_IGNOREOS,
00257         N_("don't verify package operating system"), NULL},
00258  { "ignoresize", '\0', _POPT_SET_BIT, &probFilter,
00259         (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES),
00260         N_("don't check disk space before installing"), NULL},
00261  { "includedocs", '\0', 0, &incldocs, 0,
00262         N_("install documentation"), NULL},
00263  { "install", '\0', 0, 0, GETOPT_INSTALL,
00264         N_("install package"), N_("<packagefile>+") },
00265  { "justdb", '\0', _POPT_SET_BIT, &transFlags, RPMTRANS_FLAG_JUSTDB,
00266         N_("update the database, but do not modify the filesystem"), NULL},
00267  { "nodeps", '\0', 0, &noDeps, 0,
00268         N_("do not verify package dependencies"), NULL },
00269  { "noorder", '\0', _POPT_SET_BIT, &installInterfaceFlags, INSTALL_NOORDER,
00270         N_("do not reorder package installation to satisfy dependencies"),
00271         NULL},
00272 
00273  { "noscripts", '\0', _POPT_SET_BIT, &transFlags,
00274         (_noTransScripts|_noTransTriggers),
00275         N_("do not execute package scriptlet(s)"), NULL },
00276  { "nopre", '\0', _POPT_SET_BIT|POPT_ARGFLAG_DOC_HIDDEN, &transFlags,
00277         RPMTRANS_FLAG_NOPRE,
00278         N_("do not execute %%pre scriptlet (if any)"), NULL },
00279  { "nopost", '\0', _POPT_SET_BIT|POPT_ARGFLAG_DOC_HIDDEN, &transFlags,
00280         RPMTRANS_FLAG_NOPOST,
00281         N_("do not execute %%post scriptlet (if any)"), NULL },
00282  { "nopreun", '\0', _POPT_SET_BIT|POPT_ARGFLAG_DOC_HIDDEN, &transFlags,
00283         RPMTRANS_FLAG_NOPREUN,
00284         N_("do not execute %%preun scriptlet (if any)"), NULL },
00285  { "nopostun", '\0', _POPT_SET_BIT|POPT_ARGFLAG_DOC_HIDDEN, &transFlags,
00286         RPMTRANS_FLAG_NOPOSTUN,
00287         N_("do not execute %%postun scriptlet (if any)"), NULL },
00288 
00289  { "notriggers", '\0', _POPT_SET_BIT, &transFlags,
00290         _noTransTriggers,
00291         N_("do not execute any scriptlet(s) triggered by this package"), NULL},
00292  { "notriggerprein", '\0', _POPT_SET_BIT|POPT_ARGFLAG_DOC_HIDDEN, &transFlags,
00293         RPMTRANS_FLAG_NOTRIGGERPREIN,
00294         N_("do not execute any %%triggerprein scriptlet(s)"), NULL},
00295  { "notriggerin", '\0', _POPT_SET_BIT|POPT_ARGFLAG_DOC_HIDDEN, &transFlags,
00296         RPMTRANS_FLAG_NOTRIGGERIN,
00297         N_("do not execute any %%triggerin scriptlet(s)"), NULL},
00298  { "notriggerun", '\0', _POPT_SET_BIT|POPT_ARGFLAG_DOC_HIDDEN, &transFlags,
00299         RPMTRANS_FLAG_NOTRIGGERUN,
00300         N_("do not execute any %%triggerun scriptlet(s)"), NULL},
00301  { "notriggerpostun", '\0', _POPT_SET_BIT|POPT_ARGFLAG_DOC_HIDDEN, &transFlags,
00302         RPMTRANS_FLAG_NOTRIGGERPOSTUN,
00303         N_("do not execute any %%triggerpostun scriptlet(s)"), NULL},
00304 
00305  { "oldpackage", '\0', _POPT_SET_BIT, &probFilter, RPMPROB_FILTER_OLDPACKAGE,
00306         N_("upgrade to an old version of the package (--force on upgrades does this automatically)"),
00307         NULL},
00308  { "percent", '\0', _POPT_SET_BIT, &installInterfaceFlags, INSTALL_PERCENT,
00309         N_("print percentages as package installs"), NULL},
00310  { "prefix", '\0', POPT_ARG_STRING, &prefix, 0,
00311         N_("relocate the package to <dir>, if relocatable"),
00312         N_("<dir>") },
00313  { "relocate", '\0', POPT_ARG_STRING, 0, GETOPT_RELOCATE,
00314         N_("relocate files from path <old> to <new>"),
00315         N_("<old>=<new>") },
00316  { "repackage", '\0', _POPT_SET_BIT, &transFlags, RPMTRANS_FLAG_REPACKAGE,
00317         N_("save erased package files by repackaging"), NULL},
00318  { "replacefiles", '\0', _POPT_SET_BIT, &probFilter,
00319         (RPMPROB_FILTER_REPLACEOLDFILES | RPMPROB_FILTER_REPLACENEWFILES),
00320         N_("install even if the package replaces installed files"), NULL},
00321  { "replacepkgs", '\0', _POPT_SET_BIT, &probFilter, RPMPROB_FILTER_REPLACEPKG,
00322         N_("reinstall if the package is already present"), NULL},
00323  { "test", '\0', _POPT_SET_BIT, &transFlags, RPMTRANS_FLAG_TEST,
00324         N_("don't install, but tell if it would work or not"), NULL},
00325  { "upgrade", 'U', _POPT_SET_BIT, &installInterfaceFlags, INSTALL_UPGRADE,
00326         N_("upgrade package(s)"),
00327         N_("<packagefile>+") },
00328 
00329    POPT_TABLEEND
00330 };
00331 #endif  /* IAM_RPMEIU */
00332 
00333 /* the structure describing the options we take and the defaults */
00334 static struct poptOption optionsTable[] = {
00335 #if !defined(_AUTOHELP)
00336  { "help", '\0', 0, &help, 0,                   NULL, NULL},
00337 #endif
00338 
00339  /* XXX colliding options */
00340 #if defined(IAM_RPMQV) || defined(IAM_RPMEIU) || defined(IAM_RPMBT)
00341  {  NULL, 'i', POPT_ARGFLAG_DOC_HIDDEN, 0, 'i',                 NULL, NULL},
00342 #endif
00343 
00344 #ifdef  IAM_RPMQV
00345  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQueryPoptTable, 0,
00346         N_("Query options (with -q or --query):"),
00347         NULL },
00348  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmVerifyPoptTable, 0,
00349         N_("Verify options (with -V or --verify):"),
00350         NULL },
00351 #endif  /* IAM_RPMQV */
00352 
00353 #ifdef  IAM_RPMK
00354  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmSignPoptTable, 0,
00355         N_("Signature options:"),
00356         NULL },
00357 #endif  /* IAM_RPMK */
00358 
00359 #ifdef  IAM_RPMDB
00360  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmDatabasePoptTable, 0,
00361         N_("Database options:"),
00362         NULL },
00363 #endif  /* IAM_RPMDB */
00364 
00365 #ifdef  IAM_RPMBT
00366  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmBuildPoptTable, 0,
00367         N_("Build options with [ <specfile> | <tarball> | <source package> ]:"),
00368         NULL },
00369 #endif  /* IAM_RPMBT */
00370 
00371 #ifdef  IAM_RPMEIU
00372  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmInstallPoptTable, 0,
00373         N_("Install/Upgrade/Erase options:"),
00374         NULL },
00375 #endif  /* IAM_RPMEIU */
00376 
00377  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmAllPoptTable, 0,
00378         N_("Common options for all rpm modes:"),
00379         NULL },
00380 
00381    POPT_AUTOHELP
00382    POPT_TABLEEND
00383 };
00384 
00385 #ifdef __MINT__
00386 /* MiNT cannot dynamically increase the stack.  */
00387 long _stksize = 64 * 1024L;
00388 #endif
00389 
00390 static void argerror(const char * desc) {
00391     fprintf(stderr, _("rpm: %s\n"), desc);
00392     exit(EXIT_FAILURE);
00393 }
00394 
00395 static void printVersion(void) {
00396     fprintf(stdout, _("RPM version %s\n"), rpmEVR);
00397 }
00398 
00399 static void printBanner(void) {
00400     puts(_("Copyright (C) 1998-2000 - Red Hat, Inc."));
00401     puts(_("This program may be freely redistributed under the terms of the GNU GPL"));
00402 }
00403 
00404 static void printUsage(void) {
00405     FILE * fp;
00406     printVersion();
00407     printBanner();
00408     puts("");
00409 
00410     fp = stdout;
00411 
00412     fprintf(fp, _("Usage: %s {--help}\n"), __progname);
00413     fprintf(fp,  ("       %s {--version}\n"), __progname);
00414 
00415 #ifdef  IAM_RPMEIU
00416 #ifdef  DYING
00417 --dbpath        all
00418 --ftpproxy etc  all
00419 --force         alias for --replacepkgs --replacefiles
00420 --includedocs   handle as option in table
00421                 --erase forbids many options
00422 #endif
00423 #endif  /* IAM_RPMEIU */
00424 
00425 #ifdef  IAM_RPMQV
00426 #ifdef  DYING   /* XXX popt glue needing --help doco. */
00427 --dbpath        all
00428 --ftpproxy etc  all
00429 -i,--info       Q
00430 -R,--requires   Q
00431 -P,--provides   Q
00432 --scripts       Q
00433 --triggeredby   Q
00434 --changelog     Q
00435 --triggers      Q
00436 --querytags     !V
00437 --setperms      V
00438 --setugids      V
00439 #endif  /* DYING */
00440 #endif  /* IAM_RPMQV */
00441 
00442 }
00443 
00444 #ifdef  DYING
00445 static void printHelpLine(char * prefix, char * help) {
00446     int indentLength = strlen(prefix) + 3;
00447     int lineLength = 79 - indentLength;
00448     int helpLength = strlen(help);
00449     char * ch;
00450     char format[10];
00451 
00452     fprintf(stdout, "%s - ", prefix);
00453 
00454     while (helpLength > lineLength) {
00455         ch = help + lineLength - 1;
00456         while (ch > help && !isspace(*ch)) ch--;
00457         if (ch == help) break;          /* give up */
00458         while (ch > (help + 1) && isspace(*ch)) ch--;
00459         ch++;
00460 
00461         sprintf(format, "%%.%ds\n%%%ds", (int) (ch - help), indentLength);
00462         fprintf(stdout, format, help, " ");
00463         help = ch;
00464         while (isspace(*help) && *help) help++;
00465         helpLength = strlen(help);
00466     }
00467 
00468     if (helpLength) puts(help);
00469 }
00470 
00471 static void printHelp(void) {
00472     printVersion();
00473     printBanner();
00474     puts("");
00475 
00476     puts(         _("Usage:"));
00477     printHelpLine(  "   --help                 ", 
00478                   _("print this message"));
00479     printHelpLine(  "   --version              ",
00480                   _("print the version of rpm being used"));
00481 
00482     puts("");
00483     puts(         _("  All modes support the following options:"));
00484     printHelpLine(_("   --define '<name> <body>'"),
00485                   _("define macro <name> with value <body>"));
00486     printHelpLine(_("   --eval '<expr>+'       "),
00487                   _("print the expansion of macro <expr> to stdout"));
00488     printHelpLine(_("   --pipe <cmd>           "),
00489                   _("send stdout to <cmd>"));
00490     printHelpLine(_("   --rcfile <file:...>    "),
00491                   _("use <file:...> instead of default list of macro files"));
00492     printHelpLine(  "   --showrc               ",
00493                   _("display final rpmrc and macro configuration"));
00494 #if defined(IAM_RPMBT) || defined(IAM_RPMDB) || defined(IAM_RPMEIU) || defined(IAM_RPMQV)
00495     printHelpLine(_("   --dbpath <dir>         "),
00496                   _("use <dir> as the directory for the database"));
00497     printHelpLine(_("   --root <dir>           "),
00498                   _("use <dir> as the top level directory"));
00499 #endif  /* IAM_RPMBT || IAM_RPMDB || IAM_RPMEIU || IAM_RPMQV */
00500     printHelpLine(  "   -v                     ",
00501                   _("be a little more verbose"));
00502     printHelpLine(  "   -vv                    ",
00503                   _("be incredibly verbose (for debugging)"));
00504 
00505 #if defined(IAM_RPMEIU) || defined(IAM_RPMQV)
00506     puts("");
00507     puts(         _("  Install, upgrade and query (with -p) modes allow URL's to be used in place"));
00508     puts(         _("  of file names as well as the following options:"));
00509     printHelpLine(_("     --ftpproxy <host>    "),
00510                   _("hostname or IP of ftp proxy"));
00511     printHelpLine(_("     --ftpport <port>     "),
00512                   _("port number of ftp server (or proxy)"));
00513     printHelpLine(_("     --httpproxy <host>   "),
00514                   _("hostname or IP of http proxy"));
00515     printHelpLine(_("     --httpport <port>    "),
00516                   _("port number of http server (or proxy)"));
00517 #endif  /* IAM_RPMEIU || IAM_RPMQV */
00518 
00519 #ifdef IAM_RPMQV
00520     puts("");
00521     puts(         _("  Package specification options:"));
00522     printHelpLine(  "     -a, --all            ",
00523                   _("query/verify all packages"));
00524     printHelpLine(_("     -f <file>+           "),
00525                   _("query/verify package owning <file>"));
00526     printHelpLine(_("     -p <packagefile>+    "),
00527                   _("query/verify (uninstalled) package <packagefile>"));
00528     printHelpLine(_("     --triggeredby <pkg>  "),
00529                   _("query/verify packages triggered by <pkg>"));
00530     printHelpLine(_("     --whatprovides <cap> "),
00531                   _("query/verify packages which provide <cap> capability"));
00532     printHelpLine(_("     --whatrequires <cap> "),
00533                   _("query/verify packages which require <cap> capability"));
00534     puts("");
00535     printHelpLine(  "  -q, --query             ",
00536                   _("query mode"));
00537     printHelpLine(_("     --queryformat <qfmt> "),
00538                   _("use <qfmt> as the header format (implies --info)"));
00539     puts("");
00540     puts(         _("    Information selection options:"));
00541     printHelpLine(  "       -i, --info         ",
00542                   _("display package information"));
00543     printHelpLine(  "       --changelog        ",
00544                   _("display the package's change log"));
00545     printHelpLine(  "       -l                 ",
00546                   _("display package file list"));
00547     printHelpLine(  "       -s                 ",
00548                   _("show file states (implies -l)"));
00549     printHelpLine(  "       -d                 ",
00550                   _("list only documentation files (implies -l)"));
00551     printHelpLine(  "       -c                 ",
00552                   _("list only configuration files (implies -l)"));
00553     printHelpLine(  "       --dump             ",
00554                   _("show all verifiable information for each file (must be used with -l, -c, or -d)"));
00555     printHelpLine(  "       --provides         ",
00556                   _("list capabilities provided by package"));
00557     printHelpLine(  "       -R, --requires     ",
00558                   _("list capabilities required by package"));
00559     printHelpLine(  "       --scripts          ",
00560                   _("print the various [un]install scriptlets"));
00561     printHelpLine(  "       --triggers         ",
00562                   _("show the trigger scriptlets contained in the package"));
00563     puts("");
00564     printHelpLine(  "   -V, -y, --verify       ",
00565                   _("verify a package installation using the same same package specification options as -q"));
00566     printHelpLine(  "     --nodeps             ",
00567                   _("do not verify package dependencies"));
00568     printHelpLine(  "     --nofiles            ",
00569                   _("do not verify file attributes"));
00570     printHelpLine(  "     --nomd5              ",
00571                   _("do not verify file md5 checksums"));
00572     printHelpLine(  "     --noscripts          ",
00573                   _("do not execute scripts (if any)"));
00574     puts("");
00575     printHelpLine(  "   --querytags            ",
00576                   _("list the tags that can be used in a query format"));
00577     printHelpLine(  "   --setperms             ",
00578                   _("set the file permissions to those in the package database"
00579                     " using the same package specification options as -q"));
00580     printHelpLine(  "   --setugids             ",
00581                   _("set the file owner and group to those in the package "
00582                     "database using the same package specification options as "
00583                     "-q"));
00584 #endif  /* IAM_RPMQV */
00585 
00586 #ifdef  IAM_RPMEIU
00587     puts("");
00588     puts(         _("   --install <packagefile>"));
00589     printHelpLine(_("   -i <packagefile>       "),
00590                   _("install package"));
00591     printHelpLine(  "     --allfiles           ",
00592                   _("install all files, even configurations which might "
00593                     "otherwise be skipped"));
00594     printHelpLine(  "     --badreloc           ",
00595                   _("relocate files in non-relocateable package"));
00596     printHelpLine(  "     --excludedocs        ",
00597                   _("do not install documentation"));
00598     printHelpLine(_("     --excludepath <path> "),
00599                   _("skip files with leading component <path> "));
00600     printHelpLine(  "     --force              ",
00601                   _("short hand for --replacepkgs --replacefiles"));
00602     printHelpLine(  "     -h, --hash           ",
00603                   _("print hash marks as package installs (good with -v)"));
00604     printHelpLine(  "     --ignorearch         ",
00605                   _("don't verify package architecture"));
00606     printHelpLine(  "     --ignoresize         ",
00607                   _("don't check disk space before installing"));
00608     printHelpLine(  "     --ignoreos           ",
00609                   _("don't verify package operating system"));
00610     printHelpLine(  "     --includedocs        ",
00611                   _("install documentation"));
00612     printHelpLine(  "     --justdb             ",
00613                   _("update the database, but do not modify the filesystem"));
00614     printHelpLine(  "     --nodeps             ",
00615                   _("do not verify package dependencies"));
00616     printHelpLine(  "     --noorder            ",
00617                   _("do not reorder package installation to satisfy dependencies"));
00618     printHelpLine(  "     --noscripts          ",
00619                   _("don't execute any installation scriptlets"));
00620     printHelpLine(  "     --notriggers         ",
00621                   _("don't execute any scriptlets triggered by this package"));
00622     printHelpLine(  "     --percent            ",
00623                   _("print percentages as package installs"));
00624     printHelpLine(_("     --prefix <dir>       "),
00625                   _("relocate the package to <dir>, if relocatable"));
00626     printHelpLine(_("     --relocate <oldpath>=<newpath>"),
00627                   _("relocate files from <oldpath> to <newpath>"));
00628     printHelpLine(  "     --replacefiles       ",
00629                   _("install even if the package replaces installed files"));
00630     printHelpLine(  "     --replacepkgs        ",
00631                   _("reinstall if the package is already present"));
00632     printHelpLine(  "     --test               ",
00633                   _("don't install, but tell if it would work or not"));
00634     puts("");
00635     puts(         _("   --upgrade <packagefile>"));
00636     printHelpLine(_("   -U <packagefile>       "),
00637                   _("upgrade package (same options as --install, plus)"));
00638     printHelpLine(  "     --oldpackage         ",
00639                   _("upgrade to an old version of the package (--force on upgrades does this automatically)"));
00640     puts("");
00641     puts(         _("   --erase <package>"));
00642     printHelpLine(_("   -e <package>           "),
00643                   _("erase (uninstall) package"));
00644     printHelpLine(  "     --allmatches         ",
00645                   _("remove all packages which match <package> (normally an error is generated if <package> specified multiple packages)"));
00646     printHelpLine(  "     --justdb             ",
00647                   _("update the database, but do not modify the filesystem"));
00648     printHelpLine(  "     --nodeps             ",
00649                   _("do not verify package dependencies"));
00650     printHelpLine(  "     --noorder            ",
00651                   _("do not reorder package installation to satisfy dependencies"));
00652     printHelpLine(  "     --noscripts          ",
00653                   _("do not execute any package specific scripts"));
00654     printHelpLine(  "     --notriggers         ",
00655                   _("don't execute any scripts triggered by this package"));
00656 #endif  /* IAM_RPMEIU */
00657 
00658 #ifdef IAM_RPMK
00659     puts("");
00660     printHelpLine(_("   --resign <pkg>+        "),
00661                   _("sign a package (discard current signature)"));
00662     printHelpLine(_("   --addsign <pkg>+       "),
00663                   _("add a signature to a package"));
00664 
00665     puts(         _("   --checksig <pkg>+"));
00666     printHelpLine(_("   -K <pkg>+             "),
00667                   _("verify package signature"));
00668     printHelpLine(  "     --nopgp              ",
00669                   _("skip any PGP signatures"));
00670     printHelpLine(  "     --nogpg              ",
00671                   _("skip any GPG signatures"));
00672     printHelpLine(  "     --nomd5              ",
00673                   _("skip any MD5 signatures"));
00674 #endif  /* IAM_RPMK */
00675 
00676 #ifdef  IAM_RPMDB
00677     puts("");
00678     printHelpLine(  "   --initdb               ",
00679                   _("initalize database (unnecessary, legacy use)"));
00680     printHelpLine(  "   --rebuilddb            ",
00681                   _("rebuild database indices from existing database headers"));
00682 #endif
00683 
00684 }
00685 #endif
00686 
00687 int main(int argc, const char ** argv)
00688 {
00689     enum modes bigMode = MODE_UNKNOWN;
00690 
00691 #ifdef  IAM_RPMQV
00692     QVA_t *qva = &rpmQVArgs;
00693 #endif
00694 
00695 #ifdef  IAM_RPMBT
00696     struct rpmBuildArguments *ba = &rpmBTArgs;
00697 #endif
00698 
00699 #ifdef  IAM_RPMEIU
00700     rpmRelocation * relocations = NULL;
00701     int numRelocations = 0;
00702 #endif
00703 
00704 #if defined(IAM_RPMK)
00705     rpmResignFlags addSign = RESIGN_NEW_SIGNATURE;
00706     rpmCheckSigFlags checksigFlags = CHECKSIG_NONE;
00707 #endif
00708 
00709 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
00710     char * passPhrase = "";
00711 #endif
00712 
00713     int arg;
00714     int gotDbpath = 0;
00715 
00716     const char * optArg;
00717     pid_t pipeChild = 0;
00718     poptContext optCon;
00719     int ec = 0;
00720     int status;
00721     int p[2];
00722         
00723 #if HAVE_MCHECK_H && HAVE_MTRACE
00724     mtrace();   /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
00725 #endif
00726     setprogname(argv[0]);       /* Retrofit glibc __progname */
00727 
00728     /* XXX glibc churn sanity */
00729     if (__progname == NULL) {
00730         if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
00731         else __progname = argv[0];
00732     }
00733 
00734     /* Set the major mode based on argv[0] */
00735 #ifdef  IAM_RPMBT
00736     if (!strcmp(__progname, "rpmb"))    bigMode = MODE_BUILD;
00737     if (!strcmp(__progname, "rpmt"))    bigMode = MODE_TARBUILD;
00738     if (!strcmp(__progname, "rpmbuild"))        bigMode = MODE_BUILD;
00739 #endif
00740 #ifdef  IAM_RPMQV
00741     if (!strcmp(__progname, "rpmq"))    bigMode = MODE_QUERY;
00742     if (!strcmp(__progname, "rpmv"))    bigMode = MODE_VERIFY;
00743     if (!strcmp(__progname, "rpmquery"))        bigMode = MODE_QUERY;
00744     if (!strcmp(__progname, "rpmverify"))       bigMode = MODE_VERIFY;
00745 #endif
00746 #ifdef  RPMEIU
00747     if (!strcmp(__progname, "rpme"))    bigMode = MODE_UNINSTALL;
00748     if (!strcmp(__progname, "rpmi"))    bigMode = MODE_INSTALL;
00749     if (!strcmp(__progname, "rpmu"))    bigMode = MODE_INSTALL;
00750 #endif
00751 
00752     /* set the defaults for the various command line options */
00753     _ftp_debug = 0;
00754 
00755 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
00756     noLibio = 0;
00757 #else
00758     noLibio = 1;
00759 #endif
00760     _rpmio_debug = 0;
00761     _url_debug = 0;
00762 
00763     /* XXX Eliminate query linkage loop */
00764     specedit = 0;
00765     parseSpecVec = parseSpec;
00766     freeSpecVec = freeSpec;
00767 
00768     /* set up the correct locale */
00769     setlocale(LC_ALL, "" );
00770 
00771 #ifdef  __LCLINT__
00772 #define LOCALEDIR       "/usr/share/locale"
00773 #endif
00774     bindtextdomain(PACKAGE, LOCALEDIR);
00775     textdomain(PACKAGE);
00776 
00777     rpmSetVerbosity(RPMMESS_NORMAL);    /* XXX silly use by showrc */
00778 
00779     /* Make a first pass through the arguments, looking for --rcfile */
00780     /* We need to handle that before dealing with the rest of the arguments. */
00781     optCon = poptGetContext(__progname, argc, argv, optionsTable, 0);
00782     poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
00783     poptReadDefaultConfig(optCon, 1);
00784     poptSetExecPath(optCon, RPMCONFIGDIR, 1);
00785 
00786     /* reading rcfile early makes it easy to override */
00787     /* XXX only --rcfile (and --showrc) need this pre-parse */
00788 
00789     while ((arg = poptGetNextOpt(optCon)) > 0) {
00790         switch(arg) {
00791         case 'v':
00792             rpmIncreaseVerbosity();     /* XXX silly use by showrc */
00793             break;
00794         default:
00795             break;
00796       }
00797     }
00798 
00799     if (rpmReadConfigFiles(rcfile, NULL))  
00800         exit(EXIT_FAILURE);
00801 
00802     if (showrc) {
00803         rpmShowRC(stdout);
00804         exit(EXIT_SUCCESS);
00805     }
00806 
00807     rpmSetVerbosity(RPMMESS_NORMAL);    /* XXX silly use by showrc */
00808 
00809     poptResetContext(optCon);
00810 
00811 #ifdef  IAM_RPMQV
00812     if (qva->qva_queryFormat) free((void *)qva->qva_queryFormat);
00813     memset(qva, 0, sizeof(*qva));
00814     qva->qva_source = RPMQV_PACKAGE;
00815     qva->qva_mode = ' ';
00816     qva->qva_char = ' ';
00817 #endif
00818 
00819 #ifdef  IAM_RPMBT
00820     if (ba->buildRootOverride) free((void *)ba->buildRootOverride);
00821     if (ba->targets) free(ba->targets);
00822     memset(ba, 0, sizeof(*ba));
00823     ba->buildMode = ' ';
00824     ba->buildChar = ' ';
00825 #endif
00826 
00827 #ifdef  IAM_RPMEIU
00828     transFlags = RPMTRANS_FLAG_NONE;
00829     probFilter = RPMPROB_FILTER_NONE;
00830     installInterfaceFlags = INSTALL_NONE;
00831     eraseInterfaceFlags = UNINSTALL_NONE;
00832 #endif
00833 
00834     while ((arg = poptGetNextOpt(optCon)) > 0) {
00835         optArg = poptGetOptArg(optCon);
00836 
00837         switch (arg) {
00838             
00839           case 'v':
00840             rpmIncreaseVerbosity();
00841             break;
00842 
00843 #if defined(IAM_RPMQV) || defined(IAM_RPMEIU) || defined(IAM_RPMBT)
00844           case 'i':
00845 #ifdef  IAM_RPMQV
00846             if (bigMode == MODE_QUERY) {
00847                 const char * infoCommand[] = { "--info", NULL };
00848                 poptStuffArgs(optCon, infoCommand);
00849             }
00850 #endif
00851 #ifdef  IAM_RPMEIU
00852             if (bigMode == MODE_INSTALL)
00853                 /*@-ifempty@*/ ;
00854             if (bigMode == MODE_UNKNOWN) {
00855                 const char * installCommand[] = { "--install", NULL };
00856                 poptStuffArgs(optCon, installCommand);
00857             }
00858 #endif
00859             break;
00860 #endif  /* IAM_RPMQV || IAM_RPMEIU || IAM_RPMBT */
00861 
00862 #ifdef  IAM_RPMEIU
00863         
00864           case 'e':
00865             if (bigMode != MODE_UNKNOWN && bigMode != MODE_UNINSTALL)
00866                 argerror(_("only one major mode may be specified"));
00867             bigMode = MODE_UNINSTALL;
00868             break;
00869         
00870           case GETOPT_INSTALL:
00871             if (bigMode != MODE_UNKNOWN && bigMode != MODE_INSTALL)
00872                 argerror(_("only one major mode may be specified"));
00873             bigMode = MODE_INSTALL;
00874             break;
00875 
00876 #ifdef  DYING   /* XXX handled by popt */
00877           case 'U':
00878             if (bigMode != MODE_UNKNOWN && bigMode != MODE_INSTALL)
00879                 argerror(_("only one major mode may be specified"));
00880             bigMode = MODE_INSTALL;
00881             break;
00882 
00883           case 'F':
00884             if (bigMode != MODE_UNKNOWN && bigMode != MODE_INSTALL)
00885                 argerror(_("only one major mode may be specified"));
00886             bigMode = MODE_INSTALL;
00887             break;
00888 #endif
00889 
00890           case GETOPT_EXCLUDEPATH:
00891             if (*optArg != '/') 
00892                 argerror(_("exclude paths must begin with a /"));
00893 
00894             relocations = xrealloc(relocations, 
00895                                   sizeof(*relocations) * (numRelocations + 1));
00896             relocations[numRelocations].oldPath = optArg;
00897             relocations[numRelocations++].newPath = NULL;
00898             break;
00899 
00900           case GETOPT_RELOCATE:
00901           { char * errString = NULL;
00902             if (*optArg != '/') 
00903                 argerror(_("relocations must begin with a /"));
00904             if (!(errString = strchr(optArg, '=')))
00905                 argerror(_("relocations must contain a ="));
00906             *errString++ = '\0';
00907             if (*errString != '/') 
00908                 argerror(_("relocations must have a / following the ="));
00909             relocations = xrealloc(relocations, 
00910                                   sizeof(*relocations) * (numRelocations + 1));
00911             relocations[numRelocations].oldPath = optArg;
00912             relocations[numRelocations++].newPath = errString;
00913           } break;
00914 #endif  /* IAM_RPMEIU */
00915 
00916 #ifdef  IAM_RPMDB
00917           case GETOPT_REBUILDDB:
00918             if (bigMode != MODE_UNKNOWN && bigMode != MODE_REBUILDDB)
00919                 argerror(_("only one major mode may be specified"));
00920             bigMode = MODE_REBUILDDB;
00921             break;
00922 #endif
00923 
00924 #ifdef  IAM_RPMK
00925           case 'K':
00926             if (bigMode != MODE_UNKNOWN && bigMode != MODE_CHECKSIG)
00927                 argerror(_("only one major mode may be specified"));
00928             bigMode = MODE_CHECKSIG;
00929             break;
00930 
00931           case GETOPT_RESIGN:
00932             if (bigMode != MODE_UNKNOWN && bigMode != MODE_RESIGN)
00933                 argerror(_("only one major mode may be specified"));
00934             bigMode = MODE_RESIGN;
00935             addSign = RESIGN_NEW_SIGNATURE;
00936             signIt = 1;
00937             break;
00938 
00939           case GETOPT_ADDSIGN:
00940             if (bigMode != MODE_UNKNOWN && bigMode != MODE_RESIGN)
00941                 argerror(_("only one major mode may be specified"));
00942             bigMode = MODE_RESIGN;
00943             addSign = RESIGN_ADD_SIGNATURE;
00944             signIt = 1;
00945             break;
00946 #endif  /* IAM_RPMK */
00947 
00948           case GETOPT_DEFINEMACRO:
00949             rpmDefineMacro(NULL, optArg, RMIL_CMDLINE);
00950             rpmDefineMacro(&rpmCLIMacroContext, optArg, RMIL_CMDLINE);
00951             noUsageMsg = 1;
00952             break;
00953 
00954           case GETOPT_EVALMACRO:
00955           { const char *val = rpmExpand(optArg, NULL);
00956             fprintf(stdout, "%s\n", val);
00957             free((void *)val);
00958             noUsageMsg = 1;
00959           } break;
00960 
00961           case GETOPT_RCFILE:
00962             fprintf(stderr, _("The --rcfile option has been eliminated.\n"));
00963             fprintf(stderr, _("Use \"--macros <file:...>\" instead.\n"));
00964             exit(EXIT_FAILURE);
00965             /*@notreached@*/ break;
00966 
00967           default:
00968             fprintf(stderr, _("Internal error in argument processing (%d) :-(\n"), arg);
00969             exit(EXIT_FAILURE);
00970         }
00971     }
00972 
00973     if (quiet)
00974         rpmSetVerbosity(RPMMESS_QUIET);
00975 
00976     if (showVersion) printVersion();
00977 
00978     if (arg < -1) {
00979         fprintf(stderr, "%s: %s\n", 
00980                 poptBadOption(optCon, POPT_BADOPTION_NOALIAS), 
00981                 poptStrerror(arg));
00982         exit(EXIT_FAILURE);
00983     }
00984 
00985 #ifdef  IAM_RPMBT
00986     switch (ba->buildMode) {
00987     case 'b':   bigMode = MODE_BUILD;           break;
00988     case 't':   bigMode = MODE_TARBUILD;        break;
00989     case 'B':   bigMode = MODE_REBUILD;         break;
00990     case 'C':   bigMode = MODE_RECOMPILE;       break;
00991     }
00992 
00993     if ((ba->buildAmount & RPMBUILD_RMSOURCE) && bigMode == MODE_UNKNOWN)
00994         bigMode = MODE_BUILD;
00995 
00996     if ((ba->buildAmount & RPMBUILD_RMSPEC) && bigMode == MODE_UNKNOWN)
00997         bigMode = MODE_BUILD;
00998 
00999     if (ba->buildRootOverride && bigMode != MODE_BUILD &&
01000         bigMode != MODE_REBUILD && bigMode != MODE_TARBUILD) {
01001         argerror("--buildroot may only be used during package builds");
01002     }
01003 #endif  /* IAM_RPMBT */
01004     
01005 #ifdef  IAM_RPMDB
01006     if (initdb) {
01007         if (bigMode != MODE_UNKNOWN) 
01008             argerror(_("only one major mode may be specified"));
01009         else
01010             bigMode = MODE_INITDB;
01011     }
01012 #endif  /* IAM_RPMDB */
01013 
01014 #ifdef  IAM_RPMQV
01015     switch (qva->qva_mode) {
01016     case 'q':   bigMode = MODE_QUERY;           break;
01017     case 'V':   bigMode = MODE_VERIFY;          break;
01018     case 'Q':   bigMode = MODE_QUERYTAGS;       break;
01019     }
01020 
01021     if (qva->qva_sourceCount) {
01022         if (qva->qva_sourceCount > 2)
01023             argerror(_("one type of query/verify may be performed at a "
01024                         "time"));
01025     }
01026     if (qva->qva_flags && (bigMode & ~MODES_QV)) 
01027         argerror(_("unexpected query flags"));
01028 
01029     if (qva->qva_queryFormat && (bigMode & ~MODES_QV)) 
01030         argerror(_("unexpected query format"));
01031 
01032     if (qva->qva_source != RPMQV_PACKAGE && (bigMode & ~MODES_QV)) 
01033         argerror(_("unexpected query source"));
01034 #endif
01035 
01036     if (gotDbpath && (bigMode & ~MODES_FOR_DBPATH))
01037         argerror(_("--dbpath given for operation that does not use a "
01038                         "database"));
01039 
01040 #if defined(IAM_RPMEIU)
01041 
01042     if (!( bigMode == MODE_INSTALL ) && force)
01043         argerror(_("only installation, upgrading, rmsource and rmspec may be forced"));
01044 #endif  /* IAM_RPMEIU */
01045 
01046 #ifdef  IAM_RPMEIU
01047     if (bigMode != MODE_INSTALL && (probFilter & RPMPROB_FILTER_FORCERELOCATE))
01048         argerror(_("files may only be relocated during package installation"));
01049 
01050     if (relocations && prefix)
01051         argerror(_("only one of --prefix or --relocate may be used"));
01052 
01053     if (bigMode != MODE_INSTALL && relocations)
01054         argerror(_("--relocate and --excludepath may only be used when installing new packages"));
01055 
01056     if (bigMode != MODE_INSTALL && prefix)
01057         argerror(_("--prefix may only be used when installing new packages"));
01058 
01059     if (prefix && prefix[0] != '/') 
01060         argerror(_("arguments to --prefix must begin with a /"));
01061 
01062     if (bigMode != MODE_INSTALL && (installInterfaceFlags & INSTALL_HASH))
01063         argerror(_("--hash (-h) may only be specified during package "
01064                         "installation"));
01065 
01066     if (bigMode != MODE_INSTALL && (installInterfaceFlags & INSTALL_PERCENT))
01067         argerror(_("--percent may only be specified during package "
01068                         "installation"));
01069 
01070     if (bigMode != MODE_INSTALL &&
01071  (probFilter & (RPMPROB_FILTER_REPLACEOLDFILES|RPMPROB_FILTER_REPLACENEWFILES)))
01072         argerror(_("--replacefiles may only be specified during package "
01073                         "installation"));
01074 
01075     if (bigMode != MODE_INSTALL && (probFilter & RPMPROB_FILTER_REPLACEPKG))
01076         argerror(_("--replacepkgs may only be specified during package "
01077                         "installation"));
01078 
01079     if (bigMode != MODE_INSTALL && (transFlags & RPMTRANS_FLAG_NODOCS))
01080         argerror(_("--excludedocs may only be specified during package "
01081                    "installation"));
01082 
01083     if (bigMode != MODE_INSTALL && incldocs)
01084         argerror(_("--includedocs may only be specified during package "
01085                    "installation"));
01086 
01087     if (incldocs && (transFlags & RPMTRANS_FLAG_NODOCS))
01088         argerror(_("only one of --excludedocs and --includedocs may be "
01089                  "specified"));
01090   
01091     if (bigMode != MODE_INSTALL && (probFilter & RPMPROB_FILTER_IGNOREARCH))
01092         argerror(_("--ignorearch may only be specified during package "
01093                    "installation"));
01094 
01095     if (bigMode != MODE_INSTALL && (probFilter & RPMPROB_FILTER_IGNOREOS))
01096         argerror(_("--ignoreos may only be specified during package "
01097                    "installation"));
01098 
01099     if (bigMode != MODE_INSTALL &&
01100         (probFilter & (RPMPROB_FILTER_DISKSPACE|RPMPROB_FILTER_DISKNODES)))
01101         argerror(_("--ignoresize may only be specified during package "
01102                    "installation"));
01103 
01104     if ((eraseInterfaceFlags & UNINSTALL_ALLMATCHES) && bigMode != MODE_UNINSTALL)
01105         argerror(_("--allmatches may only be specified during package "
01106                    "erasure"));
01107 
01108     if ((transFlags & RPMTRANS_FLAG_ALLFILES) && bigMode != MODE_INSTALL)
01109         argerror(_("--allfiles may only be specified during package "
01110                    "installation"));
01111 
01112     if ((transFlags & RPMTRANS_FLAG_JUSTDB) &&
01113         bigMode != MODE_INSTALL && bigMode != MODE_UNINSTALL)
01114         argerror(_("--justdb may only be specified during package "
01115                    "installation and erasure"));
01116 #endif  /* IAM_RPMEIU */
01117 
01118 #if defined(IAM_RPMEIU)
01119     if (bigMode != MODE_INSTALL && bigMode != MODE_UNINSTALL &&
01120         (transFlags & (RPMTRANS_FLAG_NOSCRIPTS | _noTransScripts | _noTransTriggers)))
01121         argerror(_("script disabling options may only be specified during "
01122                    "package installation and erasure"));
01123 
01124     if (bigMode != MODE_INSTALL && bigMode != MODE_UNINSTALL &&
01125         (transFlags & (RPMTRANS_FLAG_NOTRIGGERS | _noTransTriggers)))
01126         argerror(_("trigger disabling options may only be specified during "
01127                    "package installation and erasure"));
01128 
01129     if (noDeps & (bigMode & ~MODES_FOR_NODEPS))
01130         argerror(_("--nodeps may only be specified during package "
01131                    "building, rebuilding, recompilation, installation,"
01132                    "erasure, and verification"));
01133 
01134     if ((transFlags & RPMTRANS_FLAG_TEST) && (bigMode & ~MODES_FOR_TEST))
01135         argerror(_("--test may only be specified during package installation, "
01136                  "erasure, and building"));
01137 #endif  /* IAM_RPMEIU */
01138 
01139     if (rootdir[1] && (bigMode & ~MODES_FOR_ROOT))
01140         argerror(_("--root (-r) may only be specified during "
01141                  "installation, erasure, querying, and "
01142                  "database rebuilds"));
01143 
01144     if (rootdir) {
01145         switch (urlIsURL(rootdir)) {
01146         default:
01147             if (bigMode & MODES_FOR_ROOT)
01148                 break;
01149             /*@fallthrough@*/
01150         case URL_IS_UNKNOWN:
01151             if (rootdir[0] != '/')
01152                 argerror(_("arguments to --root (-r) must begin with a /"));
01153             break;
01154         }
01155     }
01156 
01157 #ifdef  IAM_RPMK
01158     if (noPgp && bigMode != MODE_CHECKSIG)
01159         argerror(_("--nopgp may only be used during signature checking"));
01160 
01161     if (noGpg && bigMode != MODE_CHECKSIG)
01162         argerror(_("--nogpg may only be used during signature checking"));
01163 #endif
01164 
01165 #if defined(IAM_RPMK) || defined(IAM_RPMQV)
01166     if (noMd5 && bigMode != MODE_CHECKSIG && bigMode != MODE_VERIFY)
01167         argerror(_("--nomd5 may only be used during signature checking and "
01168                    "package verification"));
01169 #endif
01170 
01171 #if defined(IAM_RPMBT) || defined(IAM_RPMK)
01172 #if defined(IAM_RPMBT)
01173     signIt = ba->sign;
01174 #endif
01175     if (signIt) {
01176         if (bigMode == MODE_REBUILD || bigMode == MODE_BUILD ||
01177             bigMode == MODE_RESIGN || bigMode == MODE_TARBUILD) {
01178             const char ** argv;
01179             struct stat sb;
01180             int errors = 0;
01181 
01182             if ((argv = poptGetArgs(optCon)) == NULL) {
01183                 fprintf(stderr, _("no files to sign\n"));
01184                 errors++;
01185             } else
01186             while (*argv) {
01187                 if (stat(*argv, &sb)) {
01188                     fprintf(stderr, _("cannot access file %s\n"), *argv);
01189                     errors++;
01190                 }
01191                 argv++;
01192             }
01193 
01194             if (errors) return errors;
01195 
01196             if (poptPeekArg(optCon)) {
01197                 int sigTag;
01198                 switch (sigTag = rpmLookupSignatureType(RPMLOOKUPSIG_QUERY)) {
01199                   case 0:
01200                     break;
01201                   case RPMSIGTAG_PGP:
01202                     if ((sigTag == RPMSIGTAG_PGP || sigTag == RPMSIGTAG_PGP5) &&
01203                         !rpmDetectPGPVersion(NULL)) {
01204                         fprintf(stderr, _("pgp not found: "));
01205                         exit(EXIT_FAILURE);
01206                     }   /*@fallthrough@*/
01207                   case RPMSIGTAG_GPG:
01208                     passPhrase = rpmGetPassPhrase(_("Enter pass phrase: "), sigTag);
01209                     if (passPhrase == NULL) {
01210                         fprintf(stderr, _("Pass phrase check failed\n"));
01211                         exit(EXIT_FAILURE);
01212                     }
01213                     fprintf(stderr, _("Pass phrase is good.\n"));
01214                     passPhrase = xstrdup(passPhrase);
01215                     break;
01216                   default:
01217                     fprintf(stderr,
01218                             _("Invalid %%_signature spec in macro file.\n"));
01219                     exit(EXIT_FAILURE);
01220                     /*@notreached@*/ break;
01221                 }
01222             }
01223         } else {
01224             argerror(_("--sign may only be used during package building"));
01225         }
01226     } else {
01227         /* Make rpmLookupSignatureType() return 0 ("none") from now on */
01228         rpmLookupSignatureType(RPMLOOKUPSIG_DISABLE);
01229     }
01230 #endif  /* IAM_RPMBT || IAM_RPMK */
01231 
01232     if (pipeOutput) {
01233         pipe(p);
01234 
01235         if (!(pipeChild = fork())) {
01236             close(p[1]);
01237             dup2(p[0], STDIN_FILENO);
01238             close(p[0]);
01239             execl("/bin/sh", "/bin/sh", "-c", pipeOutput, NULL);
01240             fprintf(stderr, _("exec failed\n"));
01241         }
01242 
01243         close(p[0]);
01244         dup2(p[1], STDOUT_FILENO);
01245         close(p[1]);
01246     }
01247         
01248     switch (bigMode) {
01249 #ifdef  IAM_RPMDB
01250       case MODE_INITDB:
01251         rpmdbInit(rootdir, 0644);
01252         break;
01253 
01254       case MODE_REBUILDDB:
01255         ec = rpmdbRebuild(rootdir);
01256         break;
01257       case MODE_QUERY:
01258       case MODE_VERIFY:
01259       case MODE_QUERYTAGS:
01260       case MODE_INSTALL:
01261       case MODE_UNINSTALL:
01262       case MODE_BUILD:
01263       case MODE_REBUILD:
01264       case MODE_RECOMPILE:
01265       case MODE_TARBUILD:
01266       case MODE_CHECKSIG:
01267       case MODE_RESIGN:
01268         if (!showVersion && !help && !noUsageMsg) printUsage();
01269         break;
01270 #endif  /* IAM_RPMDB */
01271 
01272 #ifdef  IAM_RPMBT
01273       case MODE_REBUILD:
01274       case MODE_RECOMPILE:
01275       { const char * pkg;
01276         while (!rpmIsVerbose())
01277             rpmIncreaseVerbosity();
01278 
01279         if (!poptPeekArg(optCon))
01280             argerror(_("no packages files given for rebuild"));
01281 
01282         ba->buildAmount = RPMBUILD_PREP | RPMBUILD_BUILD | RPMBUILD_INSTALL;
01283         if (bigMode == MODE_REBUILD) {
01284             ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
01285             ba->buildAmount |= RPMBUILD_RMSOURCE;
01286             ba->buildAmount |= RPMBUILD_RMSPEC;
01287             ba->buildAmount |= RPMBUILD_CLEAN;
01288             ba->buildAmount |= RPMBUILD_RMBUILD;
01289         }
01290 
01291         while ((pkg = poptGetArg(optCon))) {
01292             const char * specFile = NULL;
01293             char * cookie = NULL;
01294 
01295             ec = rpmInstallSource("", pkg, &specFile, &cookie);
01296             if (ec)
01297                 break;
01298 
01299             ba->rootdir = rootdir;
01300             ec = build(specFile, ba, passPhrase, cookie, rcfile);
01301             free(cookie);
01302             cookie = NULL;
01303             free((void *)specFile);
01304             specFile = NULL;
01305 
01306             if (ec)
01307                 break;
01308         }
01309       } break;
01310 
01311       case MODE_BUILD:
01312       case MODE_TARBUILD:
01313       { const char * pkg;
01314         while (!rpmIsVerbose())
01315             rpmIncreaseVerbosity();
01316        
01317         switch (ba->buildChar) {
01318           case 'a':
01319             ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
01320             /*@fallthrough@*/
01321           case 'b':
01322             ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
01323             ba->buildAmount |= RPMBUILD_CLEAN;
01324             /*@fallthrough@*/
01325           case 'i':
01326             ba->buildAmount |= RPMBUILD_INSTALL;
01327             if ((ba->buildChar == 'i') && ba->shortCircuit)
01328                 break;
01329             /*@fallthrough@*/
01330           case 'c':
01331             ba->buildAmount |= RPMBUILD_BUILD;
01332             if ((ba->buildChar == 'c') && ba->shortCircuit)
01333                 break;
01334             /*@fallthrough@*/
01335           case 'p':
01336             ba->buildAmount |= RPMBUILD_PREP;
01337             break;
01338             
01339           case 'l':
01340             ba->buildAmount |= RPMBUILD_FILECHECK;
01341             break;
01342           case 's':
01343             ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
01344             break;
01345         }
01346 
01347         if (!poptPeekArg(optCon)) {
01348             if (bigMode == MODE_BUILD)
01349                 argerror(_("no spec files given for build"));
01350             else
01351                 argerror(_("no tar files given for build"));
01352         }
01353 
01354         while ((pkg = poptGetArg(optCon))) {
01355             ba->rootdir = rootdir;
01356             ec = build(pkg, ba, passPhrase, NULL, rcfile);
01357             if (ec)
01358                 break;
01359             rpmFreeMacros(NULL);
01360             rpmReadConfigFiles(rcfile, NULL);
01361         }
01362       } break;
01363 
01364       case MODE_QUERY:
01365       case MODE_VERIFY:
01366       case MODE_QUERYTAGS:
01367       case MODE_INSTALL:
01368       case MODE_UNINSTALL:
01369       case MODE_CHECKSIG:
01370       case MODE_RESIGN:
01371       case MODE_INITDB:
01372       case MODE_REBUILDDB:
01373         if (!showVersion && !help && !noUsageMsg) printUsage();
01374         break;
01375 #endif  /* IAM_RPMBT */
01376 
01377 #ifdef  IAM_RPMEIU
01378       case MODE_UNINSTALL:
01379         if (!poptPeekArg(optCon))
01380             argerror(_("no packages given for uninstall"));
01381 
01382         if (noDeps) eraseInterfaceFlags |= UNINSTALL_NODEPS;
01383 
01384         ec = rpmErase(rootdir, (const char **)poptGetArgs(optCon), 
01385                          transFlags, eraseInterfaceFlags);
01386         break;
01387 
01388       case MODE_INSTALL:
01389         if (force) {
01390             probFilter |= RPMPROB_FILTER_REPLACEPKG | 
01391                           RPMPROB_FILTER_REPLACEOLDFILES |
01392                           RPMPROB_FILTER_REPLACENEWFILES |
01393                           RPMPROB_FILTER_OLDPACKAGE;
01394         }
01395 
01396         /* RPMTRANS_FLAG_BUILD_PROBS */
01397         /* RPMTRANS_FLAG_KEEPOBSOLETE */
01398 
01399         if (!incldocs) {
01400             if (transFlags & RPMTRANS_FLAG_NODOCS)
01401                 ;
01402             else if (rpmExpandNumeric("%{_excludedocs}"))
01403                 transFlags |= RPMTRANS_FLAG_NODOCS;
01404         }
01405 
01406         if (noDeps) installInterfaceFlags |= INSTALL_NODEPS;
01407 
01408         if (!poptPeekArg(optCon))
01409             argerror(_("no packages given for install"));
01410 
01411         /* we've already ensured !(!prefix && !relocations) */
01412         if (prefix) {
01413             relocations = alloca(2 * sizeof(*relocations));
01414             relocations[0].oldPath = NULL;   /* special case magic */
01415             relocations[0].newPath = prefix;
01416             relocations[1].oldPath = relocations[1].newPath = NULL;
01417         } else if (relocations) {
01418             relocations = xrealloc(relocations, 
01419                                   sizeof(*relocations) * (numRelocations + 1));
01420             relocations[numRelocations].oldPath = NULL;
01421             relocations[numRelocations].newPath = NULL;
01422         }
01423 
01424         ec += rpmInstall(rootdir, (const char **)poptGetArgs(optCon), 
01425                         transFlags, installInterfaceFlags, probFilter,
01426                         relocations);
01427         break;
01428       case MODE_QUERY:
01429       case MODE_VERIFY:
01430       case MODE_QUERYTAGS:
01431       case MODE_BUILD:
01432       case MODE_REBUILD:
01433       case MODE_RECOMPILE:
01434       case MODE_TARBUILD:
01435       case MODE_CHECKSIG:
01436       case MODE_RESIGN:
01437       case MODE_INITDB:
01438       case MODE_REBUILDDB:
01439         if (!showVersion && !help && !noUsageMsg) printUsage();
01440         break;
01441 #endif  /* IAM_RPMEIU */
01442 
01443 #ifdef  IAM_RPMQV
01444       case MODE_QUERY:
01445       { const char * pkg;
01446 
01447         qva->qva_prefix = rootdir;
01448         if (qva->qva_source == RPMQV_ALL) {
01449             if (poptPeekArg(optCon))
01450                 argerror(_("extra arguments given for query of all packages"));
01451 
01452             ec = rpmQuery(qva, RPMQV_ALL, NULL);
01453         } else {
01454             if (!poptPeekArg(optCon))
01455                 argerror(_("no arguments given for query"));
01456             while ((pkg = poptGetArg(optCon)))
01457                 ec += rpmQuery(qva, qva->qva_source, pkg);
01458