2012-11-02 19:34:25 +05:30
|
|
|
/*-
|
2014-02-23 12:53:14 +05:30
|
|
|
* Copyright (c) 2013-2014 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 <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <getopt.h>
|
2013-02-20 15:05:55 +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-pkgdb [OPTIONS] [PKGNAME...]\n\n"
|
|
|
|
"OPTIONS\n"
|
2013-08-12 18:16:54 +05:30
|
|
|
" -a --all Process all packages\n"
|
|
|
|
" -C --config <file> Full path to configuration file\n"
|
|
|
|
" -d --debug Debug mode shown to stderr\n"
|
|
|
|
" -h --help Print usage help\n"
|
|
|
|
" -m --mode <auto|manual|hold|unhold> Change PKGNAME to this mode\n"
|
|
|
|
" -r --rootdir <dir> Full path to rootdir\n"
|
|
|
|
" -u --update Update pkgdb to the latest format\n"
|
|
|
|
" -v --verbose Verbose messages\n"
|
|
|
|
" -V --version Show XBPS version\n");
|
2012-11-02 19:34:25 +05:30
|
|
|
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2013-02-20 15:05:55 +05:30
|
|
|
static int
|
2013-08-12 18:16:54 +05:30
|
|
|
change_pkg_mode(struct xbps_handle *xhp, const char *pkgname, const char *mode)
|
2013-02-20 15:05:55 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_t pkgd;
|
2013-02-20 15:05:55 +05:30
|
|
|
|
|
|
|
pkgd = xbps_pkgdb_get_pkg(xhp, pkgname);
|
|
|
|
if (pkgd == NULL)
|
|
|
|
return errno;
|
|
|
|
|
2013-08-12 18:16:54 +05:30
|
|
|
if (strcmp(mode, "auto") == 0)
|
|
|
|
xbps_dictionary_set_bool(pkgd, "automatic-install", true);
|
|
|
|
else if (strcmp(mode, "manual") == 0)
|
|
|
|
xbps_dictionary_set_bool(pkgd, "automatic-install", false);
|
|
|
|
else if (strcmp(mode, "hold") == 0)
|
|
|
|
xbps_dictionary_set_bool(pkgd, "hold", true);
|
|
|
|
else if (strcmp(mode, "unhold") == 0)
|
|
|
|
xbps_dictionary_remove(pkgd, "hold");
|
|
|
|
else
|
|
|
|
usage(true);
|
2013-02-20 15:05:55 +05:30
|
|
|
|
2014-03-04 19:07:10 +05:30
|
|
|
return 0;
|
2013-02-20 15:05:55 +05:30
|
|
|
}
|
|
|
|
|
2012-11-02 19:34:25 +05:30
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2013-03-05 08:38:42 +05:30
|
|
|
const char *shortopts = "aC:dhm:r:uVv";
|
2012-11-02 19:34:25 +05:30
|
|
|
const struct option longopts[] = {
|
|
|
|
{ "all", no_argument, NULL, 'a' },
|
|
|
|
{ "config", required_argument, NULL, 'C' },
|
|
|
|
{ "debug", no_argument, NULL, 'd' },
|
|
|
|
{ "help", no_argument, NULL, 'h' },
|
2013-02-20 15:05:55 +05:30
|
|
|
{ "mode", required_argument, NULL, 'm' },
|
2012-11-02 19:34:25 +05:30
|
|
|
{ "rootdir", required_argument, NULL, 'r' },
|
2013-03-05 08:38:42 +05:30
|
|
|
{ "update", no_argument, NULL, 'u' },
|
2012-11-02 19:34:25 +05:30
|
|
|
{ "verbose", no_argument, NULL, 'v' },
|
|
|
|
{ "version", no_argument, NULL, 'V' },
|
|
|
|
{ NULL, 0, NULL, 0 }
|
|
|
|
};
|
|
|
|
struct xbps_handle xh;
|
2013-02-20 15:05:55 +05:30
|
|
|
const char *conffile = NULL, *rootdir = NULL, *instmode = NULL;
|
2012-11-02 19:34:25 +05:30
|
|
|
int c, i, rv, flags = 0;
|
2013-03-05 08:38:42 +05:30
|
|
|
bool update_format = false, all = false;
|
2012-11-02 19:34:25 +05:30
|
|
|
|
|
|
|
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'a':
|
|
|
|
all = true;
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
conffile = optarg;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
flags |= XBPS_FLAG_DEBUG;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
usage(false);
|
|
|
|
/* NOTREACHED */
|
2013-02-20 15:05:55 +05:30
|
|
|
case 'm':
|
|
|
|
instmode = optarg;
|
|
|
|
break;
|
2012-11-02 19:34:25 +05:30
|
|
|
case 'r':
|
|
|
|
rootdir = optarg;
|
|
|
|
break;
|
2013-03-05 08:38:42 +05:30
|
|
|
case 'u':
|
|
|
|
update_format = true;
|
|
|
|
break;
|
2012-11-02 19:34:25 +05:30
|
|
|
case 'v':
|
|
|
|
flags |= XBPS_FLAG_VERBOSE;
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
printf("%s\n", XBPS_RELVER);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage(true);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
}
|
2013-03-05 08:38:42 +05:30
|
|
|
if (!update_format && !all && (argc == optind))
|
2012-11-02 19:34:25 +05:30
|
|
|
usage(true);
|
|
|
|
|
|
|
|
memset(&xh, 0, sizeof(xh));
|
2013-12-16 16:16:39 +05:30
|
|
|
if (rootdir)
|
|
|
|
strncpy(xh.rootdir, rootdir, sizeof(xh.rootdir));
|
2014-08-01 18:39:51 +05:30
|
|
|
if (conffile)
|
|
|
|
strncpy(xh.conffile, conffile, sizeof(xh.conffile));
|
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);
|
|
|
|
}
|
|
|
|
|
2014-02-23 12:53:14 +05:30
|
|
|
if ((rv = xbps_pkgdb_lock(&xh)) != 0) {
|
|
|
|
fprintf(stderr, "failed to lock pkgdb: %s\n", strerror(rv));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2013-03-05 08:38:42 +05:30
|
|
|
if (update_format)
|
|
|
|
convert_pkgdb_format(&xh);
|
|
|
|
else if (instmode) {
|
2013-02-20 15:05:55 +05:30
|
|
|
if (argc == optind) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"xbps-pkgdb: missing PKGNAME argument\n");
|
2014-02-23 12:53:14 +05:30
|
|
|
xbps_pkgdb_unlock(&xh);
|
2013-02-20 15:05:55 +05:30
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
for (i = optind; i < argc; i++) {
|
2013-08-12 18:16:54 +05:30
|
|
|
rv = change_pkg_mode(&xh, argv[i], instmode);
|
2013-02-20 15:05:55 +05:30
|
|
|
if (rv != 0) {
|
|
|
|
fprintf(stderr, "xbps-pkgdb: failed to "
|
|
|
|
"change to %s mode to %s: %s\n",
|
|
|
|
instmode, argv[i], strerror(rv));
|
2014-02-23 12:53:14 +05:30
|
|
|
xbps_pkgdb_unlock(&xh);
|
2013-02-20 15:05:55 +05:30
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (all) {
|
2012-11-02 19:34:25 +05:30
|
|
|
rv = check_pkg_integrity_all(&xh);
|
|
|
|
} else {
|
|
|
|
for (i = optind; i < argc; i++) {
|
2012-11-17 22:13:54 +05:30
|
|
|
rv = check_pkg_integrity(&xh, NULL, argv[i]);
|
2012-11-02 19:34:25 +05:30
|
|
|
if (rv != 0)
|
|
|
|
fprintf(stderr, "Failed to check "
|
|
|
|
"`%s': %s\n", argv[i], strerror(rv));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-23 12:53:14 +05:30
|
|
|
xbps_pkgdb_unlock(&xh);
|
2012-11-02 19:34:25 +05:30
|
|
|
exit(rv ? EXIT_FAILURE : EXIT_SUCCESS);
|
|
|
|
}
|