2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2012-01-15 18:54:44 +05:30
|
|
|
* Copyright (c) 2008-2012 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))
|
2012-02-14 15:19:41 +05:30
|
|
|
usage(bool fail)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2010-01-15 19:49:16 +05:30
|
|
|
fprintf(stderr,
|
2012-02-14 15:19:41 +05:30
|
|
|
"Usage: xbps-repo [options] target [arguments]\n\n"
|
|
|
|
"[options]\n"
|
|
|
|
" -C file Full path to configuration file\n"
|
|
|
|
" -c cachedir Full path to cachedir to store downloaded binpkgs\n"
|
|
|
|
" -d Debug mode shown to stderr\n"
|
|
|
|
" -h Print usage help\n"
|
|
|
|
" -o key[,key] Print package metadata keys in show target\n"
|
|
|
|
" -r rootdir Full path to rootdir\n"
|
|
|
|
" -V Show XBPS version\n\n"
|
|
|
|
"[targets]\n"
|
2012-05-05 13:37:47 +05:30
|
|
|
" clean\n"
|
|
|
|
" Removes obsolete binary packages from cachedir.\n"
|
2012-02-14 15:19:41 +05:30
|
|
|
" find-files <pattern> [patterns]\n"
|
|
|
|
" Print package name/version for any pattern matched.\n"
|
2012-07-18 18:36:47 +05:30
|
|
|
" index-add <repository>/foo-1.0.xbps ...\n"
|
|
|
|
" Registers specified package(s) to the local repository's index.\n"
|
|
|
|
" Multiple packages can be specified. An absolute path is expected.\n"
|
|
|
|
" index-clean <repository>\n"
|
|
|
|
" Removes obsolete entries from repository's index files.\n"
|
2012-02-14 15:19:41 +05:30
|
|
|
" list\n"
|
|
|
|
" List registered repositories.\n"
|
2012-06-01 18:32:06 +05:30
|
|
|
" pkg-list [repo]\n"
|
|
|
|
" Print packages in repository matching `repo' URI.\n"
|
|
|
|
" If `repo' not specified, all registered repositories will be used.\n"
|
2012-07-22 14:18:29 +05:30
|
|
|
" remove-obsoletes <repository>\n"
|
|
|
|
" Removes obsolete packages (not registered in index any longer) from\n"
|
|
|
|
" local repository \"<repository>\".\n"
|
2012-02-14 15:19:41 +05:30
|
|
|
" search <pattern> [patterns]\n"
|
|
|
|
" Search for packages in repositories matching the patterns.\n"
|
2012-02-16 13:25:41 +05:30
|
|
|
" show <pkgname|pkgpattern>\n"
|
|
|
|
" Print package information for `pkgname' or `pkgpattern'.\n"
|
|
|
|
" show-deps <pkgname|pkgpattern>\n"
|
|
|
|
" Print package's required dependencies for `pkgname' or `pkgpattern'.\n"
|
|
|
|
" show-files <pkgname|pkgpattern>\n"
|
|
|
|
" Print package's files list for `pkgname' or `pkgpattern'.\n"
|
2012-06-01 18:32:06 +05:30
|
|
|
" sync [repo]\n"
|
|
|
|
" Synchronize package index file for `repo'.\n"
|
|
|
|
" If `repo' not specified, all remote repositories will be used. \n\n"
|
2012-02-14 15:19:41 +05:30
|
|
|
"Refer to xbps-repo(8) for a more detailed description.\n");
|
|
|
|
|
|
|
|
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2012-01-17 20:47:03 +05:30
|
|
|
struct xbps_handle xh;
|
2011-07-27 21:34:38 +05:30
|
|
|
struct xferstat xfer;
|
2011-12-22 14:03:54 +05:30
|
|
|
struct repo_search_data *rsd = NULL;
|
2009-11-24 16:17:04 +05:30
|
|
|
prop_dictionary_t pkgd;
|
2011-12-15 15:49:20 +05:30
|
|
|
const char *rootdir, *cachedir, *conffile, *option;
|
2012-01-22 15:22:35 +05:30
|
|
|
int flags = 0, c, rv = 0;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-12-15 15:49:20 +05:30
|
|
|
rootdir = cachedir = conffile = option = NULL;
|
2011-02-21 22:12:47 +05:30
|
|
|
|
2012-02-14 15:19:41 +05:30
|
|
|
while ((c = getopt(argc, argv, "C:c:dho:r:V")) != -1) {
|
2009-08-17 22:37:20 +05:30
|
|
|
switch (c) {
|
2011-06-04 17:07:53 +05:30
|
|
|
case 'C':
|
2011-12-15 15:49:20 +05:30
|
|
|
conffile = 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':
|
2012-01-22 15:22:35 +05:30
|
|
|
flags |= XBPS_FLAG_DEBUG;
|
2010-11-19 18:10:13 +05:30
|
|
|
break;
|
2012-02-14 15:19:41 +05:30
|
|
|
case 'h':
|
|
|
|
usage(false);
|
|
|
|
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:
|
2012-02-14 15:19:41 +05:30
|
|
|
usage(true);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc < 1)
|
2012-02-14 15:19:41 +05:30
|
|
|
usage(true);
|
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
|
|
|
*/
|
2012-01-17 20:47:03 +05:30
|
|
|
memset(&xh, 0, sizeof(xh));
|
2012-01-22 15:22:35 +05:30
|
|
|
xh.flags = flags;
|
2012-01-17 20:47:03 +05:30
|
|
|
xh.state_cb = state_cb;
|
|
|
|
xh.fetch_cb = fetch_file_progress_cb;
|
|
|
|
xh.fetch_cb_data = &xfer;
|
|
|
|
xh.rootdir = rootdir;
|
|
|
|
xh.cachedir = cachedir;
|
|
|
|
xh.conffile = conffile;
|
2011-07-27 20:43:54 +05:30
|
|
|
|
2012-01-17 20:47:03 +05:30
|
|
|
if ((rv = xbps_init(&xh)) != 0) {
|
2011-06-04 17:07:53 +05:30
|
|
|
xbps_error_printf("xbps-repo: couldn't initialize library: %s\n",
|
2011-12-15 15:49:20 +05:30
|
|
|
strerror(rv));
|
2011-06-04 17:07:53 +05:30
|
|
|
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)
|
2012-02-14 15:19:41 +05:30
|
|
|
usage(true);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
rv = xbps_rpool_foreach(&xh, repo_list_uri_cb, NULL);
|
2011-07-29 14:47:34 +05:30
|
|
|
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));
|
2011-12-03 15:07:31 +05:30
|
|
|
} else if (strcasecmp(argv[0], "pkg-list") == 0) {
|
|
|
|
/*
|
|
|
|
* Only list packages for the target repository.
|
|
|
|
*/
|
|
|
|
if (argc < 1 || argc > 2)
|
2012-02-14 15:19:41 +05:30
|
|
|
usage(true);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
rv = xbps_rpool_foreach(&xh, repo_pkg_list_cb, argv[1]);
|
2011-12-03 15:07:31 +05:30
|
|
|
if (rv == ENOTSUP)
|
|
|
|
xbps_error_printf("xbps-repo: no repositories "
|
|
|
|
"currently registered!\n");
|
|
|
|
else if (rv != 0)
|
|
|
|
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)).
|
|
|
|
*/
|
2011-12-22 14:03:54 +05:30
|
|
|
if (argc < 2)
|
2012-02-14 15:19:41 +05:30
|
|
|
usage(true);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-12-22 14:03:54 +05:30
|
|
|
rsd = malloc(sizeof(*rsd));
|
|
|
|
if (rsd == NULL) {
|
|
|
|
rv = ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
rsd->npatterns = argc;
|
|
|
|
rsd->patterns = argv;
|
2012-06-14 11:52:11 +05:30
|
|
|
rv = xbps_rpool_foreach(&xh, repo_search_pkgs_cb, rsd);
|
2011-12-22 14:03:54 +05:30
|
|
|
free(rsd);
|
2011-07-29 14:47:34 +05:30
|
|
|
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)
|
2012-02-14 15:19:41 +05:30
|
|
|
usage(true);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
rv = show_pkg_info_from_repolist(&xh, argv[1], option);
|
2011-05-25 18:59:26 +05:30
|
|
|
if (rv == ENOENT) {
|
2012-02-25 15:00:15 +05:30
|
|
|
xbps_error_printf("Unable to locate package "
|
2011-05-25 18:59:26 +05:30
|
|
|
"`%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)
|
2012-02-14 15:19:41 +05:30
|
|
|
usage(true);
|
2009-11-24 16:17:04 +05:30
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
rv = show_pkg_deps_from_repolist(&xh, argv[1]);
|
2011-05-25 18:59:26 +05:30
|
|
|
if (rv == ENOENT) {
|
2012-02-25 15:00:15 +05:30
|
|
|
xbps_error_printf("Unable to locate package "
|
2011-05-25 18:59:26 +05:30
|
|
|
"`%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)
|
2012-02-14 15:19:41 +05:30
|
|
|
usage(true);
|
2009-11-25 07:45:56 +05:30
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
pkgd = xbps_rpool_dictionary_metadata_plist(&xh, argv[1],
|
2012-06-06 00:23:15 +05:30
|
|
|
"./files.plist");
|
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) {
|
2012-02-25 15:00:15 +05:30
|
|
|
xbps_error_printf("Unable to locate package `%s' "
|
2011-07-29 14:47:34 +05:30
|
|
|
"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. */
|
2011-12-22 15:31:28 +05:30
|
|
|
if (argc < 2)
|
2012-02-14 15:19:41 +05:30
|
|
|
usage(true);
|
2010-12-15 19:44:44 +05:30
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
rv = repo_find_files_in_packages(&xh, argc, argv);
|
2011-07-29 14:47:34 +05:30
|
|
|
if (rv == ENOTSUP) {
|
|
|
|
xbps_error_printf("xbps-repo: no repositories "
|
|
|
|
"currently registered!\n");
|
|
|
|
}
|
2012-07-22 14:18:29 +05:30
|
|
|
} else if (strcasecmp(argv[0], "remove-obsoletes") == 0) {
|
|
|
|
if (argc < 2)
|
|
|
|
usage(true);
|
|
|
|
|
|
|
|
if ((rv = repo_remove_obsoletes(&xh, argv[1])) != 0)
|
|
|
|
goto out;
|
|
|
|
|
2012-07-17 16:01:04 +05:30
|
|
|
} else if (strcasecmp(argv[0], "index-add") == 0) {
|
|
|
|
/* Registers a binary package into the repository's index. */
|
|
|
|
if (argc < 2)
|
|
|
|
usage(true);
|
|
|
|
|
|
|
|
if ((rv = repo_index_add(&xh, argc, argv)) != 0)
|
|
|
|
goto out;
|
|
|
|
if ((rv = repo_index_files_add(&xh, argc, argv)) != 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
} else if (strcasecmp(argv[0], "index-clean") == 0) {
|
|
|
|
/* Removes obsolete pkg entries from index in a repository */
|
2009-08-17 22:37:20 +05:30
|
|
|
if (argc != 2)
|
2012-02-14 15:19:41 +05:30
|
|
|
usage(true);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2012-07-17 16:01:04 +05:30
|
|
|
if ((rv = repo_index_clean(&xh, argv[1])) != 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
rv = repo_index_files_clean(&xh, argv[1]);
|
2012-01-15 18:54:44 +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 */
|
2012-06-01 18:32:06 +05:30
|
|
|
if (argc < 1 || argc > 2)
|
2012-02-14 15:19:41 +05:30
|
|
|
usage(true);
|
2009-10-31 16:27:40 +05:30
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
rv = xbps_rpool_sync(&xh, argv[1]);
|
2011-07-29 14:47:34 +05:30
|
|
|
if (rv == ENOTSUP) {
|
|
|
|
xbps_error_printf("xbps-repo: no repositories "
|
|
|
|
"currently registered!\n");
|
|
|
|
}
|
2012-05-05 13:37:47 +05:30
|
|
|
} else if (strcasecmp(argv[0], "clean") == 0) {
|
|
|
|
/* Cleans up cache directory */
|
|
|
|
if (argc != 1)
|
|
|
|
usage(true);
|
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
rv = cachedir_clean(&xh);
|
2009-08-17 22:37:20 +05:30
|
|
|
} else {
|
2012-02-14 15:19:41 +05:30
|
|
|
usage(true);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
2009-11-24 16:17:04 +05:30
|
|
|
out:
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_end(&xh);
|
2009-11-24 16:17:04 +05:30
|
|
|
exit(rv ? EXIT_FAILURE : EXIT_SUCCESS);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|