2009-08-17 19:07:20 +02:00
|
|
|
/*-
|
2014-03-04 14:37:10 +01:00
|
|
|
* Copyright (c) 2009-2014 Juan Romero Pardines.
|
2009-08-17 19:07:20 +02:00
|
|
|
* 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 <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2010-11-13 03:18:58 +01:00
|
|
|
#include "xbps_api_impl.h"
|
2010-01-21 03:10:19 +01:00
|
|
|
/**
|
2011-01-19 00:31:22 +01:00
|
|
|
* @file lib/package_configure.c
|
2010-01-21 03:10:19 +01:00
|
|
|
* @brief Package configuration routines
|
|
|
|
* @defgroup configure Package configuration functions
|
|
|
|
*
|
2010-01-23 02:37:19 +01:00
|
|
|
* Configure a package or all packages. Only packages in XBPS_PKG_STATE_UNPACKED
|
2010-01-21 03:10:19 +01:00
|
|
|
* state will be processed (unless overriden). Package configuration steps:
|
2010-01-22 23:59:55 +01:00
|
|
|
* - Its <b>post-install</b> target in the INSTALL script will be executed.
|
2010-01-23 02:37:19 +01:00
|
|
|
* - Its state will be changed to XBPS_PKG_STATE_INSTALLED if previous step
|
2010-01-22 23:59:55 +01:00
|
|
|
* ran successful.
|
2010-01-21 03:10:19 +01:00
|
|
|
*
|
2010-01-22 23:59:55 +01:00
|
|
|
* @note
|
2011-11-24 11:50:53 +01:00
|
|
|
* If the \a XBPS_FLAG_FORCE_CONFIGURE is set through xbps_init() in the flags
|
2013-03-05 04:08:42 +01:00
|
|
|
member, the package (or packages) will be reconfigured even if its
|
2011-02-21 17:42:47 +01:00
|
|
|
* state is XBPS_PKG_STATE_INSTALLED.
|
2010-01-21 03:10:19 +01:00
|
|
|
*/
|
2011-12-23 08:16:25 +01:00
|
|
|
int
|
2014-03-04 14:37:10 +01:00
|
|
|
xbps_configure_packages(struct xbps_handle *xhp)
|
2011-12-23 08:16:25 +01:00
|
|
|
{
|
2013-06-20 10:26:12 +02:00
|
|
|
xbps_dictionary_t pkgd;
|
|
|
|
xbps_object_t obj;
|
|
|
|
xbps_object_iterator_t iter;
|
2013-03-05 04:08:42 +01:00
|
|
|
const char *pkgver;
|
2012-01-04 17:41:36 +01:00
|
|
|
int rv;
|
|
|
|
|
2012-02-28 21:16:41 +01:00
|
|
|
if ((rv = xbps_pkgdb_init(xhp)) != 0)
|
|
|
|
return rv;
|
|
|
|
|
2013-06-20 10:26:12 +02:00
|
|
|
iter = xbps_dictionary_iterator(xhp->pkgdb);
|
2012-11-30 09:49:09 +01:00
|
|
|
assert(iter);
|
2013-06-20 10:26:12 +02:00
|
|
|
while ((obj = xbps_object_iterator_next(iter))) {
|
|
|
|
pkgd = xbps_dictionary_get_keysym(xhp->pkgdb, obj);
|
|
|
|
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
2014-03-04 14:37:10 +01:00
|
|
|
rv = xbps_configure_pkg(xhp, pkgver, true, false);
|
2012-12-17 11:27:10 +01:00
|
|
|
if (rv != 0) {
|
|
|
|
xbps_dbg_printf(xhp, "%s: failed to configure %s: %s\n",
|
2013-03-05 04:08:42 +01:00
|
|
|
__func__, pkgver, strerror(rv));
|
2012-02-28 21:16:41 +01:00
|
|
|
break;
|
2012-12-17 11:27:10 +01:00
|
|
|
}
|
2012-02-28 21:16:41 +01:00
|
|
|
}
|
2013-06-20 10:26:12 +02:00
|
|
|
xbps_object_iterator_release(iter);
|
2012-11-30 09:49:09 +01:00
|
|
|
|
2012-01-04 17:41:36 +01:00
|
|
|
return rv;
|
2009-08-21 11:31:26 +02:00
|
|
|
}
|
|
|
|
|
2010-01-21 03:10:19 +01:00
|
|
|
int
|
2012-06-14 08:22:11 +02:00
|
|
|
xbps_configure_pkg(struct xbps_handle *xhp,
|
2013-03-05 04:08:42 +01:00
|
|
|
const char *pkgver,
|
2010-11-19 13:40:13 +01:00
|
|
|
bool check_state,
|
2014-03-04 14:37:10 +01:00
|
|
|
bool update)
|
2009-08-17 19:07:20 +02:00
|
|
|
{
|
2013-06-20 10:26:12 +02:00
|
|
|
xbps_dictionary_t pkgd, pkgmetad;
|
2013-03-05 04:08:42 +01:00
|
|
|
char *pkgname, *plist;
|
2011-02-21 17:42:47 +01:00
|
|
|
int rv = 0;
|
2009-08-17 19:07:20 +02:00
|
|
|
pkg_state_t state = 0;
|
|
|
|
|
2013-03-05 04:08:42 +01:00
|
|
|
assert(pkgver != NULL);
|
2009-08-17 19:07:20 +02:00
|
|
|
|
2013-03-05 04:08:42 +01:00
|
|
|
pkgd = xbps_pkgdb_get_pkg(xhp, pkgver);
|
2012-04-10 10:02:27 +02:00
|
|
|
if (pkgd == NULL)
|
|
|
|
return ENOENT;
|
|
|
|
|
2012-10-26 10:24:26 +02:00
|
|
|
rv = xbps_pkg_state_dictionary(pkgd, &state);
|
2013-03-05 04:08:42 +01:00
|
|
|
xbps_dbg_printf(xhp, "%s: state %d rv %d\n", pkgver, state, rv);
|
2012-10-26 10:24:26 +02:00
|
|
|
if (rv != 0) {
|
|
|
|
xbps_dbg_printf(xhp, "%s: [configure] failed to get "
|
2013-03-05 04:08:42 +01:00
|
|
|
"pkg state: %s\n", pkgver, strerror(rv));
|
2012-10-26 10:24:26 +02:00
|
|
|
return EINVAL;
|
|
|
|
}
|
2009-08-17 19:07:20 +02:00
|
|
|
|
2012-10-26 10:24:26 +02:00
|
|
|
if (check_state) {
|
2009-08-21 11:31:26 +02:00
|
|
|
if (state == XBPS_PKG_STATE_INSTALLED) {
|
2012-06-16 09:02:07 +02:00
|
|
|
if ((xhp->flags & XBPS_FLAG_FORCE_CONFIGURE) == 0)
|
2009-08-21 11:31:26 +02:00
|
|
|
return 0;
|
2012-06-16 09:02:07 +02:00
|
|
|
} else if (state != XBPS_PKG_STATE_UNPACKED)
|
2009-08-21 11:31:26 +02:00
|
|
|
return EINVAL;
|
2009-08-25 06:03:02 +02:00
|
|
|
}
|
2012-10-26 10:24:26 +02:00
|
|
|
|
2013-03-05 04:08:42 +01:00
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE, 0, pkgver, NULL);
|
2009-08-17 19:07:20 +02:00
|
|
|
|
2012-11-26 23:25:41 +01:00
|
|
|
/* internalize pkg dictionary from metadir */
|
2013-03-05 04:08:42 +01:00
|
|
|
pkgname = xbps_pkg_name(pkgver);
|
2013-03-05 17:20:29 +01:00
|
|
|
if (pkgname == NULL) /* assume pkgname */
|
|
|
|
pkgname = strdup(pkgver);
|
|
|
|
|
2012-11-26 23:25:41 +01:00
|
|
|
plist = xbps_xasprintf("%s/.%s.plist", xhp->metadir, pkgname);
|
2013-03-05 04:08:42 +01:00
|
|
|
free(pkgname);
|
2013-03-05 17:20:29 +01:00
|
|
|
|
2013-06-20 10:26:12 +02:00
|
|
|
pkgmetad = xbps_dictionary_internalize_from_file(plist);
|
2013-03-05 17:20:29 +01:00
|
|
|
if (pkgmetad == NULL) {
|
2014-02-23 10:32:21 +01:00
|
|
|
rv = errno;
|
2013-03-05 17:20:29 +01:00
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL,
|
|
|
|
errno, pkgver,
|
|
|
|
"%s: [configure] cannot read metadata plist: %s",
|
|
|
|
pkgver, strerror(rv));
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
|
2012-11-26 23:25:41 +01:00
|
|
|
free(plist);
|
2012-11-16 16:55:35 +01:00
|
|
|
assert(pkgmetad);
|
|
|
|
|
|
|
|
rv = xbps_pkg_exec_script(xhp, pkgmetad, "install-script", "post", update);
|
|
|
|
if (rv != 0) {
|
2012-06-14 08:22:11 +02:00
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL,
|
2013-03-05 04:08:42 +01:00
|
|
|
errno, pkgver,
|
2012-11-16 16:55:35 +01:00
|
|
|
"%s: [configure] INSTALL script failed to execute "
|
|
|
|
"the post ACTION: %s", pkgver, strerror(rv));
|
|
|
|
return rv;
|
2009-08-17 19:07:20 +02:00
|
|
|
}
|
2012-11-30 07:11:51 +01:00
|
|
|
if (state == XBPS_PKG_STATE_INSTALLED) {
|
2013-06-20 10:26:12 +02:00
|
|
|
xbps_object_release(pkgmetad);
|
2012-10-26 10:24:26 +02:00
|
|
|
return rv;
|
2012-11-30 07:11:51 +01:00
|
|
|
}
|
2012-10-26 10:24:26 +02:00
|
|
|
|
2012-12-17 11:27:10 +01:00
|
|
|
rv = xbps_set_pkg_state_dictionary(pkgd, XBPS_PKG_STATE_INSTALLED);
|
2011-11-24 11:23:08 +01:00
|
|
|
if (rv != 0) {
|
2012-06-14 08:22:11 +02:00
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL, rv,
|
2013-03-05 04:08:42 +01:00
|
|
|
pkgver, "%s: [configure] failed to set state to installed: %s",
|
2011-11-24 11:23:08 +01:00
|
|
|
pkgver, strerror(rv));
|
2013-03-07 09:24:04 +01:00
|
|
|
return rv;
|
2011-11-11 09:41:48 +01:00
|
|
|
}
|
2013-06-20 10:26:12 +02:00
|
|
|
xbps_object_release(pkgmetad);
|
2012-11-30 07:11:51 +01:00
|
|
|
|
2013-03-07 09:24:04 +01:00
|
|
|
if (rv == 0)
|
|
|
|
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_DONE, 0, pkgver, NULL);
|
|
|
|
|
2011-02-22 11:09:39 +01:00
|
|
|
return rv;
|
2009-08-17 19:07:20 +02:00
|
|
|
}
|