2012-11-02 19:34:25 +05:30
|
|
|
/*-
|
2020-04-29 17:42:10 +05:30
|
|
|
* Copyright (c) 2012-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.
|
2012-11-02 19:34:25 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <getopt.h>
|
2012-11-03 14:13:28 +05:30
|
|
|
#include <syslog.h>
|
2012-11-02 19:34:25 +05:30
|
|
|
|
2013-06-20 16:01:02 +05:30
|
|
|
#include <xbps.h>
|
2022-04-24 04:19:25 +05:30
|
|
|
#include "defs.h"
|
2012-11-02 19:34:25 +05:30
|
|
|
|
|
|
|
static void __attribute__((noreturn))
|
|
|
|
usage(bool fail)
|
|
|
|
{
|
|
|
|
fprintf(stdout,
|
|
|
|
"Usage: xbps-reconfigure [OPTIONS] [PKGNAME...]\n\n"
|
|
|
|
"OPTIONS\n"
|
2020-04-21 00:55:14 +05:30
|
|
|
" -a, --all Process all packages\n"
|
|
|
|
" -C, --config <dir> Path to confdir (xbps.d)\n"
|
|
|
|
" -d, --debug Debug mode shown to stderr\n"
|
|
|
|
" -f, --force Force reconfiguration\n"
|
2022-04-24 04:19:25 +05:30
|
|
|
" --fulldeptree Full dependency tree for -x/--deps\n"
|
2020-04-21 00:55:14 +05:30
|
|
|
" -h, --help Show usage\n"
|
|
|
|
" -i, --ignore PKG Ignore PKG with -a/--all\n"
|
|
|
|
" -r, --rootdir <dir> Full path to rootdir\n"
|
2022-04-24 04:19:25 +05:30
|
|
|
" -x, --deps Also process dependencies for each package\n"
|
2020-04-21 00:55:14 +05:30
|
|
|
" -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-10-05 15:08:04 +05:30
|
|
|
static int
|
2018-07-18 07:54:26 +05:30
|
|
|
state_cb(const struct xbps_state_cb_data *xscd, void *cbd UNUSED)
|
2012-11-03 14:13:28 +05:30
|
|
|
{
|
2014-06-04 13:09:02 +05:30
|
|
|
bool slog = false;
|
|
|
|
|
|
|
|
if ((xscd->xhp->flags & XBPS_FLAG_DISABLE_SYSLOG) == 0) {
|
|
|
|
slog = true;
|
2015-10-29 11:46:49 +05:30
|
|
|
openlog("xbps-reconfigure", 0, LOG_USER);
|
2012-11-03 14:13:28 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
switch (xscd->state) {
|
|
|
|
/* notifications */
|
|
|
|
case XBPS_STATE_CONFIGURE:
|
2013-03-05 08:38:42 +05:30
|
|
|
printf("%s: configuring ...\n", xscd->arg);
|
2014-06-04 13:09:02 +05:30
|
|
|
if (slog)
|
2013-03-06 16:32:04 +05:30
|
|
|
syslog(LOG_NOTICE, "%s: configuring ...", xscd->arg);
|
2012-11-03 14:13:28 +05:30
|
|
|
break;
|
2013-03-07 13:54:04 +05:30
|
|
|
case XBPS_STATE_CONFIGURE_DONE:
|
|
|
|
printf("%s: configured successfully.\n", xscd->arg);
|
2014-06-04 13:09:02 +05:30
|
|
|
if (slog)
|
2013-03-07 13:54:04 +05:30
|
|
|
syslog(LOG_NOTICE,
|
|
|
|
"%s: configured successfully.", xscd->arg);
|
|
|
|
break;
|
2012-11-03 14:13:28 +05:30
|
|
|
/* errors */
|
|
|
|
case XBPS_STATE_CONFIGURE_FAIL:
|
|
|
|
xbps_error_printf("%s\n", xscd->desc);
|
2014-06-04 13:09:02 +05:30
|
|
|
if (slog)
|
2012-11-03 14:13:28 +05:30
|
|
|
syslog(LOG_ERR, "%s", xscd->desc);
|
|
|
|
break;
|
2015-02-18 21:32:50 +05:30
|
|
|
default:
|
|
|
|
break;
|
2012-11-03 14:13:28 +05:30
|
|
|
}
|
2013-10-05 15:08:04 +05:30
|
|
|
|
|
|
|
return 0;
|
2012-11-03 14:13:28 +05:30
|
|
|
}
|
|
|
|
|
2012-11-02 19:34:25 +05:30
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2022-04-24 04:19:25 +05:30
|
|
|
const char *shortopts = "aC:dfhi:r:xVv";
|
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' },
|
|
|
|
{ "force", no_argument, NULL, 'f' },
|
|
|
|
{ "help", no_argument, NULL, 'h' },
|
2014-12-09 17:40:48 +05:30
|
|
|
{ "ignore", required_argument, NULL, 'i' },
|
2012-11-02 19:34:25 +05:30
|
|
|
{ "rootdir", required_argument, NULL, 'r' },
|
2022-04-24 04:19:25 +05:30
|
|
|
{ "deps", no_argument, NULL, 'x' },
|
2012-11-02 19:34:25 +05:30
|
|
|
{ "verbose", no_argument, NULL, 'v' },
|
|
|
|
{ "version", no_argument, NULL, 'V' },
|
2022-04-24 04:19:25 +05:30
|
|
|
{ "fulldeptree", no_argument, NULL, 1 },
|
2012-11-02 19:34:25 +05:30
|
|
|
{ NULL, 0, NULL, 0 }
|
|
|
|
};
|
|
|
|
struct xbps_handle xh;
|
2014-11-06 14:28:04 +05:30
|
|
|
const char *confdir = NULL, *rootdir = NULL;
|
2012-11-02 19:34:25 +05:30
|
|
|
int c, i, rv, flags = 0;
|
2022-04-24 04:19:25 +05:30
|
|
|
bool all = false, rdeps = false, fulldeptree = false;
|
|
|
|
xbps_array_t ignpkgs = NULL, deps = NULL;
|
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':
|
2014-11-06 14:28:04 +05:30
|
|
|
confdir = optarg;
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
flags |= XBPS_FLAG_DEBUG;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
flags |= XBPS_FLAG_FORCE_CONFIGURE;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
usage(false);
|
|
|
|
/* NOTREACHED */
|
2014-12-09 17:40:48 +05:30
|
|
|
case 'i':
|
|
|
|
if (ignpkgs == NULL)
|
|
|
|
ignpkgs = xbps_array_create();
|
|
|
|
|
|
|
|
xbps_array_add_cstring_nocopy(ignpkgs, optarg);
|
|
|
|
break;
|
2012-11-02 19:34:25 +05:30
|
|
|
case 'r':
|
|
|
|
rootdir = optarg;
|
|
|
|
break;
|
2022-04-24 04:19:25 +05:30
|
|
|
case 'x':
|
|
|
|
rdeps = 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);
|
2022-04-24 04:19:25 +05:30
|
|
|
case 1:
|
|
|
|
fulldeptree = true;
|
|
|
|
break;
|
2012-11-02 19:34:25 +05:30
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage(true);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
}
|
2020-04-21 00:55:14 +05:30
|
|
|
if (!all && (argc == optind)) {
|
2012-11-02 19:34:25 +05:30
|
|
|
usage(true);
|
2020-04-21 00:55:14 +05:30
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
2012-11-02 19:34:25 +05:30
|
|
|
|
|
|
|
memset(&xh, 0, sizeof(xh));
|
|
|
|
xh.state_cb = state_cb;
|
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));
|
2014-08-01 18:39:51 +05:30
|
|
|
|
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-03-04 19:07:10 +05:30
|
|
|
if ((rv = xbps_pkgdb_lock(&xh)) != 0) {
|
2022-04-24 04:19:25 +05:30
|
|
|
xbps_error_printf("failed to lock pkgdb: %s\n", strerror(rv));
|
2014-03-04 19:07:10 +05:30
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2012-11-02 19:34:25 +05:30
|
|
|
if (all) {
|
2014-12-09 17:40:48 +05:30
|
|
|
rv = xbps_configure_packages(&xh, ignpkgs);
|
2012-11-02 19:34:25 +05:30
|
|
|
} else {
|
|
|
|
for (i = optind; i < argc; i++) {
|
2022-04-24 04:19:25 +05:30
|
|
|
const char* pkg = argv[i];
|
|
|
|
if (rdeps) {
|
|
|
|
rv = find_pkg_deps(&xh, pkg, fulldeptree, &deps);
|
|
|
|
if (rv != 0) {
|
|
|
|
xbps_error_printf("failed to collect dependencies for "
|
|
|
|
"`%s': %s\n", pkg, strerror(rv));
|
|
|
|
}
|
|
|
|
for (unsigned int j = 0; j < xbps_array_count(deps); j++) {
|
|
|
|
const char *pkgdep = NULL;
|
|
|
|
char pkgname[XBPS_NAME_SIZE];
|
|
|
|
xbps_array_get_cstring_nocopy(deps, j, &pkgdep);
|
|
|
|
|
|
|
|
if (fulldeptree) {
|
|
|
|
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgdep)) {
|
|
|
|
xbps_error_printf(
|
|
|
|
"unable to get package name for dependency `%s'\n", pkgdep);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!xbps_pkgpattern_name(pkgname, sizeof(pkgname), pkgdep)) {
|
|
|
|
xbps_error_printf(
|
|
|
|
"unable to get package name for dependency `%s'\n", pkgdep);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = xbps_configure_pkg(&xh, pkgname, true, false);
|
|
|
|
if (rv != 0) {
|
|
|
|
xbps_error_printf("failed to reconfigure "
|
|
|
|
"`%s': %s\n", pkgname, strerror(rv));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rv = xbps_configure_pkg(&xh, pkg, true, false);
|
2014-03-04 19:07:10 +05:30
|
|
|
if (rv != 0) {
|
2022-04-24 04:19:25 +05:30
|
|
|
xbps_error_printf("failed to reconfigure "
|
|
|
|
"`%s': %s\n", pkg, strerror(rv));
|
2014-03-04 19:07:10 +05:30
|
|
|
}
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
|
|
|
}
|
2015-01-17 16:36:13 +05:30
|
|
|
if (rv == 0)
|
2019-06-22 22:20:40 +05:30
|
|
|
xbps_pkgdb_update(&xh, true, false);
|
2015-01-17 16:36:13 +05:30
|
|
|
|
2015-01-10 23:41:31 +05:30
|
|
|
xbps_end(&xh);
|
2012-11-02 19:34:25 +05:30
|
|
|
exit(rv ? EXIT_FAILURE : EXIT_SUCCESS);
|
|
|
|
}
|