2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2020-04-29 17:42:10 +05:30
|
|
|
* Copyright (c) 2008-2015 Juan Romero Pardines.
|
|
|
|
* 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.
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#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>
|
2009-11-07 09:26:20 +05:30
|
|
|
#include <ctype.h>
|
2010-11-13 07:48:58 +05:30
|
|
|
#include <assert.h>
|
2010-11-19 18:10:13 +05:30
|
|
|
#include <unistd.h>
|
2015-06-20 15:48:45 +05:30
|
|
|
#include <getopt.h>
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2013-06-20 16:01:02 +05:30
|
|
|
#include <xbps.h>
|
2019-06-20 14:23:30 +05:30
|
|
|
#include "../xbps-install/defs.h"
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-01-15 16:29:44 +05:30
|
|
|
static void __attribute__((noreturn))
|
2012-01-17 21:26:17 +05:30
|
|
|
usage(void)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2012-09-24 14:19:45 +05:30
|
|
|
fprintf(stdout,
|
2023-02-12 02:02:36 +05:30
|
|
|
"Usage: xbps-uhelper [OPTIONS] [MODE] [ARGUMENTS]\n\n"
|
|
|
|
"OPTIONS\n"
|
|
|
|
" -C --config <dir> Path to confdir (xbps.d)\n"
|
|
|
|
" -d --debug Debug mode shown to stderr\n"
|
|
|
|
" -r --rootdir <dir> Full path to rootdir\n"
|
2023-03-30 01:34:38 +05:30
|
|
|
" -v --verbose Verbose messages\n"
|
2023-02-12 02:02:36 +05:30
|
|
|
" -V --version Show XBPS verison\n"
|
|
|
|
"\n"
|
|
|
|
"MODE\n"
|
|
|
|
" arch Prints the configured XBPS architecture\n"
|
|
|
|
" binpkgarch <binpkg...> Prints the architecture of binpkg names\n"
|
|
|
|
" binpkgver <binpkg...> Prints the pkgver of binpkg names\n"
|
|
|
|
" cmpver <version> <version> Compare two version strings\n"
|
|
|
|
" getname <pkgver|dep...> Prints pkgname from pkgvers or dependencies\n"
|
|
|
|
" getpkgdepname <dep...> Prints pkgname from dependencies\n"
|
|
|
|
" getpkgdepversion <dep...> Prints version constraint from dependencies\n"
|
|
|
|
" getpkgname <pkgver...> Prints pkgname from pkgvers\n"
|
|
|
|
" getpkgrevision <pkgver...> Prints revision from pkgvers\n"
|
|
|
|
" getpkgversion <pkgver...> Prints version from pkgvers\n"
|
|
|
|
" getversion <pkgver|dep...> Prints version from patterns or pkgvers\n"
|
|
|
|
" pkgmatch <pkgver> <dep> Match pkgver against dependency\n"
|
|
|
|
" real-version <pkgname...> Prints version of installed real packages\n"
|
|
|
|
" version <pkgname...> Prints version of installed packages\n"
|
|
|
|
" getsystemdir Prints the system xbps.d directory\n"
|
|
|
|
);
|
2009-08-17 22:37:20 +05:30
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2019-06-20 14:23:30 +05:30
|
|
|
static char *
|
|
|
|
fname(char *url)
|
|
|
|
{
|
|
|
|
char *filename;
|
|
|
|
|
|
|
|
if ((filename = strrchr(url, '>'))) {
|
|
|
|
*filename = '\0';
|
|
|
|
} else {
|
|
|
|
filename = strrchr(url, '/');
|
|
|
|
}
|
|
|
|
if (filename == NULL)
|
|
|
|
return NULL;
|
|
|
|
return filename + 1;
|
|
|
|
}
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_t dict;
|
2012-01-17 20:47:03 +05:30
|
|
|
struct xbps_handle xh;
|
2019-06-20 14:23:30 +05:30
|
|
|
struct xferstat xfer;
|
2014-11-06 14:28:04 +05:30
|
|
|
const char *version, *rootdir = NULL, *confdir = NULL;
|
2020-02-09 00:01:29 +05:30
|
|
|
char pkgname[XBPS_NAME_SIZE], *filename;
|
2023-02-09 15:51:54 +05:30
|
|
|
int flags = 0, c, rv = 0, i = 0;
|
2015-06-20 15:48:45 +05:30
|
|
|
const struct option longopts[] = {
|
2023-02-09 11:11:48 +05:30
|
|
|
{ "config", required_argument, NULL, 'C' },
|
|
|
|
{ "debug", no_argument, NULL, 'd' },
|
|
|
|
{ "rootdir", required_argument, NULL, 'r' },
|
2023-03-30 01:34:38 +05:30
|
|
|
{ "verbose", no_argument, NULL, 'v' },
|
2023-02-09 11:11:48 +05:30
|
|
|
{ "version", no_argument, NULL, 'V' },
|
2015-06-20 15:48:45 +05:30
|
|
|
{ NULL, 0, NULL, 0 }
|
|
|
|
};
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2023-03-30 01:34:38 +05:30
|
|
|
while ((c = getopt_long(argc, argv, "C:dr:vV", longopts, NULL)) != -1) {
|
2009-08-17 22:37:20 +05:30
|
|
|
switch (c) {
|
2011-06-04 17:07:53 +05:30
|
|
|
case 'C':
|
2014-11-06 14:28:04 +05:30
|
|
|
confdir = optarg;
|
2011-06-04 17:07:53 +05:30
|
|
|
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;
|
2010-12-18 14:56:12 +05:30
|
|
|
case 'd':
|
2012-01-22 15:22:35 +05:30
|
|
|
flags |= XBPS_FLAG_DEBUG;
|
2010-12-18 14:56:12 +05:30
|
|
|
break;
|
2023-03-30 01:34:38 +05:30
|
|
|
case 'v':
|
|
|
|
flags |= XBPS_FLAG_VERBOSE;
|
|
|
|
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-01-17 21:26:17 +05:30
|
|
|
usage();
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc < 1)
|
2012-01-17 21:26:17 +05:30
|
|
|
usage();
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2012-09-25 04:36:13 +05:30
|
|
|
memset(&xh, 0, sizeof(xh));
|
|
|
|
|
2013-10-22 13:26:55 +05:30
|
|
|
if ((strcmp(argv[0], "version") == 0) ||
|
|
|
|
(strcmp(argv[0], "real-version") == 0) ||
|
2014-11-19 16:06:09 +05:30
|
|
|
(strcmp(argv[0], "arch") == 0) ||
|
2019-06-20 14:23:30 +05:30
|
|
|
(strcmp(argv[0], "fetch") == 0) ||
|
2019-06-12 21:27:03 +05:30
|
|
|
(strcmp(argv[0], "getsystemdir") == 0)) {
|
2011-11-05 13:11:29 +05:30
|
|
|
/*
|
2011-12-15 15:49:20 +05:30
|
|
|
* Initialize libxbps.
|
2011-11-05 13:11:29 +05:30
|
|
|
*/
|
2019-06-20 14:23:30 +05:30
|
|
|
xh.fetch_cb = fetch_file_progress_cb;
|
|
|
|
xh.fetch_cb_data = &xfer;
|
2012-01-22 15:22:35 +05:30
|
|
|
xh.flags = flags;
|
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));
|
|
|
|
if (confdir)
|
|
|
|
xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir));
|
2012-01-17 20:47:03 +05:30
|
|
|
if ((rv = xbps_init(&xh)) != 0) {
|
2011-11-05 13:11:29 +05:30
|
|
|
xbps_error_printf("xbps-uhelper: failed to "
|
2011-12-15 15:49:20 +05:30
|
|
|
"initialize libxbps: %s.\n", strerror(rv));
|
2011-11-05 13:11:29 +05:30
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
2013-10-22 13:26:55 +05:30
|
|
|
if (strcmp(argv[0], "version") == 0) {
|
2023-02-09 15:51:54 +05:30
|
|
|
/* Prints version of installed packages */
|
|
|
|
if (argc < 2)
|
2012-01-17 21:26:17 +05:30
|
|
|
usage();
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2023-02-09 15:51:54 +05:30
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
if ((((dict = xbps_pkgdb_get_pkg(&xh, argv[i])) == NULL)) &&
|
|
|
|
(((dict = xbps_pkgdb_get_virtualpkg(&xh, argv[i])) == NULL))) {
|
|
|
|
xbps_error_printf("Could not find package '%s'\n", argv[i]);
|
|
|
|
rv = 1;
|
|
|
|
} else {
|
|
|
|
xbps_dictionary_get_cstring_nocopy(dict, "pkgver", &version);
|
|
|
|
printf("%s\n", xbps_pkg_version(version));
|
|
|
|
}
|
|
|
|
}
|
2013-10-22 13:26:55 +05:30
|
|
|
} else if (strcmp(argv[0], "real-version") == 0) {
|
2023-02-09 15:51:54 +05:30
|
|
|
/* Prints version of installed real packages, not virtual */
|
|
|
|
if (argc < 2)
|
2012-01-17 21:26:17 +05:30
|
|
|
usage();
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2023-02-09 15:51:54 +05:30
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
if ((dict = xbps_pkgdb_get_pkg(&xh, argv[i])) == NULL) {
|
|
|
|
xbps_error_printf("Could not find package '%s'\n", argv[i]);
|
|
|
|
rv = 1;
|
|
|
|
} else {
|
|
|
|
xbps_dictionary_get_cstring_nocopy(dict, "pkgver", &version);
|
|
|
|
printf("%s\n", xbps_pkg_version(version));
|
|
|
|
}
|
|
|
|
}
|
2013-10-22 13:26:55 +05:30
|
|
|
} else if (strcmp(argv[0], "getpkgversion") == 0) {
|
2023-02-09 15:51:54 +05:30
|
|
|
/* Returns the version of pkg strings */
|
|
|
|
if (argc < 2)
|
2012-01-17 21:26:17 +05:30
|
|
|
usage();
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2023-02-09 15:51:54 +05:30
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
version = xbps_pkg_version(argv[i]);
|
|
|
|
if (version == NULL) {
|
|
|
|
xbps_error_printf(
|
|
|
|
"Invalid string '%s', expected <string>-<version>_<revision>\n", argv[i]);
|
|
|
|
rv = 1;
|
|
|
|
} else {
|
|
|
|
printf("%s\n", version);
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2013-10-22 13:26:55 +05:30
|
|
|
} else if (strcmp(argv[0], "getpkgname") == 0) {
|
2023-02-09 15:51:54 +05:30
|
|
|
/* Returns the name of pkg strings */
|
|
|
|
if (argc < 2)
|
2012-01-17 21:26:17 +05:30
|
|
|
usage();
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2023-02-09 15:51:54 +05:30
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
if (!xbps_pkg_name(pkgname, sizeof(pkgname), argv[i])) {
|
|
|
|
xbps_error_printf(
|
|
|
|
"Invalid string '%s', expected <string>-<version>_<revision>\n", argv[i]);
|
|
|
|
rv = 1;
|
|
|
|
} else {
|
|
|
|
printf("%s\n", pkgname);
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2013-10-22 13:26:55 +05:30
|
|
|
} else if (strcmp(argv[0], "getpkgrevision") == 0) {
|
2023-02-09 15:51:54 +05:30
|
|
|
/* Returns the revision of pkg strings */
|
|
|
|
if (argc < 2)
|
2012-01-17 21:26:17 +05:30
|
|
|
usage();
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2023-02-09 15:51:54 +05:30
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
version = xbps_pkg_revision(argv[1]);
|
|
|
|
if (version == NULL) {
|
|
|
|
rv = 1;
|
|
|
|
} else {
|
|
|
|
printf("%s\n", version);
|
|
|
|
}
|
|
|
|
}
|
2013-10-22 13:26:55 +05:30
|
|
|
} else if (strcmp(argv[0], "getpkgdepname") == 0) {
|
2023-02-09 15:51:54 +05:30
|
|
|
/* Returns the pkgname of dependencies */
|
|
|
|
if (argc < 2)
|
2012-01-17 21:26:17 +05:30
|
|
|
usage();
|
2009-11-07 09:26:20 +05:30
|
|
|
|
2023-02-09 15:51:54 +05:30
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
if (!xbps_pkgpattern_name(pkgname, sizeof(pkgname), argv[i])) {
|
|
|
|
xbps_error_printf("Invalid string '%s', expected <string><comparator><version>\n", argv[i]);
|
|
|
|
rv = 1;
|
|
|
|
} else {
|
|
|
|
printf("%s\n", pkgname);
|
|
|
|
}
|
|
|
|
}
|
2013-10-22 13:26:55 +05:30
|
|
|
} else if (strcmp(argv[0], "getpkgdepversion") == 0) {
|
2023-02-09 15:51:54 +05:30
|
|
|
/* returns the version of package pattern dependencies */
|
|
|
|
if (argc < 2)
|
2012-01-17 21:26:17 +05:30
|
|
|
usage();
|
2011-01-24 23:43:11 +05:30
|
|
|
|
2023-02-09 15:51:54 +05:30
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
version = xbps_pkgpattern_version(argv[i]);
|
|
|
|
if (version == NULL) {
|
|
|
|
xbps_error_printf("Invalid string '%s', expected <string><comparator><version>\n", argv[i]);
|
|
|
|
rv = 1;
|
|
|
|
} else {
|
|
|
|
printf("%s\n", version);
|
|
|
|
}
|
|
|
|
}
|
2023-02-10 05:16:39 +05:30
|
|
|
} else if (strcmp(argv[0], "getname") == 0) {
|
|
|
|
/* returns the name of a pkg strings or pkg patterns */
|
|
|
|
if (argc < 2)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
if (xbps_pkgpattern_name(pkgname, sizeof(pkgname), argv[i]) ||
|
|
|
|
xbps_pkg_name(pkgname, sizeof(pkgname), argv[i])) {
|
|
|
|
printf("%s\n", pkgname);
|
|
|
|
} else {
|
|
|
|
xbps_error_printf(
|
|
|
|
"Invalid string '%s', expected <string><comparator><version> "
|
|
|
|
"or <string>-<version>_<revision>\n", argv[i]);
|
|
|
|
rv = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (strcmp(argv[0], "getversion") == 0) {
|
|
|
|
/* returns the version of a pkg strings or pkg patterns */
|
|
|
|
if (argc < 2)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
version = xbps_pkgpattern_version(argv[i]);
|
|
|
|
if (version == NULL) {
|
|
|
|
version = xbps_pkg_version(argv[i]);
|
|
|
|
if (version == NULL) {
|
|
|
|
xbps_error_printf(
|
|
|
|
"Invalid string '%s', expected <string><comparator><version> "
|
|
|
|
"or <string>-<version>_<revision>\n", argv[i]);
|
|
|
|
rv = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("%s\n", version);
|
|
|
|
}
|
2014-09-06 00:36:06 +05:30
|
|
|
} else if (strcmp(argv[0], "binpkgver") == 0) {
|
2023-02-09 15:51:54 +05:30
|
|
|
/* Returns the pkgver of binpkg strings */
|
|
|
|
if (argc < 2)
|
2014-09-06 00:36:06 +05:30
|
|
|
usage();
|
|
|
|
|
2023-02-09 15:51:54 +05:30
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
version = xbps_binpkg_pkgver(argv[i]);
|
|
|
|
if (version == NULL) {
|
|
|
|
xbps_error_printf(
|
|
|
|
"Invalid string '%s', expected <pkgname>-<version>_<revision>.<arch>.xbps\n", argv[i]);
|
|
|
|
rv = 1;
|
|
|
|
} else {
|
|
|
|
printf("%s\n", version);
|
|
|
|
}
|
2014-09-06 00:36:06 +05:30
|
|
|
}
|
|
|
|
} else if (strcmp(argv[0], "binpkgarch") == 0) {
|
2023-02-09 15:51:54 +05:30
|
|
|
/* Returns the arch of binpkg strings */
|
|
|
|
if (argc < 2)
|
2014-09-06 00:36:06 +05:30
|
|
|
usage();
|
|
|
|
|
2023-02-09 15:51:54 +05:30
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
version = xbps_binpkg_arch(argv[i]);
|
|
|
|
if (version == NULL) {
|
|
|
|
xbps_error_printf(
|
|
|
|
"Invalid string '%s', expected <pkgname>-<version>_<revision>.<arch>.xbps\n", argv[i]);
|
|
|
|
rv = 1;
|
|
|
|
} else {
|
|
|
|
printf("%s\n", version);
|
|
|
|
}
|
2014-09-06 00:36:06 +05:30
|
|
|
}
|
2013-10-22 13:26:55 +05:30
|
|
|
} else if (strcmp(argv[0], "pkgmatch") == 0) {
|
2009-11-07 09:26:20 +05:30
|
|
|
/* Matches a pkg with a pattern */
|
|
|
|
if (argc != 3)
|
2012-01-17 21:26:17 +05:30
|
|
|
usage();
|
2023-03-30 01:34:38 +05:30
|
|
|
rv = xbps_pkgpattern_match(argv[1], argv[2]);
|
|
|
|
if (flags & XBPS_FLAG_VERBOSE) {
|
|
|
|
if (rv >= 0)
|
|
|
|
fprintf(stderr, "%s %s %s\n",
|
|
|
|
argv[1],
|
|
|
|
(rv == 1) ? "matches" : "does not match",
|
|
|
|
argv[2]);
|
|
|
|
else
|
|
|
|
xbps_error_printf("%s: not a pattern\n", argv[2]);
|
|
|
|
}
|
|
|
|
exit(rv);
|
2013-10-22 13:26:55 +05:30
|
|
|
} else if (strcmp(argv[0], "cmpver") == 0) {
|
2009-11-24 17:29:47 +05:30
|
|
|
/* Compare two version strings, installed vs required */
|
|
|
|
if (argc != 3)
|
2012-01-17 21:26:17 +05:30
|
|
|
usage();
|
2009-11-24 17:29:47 +05:30
|
|
|
|
2023-03-30 01:34:38 +05:30
|
|
|
rv = xbps_cmpver(argv[1], argv[2]);
|
|
|
|
if (flags & XBPS_FLAG_VERBOSE)
|
|
|
|
fprintf(stderr, "%s %s %s\n",
|
|
|
|
argv[1],
|
|
|
|
(rv == 1) ? ">" : ((rv == 0) ? "=" : "<"),
|
|
|
|
argv[2]);
|
|
|
|
exit(rv);
|
2014-11-19 16:06:09 +05:30
|
|
|
} else if (strcmp(argv[0], "arch") == 0) {
|
|
|
|
/* returns the xbps native arch */
|
|
|
|
if (argc != 1)
|
|
|
|
usage();
|
|
|
|
|
2016-07-17 15:04:39 +05:30
|
|
|
if (xh.native_arch[0] && xh.target_arch && strcmp(xh.native_arch, xh.target_arch)) {
|
2016-04-13 12:23:26 +05:30
|
|
|
printf("%s\n", xh.target_arch);
|
|
|
|
} else {
|
|
|
|
printf("%s\n", xh.native_arch);
|
|
|
|
}
|
2014-11-21 15:10:11 +05:30
|
|
|
} else if (strcmp(argv[0], "getsystemdir") == 0) {
|
|
|
|
/* returns the xbps system directory (<sharedir>/xbps.d) */
|
|
|
|
if (argc != 1)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
printf("%s\n", XBPS_SYSDEFCONF_PATH);
|
2019-06-20 14:23:30 +05:30
|
|
|
} else if (strcmp(argv[0], "digest") == 0) {
|
2020-02-10 06:24:52 +05:30
|
|
|
char sha256[XBPS_SHA256_SIZE];
|
|
|
|
|
2019-06-20 14:23:30 +05:30
|
|
|
/* Prints SHA256 hashes for specified files */
|
|
|
|
if (argc < 2)
|
|
|
|
usage();
|
|
|
|
|
2023-02-09 15:51:54 +05:30
|
|
|
for (i = 1; i < argc; i++) {
|
2020-02-10 06:24:52 +05:30
|
|
|
if (!xbps_file_sha256(sha256, sizeof sha256, argv[i])) {
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf(
|
|
|
|
"couldn't get hash for %s (%s)\n",
|
2019-06-20 14:23:30 +05:30
|
|
|
argv[i], strerror(errno));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2020-02-10 06:24:52 +05:30
|
|
|
printf("%s\n", sha256);
|
2019-06-20 14:23:30 +05:30
|
|
|
}
|
|
|
|
} else if (strcmp(argv[0], "fetch") == 0) {
|
|
|
|
/* Fetch a file from specified URL */
|
|
|
|
if (argc < 2)
|
|
|
|
usage();
|
|
|
|
|
2023-02-09 15:51:54 +05:30
|
|
|
for (i = 1; i < argc; i++) {
|
2019-06-20 14:23:30 +05:30
|
|
|
filename = fname(argv[i]);
|
|
|
|
rv = xbps_fetch_file_dest(&xh, argv[i], filename, "v");
|
|
|
|
|
|
|
|
if (rv == -1) {
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("%s: %s\n", argv[i],
|
2019-06-20 14:23:30 +05:30
|
|
|
xbps_fetch_error_string());
|
|
|
|
} else if (rv == 0) {
|
|
|
|
printf("%s: file is identical with remote.\n", argv[i]);
|
|
|
|
} else {
|
|
|
|
rv = 0;
|
|
|
|
}
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
} else {
|
2012-01-17 21:26:17 +05:30
|
|
|
usage();
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2012-12-14 16:28:30 +05:30
|
|
|
|
2011-12-24 21:07:42 +05:30
|
|
|
exit(rv ? EXIT_FAILURE : EXIT_SUCCESS);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|