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