00001
00006 #include "system.h"
00007
00008 #include <rpmcli.h>
00009
00010 #include "debug.h"
00011
00012 #define POPT_SHOWVERSION -999
00013 #define POPT_SHOWRC -998
00014 #define POPT_QUERYTAGS -997
00015 #define POPT_PREDEFINE -996
00016 #ifdef NOTYET
00017 #define POPT_RCFILE -995
00018 #endif
00019
00020
00021 static int _debug = 0;
00022
00023
00024
00025 extern int _rpmds_nopromote;
00026
00027
00028 extern int _fps_debug;
00029
00030
00031 extern int _fsm_debug;
00032
00033
00034 extern int _fsm_threads;
00035
00036
00037 extern int _hdr_debug;
00038
00039
00040 extern int _print_pkts;
00041
00042
00043 extern int _psm_debug;
00044
00045
00046 extern int _psm_threads;
00047
00048
00049 extern int _rpmal_debug;
00050
00051
00052 extern int _rpmdb_debug;
00053
00054
00055 extern int _rpmds_debug;
00056
00057
00058
00059 int _rpmfc_debug;
00060
00061
00062 extern int _rpmfi_debug;
00063
00064
00065 extern int _rpmps_debug;
00066
00067
00068 extern int _rpmsq_debug;
00069
00070
00071 extern int _rpmsx_debug;
00072
00073
00074 extern int _rpmte_debug;
00075
00076
00077 extern int _rpmts_debug;
00078
00079
00080 extern int _rpmts_stats;
00081
00082
00083 extern int noLibio;
00084
00085
00086
00087 const char * rpmcliPipeOutput = NULL;
00088
00089
00090 const char * rpmcliRcfile = NULL;
00091
00092
00093 const char * rpmcliRootDir = "/";
00094
00095
00096 rpmQueryFlags rpmcliQueryFlags;
00097
00098
00099
00100 extern int _ftp_debug;
00101
00102
00103 extern int noLibio;
00104
00105
00106 extern int _rpmio_debug;
00107
00108
00109
00110 static int rpmcliInitialized = -1;
00111
00115 static void printVersion(FILE * fp)
00116
00117
00118 {
00119 fprintf(fp, _("RPM version %s\n"), rpmEVR);
00120 }
00121
00126
00127 void rpmcliConfigured(void)
00128
00129
00130
00131
00132 {
00133
00134 if (rpmcliInitialized < 0)
00135 rpmcliInitialized = rpmReadConfigFiles(rpmcliRcfile, NULL);
00136 if (rpmcliInitialized)
00137 exit(EXIT_FAILURE);
00138 }
00139
00142
00143 static void rpmcliAllArgCallback( poptContext con,
00144 enum poptCallbackReason reason,
00145 const struct poptOption * opt, const char * arg,
00146 const void * data)
00147
00148
00149
00150
00151 {
00152
00153
00154
00155 if (opt->arg == NULL)
00156 switch (opt->val) {
00157 case 'q':
00158 rpmSetVerbosity(RPMMESS_QUIET);
00159 break;
00160 case 'v':
00161 rpmIncreaseVerbosity();
00162 break;
00163 case POPT_PREDEFINE:
00164 (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
00165 break;
00166 case 'D':
00167
00168 if (rpmcliInitialized < 0)
00169 (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
00170 rpmcliConfigured();
00171
00172 (void) rpmDefineMacro(NULL, arg, RMIL_CMDLINE);
00173 (void) rpmDefineMacro(rpmCLIMacroContext, arg, RMIL_CMDLINE);
00174
00175 break;
00176 case 'E':
00177 rpmcliConfigured();
00178 { const char *val = rpmExpand(arg, NULL);
00179 fprintf(stdout, "%s\n", val);
00180 val = _free(val);
00181 }
00182 break;
00183 case POPT_SHOWVERSION:
00184 printVersion(stdout);
00185 exit(EXIT_SUCCESS);
00186 break;
00187 case POPT_SHOWRC:
00188 rpmcliConfigured();
00189 (void) rpmShowRC(stdout);
00190 exit(EXIT_SUCCESS);
00191 break;
00192 case POPT_QUERYTAGS:
00193 rpmDisplayQueryTags(stdout);
00194 exit(EXIT_SUCCESS);
00195 break;
00196 #if defined(POPT_RCFILE)
00197 case POPT_RCFILE:
00198 break;
00199 #endif
00200 case RPMCLI_POPT_NODIGEST:
00201 rpmcliQueryFlags |= VERIFY_DIGEST;
00202 break;
00203
00204 case RPMCLI_POPT_NOSIGNATURE:
00205 rpmcliQueryFlags |= VERIFY_SIGNATURE;
00206 break;
00207
00208 case RPMCLI_POPT_NOHDRCHK:
00209 rpmcliQueryFlags |= VERIFY_HDRCHK;
00210 break;
00211 }
00212
00213 }
00214
00215
00216
00217 struct poptOption rpmcliAllPoptTable[] = {
00218
00219 { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
00220 rpmcliAllArgCallback, 0, NULL, NULL },
00221
00222
00223 { "debug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_debug, -1,
00224 NULL, NULL },
00225
00226 { "predefine", 'D', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_PREDEFINE,
00227 N_("predefine MACRO with value EXPR"),
00228 N_("'MACRO EXPR'") },
00229 { "define", 'D', POPT_ARG_STRING, 0, 'D',
00230 N_("define MACRO with value EXPR"),
00231 N_("'MACRO EXPR'") },
00232 { "eval", 'E', POPT_ARG_STRING, 0, 'E',
00233 N_("print macro expansion of EXPR"),
00234 N_("'EXPR'") },
00235 { "macros", '\0', POPT_ARG_STRING, ¯ofiles, 0,
00236 N_("read <FILE:...> instead of default file(s)"),
00237 N_("<FILE:...>") },
00238
00239 { "nodigest", '\0', 0, 0, RPMCLI_POPT_NODIGEST,
00240 N_("don't verify package digest(s)"), NULL },
00241 { "nohdrchk", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, RPMCLI_POPT_NOHDRCHK,
00242 N_("don't verify database header(s) when retrieved"), NULL },
00243 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
00244 { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
00245 N_("disable use of libio(3) API"), NULL},
00246 #endif
00247 { "nosignature", '\0', 0, 0, RPMCLI_POPT_NOSIGNATURE,
00248 N_("don't verify package signature(s)"), NULL },
00249
00250 { "pipe", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, &rpmcliPipeOutput, 0,
00251 N_("send stdout to CMD"),
00252 N_("CMD") },
00253 #if !defined(POPT_RCFILE)
00254 { "rcfile", '\0', POPT_ARG_STRING, &rpmcliRcfile, 0,
00255 N_("read <FILE:...> instead of default file(s)"),
00256 N_("<FILE:...>") },
00257 #else
00258 { "rcfile", '\0', 0, NULL, POPT_RCFILE,
00259 N_("read <FILE:...> instead of default file(s)"),
00260 N_("<FILE:...>") },
00261 #endif
00262 { "root", 'r', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT, &rpmcliRootDir, 0,
00263 N_("use ROOT as top level directory"),
00264 N_("ROOT") },
00265
00266 { "querytags", '\0', 0, 0, POPT_QUERYTAGS,
00267 N_("display known query tags"), NULL },
00268 { "showrc", '\0', 0, NULL, POPT_SHOWRC,
00269 N_("display final rpmrc and macro configuration"), NULL },
00270 { "quiet", '\0', 0, NULL, 'q',
00271 N_("provide less detailed output"), NULL},
00272 { "verbose", 'v', 0, NULL, 'v',
00273 N_("provide more detailed output"), NULL},
00274 { "version", '\0', 0, NULL, POPT_SHOWVERSION,
00275 N_("print the version of rpm being used"), NULL },
00276
00277 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
00278 { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
00279 N_("disable use of libio(3) API"), NULL},
00280 #endif
00281
00282 { "promoteepoch", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_nopromote, 0,
00283 NULL, NULL},
00284
00285 { "fpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fps_debug, -1,
00286 NULL, NULL},
00287 { "fsmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_debug, -1,
00288 N_("debug payload file state machine"), NULL},
00289 { "fsmthreads", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_threads, -1,
00290 N_("use threads for file state machine"), NULL},
00291 { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
00292 N_("debug protocol data stream"), NULL},
00293 { "hdrdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_hdr_debug, -1,
00294 NULL, NULL},
00295 #ifdef DYING
00296 { "poptdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_popt_debug, -1,
00297 N_("debug option/argument processing"), NULL},
00298 #endif
00299 { "prtpkts", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_print_pkts, -1,
00300 NULL, NULL},
00301 { "psmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_psm_debug, -1,
00302 N_("debug package state machine"), NULL},
00303 { "psmthreads", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_psm_threads, -1,
00304 N_("use threads for package state machine"), NULL},
00305 { "rpmaldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmal_debug, -1,
00306 NULL, NULL},
00307 { "rpmdbdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmdb_debug, -1,
00308 NULL, NULL},
00309 { "rpmdsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_debug, -1,
00310 NULL, NULL},
00311 { "rpmfcdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfc_debug, -1,
00312 NULL, NULL},
00313 { "rpmfidebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfi_debug, -1,
00314 NULL, NULL},
00315 { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
00316 N_("debug rpmio I/O"), NULL},
00317 { "rpmpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmps_debug, -1,
00318 NULL, NULL},
00319 { "rpmsqdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmsq_debug, -1,
00320 NULL, NULL},
00321 { "rpmsxdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmsx_debug, -1,
00322 NULL, NULL},
00323 { "rpmtedebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmte_debug, -1,
00324 NULL, NULL},
00325 { "rpmtsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_debug, -1,
00326 NULL, NULL},
00327 { "stats", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_stats, -1,
00328 NULL, NULL},
00329 { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
00330 N_("debug URL cache handling"), NULL},
00331
00332 POPT_TABLEEND
00333 };
00334
00335
00336 poptContext
00337 rpmcliFini(poptContext optCon)
00338 {
00339 optCon = poptFreeContext(optCon);
00340
00341 #if HAVE_MCHECK_H && HAVE_MTRACE
00342
00343 muntrace();
00344
00345 #endif
00346
00347 return NULL;
00348 }
00349
00350
00351 poptContext
00352 rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable)
00353 {
00354 const char * optArg;
00355 poptContext optCon;
00356 int rc;
00357
00358 #if HAVE_MCHECK_H && HAVE_MTRACE
00359
00360 mtrace();
00361
00362 #endif
00363
00364 setprogname(argv[0]);
00365
00366
00367 if (__progname == NULL) {
00368 if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
00369 else __progname = argv[0];
00370 }
00371
00372
00373 #if defined(ENABLE_NLS) && !defined(__LCLINT__)
00374 (void) setlocale(LC_ALL, "" );
00375 (void) bindtextdomain(PACKAGE, LOCALEDIR);
00376 (void) textdomain(PACKAGE);
00377 #endif
00378
00379 rpmSetVerbosity(RPMMESS_NORMAL);
00380
00381 if (optionsTable == NULL) {
00382
00383 rpmcliConfigured();
00384 return NULL;
00385 }
00386
00387
00388 optCon = poptGetContext(__progname, argc, (const char **)argv, optionsTable, 0);
00389
00390 (void) poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
00391 (void) poptReadDefaultConfig(optCon, 1);
00392 poptSetExecPath(optCon, RPMCONFIGDIR, 1);
00393
00394
00395 while ((rc = poptGetNextOpt(optCon)) > 0) {
00396 optArg = poptGetOptArg(optCon);
00397 switch (rc) {
00398 default:
00399
00400 fprintf(stderr, _("%s: option table misconfigured (%d)\n"),
00401 __progname, rc);
00402
00403 exit(EXIT_FAILURE);
00404
00405 break;
00406 }
00407 }
00408
00409 if (rc < -1) {
00410
00411 fprintf(stderr, "%s: %s: %s\n", __progname,
00412 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
00413 poptStrerror(rc));
00414
00415 exit(EXIT_FAILURE);
00416 }
00417
00418
00419 rpmcliConfigured();
00420
00421 if (_debug) {
00422 rpmIncreaseVerbosity();
00423 rpmIncreaseVerbosity();
00424 }
00425
00426 return optCon;
00427 }
00428