2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2011-01-25 17:30:23 +05:30
|
|
|
* Copyright (c) 2008-2011 Juan Romero Pardines.
|
2009-08-17 22:37:20 +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 <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2011-01-25 17:30:23 +05:30
|
|
|
#include <strings.h>
|
2009-08-17 22:37:20 +05:30
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <libgen.h>
|
2010-11-19 18:10:13 +05:30
|
|
|
#include <unistd.h>
|
2011-07-11 15:42:55 +05:30
|
|
|
#include <inttypes.h>
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
#include <xbps_api.h>
|
2009-11-24 16:35:39 +05:30
|
|
|
#include "defs.h"
|
2011-01-22 17:10:19 +05:30
|
|
|
#include "../xbps-bin/defs.h"
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-01-15 16:29:44 +05:30
|
|
|
static void __attribute__((noreturn))
|
2011-07-29 14:57:43 +05:30
|
|
|
usage(struct xbps_handle *xhp)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2011-07-29 14:57:43 +05:30
|
|
|
if (xhp != NULL)
|
|
|
|
xbps_end(xhp);
|
2011-07-27 20:43:54 +05:30
|
|
|
|
2010-01-15 19:49:16 +05:30
|
|
|
fprintf(stderr,
|
2010-12-03 22:06:07 +05:30
|
|
|
"Usage: xbps-repo [options] [action] [arguments]\n"
|
|
|
|
"See xbps-repo(8) for more information.\n");
|
2009-08-17 22:37:20 +05:30
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
static int
|
|
|
|
repo_list_uri_cb(struct repository_pool_index *rpi, void *arg, bool *done)
|
|
|
|
{
|
2011-06-04 17:07:53 +05:30
|
|
|
const char *pkgidx;
|
|
|
|
uint64_t npkgs;
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
(void)arg;
|
|
|
|
(void)done;
|
|
|
|
|
2011-06-04 17:07:53 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(rpi->rpi_repod,
|
|
|
|
"pkgindex-version", &pkgidx);
|
|
|
|
prop_dictionary_get_uint64(rpi->rpi_repod, "total-pkgs", &npkgs);
|
2011-07-11 15:42:55 +05:30
|
|
|
printf("%s (index %s, " "%" PRIu64 " packages)\n",
|
|
|
|
rpi->rpi_uri, pkgidx, npkgs);
|
2010-11-24 21:07:30 +05:30
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
repo_search_pkgs_cb(struct repository_pool_index *rpi, void *arg, bool *done)
|
|
|
|
{
|
2010-11-24 21:07:30 +05:30
|
|
|
struct repo_search_data rsd;
|
2010-11-19 18:10:13 +05:30
|
|
|
(void)done;
|
|
|
|
|
2010-11-24 21:07:30 +05:30
|
|
|
rsd.pattern = arg;
|
|
|
|
rsd.pkgver_len = find_longest_pkgver(rpi->rpi_repod);
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
printf("From %s repository ...\n", rpi->rpi_uri);
|
|
|
|
(void)xbps_callback_array_iter_in_dict(rpi->rpi_repod,
|
2010-11-24 21:07:30 +05:30
|
|
|
"packages", show_pkg_namedesc, &rsd);
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2011-07-27 20:43:54 +05:30
|
|
|
struct xbps_handle *xhp;
|
2011-07-27 21:34:38 +05:30
|
|
|
struct xferstat xfer;
|
2009-11-24 16:17:04 +05:30
|
|
|
prop_dictionary_t pkgd;
|
2011-10-29 11:47:54 +05:30
|
|
|
const char *rootdir, *cachedir, *confdir, *option;
|
2009-08-17 22:37:20 +05:30
|
|
|
int c, rv = 0;
|
2011-06-04 17:07:53 +05:30
|
|
|
bool debug = false;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-10-29 11:47:54 +05:30
|
|
|
rootdir = cachedir = confdir = option = NULL;
|
2011-02-21 22:12:47 +05:30
|
|
|
|
2011-10-29 11:47:54 +05:30
|
|
|
while ((c = getopt(argc, argv, "C:c:do:r:V")) != -1) {
|
2009-08-17 22:37:20 +05:30
|
|
|
switch (c) {
|
2011-06-04 17:07:53 +05:30
|
|
|
case 'C':
|
2011-10-17 18:41:54 +05:30
|
|
|
confdir = optarg;
|
2011-06-04 17:07:53 +05:30
|
|
|
break;
|
2009-11-28 08:26:16 +05:30
|
|
|
case 'c':
|
2011-02-21 22:12:47 +05:30
|
|
|
cachedir = optarg;
|
2009-11-28 08:26:16 +05:30
|
|
|
break;
|
2010-11-19 18:10:13 +05:30
|
|
|
case 'd':
|
2011-06-04 17:07:53 +05:30
|
|
|
debug = true;
|
2010-11-19 18:10:13 +05:30
|
|
|
break;
|
2011-10-29 11:47:54 +05:30
|
|
|
case 'o':
|
|
|
|
option = optarg;
|
|
|
|
break;
|
2009-08-17 22:37:20 +05:30
|
|
|
case 'r':
|
|
|
|
/* To specify the root directory */
|
2011-02-21 22:12:47 +05:30
|
|
|
rootdir = optarg;
|
2009-08-17 22:37:20 +05:30
|
|
|
break;
|
2009-10-18 14:12:04 +05:30
|
|
|
case 'V':
|
|
|
|
printf("%s\n", XBPS_RELVER);
|
|
|
|
exit(EXIT_SUCCESS);
|
2009-08-17 22:37:20 +05:30
|
|
|
case '?':
|
|
|
|
default:
|
2011-07-29 14:57:43 +05:30
|
|
|
usage(NULL);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc < 1)
|
2011-07-29 14:57:43 +05:30
|
|
|
usage(NULL);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-02-21 18:08:44 +05:30
|
|
|
/*
|
2011-06-04 17:07:53 +05:30
|
|
|
* Initialize XBPS subsystems.
|
2011-02-21 18:08:44 +05:30
|
|
|
*/
|
2011-07-27 20:43:54 +05:30
|
|
|
xhp = xbps_handle_alloc();
|
|
|
|
if (xhp == NULL) {
|
|
|
|
xbps_error_printf("xbps-repo: failed to allocate resources.\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
xhp->debug = debug;
|
2011-07-28 12:55:30 +05:30
|
|
|
xhp->xbps_transaction_cb = transaction_cb;
|
|
|
|
xhp->xbps_transaction_err_cb = transaction_err_cb;
|
2011-07-27 20:43:54 +05:30
|
|
|
xhp->xbps_fetch_cb = fetch_file_progress_cb;
|
2011-07-27 21:34:38 +05:30
|
|
|
xhp->xfcd->cookie = &xfer;
|
2011-10-17 16:07:15 +05:30
|
|
|
if (rootdir)
|
|
|
|
xhp->rootdir = prop_string_create_cstring(rootdir);
|
|
|
|
if (cachedir)
|
|
|
|
xhp->cachedir = prop_string_create_cstring(cachedir);
|
2011-10-17 18:41:54 +05:30
|
|
|
if (confdir)
|
|
|
|
xhp->confdir = prop_string_create_cstring(confdir);
|
2011-07-27 20:43:54 +05:30
|
|
|
|
|
|
|
if ((rv = xbps_init(xhp)) != 0) {
|
2011-06-04 17:07:53 +05:30
|
|
|
xbps_error_printf("xbps-repo: couldn't initialize library: %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
exit(EXIT_FAILURE);
|
2009-11-24 16:17:04 +05:30
|
|
|
}
|
|
|
|
|
2011-06-04 17:07:53 +05:30
|
|
|
if (strcasecmp(argv[0], "list") == 0) {
|
2009-08-17 22:37:20 +05:30
|
|
|
/* Lists all repositories registered in pool. */
|
|
|
|
if (argc != 1)
|
2011-07-29 14:57:43 +05:30
|
|
|
usage(xhp);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-07-29 14:47:34 +05:30
|
|
|
rv = xbps_repository_pool_foreach(repo_list_uri_cb, NULL);
|
|
|
|
if (rv == ENOTSUP)
|
|
|
|
xbps_error_printf("xbps-repo: no repositories "
|
|
|
|
"currently registered!\n");
|
|
|
|
else if (rv != 0 && rv != ENOTSUP)
|
|
|
|
xbps_error_printf("xbps-repo: failed to initialize "
|
|
|
|
"rpool: %s\n", strerror(rv));
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
} else if (strcasecmp(argv[0], "search") == 0) {
|
|
|
|
/*
|
|
|
|
* Search for a package by looking at pkgname/short_desc
|
|
|
|
* by using shell style match patterns (fnmatch(3)).
|
|
|
|
*/
|
|
|
|
if (argc != 2)
|
2011-07-29 14:57:43 +05:30
|
|
|
usage(xhp);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-07-29 14:47:34 +05:30
|
|
|
rv = xbps_repository_pool_foreach(repo_search_pkgs_cb, argv[1]);
|
|
|
|
if (rv == ENOTSUP)
|
|
|
|
xbps_error_printf("xbps-repo: no repositories "
|
|
|
|
"currently registered!\n");
|
|
|
|
else if (rv != 0 && rv != ENOTSUP)
|
|
|
|
xbps_error_printf("xbps-repo: failed to initialize "
|
|
|
|
"rpool: %s\n", strerror(rv));
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
} else if (strcasecmp(argv[0], "show") == 0) {
|
|
|
|
/* Shows info about a binary package. */
|
|
|
|
if (argc != 2)
|
2011-07-29 14:57:43 +05:30
|
|
|
usage(xhp);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-10-29 11:47:54 +05:30
|
|
|
rv = show_pkg_info_from_repolist(argv[1], option);
|
2011-05-25 18:59:26 +05:30
|
|
|
if (rv == ENOENT) {
|
|
|
|
xbps_printf("Unable to locate package "
|
|
|
|
"`%s' in repository pool.\n", argv[1]);
|
2011-07-29 14:47:34 +05:30
|
|
|
} else if (rv == ENOTSUP) {
|
|
|
|
xbps_error_printf("xbps-repo: no repositories "
|
|
|
|
"currently registered!\n");
|
2011-05-25 18:59:26 +05:30
|
|
|
} else if (rv != 0 && rv != ENOENT) {
|
|
|
|
xbps_error_printf("xbps-repo: unexpected error '%s' ",
|
|
|
|
"searching for '%s'\n", strerror(rv), argv[1]);
|
2009-11-24 16:17:04 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
} else if (strcasecmp(argv[0], "show-deps") == 0) {
|
|
|
|
/* Shows the required run dependencies for a package. */
|
|
|
|
if (argc != 2)
|
2011-07-29 14:57:43 +05:30
|
|
|
usage(xhp);
|
2009-11-24 16:17:04 +05:30
|
|
|
|
2009-11-25 10:02:04 +05:30
|
|
|
rv = show_pkg_deps_from_repolist(argv[1]);
|
2011-05-25 18:59:26 +05:30
|
|
|
if (rv == ENOENT) {
|
|
|
|
xbps_printf("Unable to locate package "
|
|
|
|
"`%s' in repository pool.\n", argv[1]);
|
2011-07-29 14:47:34 +05:30
|
|
|
} else if (rv == ENOTSUP) {
|
|
|
|
xbps_error_printf("xbps-repo: no repositories "
|
|
|
|
"currently registered!\n");
|
2011-05-25 18:59:26 +05:30
|
|
|
} else if (rv != 0 && rv != ENOENT) {
|
|
|
|
xbps_error_printf("xbps-repo: unexpected error '%s' "
|
|
|
|
"searching for '%s'\n", strerror(errno), argv[1]);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
2009-11-25 07:45:56 +05:30
|
|
|
} else if (strcasecmp(argv[0], "show-files") == 0) {
|
|
|
|
/* Shows the package files in a binary package */
|
|
|
|
if (argc != 2)
|
2011-07-29 14:57:43 +05:30
|
|
|
usage(xhp);
|
2009-11-25 07:45:56 +05:30
|
|
|
|
2011-06-01 13:07:32 +05:30
|
|
|
pkgd = xbps_repository_pool_dictionary_metadata_plist(argv[1],
|
2009-11-25 10:02:04 +05:30
|
|
|
XBPS_PKGFILES);
|
2009-11-25 07:45:56 +05:30
|
|
|
if (pkgd == NULL) {
|
2011-07-29 14:47:34 +05:30
|
|
|
if (errno == ENOTSUP) {
|
|
|
|
xbps_error_printf("xbps-repo: no repositories "
|
|
|
|
"currently registered!\n");
|
|
|
|
} else if (errno == ENOENT) {
|
|
|
|
xbps_printf("Unable to locate package `%s' "
|
|
|
|
"in repository pool.\n", argv[1]);
|
|
|
|
} else {
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_error_printf("xbps-repo: unexpected "
|
2010-11-19 18:10:13 +05:30
|
|
|
"error '%s' searching for '%s'\n",
|
|
|
|
strerror(errno), argv[1]);
|
|
|
|
}
|
2009-11-25 07:45:56 +05:30
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
rv = show_pkg_files(pkgd);
|
|
|
|
prop_object_release(pkgd);
|
|
|
|
|
2010-12-15 19:44:44 +05:30
|
|
|
} else if (strcasecmp(argv[0], "find-files") == 0) {
|
|
|
|
/* Finds files by patterns, exact matches and components. */
|
|
|
|
if (argc != 2)
|
2011-07-29 14:57:43 +05:30
|
|
|
usage(xhp);
|
2010-12-15 19:44:44 +05:30
|
|
|
|
|
|
|
rv = repo_find_files_in_packages(argv[1]);
|
2011-07-29 14:47:34 +05:30
|
|
|
if (rv == ENOTSUP) {
|
|
|
|
xbps_error_printf("xbps-repo: no repositories "
|
|
|
|
"currently registered!\n");
|
|
|
|
}
|
2010-12-15 19:44:44 +05:30
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
} else if (strcasecmp(argv[0], "genindex") == 0) {
|
|
|
|
/* Generates a package repository index plist file. */
|
|
|
|
if (argc != 2)
|
2011-07-29 14:57:43 +05:30
|
|
|
usage(xhp);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-07-27 20:43:54 +05:30
|
|
|
rv = repo_genindex(argv[1]);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-10-31 16:27:40 +05:30
|
|
|
} else if (strcasecmp(argv[0], "sync") == 0) {
|
2009-11-23 09:53:16 +05:30
|
|
|
/* Syncs the pkg index for all registered remote repos */
|
|
|
|
if (argc != 1)
|
2011-07-29 14:57:43 +05:30
|
|
|
usage(xhp);
|
2009-10-31 16:27:40 +05:30
|
|
|
|
2011-11-11 03:44:50 +05:30
|
|
|
rv = xbps_repository_pool_sync();
|
2011-07-29 14:47:34 +05:30
|
|
|
if (rv == ENOTSUP) {
|
|
|
|
xbps_error_printf("xbps-repo: no repositories "
|
|
|
|
"currently registered!\n");
|
|
|
|
}
|
2009-10-31 16:27:40 +05:30
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
} else {
|
2011-07-29 14:57:43 +05:30
|
|
|
usage(xhp);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
2009-11-24 16:17:04 +05:30
|
|
|
out:
|
2011-07-27 20:43:54 +05:30
|
|
|
xbps_end(xhp);
|
2009-11-24 16:17:04 +05:30
|
|
|
exit(rv ? EXIT_FAILURE : EXIT_SUCCESS);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|