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