krh@215: /* krh@215: * Copyright (C) 2008 Kristian Høgsberg krh@215: * Copyright (C) 2008 Red Hat, Inc krh@215: * krh@215: * This program is free software; you can redistribute it and/or modify krh@215: * it under the terms of the GNU General Public License as published by krh@215: * the Free Software Foundation; either version 2 of the License, or krh@215: * (at your option) any later version. krh@215: * krh@215: * This program is distributed in the hope that it will be useful, krh@215: * but WITHOUT ANY WARRANTY; without even the implied warranty of krh@215: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the krh@215: * GNU General Public License for more details. krh@215: * krh@215: * You should have received a copy of the GNU General Public License along krh@215: * with this program; if not, write to the Free Software Foundation, Inc., krh@215: * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. krh@215: */ krh@215: krh@215: #include krh@215: #include krh@215: #include krh@236: #include krh@215: #include "razor.h" krh@215: krh@215: enum option_type { krh@215: OPTION_LAST, krh@215: OPTION_GROUP, krh@215: OPTION_BOOL, krh@215: OPTION_STRING krh@215: }; krh@215: krh@215: struct option { krh@215: enum option_type type; krh@215: const char *name; krh@215: char short_name; krh@215: const char *arg_name; krh@215: const char *description; krh@215: void *data; krh@215: }; krh@215: krh@218: /* A note about all these options: rpm allows options to mean krh@218: * different things depending on what other options are present on the krh@218: * command line. For example, if -q or --query is present, -i no krh@218: * longer means install, but info. The way we handle this is by krh@218: * setting all the options that may match (ie if -i is given we set krh@218: * install and info), and then look at the relevent one depending on krh@218: * what else in on the command line. */ krh@218: krh@216: static int option_all, option_whatrequires, option_whatprovides; krh@217: static int option_package; krh@215: krh@215: static const struct option query_options[] = { krh@215: { OPTION_BOOL, "configfiles", 'c', NULL, "list all configuration files", NULL }, krh@215: { OPTION_BOOL, "docfiles", 'd', NULL, "list all documentation files", NULL }, krh@215: { OPTION_BOOL, "dump", 0, NULL, "dump basic file information", NULL }, krh@215: { OPTION_BOOL, "list", 0, NULL, "list files in package", NULL }, krh@215: { OPTION_STRING, "queryformat", 0, "QUERYFORMAT", "use the following query format", NULL }, krh@215: { OPTION_BOOL, "state", 's', NULL, "display the states of the listed files", NULL }, krh@215: { OPTION_BOOL, "all", 'a', NULL, "query/verify all packages", &option_all }, krh@215: { OPTION_BOOL, "file", 'f', NULL, "query/verify package(s) owning file", NULL }, krh@215: { OPTION_BOOL, "group", 'g', NULL, "query/verify package(s) in group", NULL }, krh@217: { OPTION_BOOL, "package", 'p', NULL, "query/verify a package file", &option_package }, krh@215: { OPTION_BOOL, "ftswalk", 'W', NULL, "query/verify package(s) from TOP file tree walk", NULL }, krh@215: { OPTION_BOOL, "pkgid", 0, NULL, "query/verify package(s) with package identifier", NULL }, krh@215: { OPTION_BOOL, "hdrid", 0, NULL, "query/verify package(s) with header identifier", NULL }, krh@215: { OPTION_BOOL, "fileid", 0, NULL, "query/verify package(s) with file identifier", NULL }, krh@215: { OPTION_BOOL, "specfile", 0, NULL, "query a spec file", NULL, }, krh@215: { OPTION_BOOL, "triggeredby", 0, NULL, "query the package(s) triggered by the package", NULL }, krh@216: { OPTION_BOOL, "whatrequires", 0, NULL, "query/verify the package(s) which require a dependency", &option_whatrequires }, krh@216: { OPTION_BOOL, "whatprovides", 0, NULL, "query/verify the package(s) which provide a dependency", &option_whatprovides }, krh@215: { OPTION_BOOL, "nomanifest", 0, NULL, "do not process non-package files as manifests", NULL }, krh@215: { } krh@215: }; krh@215: krh@215: static const struct option verify_options[] = { krh@215: { OPTION_BOOL, "nomd5", 0, NULL, "don't verify MD5 digest of files", NULL }, krh@215: { OPTION_BOOL, "nofiles", 0, NULL, "don't verify files in package", NULL }, krh@215: { OPTION_BOOL, "nodeps", 0, NULL, "don't verify package dependencies", NULL }, krh@215: { OPTION_BOOL, "noscript", 0, NULL, "don't execute verify script(s)", NULL, }, krh@222: { OPTION_BOOL, "all", 'a', NULL, "query/verify all packages", &option_all }, krh@215: { OPTION_BOOL, "file", 'f', NULL, "query/verify package(s) owning file", NULL }, krh@215: { OPTION_BOOL, "group", 'g', NULL, "query/verify package(s) in group", NULL }, krh@222: { OPTION_BOOL, "package", 'p', NULL, "query/verify a package file", &option_package }, krh@215: { OPTION_BOOL, "ftswalk", 'W', NULL, "query/verify package(s) from TOP file tree walk", NULL }, krh@215: { OPTION_BOOL, "pkgid", 0, NULL, "query/verify package(s) with package identifier", NULL }, krh@215: { OPTION_BOOL, "hdrid", 0, NULL, "query/verify package(s) with header identifier", NULL }, krh@215: { OPTION_BOOL, "fileid", 0, NULL, "query/verify package(s) with file identifier", NULL }, krh@215: { OPTION_BOOL, "specfile", 0, NULL, "query a spec file", NULL }, krh@215: { OPTION_BOOL, "triggeredby", 0, NULL, "query the package(s) triggered by the package", NULL }, krh@216: { OPTION_BOOL, "whatrequires", 0, NULL, "query/verify the package(s) which require a dependency", &option_whatrequires }, krh@216: { OPTION_BOOL, "whatprovides", 0, NULL, "query/verify the package(s) which provide a dependency", &option_whatprovides }, krh@215: { OPTION_BOOL, "nomanifest", 0, NULL, "do not process non-package files as manifests", NULL }, krh@215: { } krh@215: }; krh@215: krh@215: static const struct option ftw_options[] = { krh@215: { OPTION_BOOL, "comfollow", 0, NULL, "FTS_COMFOLLOW: follow command line symlinks", NULL }, krh@215: { OPTION_BOOL, "logical", 0, NULL, "FTS_LOGICAL: logical walk", NULL }, krh@215: { OPTION_BOOL, "nochdir", 0, NULL, "FTS_NOCHDIR: don't change directories", NULL }, krh@215: { OPTION_BOOL, "nostat", 0, NULL, "FTS_NOSTAT: don't get stat info", NULL }, krh@215: { OPTION_BOOL, "physical", 0, NULL, "FTS_PHYSICAL: physical walk", NULL }, krh@215: { OPTION_BOOL, "seedot", 0, NULL, "FTS_SEEDOT: return dot and dot-dot", NULL }, krh@215: { OPTION_BOOL, "xdev", 0, NULL, "FTS_XDEV: don't cross devices", NULL }, krh@215: { OPTION_BOOL, "whiteout", 0, NULL, "FTS_WHITEOUT: return whiteout information", NULL }, krh@215: { } krh@215: }; krh@215: krh@215: static const struct option signature_options[] = { krh@215: { OPTION_BOOL, "addsign", 0, NULL, "sign package(s) (identical to --resign)", NULL, }, krh@215: { OPTION_BOOL, "checksig", 'K', NULL, "verify package signature(s)", NULL, }, krh@215: { OPTION_BOOL, "delsign", 0, NULL, "delete package signatures", NULL, }, krh@215: { OPTION_BOOL, "import", 0, NULL, "import an armored public key", NULL, }, krh@215: { OPTION_BOOL, "resign", 0, NULL, "sign package(s) (identical to --addsign)", NULL, }, krh@215: { OPTION_BOOL, "nodigest", 0, NULL, "don't verify package digest(s)", NULL, }, krh@215: { OPTION_BOOL, "nosignature", 0, NULL, "don't verify package signature(s)", NULL }, krh@215: { } krh@215: }; krh@215: krh@235: static int option_initdb; krh@235: krh@215: static const struct option database_options[] = { krh@235: { OPTION_BOOL, "initdb", 0, NULL, "initialize database", &option_initdb }, krh@215: { OPTION_BOOL, "rebuilddb", 0, NULL, "rebuild database inverted lists from installed package headers", NULL }, krh@215: { } krh@215: }; krh@215: krh@215: static int option_erase, option_install, option_upgrade; krh@215: krh@215: static const struct option install_options[] = { krh@215: { OPTION_BOOL, "aid", 0, NULL, "add suggested packages to transaction", NULL, }, krh@215: { OPTION_BOOL, "allfiles", 0, NULL, "install all files, even configurations which might otherwise be skipped", NULL, }, krh@215: { OPTION_BOOL, "allmatches", 0, NULL, "remove all packages which match (normally an error is generated if specified multiple packages)", NULL, }, krh@215: { OPTION_BOOL, "badreloc", 0, NULL, "relocate files in non-relocatable package", NULL }, krh@215: { OPTION_BOOL, "erase", 'e', "", "erase (uninstall) package", &option_erase }, krh@215: { OPTION_BOOL, "excludedocs", 0, NULL, "do not install documentation", NULL, }, krh@215: { OPTION_BOOL, "excludepath", 0, "", "skip files with leading component ", NULL, }, krh@215: { OPTION_BOOL, "fileconflicts", 0, NULL, "detect file conflicts between packages", NULL, }, krh@215: { OPTION_BOOL, "force", 0, NULL, "short hand for --replacepkgs --replacefiles", NULL }, krh@215: { OPTION_BOOL, "freshen", 'F', "+", "upgrade package(s) if already installed", NULL }, krh@215: { OPTION_BOOL, "hash", 'h', NULL, "print hash marks as package installs (good with -v)", NULL }, krh@215: { OPTION_BOOL, "ignorearch", 0, NULL, "don't verify package architecture", NULL, }, krh@215: { OPTION_BOOL, "ignoreos", 0, NULL, "don't verify package operating system", NULL, }, krh@215: { OPTION_BOOL, "ignoresize", 0, NULL, "don't check disk space before installing", NULL }, krh@215: { OPTION_BOOL, "install", 'i', NULL, "install package(s)", &option_install }, krh@215: { OPTION_BOOL, "justdb", 0, NULL, "update the database, but do not modify the filesystem", NULL, }, krh@215: { OPTION_BOOL, "nodeps", 0, NULL, "do not verify package dependencies", NULL, }, krh@215: { OPTION_BOOL, "nomd5", 0, NULL, "don't verify MD5 digest of files", NULL, }, krh@215: { OPTION_BOOL, "nocontexts", 0, NULL, "don't install file security contexts", NULL, }, krh@215: { OPTION_BOOL, "noorder", 0, NULL, "do not reorder package installation to satisfy dependencies", NULL, }, krh@215: { OPTION_BOOL, "nosuggest", 0, NULL, "do not suggest missing dependency resolution(s)", NULL, }, krh@215: { OPTION_BOOL, "noscripts", 0, NULL, "do not execute package scriptlet(s)", NULL, }, krh@215: { OPTION_BOOL, "notriggers", 0, NULL, "do not execute any scriptlet(s) triggered by this package", NULL, }, krh@215: { OPTION_BOOL, "oldpackage", 0, NULL, "upgrade to an old version of the package (--force on upgrades does this automatically)", NULL }, krh@215: { OPTION_BOOL, "percent", 0, NULL, "print percentages as package installs", NULL, }, krh@215: { OPTION_STRING, "prefix", 0, "", "relocate the package to , if relocatable", NULL, }, krh@215: { OPTION_STRING, "relocate", 0, "=", "relocate files from path to ", NULL, }, krh@215: { OPTION_BOOL, "repackage", 0, NULL, "save erased package files by repackaging", NULL, }, krh@215: { OPTION_BOOL, "replacefiles", 0, NULL, "ignore file conflicts between packages", NULL, }, krh@215: { OPTION_BOOL, "replacepkgs", 0, NULL, "reinstall if the package is already present", NULL, }, krh@215: { OPTION_BOOL, "test", 0, NULL, "don't install, but tell if it would work or not", NULL }, krh@215: { OPTION_BOOL, "upgrade", 'U', "+", "upgrade package(s)", &option_upgrade }, krh@215: { } krh@215: }; krh@215: krh@215: static int option_version; krh@236: static const char *option_root = "install"; krh@215: krh@215: static const struct option common_options[] = { krh@215: { OPTION_STRING, "define", 'D', "MACRO EXPR", "define MACRO with value EXPR", NULL, }, krh@215: { OPTION_STRING, "eval", 'E', "EXPR", "print macro expansion of EXPR", NULL }, krh@215: { OPTION_STRING, "macros", 0, "", "read instead of default file(s)", NULL }, krh@215: { OPTION_BOOL, "nodigest", 0, NULL, "don't verify package digest(s)", NULL, }, krh@215: { OPTION_BOOL, "nosignature", 0, NULL, "don't verify package signature(s)", NULL, }, krh@215: { OPTION_STRING, "rcfile", 0, "", "read instead of default file(s)", NULL }, krh@236: { OPTION_STRING, "root", 'r', "ROOT", "use ROOT as top level directory (default: \"/\")", &option_root }, krh@215: { OPTION_BOOL, "querytags", 0, NULL, "display known query tags", NULL, }, krh@215: { OPTION_BOOL, "showrc", 0, NULL, "display final rpmrc and macro configuration", NULL, }, krh@215: { OPTION_BOOL, "quiet", 0, NULL, "provide less detailed output", NULL }, krh@215: { OPTION_BOOL, "verbose", 'v', NULL, "provide more detailed output", NULL }, krh@215: { OPTION_BOOL, "version", 0, NULL, "print the version of rpm being used", &option_version }, krh@215: { } krh@215: }; krh@215: krh@218: static int option_conflicts, option_obsoletes, option_requires; krh@218: static int option_provides, option_info, option_changelog; krh@216: krh@215: static const struct option alias_options[] = { krh@215: { OPTION_BOOL, "scripts", 0, NULL, "list install/erase scriptlets from package(s)", NULL, }, krh@215: { OPTION_BOOL, "setperms", 0, NULL, "set permissions of files in a package", NULL, }, krh@215: { OPTION_BOOL, "setugids", 0, NULL, "set user/group ownership of files in a package", NULL, }, krh@216: { OPTION_BOOL, "conflicts", 0, NULL, "list capabilities this package conflicts with", &option_conflicts, }, krh@216: { OPTION_BOOL, "obsoletes", 0, NULL, "list other packages removed by installing this package", &option_obsoletes, }, krh@216: { OPTION_BOOL, "provides", 0, NULL, "list capabilities that this package provides", &option_provides, }, krh@216: { OPTION_BOOL, "requires", 0, NULL, "list capabilities required by package(s)", &option_requires, }, krh@218: { OPTION_BOOL, "info", 'i', NULL, "list descriptive information from package(s)", &option_info, }, krh@218: { OPTION_BOOL, "changelog", 0, NULL, "list change logs for this package", &option_changelog, }, krh@215: { OPTION_BOOL, "xml", 0, NULL, "list metadata in xml", NULL, }, krh@215: { OPTION_BOOL, "triggers", 0, NULL, "list trigger scriptlets from package(s)", NULL, }, krh@215: { OPTION_BOOL, "last", 0, NULL, "list package(s) by install time, most recent first", NULL, }, krh@215: { OPTION_BOOL, "dupes", 0, NULL, "list duplicated packages", NULL, }, krh@215: { OPTION_BOOL, "filesbypkg", 0, NULL, "list all files from each package", NULL, }, krh@215: { OPTION_BOOL, "fileclass", 0, NULL, "list file names with classes", NULL, }, krh@215: { OPTION_BOOL, "filecolor", 0, NULL, "list file names with colors", NULL, }, krh@215: { OPTION_BOOL, "filecontext", 0, NULL, "list file names with security context from header", NULL, }, krh@215: { OPTION_BOOL, "fscontext", 0, NULL, "list file names with security context from file system", NULL, }, krh@215: { OPTION_BOOL, "recontext", 0, NULL, "list file names with security context from policy RE", NULL, }, krh@215: { OPTION_BOOL, "fileprovide", 0, NULL, "list file names with provides", NULL, }, krh@215: { OPTION_BOOL, "filerequire", 0, NULL, "list file names with requires", NULL, }, krh@215: { OPTION_BOOL, "redhatprovides", 0, NULL, "find package name that contains a provided capability (needs rpmdb-redhat package installed)", NULL, }, krh@215: { OPTION_BOOL, "redhatrequires", 0, NULL, "find package name that contains a required capability (needs rpmdb-redhat package installed)", NULL, }, krh@215: { OPTION_STRING, "buildpolicy", 0, "", "set buildroot (e.g. compress man pages)", NULL, }, krh@215: { OPTION_BOOL, "with", 0, "