11 #include "lib/messages.h"
12 #include "lib/signature.h"
17 #include "build/build.h"
19 #define GETOPT_QUERYFORMAT 1000
20 #define GETOPT_WHATREQUIRES 1001
21 #define GETOPT_WHATPROVIDES 1002
22 #define GETOPT_REBUILD 1003
23 #define GETOPT_RECOMPILE 1004
24 #define GETOPT_ADDSIGN 1005
25 #define GETOPT_RESIGN 1006
26 #define GETOPT_BUILDROOT 1007
27 #define GETOPT_PROVIDES 1008
28 #define GETOPT_QUERYBYNUMBER 1009
29 #define GETOPT_DBPATH 1010
30 #define GETOPT_PREFIX 1011
31 #define GETOPT_TIMECHECK 1012
32 #define GETOPT_REBUILDDB 1013
33 #define GETOPT_FTPPORT 1014
34 #define GETOPT_FTPPROXY 1015
36 char * version = VERSION;
38 enum modes { MODE_QUERY, MODE_INSTALL, MODE_UNINSTALL, MODE_VERIFY,
39 MODE_BUILD, MODE_REBUILD, MODE_CHECKSIG, MODE_RESIGN,
40 MODE_RECOMPILE, MODE_QUERYTAGS, MODE_INITDB,
41 MODE_REBUILDDB, MODE_UNKNOWN };
43 static void argerror(char * desc);
45 static void argerror(char * desc) {
46 fprintf(stderr, "rpm: %s\n", desc);
51 void printVersion(void);
52 void printBanner(void);
53 void printUsage(void);
54 int build(char *arg, int buildAmount, char *passPhrase,
55 char *buildRootOverride);
57 void printVersion(void) {
58 printf(_("RPM version %s\n"), version);
61 void printBanner(void) {
62 puts(_("Copyright (C) 1995 - Red Hat Software"));
63 puts(_("This may be freely redistributed under the terms of the GNU "
67 void printUsage(void) {
72 puts(_("usage: rpm {--help}"));
73 puts(_(" rpm {--version}"));
74 puts(_(" rpm {--query -q} [-afFpP] [-i] [-l] [-s] [-d] [-c] [-v] [-R]"));
75 puts(_(" [--scripts] [--root <dir>] [--rcfile <file>]"));
76 puts(_(" [--whatprovides] [--whatrequires] [--requires]"));
77 puts(_(" [--ftpuseport] [--ftpproxy <host>] [--ftpport <port>]"));
78 puts(_(" [--provides] [--dump] [--dbpath <dir>] [targets]"));
79 puts(_(" rpm {--querytags}"));
82 void printHelp(void) {
88 puts(_(" --help - print this message"));
89 puts(_(" --version - print the version of rpm being used"));
90 puts(_(" all modes support the following arguments:"));
91 puts(_(" -v - be a little more verbose"));
92 puts(_(" -vv - be incredibly verbose (for debugging)"));
93 puts(_(" -q - query mode"));
94 puts(_(" --queryformat <s> - use s as the header format (implies -i)"));
95 puts(_(" Package specification options:"));
96 puts(_(" -a - query all packages"));
97 puts(_(" -f <file>+ - query package owning <file>"));
98 puts(_(" -F - like -f, but read file names from stdin"));
99 puts(_(" -p <packagefile>+ - query (uninstalled) package <packagefile>"));
100 puts(_(" -P - like -p, but read package names from stdin"));
101 puts(_(" --whatprovides <i> - query packages which provide <i> capability"));
102 puts(_(" --whatrequires <i> - query packages which require <i> capability"));
103 puts(_(" Information selection options:"));
104 puts(_(" -i - display package information"));
105 puts(_(" -l - display package file list"));
106 puts(_(" -s - show file states (implies -l)"));
107 puts(_(" -d - list only documentation files (implies -l)"));
108 puts(_(" -c - list only configuration files (implies -l)"));
109 puts(_(" --dump - show all verifiable information for each file"));
110 puts(_(" (must be used with -l, -c, or -d)"));
111 puts(_(" --provides - list capabilbities package provides"));
112 puts(_(" --requires"));
113 puts(_(" -R - list package dependencies"));
114 puts(_(" --scripts - print the various [un]install scripts"));
116 puts(_(" --querytags - list the tags that can be used in a query format"));
119 int main(int argc, char ** argv) {
121 enum modes bigMode = MODE_UNKNOWN;
122 enum querysources querySource = QUERY_PACKAGE;
123 enum verifysources verifySource = VERIFY_PACKAGE;
125 int queryFor = 0, test = 0, version = 0, help = 0, force = 0;
126 int quiet = 0, replaceFiles = 0, replacePackages = 0, showPercents = 0;
127 int showHash = 0, installFlags = 0, uninstallFlags = 0, interfaceFlags = 0;
128 int buildAmount = 0, oldPackage = 0, clean = 0, signIt = 0;
129 int shortCircuit = 0, badOption = 0, queryTags = 0, excldocs = 0;
130 int incldocs = 0, queryScripts = 0, noScripts = 0, noDeps = 0;
131 int noPgp = 0, dump = 0, initdb = 0, ignoreArch = 0, showrc = 0;
132 int gotDbpath = 0, building = 0, ignoreOs = 0, noFiles = 0, verifyFlags;
135 int addSign = NEW_SIGNATURE;
136 char * rcfile = NULL, * queryFormat = NULL, * prefix = NULL;
137 char buildChar = ' ';
138 char * rootdir = "/";
140 char *passPhrase = "";
141 char *buildRootOverride = NULL;
143 char * ftpProxy = NULL, * ftpPort = NULL;
145 char * smallArgv[2] = { NULL, NULL };
148 struct option optionsTable[] = {
149 { "all", 0, 0, 'a' },
150 { "configfiles", 0, 0, 'c' },
151 { "docfiles", 0, 0, 'd' },
152 { "dump", 0, &dump, 0 },
153 { "group", 0, 0, 'g' },
154 { "help", 0, &help, 0 },
155 { "info", 0, 0, 'i' },
156 { "package", 0, 0, 'p' },
157 { "provides", 0, 0, GETOPT_PROVIDES },
158 { "qf", 1, 0, GETOPT_QUERYFORMAT },
159 { "query", 0, 0, 'q' },
160 { "querybynumber", 0, 0, GETOPT_QUERYBYNUMBER },
161 { "queryformat", 1, 0, GETOPT_QUERYFORMAT },
162 { "querytags", 0, &queryTags, 0 },
163 { "quiet", 0, &quiet, 0 },
164 { "requires", 0, 0, 'R' },
165 { "scripts", 0, &queryScripts, 0 },
166 { "state", 0, 0, 's' },
167 { "stdin-files", 0, 0, 'F' },
168 { "stdin-group", 0, 0, 'G' },
169 { "stdin-packages", 0, 0, 'P' },
170 { "stdin-query", 0, 0, 'Q' },
171 { "verbose", 0, 0, 'v' },
172 { "version", 0, &version, 0 },
173 { "whatrequires", 0, 0, GETOPT_WHATREQUIRES },
174 { "whatprovides", 0, 0, GETOPT_WHATPROVIDES },
177 struct option * options = optionsTable;
179 /* set up the correct locale via the LANG environment variable */
180 setlocale(LC_ALL, "" );
182 bindtextdomain(NLSPACKAGE, "/usr/lib/locale");
183 textdomain(NLSPACKAGE);
185 /* reading this early makes it easy to override */
186 if (rpmReadConfigFiles(rcfile, arch, os, building))
196 arg = getopt_long(argc, argv, "RQqVyUYhpvKPfFilseagGDducr:b:", options,
198 if (arg == -1) break;
206 if (querySource != QUERY_PACKAGE && querySource != QUERY_SPACKAGE)
207 argerror(_("only one type of query may be performed at a "
209 querySource = QUERY_SPACKAGE;
212 if (bigMode != MODE_UNKNOWN && bigMode != MODE_QUERY)
213 argerror(_("only one major mode may be specified"));
214 bigMode = MODE_QUERY;
218 rpmIncreaseVerbosity();
223 if (bigMode == MODE_QUERY)
224 queryFor |= QUERY_FOR_INFO;
225 else if (bigMode == MODE_INSTALL)
227 else if (bigMode == MODE_UNKNOWN)
228 bigMode = MODE_INSTALL;
230 else if (!strcmp(options[long_index].name, "info"))
231 queryFor |= QUERY_FOR_INFO;
233 bigMode = MODE_INSTALL;
238 queryFor |= QUERY_FOR_LIST | QUERY_FOR_STATE;
242 queryFor |= QUERY_FOR_REQUIRES;
246 queryFor |= QUERY_FOR_LIST;
250 queryFor |= QUERY_FOR_DOCS | QUERY_FOR_LIST;
254 queryFor |= QUERY_FOR_CONFIG | QUERY_FOR_LIST;
258 if (querySource != QUERY_PACKAGE && querySource != QUERY_SRPM)
259 argerror(_("one type of query/verify may be performed at a "
261 querySource = QUERY_SRPM;
262 verifySource = VERIFY_SRPM;
266 if (querySource != QUERY_PACKAGE && querySource != QUERY_RPM)
267 argerror(_("one type of query/verify may be performed at a " "time"));
268 querySource = QUERY_RPM;
269 verifySource = VERIFY_RPM;
273 if (querySource != QUERY_PACKAGE && querySource != QUERY_SGROUP)
274 argerror(_("one type of query/verify may be performed at a "
276 querySource = QUERY_SGROUP;
277 verifySource = VERIFY_SGROUP;
281 if (querySource != QUERY_PACKAGE && querySource != QUERY_GROUP)
282 argerror(_("one type of query/verify may be performed at a "
284 querySource = QUERY_GROUP;
285 verifySource = VERIFY_GRP;
289 if (querySource != QUERY_PACKAGE && querySource != QUERY_SPATH)
290 argerror(_("one type of query/verify may be performed at a "
292 querySource = QUERY_SPATH;
293 verifySource = VERIFY_SPATH;
297 if (querySource != QUERY_PACKAGE && querySource != QUERY_PATH)
298 argerror(_("one type of query/verify may be performed at a "
300 querySource = QUERY_PATH;
301 verifySource = VERIFY_PATH;
305 if (querySource != QUERY_PACKAGE && querySource != QUERY_ALL)
306 argerror(_("one type of query/verify may be performed at a "
308 querySource = QUERY_ALL;
309 verifySource = VERIFY_EVERY;
312 case GETOPT_QUERYFORMAT:
313 if (bigMode != MODE_UNKNOWN && bigMode != MODE_QUERY)
314 argerror(_("only one major mode may be specified"));
315 bigMode = MODE_QUERY;
316 queryFormat = optarg;
317 queryFor |= QUERY_FOR_INFO;
320 case GETOPT_WHATREQUIRES:
321 if (querySource != QUERY_PACKAGE &&
322 querySource != QUERY_WHATREQUIRES)
323 argerror(_("one type of query/verify may be performed at a "
325 querySource = QUERY_WHATREQUIRES;
328 case GETOPT_WHATPROVIDES:
329 if (querySource != QUERY_PACKAGE &&
330 querySource != QUERY_WHATPROVIDES)
331 argerror(_("one type of query/verify may be performed at a "
333 querySource = QUERY_WHATPROVIDES;
336 case GETOPT_PROVIDES:
337 queryFor |= QUERY_FOR_PROVIDES;
341 if (options[long_index].flag) {
342 *options[long_index].flag = 1;
351 rpmSetVerbosity(RPMMESS_QUIET);
353 if (version) printVersion();
354 if (help) printHelp();
360 queryFor |= QUERY_FOR_SCRIPTS;
364 if (bigMode != MODE_UNKNOWN)
365 argerror(_("only one major mode may be specified"));
367 bigMode = MODE_QUERYTAGS;
369 if (bigMode != MODE_QUERY && bigMode != MODE_INSTALL &&
370 bigMode != MODE_UNINSTALL && bigMode != MODE_VERIFY &&
371 bigMode != MODE_INITDB && gotDbpath)
372 argerror(_("--dbpath given for operation that does not use a "
375 if (bigMode != MODE_QUERY && queryFor)
376 argerror(_("unexpected query specifiers"));
378 if (bigMode != MODE_QUERY && bigMode != MODE_VERIFY &&
379 querySource != QUERY_PACKAGE)
380 argerror(_("unexpected query source"));
382 if (bigMode != MODE_INSTALL && force)
383 argerror(_("only installation and upgrading may be forced"));
385 if (bigMode != MODE_INSTALL && prefix)
386 argerror(_("--prefix may only be used when installing new packages"));
388 if (bigMode != MODE_INSTALL && showHash)
389 argerror(_("--hash (-h) may only be specified during package "
392 if (bigMode != MODE_INSTALL && showPercents)
393 argerror(_("--percent may only be specified during package "
396 if (bigMode != MODE_INSTALL && replaceFiles)
397 argerror(_("--replacefiles may only be specified during package "
400 if (bigMode != MODE_INSTALL && replacePackages)
401 argerror(_("--replacepkgs may only be specified during package "
404 if (bigMode != MODE_INSTALL && excldocs)
405 argerror(_("--excludedocs may only be specified during package "
408 if (bigMode != MODE_INSTALL && incldocs)
409 argerror(_("--includedocs may only be specified during package "
412 if (excldocs && incldocs)
413 argerror(_("only one of --excludedocs and --includedocs may be "
416 if (bigMode != MODE_INSTALL && ignoreArch)
417 argerror(_("--ignorearch may only be specified during package "
420 if (bigMode != MODE_INSTALL && ignoreOs)
421 argerror(_("--ignoreos may only be specified during package "
424 if (bigMode != MODE_INSTALL && bigMode != MODE_UNINSTALL && noScripts)
425 argerror(_("--noscripts may only be specified during package "
426 "installation and uninstallation"));
428 if (bigMode != MODE_INSTALL && bigMode != MODE_UNINSTALL &&
429 bigMode != MODE_VERIFY && noDeps)
430 argerror(_("--nodeps may only be specified during package "
431 "installation, uninstallation, and verification"));
433 if (bigMode != MODE_VERIFY && noFiles)
434 argerror(_("--nofiles may only be specified during package "
437 if (bigMode != MODE_INSTALL && bigMode != MODE_UNINSTALL &&
438 bigMode != MODE_BUILD && test)
439 argerror(_("--test may only be specified during package installation, "
440 "uninstallation, and building"));
442 if (bigMode != MODE_INSTALL && bigMode != MODE_UNINSTALL &&
443 bigMode != MODE_QUERY && bigMode != MODE_VERIFY && bigMode != MODE_REBUILDDB && rootdir[1])
444 argerror(_("--root (-r) may only be specified during "
445 "installation, uninstallation, querying, and "
446 "database rebuilds"));
448 if (bigMode != MODE_BUILD && clean)
449 argerror(_("--clean may only be used during package building"));
451 if (bigMode != MODE_BUILD && shortCircuit)
452 argerror(_("--short-circuit may only be used during package building"));
454 if (shortCircuit && (buildChar != 'c') && (buildChar != 'i')) {
455 argerror(_("--short-circuit may only be used with -bc or -bi"));
458 if (oldPackage && !(installFlags & RPMINSTALL_UPGRADE))
459 argerror(_("--oldpackage may only be used during upgrades"));
461 if (bigMode != MODE_QUERY && dump)
462 argerror(_("--dump may only be used during queryies"));
464 if (bigMode == MODE_QUERY && dump && !(queryFor & QUERY_FOR_LIST))
465 argerror(_("--dump of queries must be used with -l, -c, or -d"));
467 if ((ftpProxy || ftpPort) && !(bigMode == MODE_INSTALL ||
468 (bigMode == MODE_QUERY && (querySource == QUERY_RPM ||
469 querySource == QUERY_SRPM))))
470 argerror(_("ftp options can only be used during package queries, "
471 "installs, and upgrades"));
473 if (oldPackage || (force && (installFlags & RPMINSTALL_UPGRADE)))
474 installFlags |= RPMINSTALL_UPGRADETOOLD;
478 if (!version && !help) printUsage();
483 argerror(_("unexpected arguments to --querytags "));
489 if (dump) queryFor |= QUERY_FOR_DUMPFILES;
491 if (querySource == QUERY_ALL) {
493 argerror(_("extra arguments given for query of all packages"));
495 ec = doQuery(rootdir, QUERY_ALL, queryFor, NULL, queryFormat);
496 } else if (querySource == QUERY_SPATH ||
497 querySource == QUERY_SPACKAGE ||
498 querySource == QUERY_SRPM) {
502 while (fgets(buffer, 255, stdin)) {
503 i = strlen(buffer) - 1;
504 if (buffer[i] == '\n') buffer[i] = 0;
506 ec += doQuery(rootdir, querySource, queryFor, buffer,
511 argerror(_("no arguments given for query"));
512 while (optind < argc)
513 ec = doQuery(rootdir, querySource, queryFor, argv[optind++],