1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/rpm-razor.c Tue Jun 03 15:21:22 2008 -0400
1.3 @@ -0,0 +1,482 @@
1.4 +/*
1.5 + * Copyright (C) 2008 Kristian Høgsberg <krh@redhat.com>
1.6 + * Copyright (C) 2008 Red Hat, Inc
1.7 + *
1.8 + * This program is free software; you can redistribute it and/or modify
1.9 + * it under the terms of the GNU General Public License as published by
1.10 + * the Free Software Foundation; either version 2 of the License, or
1.11 + * (at your option) any later version.
1.12 + *
1.13 + * This program is distributed in the hope that it will be useful,
1.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.16 + * GNU General Public License for more details.
1.17 + *
1.18 + * You should have received a copy of the GNU General Public License along
1.19 + * with this program; if not, write to the Free Software Foundation, Inc.,
1.20 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1.21 + */
1.22 +
1.23 +#include <stdlib.h>
1.24 +#include <string.h>
1.25 +#include <stdio.h>
1.26 +#include "razor.h"
1.27 +
1.28 +enum option_type {
1.29 + OPTION_LAST,
1.30 + OPTION_GROUP,
1.31 + OPTION_BOOL,
1.32 + OPTION_STRING
1.33 +};
1.34 +
1.35 +struct option {
1.36 + enum option_type type;
1.37 + const char *name;
1.38 + char short_name;
1.39 + const char *arg_name;
1.40 + const char *description;
1.41 + void *data;
1.42 +};
1.43 +
1.44 +static int option_all;
1.45 +
1.46 +static const struct option query_options[] = {
1.47 + { OPTION_BOOL, "configfiles", 'c', NULL, "list all configuration files", NULL },
1.48 + { OPTION_BOOL, "docfiles", 'd', NULL, "list all documentation files", NULL },
1.49 + { OPTION_BOOL, "dump", 0, NULL, "dump basic file information", NULL },
1.50 + { OPTION_BOOL, "list", 0, NULL, "list files in package", NULL },
1.51 + { OPTION_STRING, "queryformat", 0, "QUERYFORMAT", "use the following query format", NULL },
1.52 + { OPTION_BOOL, "state", 's', NULL, "display the states of the listed files", NULL },
1.53 + { OPTION_BOOL, "all", 'a', NULL, "query/verify all packages", &option_all },
1.54 + { OPTION_BOOL, "file", 'f', NULL, "query/verify package(s) owning file", NULL },
1.55 + { OPTION_BOOL, "group", 'g', NULL, "query/verify package(s) in group", NULL },
1.56 + { OPTION_BOOL, "package", 'p', NULL, "query/verify a package file", NULL },
1.57 + { OPTION_BOOL, "ftswalk", 'W', NULL, "query/verify package(s) from TOP file tree walk", NULL },
1.58 + { OPTION_BOOL, "pkgid", 0, NULL, "query/verify package(s) with package identifier", NULL },
1.59 + { OPTION_BOOL, "hdrid", 0, NULL, "query/verify package(s) with header identifier", NULL },
1.60 + { OPTION_BOOL, "fileid", 0, NULL, "query/verify package(s) with file identifier", NULL },
1.61 + { OPTION_BOOL, "specfile", 0, NULL, "query a spec file", NULL, },
1.62 + { OPTION_BOOL, "triggeredby", 0, NULL, "query the package(s) triggered by the package", NULL },
1.63 + { OPTION_BOOL, "whatrequires", 0, NULL, "query/verify the package(s) which require a dependency", NULL },
1.64 + { OPTION_BOOL, "whatprovides", 0, NULL, "query/verify the package(s) which provide a dependency", NULL },
1.65 + { OPTION_BOOL, "nomanifest", 0, NULL, "do not process non-package files as manifests", NULL },
1.66 + { }
1.67 +};
1.68 +
1.69 +static const struct option verify_options[] = {
1.70 + { OPTION_BOOL, "nomd5", 0, NULL, "don't verify MD5 digest of files", NULL },
1.71 + { OPTION_BOOL, "nofiles", 0, NULL, "don't verify files in package", NULL },
1.72 + { OPTION_BOOL, "nodeps", 0, NULL, "don't verify package dependencies", NULL },
1.73 + { OPTION_BOOL, "noscript", 0, NULL, "don't execute verify script(s)", NULL, },
1.74 + { OPTION_BOOL, "all", 'a', NULL, "query/verify all packages", NULL },
1.75 + { OPTION_BOOL, "file", 'f', NULL, "query/verify package(s) owning file", NULL },
1.76 + { OPTION_BOOL, "group", 'g', NULL, "query/verify package(s) in group", NULL },
1.77 + { OPTION_BOOL, "package", 'p', NULL, "query/verify a package file", NULL },
1.78 + { OPTION_BOOL, "ftswalk", 'W', NULL, "query/verify package(s) from TOP file tree walk", NULL },
1.79 + { OPTION_BOOL, "pkgid", 0, NULL, "query/verify package(s) with package identifier", NULL },
1.80 + { OPTION_BOOL, "hdrid", 0, NULL, "query/verify package(s) with header identifier", NULL },
1.81 + { OPTION_BOOL, "fileid", 0, NULL, "query/verify package(s) with file identifier", NULL },
1.82 + { OPTION_BOOL, "specfile", 0, NULL, "query a spec file", NULL },
1.83 + { OPTION_BOOL, "triggeredby", 0, NULL, "query the package(s) triggered by the package", NULL },
1.84 + { OPTION_BOOL, "whatrequires", 0, NULL, "query/verify the package(s) which require a dependency", NULL },
1.85 + { OPTION_BOOL, "whatprovides", 0, NULL, "query/verify the package(s) which provide a dependency", NULL },
1.86 + { OPTION_BOOL, "nomanifest", 0, NULL, "do not process non-package files as manifests", NULL },
1.87 + { }
1.88 +};
1.89 +
1.90 +static const struct option ftw_options[] = {
1.91 + { OPTION_BOOL, "comfollow", 0, NULL, "FTS_COMFOLLOW: follow command line symlinks", NULL },
1.92 + { OPTION_BOOL, "logical", 0, NULL, "FTS_LOGICAL: logical walk", NULL },
1.93 + { OPTION_BOOL, "nochdir", 0, NULL, "FTS_NOCHDIR: don't change directories", NULL },
1.94 + { OPTION_BOOL, "nostat", 0, NULL, "FTS_NOSTAT: don't get stat info", NULL },
1.95 + { OPTION_BOOL, "physical", 0, NULL, "FTS_PHYSICAL: physical walk", NULL },
1.96 + { OPTION_BOOL, "seedot", 0, NULL, "FTS_SEEDOT: return dot and dot-dot", NULL },
1.97 + { OPTION_BOOL, "xdev", 0, NULL, "FTS_XDEV: don't cross devices", NULL },
1.98 + { OPTION_BOOL, "whiteout", 0, NULL, "FTS_WHITEOUT: return whiteout information", NULL },
1.99 + { }
1.100 +};
1.101 +
1.102 +static const struct option signature_options[] = {
1.103 + { OPTION_BOOL, "addsign", 0, NULL, "sign package(s) (identical to --resign)", NULL, },
1.104 + { OPTION_BOOL, "checksig", 'K', NULL, "verify package signature(s)", NULL, },
1.105 + { OPTION_BOOL, "delsign", 0, NULL, "delete package signatures", NULL, },
1.106 + { OPTION_BOOL, "import", 0, NULL, "import an armored public key", NULL, },
1.107 + { OPTION_BOOL, "resign", 0, NULL, "sign package(s) (identical to --addsign)", NULL, },
1.108 + { OPTION_BOOL, "nodigest", 0, NULL, "don't verify package digest(s)", NULL, },
1.109 + { OPTION_BOOL, "nosignature", 0, NULL, "don't verify package signature(s)", NULL },
1.110 + { }
1.111 +};
1.112 +
1.113 +static const struct option database_options[] = {
1.114 + { OPTION_BOOL, "initdb", 0, NULL, "initialize database", NULL },
1.115 + { OPTION_BOOL, "rebuilddb", 0, NULL, "rebuild database inverted lists from installed package headers", NULL },
1.116 + { }
1.117 +};
1.118 +
1.119 +static int option_erase, option_install, option_upgrade;
1.120 +
1.121 +static const struct option install_options[] = {
1.122 + { OPTION_BOOL, "aid", 0, NULL, "add suggested packages to transaction", NULL, },
1.123 + { OPTION_BOOL, "allfiles", 0, NULL, "install all files, even configurations which might otherwise be skipped", NULL, },
1.124 + { OPTION_BOOL, "allmatches", 0, NULL, "remove all packages which match <package> (normally an error is generated if <package> specified multiple packages)", NULL, },
1.125 + { OPTION_BOOL, "badreloc", 0, NULL, "relocate files in non-relocatable package", NULL },
1.126 + { OPTION_BOOL, "erase", 'e', "<package>", "erase (uninstall) package", &option_erase },
1.127 + { OPTION_BOOL, "excludedocs", 0, NULL, "do not install documentation", NULL, },
1.128 + { OPTION_BOOL, "excludepath", 0, "<path>", "skip files with leading component <path> ", NULL, },
1.129 + { OPTION_BOOL, "fileconflicts", 0, NULL, "detect file conflicts between packages", NULL, },
1.130 + { OPTION_BOOL, "force", 0, NULL, "short hand for --replacepkgs --replacefiles", NULL },
1.131 + { OPTION_BOOL, "freshen", 'F', "<packagefile>+", "upgrade package(s) if already installed", NULL },
1.132 + { OPTION_BOOL, "hash", 'h', NULL, "print hash marks as package installs (good with -v)", NULL },
1.133 + { OPTION_BOOL, "ignorearch", 0, NULL, "don't verify package architecture", NULL, },
1.134 + { OPTION_BOOL, "ignoreos", 0, NULL, "don't verify package operating system", NULL, },
1.135 + { OPTION_BOOL, "ignoresize", 0, NULL, "don't check disk space before installing", NULL },
1.136 + { OPTION_BOOL, "install", 'i', NULL, "install package(s)", &option_install },
1.137 + { OPTION_BOOL, "justdb", 0, NULL, "update the database, but do not modify the filesystem", NULL, },
1.138 + { OPTION_BOOL, "nodeps", 0, NULL, "do not verify package dependencies", NULL, },
1.139 + { OPTION_BOOL, "nomd5", 0, NULL, "don't verify MD5 digest of files", NULL, },
1.140 + { OPTION_BOOL, "nocontexts", 0, NULL, "don't install file security contexts", NULL, },
1.141 + { OPTION_BOOL, "noorder", 0, NULL, "do not reorder package installation to satisfy dependencies", NULL, },
1.142 + { OPTION_BOOL, "nosuggest", 0, NULL, "do not suggest missing dependency resolution(s)", NULL, },
1.143 + { OPTION_BOOL, "noscripts", 0, NULL, "do not execute package scriptlet(s)", NULL, },
1.144 + { OPTION_BOOL, "notriggers", 0, NULL, "do not execute any scriptlet(s) triggered by this package", NULL, },
1.145 + { OPTION_BOOL, "oldpackage", 0, NULL, "upgrade to an old version of the package (--force on upgrades does this automatically)", NULL },
1.146 + { OPTION_BOOL, "percent", 0, NULL, "print percentages as package installs", NULL, },
1.147 + { OPTION_STRING, "prefix", 0, "<dir>", "relocate the package to <dir>, if relocatable", NULL, },
1.148 + { OPTION_STRING, "relocate", 0, "<old>=<new>", "relocate files from path <old> to <new>", NULL, },
1.149 + { OPTION_BOOL, "repackage", 0, NULL, "save erased package files by repackaging", NULL, },
1.150 + { OPTION_BOOL, "replacefiles", 0, NULL, "ignore file conflicts between packages", NULL, },
1.151 + { OPTION_BOOL, "replacepkgs", 0, NULL, "reinstall if the package is already present", NULL, },
1.152 + { OPTION_BOOL, "test", 0, NULL, "don't install, but tell if it would work or not", NULL },
1.153 + { OPTION_BOOL, "upgrade", 'U', "<packagefile>+", "upgrade package(s)", &option_upgrade },
1.154 + { }
1.155 +};
1.156 +
1.157 +static int option_version;
1.158 +
1.159 +static const struct option common_options[] = {
1.160 + { OPTION_STRING, "define", 'D', "MACRO EXPR", "define MACRO with value EXPR", NULL, },
1.161 + { OPTION_STRING, "eval", 'E', "EXPR", "print macro expansion of EXPR", NULL },
1.162 + { OPTION_STRING, "macros", 0, "<FILE:...>", "read <FILE:...> instead of default file(s)", NULL },
1.163 + { OPTION_BOOL, "nodigest", 0, NULL, "don't verify package digest(s)", NULL, },
1.164 + { OPTION_BOOL, "nosignature", 0, NULL, "don't verify package signature(s)", NULL, },
1.165 + { OPTION_STRING, "rcfile", 0, "<FILE:...>", "read <FILE:...> instead of default file(s)", NULL },
1.166 + { OPTION_STRING, "root", 'r', "ROOT", "use ROOT as top level directory (default: \"/\")", NULL },
1.167 + { OPTION_BOOL, "querytags", 0, NULL, "display known query tags", NULL, },
1.168 + { OPTION_BOOL, "showrc", 0, NULL, "display final rpmrc and macro configuration", NULL, },
1.169 + { OPTION_BOOL, "quiet", 0, NULL, "provide less detailed output", NULL },
1.170 + { OPTION_BOOL, "verbose", 'v', NULL, "provide more detailed output", NULL },
1.171 + { OPTION_BOOL, "version", 0, NULL, "print the version of rpm being used", &option_version },
1.172 + { }
1.173 +};
1.174 +
1.175 +static const struct option alias_options[] = {
1.176 + { OPTION_BOOL, "scripts", 0, NULL, "list install/erase scriptlets from package(s)", NULL, },
1.177 + { OPTION_BOOL, "setperms", 0, NULL, "set permissions of files in a package", NULL, },
1.178 + { OPTION_BOOL, "setugids", 0, NULL, "set user/group ownership of files in a package", NULL, },
1.179 + { OPTION_BOOL, "conflicts", 0, NULL, "list capabilities this package conflicts with", NULL, },
1.180 + { OPTION_BOOL, "obsoletes", 0, NULL, "list other packages removed by installing this package", NULL, },
1.181 + { OPTION_BOOL, "provides", 0, NULL, "list capabilities that this package provides", NULL, },
1.182 + { OPTION_BOOL, "requires", 0, NULL, "list capabilities required by package(s)", NULL, },
1.183 + { OPTION_BOOL, "info", 0, NULL, "list descriptive information from package(s)", NULL, },
1.184 + { OPTION_BOOL, "changelog", 0, NULL, "list change logs for this package", NULL, },
1.185 + { OPTION_BOOL, "xml", 0, NULL, "list metadata in xml", NULL, },
1.186 + { OPTION_BOOL, "triggers", 0, NULL, "list trigger scriptlets from package(s)", NULL, },
1.187 + { OPTION_BOOL, "last", 0, NULL, "list package(s) by install time, most recent first", NULL, },
1.188 + { OPTION_BOOL, "dupes", 0, NULL, "list duplicated packages", NULL, },
1.189 + { OPTION_BOOL, "filesbypkg", 0, NULL, "list all files from each package", NULL, },
1.190 + { OPTION_BOOL, "fileclass", 0, NULL, "list file names with classes", NULL, },
1.191 + { OPTION_BOOL, "filecolor", 0, NULL, "list file names with colors", NULL, },
1.192 + { OPTION_BOOL, "filecontext", 0, NULL, "list file names with security context from header", NULL, },
1.193 + { OPTION_BOOL, "fscontext", 0, NULL, "list file names with security context from file system", NULL, },
1.194 + { OPTION_BOOL, "recontext", 0, NULL, "list file names with security context from policy RE", NULL, },
1.195 + { OPTION_BOOL, "fileprovide", 0, NULL, "list file names with provides", NULL, },
1.196 + { OPTION_BOOL, "filerequire", 0, NULL, "list file names with requires", NULL, },
1.197 + { OPTION_BOOL, "redhatprovides", 0, NULL, "find package name that contains a provided capability (needs rpmdb-redhat package installed)", NULL, },
1.198 + { OPTION_BOOL, "redhatrequires", 0, NULL, "find package name that contains a required capability (needs rpmdb-redhat package installed)", NULL, },
1.199 + { OPTION_STRING, "buildpolicy", 0, "<policy>", "set buildroot <policy> (e.g. compress man pages)", NULL, },
1.200 + { OPTION_BOOL, "with", 0, "<option>", "enable configure <option> for build", NULL, },
1.201 + { OPTION_BOOL, "without", 0, "<option>", "disable configure <option> for build", NULL },
1.202 + { }
1.203 +};
1.204 +
1.205 +static int option_help, option_usage;
1.206 +
1.207 +static const struct option help_options[] = {
1.208 + { OPTION_BOOL, "help", '?', NULL, "Show this help message", &option_help },
1.209 + { OPTION_BOOL, "usage", 0, NULL, "Display brief usage message", &option_usage},
1.210 + { }
1.211 +};
1.212 +
1.213 +static int option_query, option_verify;
1.214 +
1.215 +static const struct option rpm_options[] = {
1.216 + { OPTION_BOOL, "query", 'q', NULL, "Query rpm database", &option_query },
1.217 + { OPTION_BOOL, "verify", 'V', NULL, "Verify rpm database", &option_verify },
1.218 + { OPTION_GROUP, NULL, 0, NULL, "Query options (with -q or --query):", &query_options },
1.219 + { OPTION_GROUP, NULL, 0, NULL, "Verify options (with -V or --verify):", &verify_options },
1.220 + { OPTION_GROUP, NULL, 0, NULL, "File tree walk options (with --ftswalk):", &ftw_options },
1.221 + { OPTION_GROUP, NULL, 0, NULL, "Signature options:", &signature_options },
1.222 + { OPTION_GROUP, NULL, 0, NULL, "Database options:", &database_options },
1.223 + { OPTION_GROUP, NULL, 0, NULL, "Install/Upgrade/Erase options:", &install_options },
1.224 + { OPTION_GROUP, NULL, 0, NULL, "Common options for all rpm modes and executables:", &common_options },
1.225 + { OPTION_GROUP, NULL, 0, NULL, "Options implemented via popt alias/exec:", &alias_options },
1.226 + { OPTION_GROUP, NULL, 0, NULL, "Help options", &help_options },
1.227 + { }
1.228 +};
1.229 +
1.230 +static void
1.231 +command_query(int argc, const char *argv[])
1.232 +{
1.233 + if (argc == 0 && !option_all) {
1.234 + printf("no arguments given for query\n");
1.235 + exit(1);
1.236 + }
1.237 +
1.238 + printf("command query - not implemented\n");
1.239 +}
1.240 +
1.241 +static void
1.242 +command_verify(int argc, const char *argv[])
1.243 +{
1.244 + if (argc == 0) {
1.245 + printf("no arguments given for verify\n");
1.246 + exit(1);
1.247 + }
1.248 +
1.249 + printf("command verify - not implemented\n");
1.250 +}
1.251 +
1.252 +static void
1.253 +command_erase(int argc, const char *argv[])
1.254 +{
1.255 + if (argc == 0) {
1.256 + printf("no packages given for erase\n");
1.257 + exit(1);
1.258 + }
1.259 +
1.260 + printf("command erase - not implemented\n");
1.261 +}
1.262 +
1.263 +static void
1.264 +command_install(int argc, const char *argv[])
1.265 +{
1.266 + if (argc == 0) {
1.267 + printf("no packages given for install\n");
1.268 + exit(1);
1.269 + }
1.270 +
1.271 + printf("command install - not implemented\n");
1.272 +}
1.273 +
1.274 +static void
1.275 +command_update(int argc, const char *argv[])
1.276 +{
1.277 + if (argc == 0) {
1.278 + printf("no packages given for update\n");
1.279 + exit(1);
1.280 + }
1.281 +
1.282 + printf("command update - not implemented\n");
1.283 +}
1.284 +
1.285 +static const struct option *
1.286 +find_option(const struct option *options, const char *s)
1.287 +{
1.288 + const struct option *o;
1.289 + int i;
1.290 +
1.291 + for (i = 0; options[i].type != OPTION_LAST; i++) {
1.292 + switch (options[i].type) {
1.293 + case OPTION_GROUP:
1.294 + o = find_option(options[i].data, s);
1.295 + if (o != NULL)
1.296 + return o;
1.297 + break;
1.298 +
1.299 + case OPTION_BOOL:
1.300 + case OPTION_STRING:
1.301 + if (s[0] == '-' &&
1.302 + s[1] == options[i].short_name && s[2] == '\0')
1.303 + return &options[i];
1.304 + if (s[0] == '-' && s[1] == '-' &&
1.305 + strcmp(options[i].name, s + 2) == 0)
1.306 + return &options[i];
1.307 + break;
1.308 +
1.309 + case OPTION_LAST:
1.310 + break;
1.311 + }
1.312 + }
1.313 +
1.314 + return NULL;
1.315 +}
1.316 +
1.317 +static int
1.318 +parse_options(const struct option *options, int argc, const char **argv)
1.319 +{
1.320 + const struct option *o;
1.321 + int i, j;
1.322 +
1.323 + /* FIXME: Bundling... rpm -Uvh must work :) */
1.324 +
1.325 + for (i = 1, j = 0; i < argc; i++) {
1.326 + if (argv[i][0] != '-') {
1.327 + argv[j++] = argv[i];
1.328 + continue;
1.329 + }
1.330 + o = find_option(options, argv[i]);
1.331 + if (o == NULL) {
1.332 + printf("unknown option: \"%s\"\n", argv[i]);
1.333 + continue;
1.334 + }
1.335 + if (o->data == NULL) {
1.336 + printf("option \"%s\" not supported\n", argv[i]);
1.337 + continue;
1.338 + }
1.339 + switch (o->type) {
1.340 + case OPTION_BOOL:
1.341 + *(int *) o->data = 1;
1.342 + break;
1.343 +
1.344 + case OPTION_STRING:
1.345 + *(const char **) o->data =
1.346 + argv[i] + strlen(o->name) + 3;
1.347 + break;
1.348 +
1.349 + case OPTION_LAST:
1.350 + case OPTION_GROUP:
1.351 + /* Shouldn't happen. */
1.352 + break;
1.353 + }
1.354 + }
1.355 +
1.356 + return j;
1.357 +}
1.358 +
1.359 +static void
1.360 +print_options_help(const struct option *options)
1.361 +{
1.362 + int i;
1.363 +
1.364 + for (i = 0; options[i].type != OPTION_LAST; i++) {
1.365 + switch (options[i].type) {
1.366 + case OPTION_GROUP:
1.367 + printf("%s\n", options[i].description);
1.368 + print_options_help(options[i].data);
1.369 + printf("\n");
1.370 + break;
1.371 +
1.372 + case OPTION_BOOL:
1.373 + case OPTION_STRING:
1.374 + printf(" ");
1.375 + if (options[i].short_name)
1.376 + printf("-%c", options[i].short_name);
1.377 + if (options[i].short_name && options[i].name)
1.378 + printf(", ");
1.379 + if (options[i].name)
1.380 + printf("--%s", options[i].name);
1.381 + if (options[i].arg_name)
1.382 + printf("=%s", options[i].arg_name);
1.383 + if (options[i].description)
1.384 + printf("\t\t%s", options[i].description);
1.385 + printf("\n");
1.386 + break;
1.387 +
1.388 + case OPTION_LAST:
1.389 + break;
1.390 + }
1.391 + }
1.392 +}
1.393 +
1.394 +static void
1.395 +print_options_usage(const struct option *options)
1.396 +{
1.397 + int i;
1.398 +
1.399 + for (i = 0; options[i].type != OPTION_LAST; i++) {
1.400 + switch (options[i].type) {
1.401 + case OPTION_GROUP:
1.402 + print_options_usage(options[i].data);
1.403 + break;
1.404 +
1.405 + case OPTION_BOOL:
1.406 + printf("[");
1.407 + if (options[i].short_name)
1.408 + printf("-%c", options[i].short_name);
1.409 + if (options[i].short_name && options[i].name)
1.410 + printf("|");
1.411 + if (options[i].name)
1.412 + printf("--%s", options[i].name);
1.413 + printf("] ");
1.414 + break;
1.415 +
1.416 + case OPTION_STRING:
1.417 + printf("[");
1.418 + if (options[i].short_name)
1.419 + printf("-%c", options[i].short_name);
1.420 + if (options[i].short_name && options[i].name)
1.421 + printf("|");
1.422 + if (options[i].name)
1.423 + printf("--%s", options[i].name);
1.424 + if (options[i].arg_name)
1.425 + printf("=%s", options[i].arg_name);
1.426 + printf("] ");
1.427 + break;
1.428 +
1.429 +
1.430 + break;
1.431 +
1.432 + case OPTION_LAST:
1.433 + break;
1.434 + }
1.435 + }
1.436 +}
1.437 +
1.438 +int
1.439 +main(int argc, const char *argv[])
1.440 +{
1.441 + argc = parse_options(rpm_options, argc, argv);
1.442 +
1.443 + if (option_version) {
1.444 + printf("razor rpm version hoopla.\n");
1.445 + exit(0);
1.446 + }
1.447 +
1.448 + if (option_help) {
1.449 + printf("Usage: rpm [OPTION...]\n");
1.450 + print_options_help(rpm_options);
1.451 + exit(0);
1.452 + }
1.453 +
1.454 + if (option_usage) {
1.455 + printf("Usage: rpm [OPTION...]\n");
1.456 + print_options_usage(rpm_options);
1.457 + printf("\n");
1.458 + exit(0);
1.459 + }
1.460 +
1.461 + if (option_query + option_verify +
1.462 + option_erase + option_install + option_upgrade > 1) {
1.463 + printf("specify only one of query, verify, erase, install "
1.464 + "or upgrade\n");
1.465 + exit(1);
1.466 + }
1.467 +
1.468 + if (option_query) {
1.469 + command_query(argc, argv);
1.470 + } else if (option_verify) {
1.471 + command_verify(argc, argv);
1.472 + } else if (option_erase) {
1.473 + command_erase(argc, argv);
1.474 + } else if (option_install) {
1.475 + command_install(argc, argv);
1.476 + } else if (option_upgrade) {
1.477 + command_update(argc, argv);
1.478 + } else {
1.479 + print_options_usage(rpm_options);
1.480 + printf("\n");
1.481 + exit(0);
1.482 + }
1.483 +
1.484 + return 0;
1.485 +}