2012-11-02 19:34:25 +05:30
|
|
|
/*-
|
2015-01-10 23:41:31 +05:30
|
|
|
* Copyright (c) 2012-2015 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>
|
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>
|
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"
|
|
|
|
" -a --all Process all packages\n"
|
2014-11-06 14:28:04 +05:30
|
|
|
" -C --config <dir> Path to confdir (xbps.d)\n"
|
2012-11-02 19:34:25 +05:30
|
|
|
" -d --debug Debug mode shown to stderr\n"
|
|
|
|
" -f --force Force reconfiguration\n"
|
|
|
|
" -h --help Print usage help\n"
|
2015-03-08 14:51:40 +05:30
|
|
|
" -i --ignore PKG Ignore PKG with -a/--all\n"
|
2012-11-02 19:34:25 +05:30
|
|
|
" -r --rootdir <dir> Full path to rootdir\n"
|
|
|
|
" -v --verbose Verbose messages\n"
|
|
|
|
" -V --version Show XBPS version\n");
|
|
|
|
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2013-10-05 15:08:04 +05:30
|
|
|
static int
|
2014-09-06 13:16:03 +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)
|
|
|
|
{
|
2014-12-09 17:40:48 +05:30
|
|
|
const char *shortopts = "aC:dfhi:r:Vv";
|
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' },
|
|
|
|
{ "verbose", no_argument, NULL, 'v' },
|
|
|
|
{ "version", no_argument, NULL, 'V' },
|
|
|
|
{ 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;
|
|
|
|
bool all = false;
|
2014-12-09 17:40:48 +05:30
|
|
|
xbps_array_t ignpkgs = 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;
|
|
|
|
case 'v':
|
|
|
|
flags |= XBPS_FLAG_VERBOSE;
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
printf("%s\n", XBPS_RELVER);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage(true);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!all && (argc == optind))
|
|
|
|
usage(true);
|
|
|
|
|
|
|
|
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) {
|
|
|
|
fprintf(stderr, "failed to lock pkgdb: %s\n", strerror(rv));
|
|
|
|
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++) {
|
2014-03-04 19:07:10 +05:30
|
|
|
rv = xbps_configure_pkg(&xh, argv[i], true, false);
|
|
|
|
if (rv != 0) {
|
2012-11-02 19:34:25 +05:30
|
|
|
fprintf(stderr, "Failed to reconfigure "
|
|
|
|
"`%s': %s\n", argv[i], 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)
|
|
|
|
xbps_pkgdb_update(&xh, true, true);
|
|
|
|
|
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);
|
|
|
|
}
|