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

Generated at Sun Apr 8 18:43:02 2001 for rpm by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000