2012-11-02 19:34:25 +05:30
|
|
|
/*-
|
2013-02-02 16:32:10 +05:30
|
|
|
* Copyright (c) 2008-2013 Juan Romero Pardines.
|
2012-11-02 19:34:25 +05:30
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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,
|
|
|
|
"Usage: xbps-query [OPTIONS...] [PKGNAME]\n"
|
|
|
|
"\nOPTIONS\n"
|
|
|
|
" -C --config <file> Full path to configuration file\n"
|
|
|
|
" -c --cachedir <dir> Full path to cachedir\n"
|
|
|
|
" -d --debug Debug mode shown to stderr\n"
|
|
|
|
" -h --help Print help usage\n"
|
2013-09-18 20:43:43 +05:30
|
|
|
" -R --repository Enable repository mode. This mode explicitly\n"
|
|
|
|
" looks for packages in repositories.\n"
|
|
|
|
" --repository=<url> Enable repository mode and explicitly add the\n"
|
|
|
|
" repository to the list; can be specified\n"
|
|
|
|
" multiple times. This overrides the repositories\n"
|
|
|
|
" list of a configuration file.\n"
|
2012-11-02 19:34:25 +05:30
|
|
|
" -r --rootdir <dir> Full path to rootdir\n"
|
|
|
|
" -V --version Show XBPS version\n"
|
|
|
|
" -v --verbose Verbose messages\n"
|
|
|
|
"\nMODE [only one mode may be specified]\n"
|
|
|
|
" -l --list-pkgs List available packages\n"
|
|
|
|
" -L --list-repos List working repositories\n"
|
2013-08-12 18:16:54 +05:30
|
|
|
" -H --list-hold-pkgs List packages on hold state\n"
|
2012-11-02 19:34:25 +05:30
|
|
|
" -m --list-manual-pkgs List packages installed explicitly\n"
|
2013-02-13 20:17:46 +05:30
|
|
|
" -O --list-orphans List package orphans\n"
|
2012-11-02 19:34:25 +05:30
|
|
|
" -o --ownedby PATTERN(s) Search for packages owning PATTERN(s)\n"
|
|
|
|
" -s --search PATTERN(s) Search for packages matching PATTERN(s)\n"
|
|
|
|
" -f --files Show files for PKGNAME\n"
|
|
|
|
" -p --property PROP,... Show properties for PKGNAME\n"
|
2013-03-05 08:38:42 +05:30
|
|
|
" -x --deps Show dependencies for PKGNAME (set it twice for a full dependency tree)\n"
|
2012-11-02 19:34:25 +05:30
|
|
|
" -X --revdeps Show reverse dependencies for PKGNAME\n");
|
|
|
|
|
|
|
|
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2013-08-12 18:16:54 +05:30
|
|
|
const char *shortopts = "C:c:D:dfhHLlmOop:Rr:sVvXx";
|
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' },
|
|
|
|
{ "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' },
|
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' },
|
2012-11-02 19:34:25 +05:30
|
|
|
{ "ownedby", no_argument, NULL, 'o' },
|
|
|
|
{ "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' },
|
|
|
|
{ "search", no_argument, NULL, 's' },
|
|
|
|
{ "version", no_argument, NULL, 'V' },
|
|
|
|
{ "verbose", no_argument, NULL, 'v' },
|
|
|
|
{ "files", no_argument, NULL, 'f' },
|
|
|
|
{ "deps", no_argument, NULL, 'x' },
|
|
|
|
{ "revdeps", no_argument, NULL, 'X' },
|
|
|
|
{ NULL, 0, NULL, 0 },
|
|
|
|
};
|
|
|
|
struct xbps_handle xh;
|
2013-09-18 20:43:43 +05:30
|
|
|
const char *rootdir, *cachedir, *conffile, *props;
|
2013-03-05 08:38:42 +05:30
|
|
|
int c, flags, rv, show_deps = 0;
|
2012-11-02 19:34:25 +05:30
|
|
|
bool list_pkgs, list_repos, orphans, own;
|
2013-08-12 18:16:54 +05:30
|
|
|
bool list_manual, list_hold, show_prop, show_files, show_rdeps;
|
2013-03-05 08:38:42 +05:30
|
|
|
bool show, search, repo_mode, opmode, fulldeptree;
|
2012-11-02 19:34:25 +05:30
|
|
|
|
2013-09-18 20:43:43 +05:30
|
|
|
rootdir = cachedir = conffile = props = NULL;
|
2012-11-02 19:34:25 +05:30
|
|
|
flags = rv = c = 0;
|
2013-08-12 18:16:54 +05:30
|
|
|
list_pkgs = list_repos = list_hold = orphans = search = own = false;
|
2012-11-06 13:58:34 +05:30
|
|
|
list_manual = show_prop = show_files = false;
|
2013-03-05 08:38:42 +05:30
|
|
|
show = 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':
|
|
|
|
conffile = optarg;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
cachedir = optarg;
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
flags |= XBPS_FLAG_DEBUG;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
show_files = opmode = true;
|
|
|
|
break;
|
2013-08-12 18:16:54 +05:30
|
|
|
case 'H':
|
|
|
|
list_hold = true;
|
|
|
|
break;
|
2012-11-02 19:34:25 +05:30
|
|
|
case 'h':
|
|
|
|
usage(false);
|
|
|
|
/* NOTREACHED */
|
|
|
|
case 'L':
|
2012-11-18 17:27:38 +05:30
|
|
|
list_repos = true;
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case 'l':
|
2012-11-18 17:27:38 +05:30
|
|
|
list_pkgs = true;
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case 'm':
|
2012-11-18 17:27:38 +05:30
|
|
|
list_manual = true;
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
2013-02-13 20:17:46 +05:30
|
|
|
case 'O':
|
2012-11-18 17:27:38 +05:30
|
|
|
orphans = true;
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
own = opmode = true;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
props = optarg;
|
2013-03-09 00:53:13 +05:30
|
|
|
show_prop = opmode = true;
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case 'R':
|
2013-09-18 20:43:43 +05:30
|
|
|
if (optarg != NULL) {
|
|
|
|
if (xh.repositories == NULL)
|
|
|
|
xh.repositories = xbps_array_create();
|
|
|
|
|
|
|
|
xbps_array_add_cstring_nocopy(xh.repositories, optarg);
|
|
|
|
}
|
2012-11-02 19:34:25 +05:30
|
|
|
repo_mode = true;
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
rootdir = optarg;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
search = opmode = true;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
flags |= XBPS_FLAG_VERBOSE;
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
printf("%s\n", XBPS_RELVER);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
case 'x':
|
2013-03-05 08:38:42 +05:30
|
|
|
show_deps++;
|
|
|
|
opmode = true;
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case 'X':
|
|
|
|
show_rdeps = opmode = true;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
usage(true);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!opmode && argc > optind)
|
|
|
|
show = true;
|
2012-11-20 01:36:37 +05:30
|
|
|
else if (argc == 1 || (opmode && (argc == optind)))
|
2012-11-02 19:34:25 +05:30
|
|
|
usage(true);
|
2012-11-05 16:42:34 +05:30
|
|
|
else if ((search || own) && (argc == optind))
|
|
|
|
usage(true);
|
2012-11-02 19:34:25 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize libxbps.
|
|
|
|
*/
|
2013-12-16 16:16:39 +05:30
|
|
|
if (rootdir)
|
|
|
|
strncpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
|
|
|
|
if (cachedir)
|
|
|
|
strncpy(xh.cachedir, cachedir, sizeof(xh.cachedir));
|
2012-11-02 19:34:25 +05:30
|
|
|
xh.conffile = conffile;
|
|
|
|
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);
|
|
|
|
|
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 */
|
|
|
|
if (repo_mode)
|
|
|
|
rv = repo_ownedby(&xh, argc - optind, argv + optind);
|
|
|
|
else
|
|
|
|
rv = ownedby(&xh, argc - optind, argv + optind);
|
|
|
|
|
|
|
|
} else if (search) {
|
|
|
|
/* search mode */
|
|
|
|
rv = repo_search(&xh, argc - optind, argv + optind);
|
|
|
|
|
|
|
|
} else if (show || show_prop) {
|
|
|
|
/* show mode */
|
|
|
|
if (repo_mode)
|
|
|
|
rv = repo_show_pkg_info(&xh, argv[optind], props);
|
2013-02-02 16:32:10 +05:30
|
|
|
else
|
2012-11-02 19:34:25 +05:30
|
|
|
rv = show_pkg_info_from_metadir(&xh,
|
|
|
|
argv[optind], props);
|
|
|
|
|
|
|
|
} else if (show_files) {
|
|
|
|
/* show-files mode */
|
|
|
|
if (repo_mode)
|
|
|
|
rv = repo_show_pkg_files(&xh, argv[optind]);
|
2013-02-02 16:32:10 +05:30
|
|
|
else
|
2012-11-02 19:34:25 +05:30
|
|
|
rv = show_pkg_files_from_metadir(&xh, argv[optind]);
|
|
|
|
|
|
|
|
} else if (show_deps) {
|
|
|
|
/* show-deps mode */
|
2013-03-05 08:38:42 +05:30
|
|
|
if (show_deps > 1)
|
|
|
|
fulldeptree = true;
|
|
|
|
|
2012-11-02 19:34:25 +05:30
|
|
|
if (repo_mode)
|
2013-03-05 08:38:42 +05:30
|
|
|
rv = repo_show_pkg_deps(&xh, argv[optind], fulldeptree);
|
2013-02-02 16:32:10 +05:30
|
|
|
else
|
2013-03-05 08:38:42 +05:30
|
|
|
rv = show_pkg_deps(&xh, argv[optind], fulldeptree);
|
2012-11-02 19:34:25 +05:30
|
|
|
|
|
|
|
} else if (show_rdeps) {
|
|
|
|
/* show-rdeps mode */
|
2012-11-21 07:22:36 +05:30
|
|
|
if (repo_mode)
|
|
|
|
rv = repo_show_pkg_revdeps(&xh, argv[optind]);
|
2013-02-02 16:32:10 +05:30
|
|
|
else
|
2012-11-21 07:22:36 +05:30
|
|
|
rv = show_pkg_revdeps(&xh, argv[optind]);
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
exit(rv);
|
|
|
|
}
|