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 { char *s, *t;
00177
00178 s = t = xstrdup(arg);
00179 while (*t && !xisspace(*t)) {
00180 if (*t == '-') *t = '_';
00181 t++;
00182 }
00183 t = s;
00184 if (*t == '%') t++;
00185
00186 if (rpmcliInitialized < 0)
00187 (void) rpmDefineMacro(NULL, t, RMIL_CMDLINE);
00188 rpmcliConfigured();
00189 (void) rpmDefineMacro(NULL, t, RMIL_CMDLINE);
00190 (void) rpmDefineMacro(rpmCLIMacroContext, t, RMIL_CMDLINE);
00191 s = _free(s);
00192 break;
00193 }
00194 case 'E':
00195 rpmcliConfigured();
00196 { const char *val = rpmExpand(arg, NULL);
00197 fprintf(stdout, "%s\n", val);
00198 val = _free(val);
00199 }
00200 break;
00201 case POPT_SHOWVERSION:
00202 printVersion(stdout);
00203 exit(EXIT_SUCCESS);
00204 break;
00205 case POPT_SHOWRC:
00206 rpmcliConfigured();
00207 (void) rpmShowRC(stdout);
00208 exit(EXIT_SUCCESS);
00209 break;
00210 case POPT_QUERYTAGS:
00211 rpmDisplayQueryTags(stdout);
00212 exit(EXIT_SUCCESS);
00213 break;
00214 #if defined(POPT_RCFILE)
00215 case POPT_RCFILE:
00216 break;
00217 #endif
00218 case RPMCLI_POPT_NODIGEST:
00219 rpmcliQueryFlags |= VERIFY_DIGEST;
00220 break;
00221
00222 case RPMCLI_POPT_NOSIGNATURE:
00223 rpmcliQueryFlags |= VERIFY_SIGNATURE;
00224 break;
00225
00226 case RPMCLI_POPT_NOHDRCHK:
00227 rpmcliQueryFlags |= VERIFY_HDRCHK;
00228 break;
00229 }
00230
00231 }
00232
00233
00234 int ftsOpts = 0;
00235
00236
00237 struct poptOption rpmcliFtsPoptTable[] = {
00238 { "comfollow", '\0', POPT_BIT_SET, &ftsOpts, FTS_COMFOLLOW,
00239 N_("FTS_COMFOLLOW: follow command line symlinks"), NULL },
00240 { "logical", '\0', POPT_BIT_SET, &ftsOpts, FTS_LOGICAL,
00241 N_("FTS_LOGICAL: logical walk"), NULL },
00242 { "nochdir", '\0', POPT_BIT_SET, &ftsOpts, FTS_NOCHDIR,
00243 N_("FTS_NOCHDIR: don't change directories"), NULL },
00244 { "nostat", '\0', POPT_BIT_SET, &ftsOpts, FTS_NOSTAT,
00245 N_("FTS_NOSTAT: don't get stat info"), NULL },
00246 { "physical", '\0', POPT_BIT_SET, &ftsOpts, FTS_PHYSICAL,
00247 N_("FTS_PHYSICAL: physical walk"), NULL },
00248 { "seedot", '\0', POPT_BIT_SET, &ftsOpts, FTS_SEEDOT,
00249 N_("FTS_SEEDOT: return dot and dot-dot"), NULL },
00250 { "xdev", '\0', POPT_BIT_SET, &ftsOpts, FTS_XDEV,
00251 N_("FTS_XDEV: don't cross devices"), NULL },
00252 { "whiteout", '\0', POPT_BIT_SET, &ftsOpts, FTS_WHITEOUT,
00253 N_("FTS_WHITEOUT: return whiteout information"), NULL },
00254 POPT_TABLEEND
00255 };
00256
00257
00258
00259 struct poptOption rpmcliAllPoptTable[] = {
00260
00261 { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
00262 rpmcliAllArgCallback, 0, NULL, NULL },
00263
00264
00265 { "debug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_debug, -1,
00266 NULL, NULL },
00267
00268 { "predefine", 'D', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_PREDEFINE,
00269 N_("predefine MACRO with value EXPR"),
00270 N_("'MACRO EXPR'") },
00271 { "define", 'D', POPT_ARG_STRING, 0, 'D',
00272 N_("define MACRO with value EXPR"),
00273 N_("'MACRO EXPR'") },
00274 { "eval", 'E', POPT_ARG_STRING, 0, 'E',
00275 N_("print macro expansion of EXPR"),
00276 N_("'EXPR'") },
00277 { "macros", '\0', POPT_ARG_STRING, ¯ofiles, 0,
00278 N_("read <FILE:...> instead of default file(s)"),
00279 N_("<FILE:...>") },
00280
00281 { "nodigest", '\0', 0, 0, RPMCLI_POPT_NODIGEST,
00282 N_("don't verify package digest(s)"), NULL },
00283 { "nohdrchk", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, RPMCLI_POPT_NOHDRCHK,
00284 N_("don't verify database header(s) when retrieved"), NULL },
00285 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
00286 { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
00287 N_("disable use of libio(3) API"), NULL},
00288 #endif
00289 { "nosignature", '\0', 0, 0, RPMCLI_POPT_NOSIGNATURE,
00290 N_("don't verify package signature(s)"), NULL },
00291
00292 { "pipe", '\0', POPT_ARG_STRING|POPT_ARGFLAG_DOC_HIDDEN, &rpmcliPipeOutput, 0,
00293 N_("send stdout to CMD"),
00294 N_("CMD") },
00295 #if !defined(POPT_RCFILE)
00296 { "rcfile", '\0', POPT_ARG_STRING, &rpmcliRcfile, 0,
00297 N_("read <FILE:...> instead of default file(s)"),
00298 N_("<FILE:...>") },
00299 #else
00300 { "rcfile", '\0', 0, NULL, POPT_RCFILE,
00301 N_("read <FILE:...> instead of default file(s)"),
00302 N_("<FILE:...>") },
00303 #endif
00304 { "root", 'r', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT, &rpmcliRootDir, 0,
00305 N_("use ROOT as top level directory"),
00306 N_("ROOT") },
00307
00308 { "querytags", '\0', 0, 0, POPT_QUERYTAGS,
00309 N_("display known query tags"), NULL },
00310 { "showrc", '\0', 0, NULL, POPT_SHOWRC,
00311 N_("display final rpmrc and macro configuration"), NULL },
00312 { "quiet", '\0', 0, NULL, 'q',
00313 N_("provide less detailed output"), NULL},
00314 { "verbose", 'v', 0, NULL, 'v',
00315 N_("provide more detailed output"), NULL},
00316 { "version", '\0', 0, NULL, POPT_SHOWVERSION,
00317 N_("print the version of rpm being used"), NULL },
00318
00319 #if HAVE_LIBIO_H && defined(_G_IO_IO_FILE_VERSION)
00320 { "nolibio", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &noLibio, 1,
00321 N_("disable use of libio(3) API"), NULL},
00322 #endif
00323
00324 { "promoteepoch", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_nopromote, 0,
00325 NULL, NULL},
00326
00327 { "fpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fps_debug, -1,
00328 NULL, NULL},
00329 { "fsmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_debug, -1,
00330 N_("debug payload file state machine"), NULL},
00331 { "fsmthreads", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_fsm_threads, -1,
00332 N_("use threads for file state machine"), NULL},
00333 { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
00334 N_("debug FTP/HTTP data stream"), NULL},
00335 { "avdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_av_debug, -1,
00336 N_("debug argv collections"), NULL},
00337 { "davdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_dav_debug, -1,
00338 N_("debug WebDAV data stream"), NULL},
00339 { "hdrdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_hdr_debug, -1,
00340 NULL, NULL},
00341 #ifdef DYING
00342 { "poptdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_popt_debug, -1,
00343 N_("debug option/argument processing"), NULL},
00344 #endif
00345 { "prtpkts", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_print_pkts, -1,
00346 NULL, NULL},
00347 { "psmdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_psm_debug, -1,
00348 N_("debug package state machine"), NULL},
00349 { "psmthreads", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_psm_threads, -1,
00350 N_("use threads for package state machine"), NULL},
00351 { "rpmaldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmal_debug, -1,
00352 NULL, NULL},
00353 { "rpmdbdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmdb_debug, -1,
00354 NULL, NULL},
00355 { "rpmdsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmds_debug, -1,
00356 NULL, NULL},
00357 { "rpmfcdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfc_debug, -1,
00358 NULL, NULL},
00359 { "rpmfidebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmfi_debug, -1,
00360 NULL, NULL},
00361 { "rpmgidebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmgi_debug, -1,
00362 NULL, NULL},
00363 { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
00364 N_("debug rpmio I/O"), NULL},
00365 { "rpmpsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmps_debug, -1,
00366 NULL, NULL},
00367 { "rpmsqdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmsq_debug, -1,
00368 NULL, NULL},
00369 { "rpmsxdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmsx_debug, -1,
00370 NULL, NULL},
00371 { "rpmtedebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmte_debug, -1,
00372 NULL, NULL},
00373 { "rpmtsdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_debug, -1,
00374 NULL, NULL},
00375 { "stats", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmts_stats, -1,
00376 NULL, NULL},
00377 { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
00378 N_("debug URL cache handling"), NULL},
00379
00380 POPT_TABLEEND
00381 };
00382
00383
00384 poptContext
00385 rpmcliFini(poptContext optCon)
00386 {
00387 optCon = poptFreeContext(optCon);
00388
00389 #if HAVE_MCHECK_H && HAVE_MTRACE
00390
00391 muntrace();
00392
00393 #endif
00394
00395 return NULL;
00396 }
00397
00398
00399 poptContext
00400 rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable)
00401 {
00402 const char * optArg;
00403 poptContext optCon;
00404 int rc;
00405
00406 #if HAVE_MCHECK_H && HAVE_MTRACE
00407
00408 mtrace();
00409
00410 #endif
00411
00412 setprogname(argv[0]);
00413
00414
00415 if (__progname == NULL) {
00416 if ((__progname = strrchr(argv[0], '/')) != NULL) __progname++;
00417 else __progname = argv[0];
00418 }
00419
00420
00421 #if defined(ENABLE_NLS) && !defined(__LCLINT__)
00422 (void) setlocale(LC_ALL, "" );
00423 (void) bindtextdomain(PACKAGE, LOCALEDIR);
00424 (void) textdomain(PACKAGE);
00425 #endif
00426
00427 rpmSetVerbosity(RPMMESS_NORMAL);
00428
00429 if (optionsTable == NULL) {
00430
00431 rpmcliConfigured();
00432 return NULL;
00433 }
00434
00435
00436 optCon = poptGetContext(__progname, argc, (const char **)argv, optionsTable, 0);
00437
00438 (void) poptReadConfigFile(optCon, LIBRPMALIAS_FILENAME);
00439 (void) poptReadDefaultConfig(optCon, 1);
00440 poptSetExecPath(optCon, RPMCONFIGDIR, 1);
00441
00442
00443 while ((rc = poptGetNextOpt(optCon)) > 0) {
00444 optArg = poptGetOptArg(optCon);
00445 switch (rc) {
00446 default:
00447
00448 fprintf(stderr, _("%s: option table misconfigured (%d)\n"),
00449 __progname, rc);
00450
00451 exit(EXIT_FAILURE);
00452
00453 break;
00454 }
00455 }
00456
00457 if (rc < -1) {
00458
00459 fprintf(stderr, "%s: %s: %s\n", __progname,
00460 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
00461 poptStrerror(rc));
00462
00463 exit(EXIT_FAILURE);
00464 }
00465
00466
00467 rpmcliConfigured();
00468
00469 if (_debug) {
00470 rpmIncreaseVerbosity();
00471 rpmIncreaseVerbosity();
00472 }
00473
00474 return optCon;
00475 }
00476