3 * Popt tables for all rpm modes.
7 const char *__progname;
9 #include <rpm/rpmcli.h>
10 #include <rpm/rpmlib.h> /* rpmEVR, rpmReadConfigFiles etc */
11 #include <rpm/rpmlog.h>
12 #include <rpm/rpmstring.h>
13 #include <rpm/rpmfileutil.h>
17 #define POPT_SHOWVERSION -999
18 #define POPT_SHOWRC -998
19 #define POPT_QUERYTAGS -997
20 #define POPT_PREDEFINE -996
21 #define POPT_DBPATH -995
22 #define POPT_UNDEFINE -994
24 static int _debug = 0;
26 extern int _rpmds_nopromote;
28 extern int _fsm_debug;
30 extern int _print_pkts;
32 extern int _psm_debug;
34 /* XXX avoid -lrpmbuild linkage. */
37 extern int _rpmts_stats;
39 const char * rpmcliPipeOutput = NULL;
41 const char * rpmcliRcfile = NULL;
43 const char * rpmcliRootDir = "/";
45 rpmQueryFlags rpmcliQueryFlags;
47 extern int _rpmio_debug;
49 static int rpmcliInitialized = -1;
52 * Display rpm version.
54 static void printVersion(FILE * fp)
56 fprintf(fp, _("RPM version %s\n"), rpmEVR);
60 * Make sure that config files have been read.
61 * @warning Options like --rcfile and --verbose must precede callers option.
63 void rpmcliConfigured(void)
66 if (rpmcliInitialized < 0)
67 rpmcliInitialized = rpmReadConfigFiles(rpmcliRcfile, NULL);
68 if (rpmcliInitialized)
74 static void rpmcliAllArgCallback( poptContext con,
75 enum poptCallbackReason reason,
76 const struct poptOption * opt, const char * arg,
80 /* XXX avoid accidental collisions with POPT_BIT_SET for flags */
84 rpmSetVerbosity(RPMLOG_WARNING);
87 rpmIncreaseVerbosity();
90 (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
94 /* XXX Convert '-' in macro name to underscore, skip leading %. */
96 while (*t && !risspace(*t)) {
97 if (*t == '-') *t = '_';
102 /* XXX Predefine macro if not initialized yet. */
103 if (rpmcliInitialized < 0)
104 (void) rpmDefineMacro(NULL, t, RMIL_CMDLINE);
106 (void) rpmDefineMacro(NULL, t, RMIL_CMDLINE);
107 (void) rpmDefineMacro(rpmCLIMacroContext, t, RMIL_CMDLINE);
119 { char *val = rpmExpand(arg, NULL);
120 fprintf(stdout, "%s\n", val);
126 addMacro(NULL, "_dbpath", NULL, arg, RMIL_CMDLINE);
128 case POPT_SHOWVERSION:
129 printVersion(stdout);
134 (void) rpmShowRC(stdout);
138 rpmDisplayQueryTags(stdout);
141 case RPMCLI_POPT_NODIGEST:
142 rpmcliQueryFlags |= VERIFY_DIGEST;
145 case RPMCLI_POPT_NOSIGNATURE:
146 rpmcliQueryFlags |= VERIFY_SIGNATURE;
149 case RPMCLI_POPT_NOHDRCHK:
150 rpmcliQueryFlags |= VERIFY_HDRCHK;
155 struct poptOption rpmcliAllPoptTable[] = {
157 { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
158 rpmcliAllArgCallback, 0, NULL, NULL },
160 { "debug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_debug, -1,
163 { "predefine", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_PREDEFINE,
164 N_("predefine MACRO with value EXPR"),
165 N_("'MACRO EXPR'") },
166 { "define", 'D', POPT_ARG_STRING, 0, 'D',
167 N_("define MACRO with value EXPR"),
168 N_("'MACRO EXPR'") },
169 { "undefine", '\0', POPT_ARG_STRING, 0, POPT_UNDEFINE,
170 N_("undefine MACRO"),
172 { "eval", 'E', POPT_ARG_STRING, 0, 'E',
173 N_("print macro expansion of EXPR"),
175 { "macros", '\0', POPT_ARG_STRING, ¯ofiles, 0,
176 N_("read <FILE:...> instead of default file(s)"),
179 { "nodigest", '\0', 0, 0, RPMCLI_POPT_NODIGEST,
180 N_("don't verify package digest(s)"), NULL },
181 { "nohdrchk", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, RPMCLI_POPT_NOHDRCHK,
182 N_("don't verify database header(s) when retrieved"), NULL },
183 { "nosignature", '\0', 0, 0, RPMCLI_POPT_NOSIGNATURE,
184 N_("don't verify package signature(s)"), NULL },
186 { "pipe", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, &rpmcliPipeOutput, 0,
187 N_("send stdout to CMD"),
189 { "rcfile", '\0', POPT_ARG_STRING, &rpmcliRcfile, 0,
190 N_("read <FILE:...> instead of default file(s)"),
192 { "root", 'r', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT, &rpmcliRootDir, 0,
193 N_("use ROOT as top level directory"),
195 { "dbpath", '\0', POPT_ARG_STRING, 0, POPT_DBPATH,
196 N_("use database in DIRECTORY"),
199 { "querytags", '\0', 0, 0, POPT_QUERYTAGS,
200 N_("display known query tags"), NULL },
201 { "showrc", '\0', 0, NULL, POPT_SHOWRC,
202 N_("display final rpmrc and macro configuration"), NULL },
203 { "quiet", '\0', 0, NULL, 'q',
204 N_("provide less detailed output"), NULL},
205 { "verbose", 'v', 0, NULL, 'v',
206 N_("provide more detailed output"), NULL},
207 { "version", '\0', 0, NULL, POPT_SHOWVERSION,
208 N_("print the version of rpm being used"), NULL },
210 { "promoteepoch", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_nopromote, 0,
213 { "fsmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_debug, -1,
214 N_("debug payload file state machine"), NULL},
215 { "prtpkts", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_print_pkts, -1,
217 { "rpmfcdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfc_debug, -1,
219 { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
220 N_("debug rpmio I/O"), NULL},
221 { "stats", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_stats, -1,
228 rpmcliFini(poptContext optCon)
230 poptFreeContext(optCon);
232 rpmFreeMacros(rpmCLIMacroContext);
235 rpmcliInitialized = -1;
241 rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable)
245 const char *ctx, *execPath;
247 setprogname(argv[0]); /* Retrofit glibc __progname */
249 /* XXX glibc churn sanity */
250 if (__progname == NULL) {
251 if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
252 else __progname = argv[0];
255 #if defined(ENABLE_NLS)
256 (void) setlocale(LC_ALL, "" );
258 (void) bindtextdomain(PACKAGE, LOCALEDIR);
259 (void) textdomain(PACKAGE);
262 rpmSetVerbosity(RPMLOG_NOTICE);
264 if (optionsTable == NULL) {
265 /* Read rpm configuration (if not already read). */
270 /* XXX hack to get popt working from build tree wrt lt-foo names */
271 ctx = rstreqn(__progname, "lt-", 3) ? __progname + 3 : __progname;
273 optCon = poptGetContext(ctx, argc, (const char **)argv, optionsTable, 0);
275 char *poptfile = rpmGenPath(rpmConfigDir(), LIBRPMALIAS_FILENAME, NULL);
276 (void) poptReadConfigFile(optCon, poptfile);
279 (void) poptReadDefaultConfig(optCon, 1);
281 if ((execPath = getenv("RPM_POPTEXEC_PATH")) == NULL)
282 execPath = LIBRPMALIAS_EXECPATH;
283 poptSetExecPath(optCon, execPath, 1);
285 /* Process all options, whine if unknown. */
286 while ((rc = poptGetNextOpt(optCon)) > 0) {
287 fprintf(stderr, _("%s: option table misconfigured (%d)\n"),
293 fprintf(stderr, "%s: %s: %s\n", __progname,
294 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
299 /* Read rpm configuration (if not already read). */
303 rpmIncreaseVerbosity();
304 rpmIncreaseVerbosity();