2012-11-02 19:34:25 +05:30
|
|
|
/*-
|
2020-04-24 15:14:19 +05:30
|
|
|
* Licensed under the SPDX BSD-2-Clause identifier.
|
|
|
|
* Use is subject to license terms, as specified in the LICENSE file.
|
2012-11-02 19:34:25 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <getopt.h>
|
2012-11-05 17:47:15 +05:30
|
|
|
#include <errno.h>
|
2012-11-02 19:34:25 +05:30
|
|
|
|
2013-06-20 16:01:02 +05:30
|
|
|
#include <xbps.h>
|
2012-11-02 19:34:25 +05:30
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
static void __attribute__((noreturn))
|
|
|
|
usage(bool fail)
|
|
|
|
{
|
|
|
|
fprintf(stdout,
|
2014-05-26 21:00:44 +05:30
|
|
|
"Usage: xbps-query [OPTIONS] MODE [ARGUMENTS]\n"
|
2012-11-02 19:34:25 +05:30
|
|
|
"\nOPTIONS\n"
|
2020-04-21 00:55:14 +05:30
|
|
|
" -C, --config <dir> Path to confdir (xbps.d)\n"
|
|
|
|
" -c, --cachedir <dir> Path to cachedir\n"
|
|
|
|
" -d, --debug Debug mode shown to stderr\n"
|
|
|
|
" -h, --help Show usage\n"
|
|
|
|
" -i, --ignore-conf-repos Ignore repositories defined in xbps.d\n"
|
|
|
|
" -M, --memory-sync Remote repository data is fetched and stored\n"
|
|
|
|
" in memory, ignoring on-disk repodata archives\n"
|
|
|
|
" -p, --property PROP[,...] Show properties for PKGNAME\n"
|
|
|
|
" -R, --repository Enable repository mode. This mode explicitly\n"
|
|
|
|
" looks for packages in repositories\n"
|
|
|
|
" --repository=<url> Enable repository mode and add repository\n"
|
|
|
|
" to the top of the list. This option can be\n"
|
|
|
|
" specified multiple times\n"
|
|
|
|
" --regex Use Extended Regular Expressions to match\n"
|
|
|
|
" --fulldeptree Full dependency tree for -x/--deps\n"
|
|
|
|
" -r, --rootdir <dir> Full path to rootdir\n"
|
|
|
|
" -V, --version Show XBPS version\n"
|
|
|
|
" -v, --verbose Verbose messages\n"
|
2014-05-26 21:00:44 +05:30
|
|
|
"\nMODE\n"
|
2020-04-21 00:55:14 +05:30
|
|
|
" -l, --list-pkgs List installed packages\n"
|
|
|
|
" -L, --list-repos List registered repositories\n"
|
|
|
|
" -H, --list-hold-pkgs List packages on hold state\n"
|
|
|
|
" --list-repolock-pkgs List repolocked packages\n"
|
|
|
|
" -m, --list-manual-pkgs List packages installed explicitly\n"
|
|
|
|
" -O, --list-orphans List package orphans\n"
|
|
|
|
" -o, --ownedby FILE Search for package files by matching STRING or REGEX\n"
|
|
|
|
" -S, --show PKG Show information for PKG [default mode]\n"
|
|
|
|
" -s, --search PKG Search for packages by matching PKG, STRING or REGEX\n"
|
|
|
|
" --cat=FILE PKG Print FILE from PKG binpkg to stdout\n"
|
|
|
|
" -f, --files PKG Show package files for PKG\n"
|
|
|
|
" -x, --deps PKG Show dependencies for PKG\n"
|
|
|
|
" -X, --revdeps PKG Show reverse dependencies for PKG\n");
|
2012-11-02 19:34:25 +05:30
|
|
|
|
|
|
|
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2014-11-27 15:12:05 +05:30
|
|
|
const char *shortopts = "C:c:df:hHiLlMmOo:p:Rr:s:S:VvX:x:";
|
2012-11-02 19:34:25 +05:30
|
|
|
const struct option longopts[] = {
|
|
|
|
{ "config", required_argument, NULL, 'C' },
|
|
|
|
{ "cachedir", required_argument, NULL, 'c' },
|
|
|
|
{ "debug", no_argument, NULL, 'd' },
|
|
|
|
{ "help", no_argument, NULL, 'h' },
|
2014-11-21 15:26:41 +05:30
|
|
|
{ "ignore-conf-repos", no_argument, NULL, 'i' },
|
2012-11-02 19:34:25 +05:30
|
|
|
{ "list-repos", no_argument, NULL, 'L' },
|
|
|
|
{ "list-pkgs", no_argument, NULL, 'l' },
|
2013-08-12 18:16:54 +05:30
|
|
|
{ "list-hold-pkgs", no_argument, NULL, 'H' },
|
2016-09-21 17:41:04 +05:30
|
|
|
{ "list-repolock-pkgs", no_argument, NULL, 3 },
|
2014-11-27 15:12:05 +05:30
|
|
|
{ "memory-sync", no_argument, NULL, 'M' },
|
2012-11-02 19:34:25 +05:30
|
|
|
{ "list-manual-pkgs", no_argument, NULL, 'm' },
|
2013-02-13 20:17:46 +05:30
|
|
|
{ "list-orphans", no_argument, NULL, 'O' },
|
2014-05-26 21:00:44 +05:30
|
|
|
{ "ownedby", required_argument, NULL, 'o' },
|
2012-11-02 19:34:25 +05:30
|
|
|
{ "property", required_argument, NULL, 'p' },
|
2013-09-18 20:43:43 +05:30
|
|
|
{ "repository", optional_argument, NULL, 'R' },
|
2012-11-02 19:34:25 +05:30
|
|
|
{ "rootdir", required_argument, NULL, 'r' },
|
2014-05-26 21:00:44 +05:30
|
|
|
{ "show", required_argument, NULL, 'S' },
|
|
|
|
{ "search", required_argument, NULL, 's' },
|
2012-11-02 19:34:25 +05:30
|
|
|
{ "version", no_argument, NULL, 'V' },
|
|
|
|
{ "verbose", no_argument, NULL, 'v' },
|
2014-05-26 21:00:44 +05:30
|
|
|
{ "files", required_argument, NULL, 'f' },
|
|
|
|
{ "deps", required_argument, NULL, 'x' },
|
|
|
|
{ "revdeps", required_argument, NULL, 'X' },
|
2014-11-17 20:15:46 +05:30
|
|
|
{ "regex", no_argument, NULL, 0 },
|
2014-08-19 16:44:37 +05:30
|
|
|
{ "fulldeptree", no_argument, NULL, 1 },
|
2014-11-17 20:15:46 +05:30
|
|
|
{ "cat", required_argument, NULL, 2 },
|
2012-11-02 19:34:25 +05:30
|
|
|
{ NULL, 0, NULL, 0 },
|
|
|
|
};
|
|
|
|
struct xbps_handle xh;
|
2014-11-17 20:15:46 +05:30
|
|
|
const char *pkg, *rootdir, *cachedir, *confdir, *props, *catfile;
|
2014-08-19 16:44:37 +05:30
|
|
|
int c, flags, rv;
|
2016-09-21 17:41:04 +05:30
|
|
|
bool list_pkgs, list_repos, orphans, own, list_repolock;
|
2014-08-19 16:44:37 +05:30
|
|
|
bool list_manual, list_hold, show_prop, show_files, show_deps, show_rdeps;
|
2014-09-11 04:45:51 +05:30
|
|
|
bool show, pkg_search, regex, repo_mode, opmode, fulldeptree;
|
2012-11-02 19:34:25 +05:30
|
|
|
|
2014-11-17 20:15:46 +05:30
|
|
|
rootdir = cachedir = confdir = props = pkg = catfile = NULL;
|
2012-11-02 19:34:25 +05:30
|
|
|
flags = rv = c = 0;
|
2014-09-11 04:45:51 +05:30
|
|
|
list_pkgs = list_repos = list_hold = orphans = pkg_search = own = false;
|
2016-09-21 17:41:04 +05:30
|
|
|
list_manual = list_repolock = show_prop = show_files = false;
|
2014-08-19 16:44:37 +05:30
|
|
|
regex = show = show_deps = show_rdeps = fulldeptree = false;
|
2012-11-02 19:34:25 +05:30
|
|
|
repo_mode = opmode = false;
|
|
|
|
|
2013-09-18 20:15:05 +05:30
|
|
|
memset(&xh, 0, sizeof(xh));
|
|
|
|
|
2012-11-02 19:34:25 +05:30
|
|
|
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'C':
|
2014-11-06 14:28:04 +05:30
|
|
|
confdir = optarg;
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
cachedir = optarg;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
flags |= XBPS_FLAG_DEBUG;
|
|
|
|
break;
|
|
|
|
case 'f':
|
2014-05-26 21:00:44 +05:30
|
|
|
pkg = optarg;
|
2012-11-02 19:34:25 +05:30
|
|
|
show_files = opmode = true;
|
|
|
|
break;
|
2013-08-12 18:16:54 +05:30
|
|
|
case 'H':
|
2014-05-26 21:29:58 +05:30
|
|
|
list_hold = opmode = true;
|
2013-08-12 18:16:54 +05:30
|
|
|
break;
|
2012-11-02 19:34:25 +05:30
|
|
|
case 'h':
|
|
|
|
usage(false);
|
|
|
|
/* NOTREACHED */
|
2014-11-21 15:26:41 +05:30
|
|
|
case 'i':
|
|
|
|
flags |= XBPS_FLAG_IGNORE_CONF_REPOS;
|
|
|
|
break;
|
2012-11-02 19:34:25 +05:30
|
|
|
case 'L':
|
2014-05-26 21:29:58 +05:30
|
|
|
list_repos = opmode = true;
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case 'l':
|
2014-05-26 21:29:58 +05:30
|
|
|
list_pkgs = opmode = true;
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
2014-11-27 15:12:05 +05:30
|
|
|
case 'M':
|
|
|
|
flags |= XBPS_FLAG_REPOS_MEMSYNC;
|
|
|
|
break;
|
2012-11-02 19:34:25 +05:30
|
|
|
case 'm':
|
2014-05-26 21:29:58 +05:30
|
|
|
list_manual = opmode = true;
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
2013-02-13 20:17:46 +05:30
|
|
|
case 'O':
|
2014-05-26 21:29:58 +05:30
|
|
|
orphans = opmode = true;
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case 'o':
|
2014-05-26 21:00:44 +05:30
|
|
|
pkg = optarg;
|
2012-11-02 19:34:25 +05:30
|
|
|
own = opmode = true;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
props = optarg;
|
2014-05-26 21:22:41 +05:30
|
|
|
show_prop = true;
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case 'R':
|
2013-09-18 20:43:43 +05:30
|
|
|
if (optarg != NULL) {
|
2015-01-10 16:29:31 +05:30
|
|
|
xbps_repo_store(&xh, optarg);
|
2013-09-18 20:43:43 +05:30
|
|
|
}
|
2012-11-02 19:34:25 +05:30
|
|
|
repo_mode = true;
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
rootdir = optarg;
|
|
|
|
break;
|
2014-05-26 21:00:44 +05:30
|
|
|
case 'S':
|
|
|
|
pkg = optarg;
|
|
|
|
show = opmode = true;
|
|
|
|
break;
|
2012-11-02 19:34:25 +05:30
|
|
|
case 's':
|
2014-05-26 21:00:44 +05:30
|
|
|
pkg = optarg;
|
2014-09-11 04:45:51 +05:30
|
|
|
pkg_search = opmode = true;
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
flags |= XBPS_FLAG_VERBOSE;
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
printf("%s\n", XBPS_RELVER);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
case 'x':
|
2014-05-26 21:00:44 +05:30
|
|
|
pkg = optarg;
|
2014-08-19 16:44:37 +05:30
|
|
|
show_deps = opmode = true;
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case 'X':
|
2014-05-26 21:00:44 +05:30
|
|
|
pkg = optarg;
|
2012-11-02 19:34:25 +05:30
|
|
|
show_rdeps = opmode = true;
|
|
|
|
break;
|
2014-05-26 21:00:44 +05:30
|
|
|
case 0:
|
|
|
|
regex = true;
|
|
|
|
break;
|
2014-08-19 16:44:37 +05:30
|
|
|
case 1:
|
|
|
|
fulldeptree = true;
|
|
|
|
break;
|
2014-11-17 20:15:46 +05:30
|
|
|
case 2:
|
|
|
|
catfile = optarg;
|
|
|
|
break;
|
2016-09-21 17:41:04 +05:30
|
|
|
case 3:
|
|
|
|
list_repolock = opmode = true;
|
|
|
|
break;
|
2012-11-02 19:34:25 +05:30
|
|
|
case '?':
|
2020-04-21 00:55:14 +05:30
|
|
|
default:
|
2012-11-02 19:34:25 +05:30
|
|
|
usage(true);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
}
|
2014-05-26 21:00:44 +05:30
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
2012-11-02 19:34:25 +05:30
|
|
|
|
2014-05-27 11:49:08 +05:30
|
|
|
if (!argc && !opmode) {
|
2014-05-26 21:00:44 +05:30
|
|
|
usage(true);
|
2020-04-21 00:55:14 +05:30
|
|
|
/* NOTREACHED */
|
2014-05-26 21:22:41 +05:30
|
|
|
} else if (!opmode) {
|
2014-05-26 21:00:44 +05:30
|
|
|
/* show mode by default */
|
|
|
|
show = opmode = true;
|
2015-09-23 16:52:18 +05:30
|
|
|
pkg = *(argv++);
|
|
|
|
argc--;
|
|
|
|
}
|
|
|
|
if (argc) {
|
|
|
|
/* trailing parameters */
|
|
|
|
usage(true);
|
2020-04-21 00:55:14 +05:30
|
|
|
/* NOTREACHED */
|
2014-05-26 21:00:44 +05:30
|
|
|
}
|
2012-11-02 19:34:25 +05:30
|
|
|
/*
|
|
|
|
* Initialize libxbps.
|
|
|
|
*/
|
2013-12-16 16:16:39 +05:30
|
|
|
if (rootdir)
|
2014-11-06 14:28:04 +05:30
|
|
|
xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
|
2013-12-16 16:16:39 +05:30
|
|
|
if (cachedir)
|
2014-11-06 14:28:04 +05:30
|
|
|
xbps_strlcpy(xh.cachedir, cachedir, sizeof(xh.cachedir));
|
|
|
|
if (confdir)
|
|
|
|
xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir));
|
2014-08-01 18:39:51 +05:30
|
|
|
|
2012-11-02 19:34:25 +05:30
|
|
|
xh.flags = flags;
|
|
|
|
|
|
|
|
if ((rv = xbps_init(&xh)) != 0) {
|
|
|
|
xbps_error_printf("Failed to initialize libxbps: %s\n",
|
|
|
|
strerror(rv));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (list_repos) {
|
|
|
|
/* list repositories */
|
|
|
|
rv = repo_list(&xh);
|
|
|
|
|
2013-08-12 18:16:54 +05:30
|
|
|
} else if (list_hold) {
|
|
|
|
/* list on hold pkgs */
|
|
|
|
rv = xbps_pkgdb_foreach_cb(&xh, list_hold_pkgs, NULL);
|
|
|
|
|
2016-09-21 17:41:04 +05:30
|
|
|
} else if (list_repolock) {
|
|
|
|
/* list repolocked packages */
|
|
|
|
rv = xbps_pkgdb_foreach_cb(&xh, list_repolock_pkgs, NULL);
|
|
|
|
|
2012-11-02 19:34:25 +05:30
|
|
|
} else if (list_manual) {
|
|
|
|
/* list manual pkgs */
|
|
|
|
rv = xbps_pkgdb_foreach_cb(&xh, list_manual_pkgs, NULL);
|
|
|
|
|
|
|
|
} else if (list_pkgs) {
|
|
|
|
/* list available pkgs */
|
|
|
|
rv = list_pkgs_pkgdb(&xh);
|
|
|
|
|
|
|
|
} else if (orphans) {
|
|
|
|
/* list pkg orphans */
|
|
|
|
rv = list_orphans(&xh);
|
|
|
|
|
|
|
|
} else if (own) {
|
|
|
|
/* ownedby mode */
|
2014-05-26 21:00:44 +05:30
|
|
|
rv = ownedby(&xh, pkg, repo_mode, regex);
|
2012-11-02 19:34:25 +05:30
|
|
|
|
2014-09-11 04:45:51 +05:30
|
|
|
} else if (pkg_search) {
|
2012-11-02 19:34:25 +05:30
|
|
|
/* search mode */
|
2014-09-11 04:45:51 +05:30
|
|
|
rv = search(&xh, repo_mode, pkg, props, regex);
|
2012-11-02 19:34:25 +05:30
|
|
|
|
2014-11-17 20:15:46 +05:30
|
|
|
} else if (catfile) {
|
|
|
|
/* repo cat file mode */
|
|
|
|
rv = repo_cat_file(&xh, pkg, catfile);
|
|
|
|
|
2012-11-02 19:34:25 +05:30
|
|
|
} else if (show || show_prop) {
|
|
|
|
/* show mode */
|
|
|
|
if (repo_mode)
|
2014-05-26 21:00:44 +05:30
|
|
|
rv = repo_show_pkg_info(&xh, pkg, props);
|
2013-02-02 16:32:10 +05:30
|
|
|
else
|
2014-05-26 21:00:44 +05:30
|
|
|
rv = show_pkg_info_from_metadir(&xh, pkg, props);
|
2012-11-02 19:34:25 +05:30
|
|
|
|
|
|
|
} else if (show_files) {
|
|
|
|
/* show-files mode */
|
|
|
|
if (repo_mode)
|
2014-05-26 21:00:44 +05:30
|
|
|
rv = repo_show_pkg_files(&xh, pkg);
|
2013-02-02 16:32:10 +05:30
|
|
|
else
|
2014-05-26 21:00:44 +05:30
|
|
|
rv = show_pkg_files_from_metadir(&xh, pkg);
|
2012-11-02 19:34:25 +05:30
|
|
|
|
|
|
|
} else if (show_deps) {
|
|
|
|
/* show-deps mode */
|
2014-08-19 16:44:37 +05:30
|
|
|
rv = show_pkg_deps(&xh, pkg, repo_mode, fulldeptree);
|
2012-11-02 19:34:25 +05:30
|
|
|
|
|
|
|
} else if (show_rdeps) {
|
|
|
|
/* show-rdeps mode */
|
2014-08-19 16:44:37 +05:30
|
|
|
rv = show_pkg_revdeps(&xh, pkg, repo_mode);
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
|
|
|
|
2015-01-10 23:41:31 +05:30
|
|
|
xbps_end(&xh);
|
2012-11-02 19:34:25 +05:30
|
|
|
exit(rv);
|
|
|
|
}
|