2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2010-05-18 11:16:27 +05:30
|
|
|
* Copyright (c) 2009-2010 Juan Romero Pardines.
|
2009-08-17 22:37:20 +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 <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2010-11-13 07:48:58 +05:30
|
|
|
#include <xbps_api.h>
|
|
|
|
#include "xbps_api_impl.h"
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
/**
|
|
|
|
* @file lib/configure.c
|
|
|
|
* @brief Package configuration routines
|
|
|
|
* @defgroup configure Package configuration functions
|
|
|
|
*
|
2010-01-23 07:07:19 +05:30
|
|
|
* Configure a package or all packages. Only packages in XBPS_PKG_STATE_UNPACKED
|
2010-01-21 07:40:19 +05:30
|
|
|
* state will be processed (unless overriden). Package configuration steps:
|
2010-01-23 04:29:55 +05:30
|
|
|
* - Its <b>post-install</b> target in the INSTALL script will be executed.
|
2010-01-23 07:07:19 +05:30
|
|
|
* - Its state will be changed to XBPS_PKG_STATE_INSTALLED if previous step
|
2010-01-23 04:29:55 +05:30
|
|
|
* ran successful.
|
2010-01-21 07:40:19 +05:30
|
|
|
*
|
2010-01-23 04:29:55 +05:30
|
|
|
* @note
|
2010-01-21 07:40:19 +05:30
|
|
|
* If the \a XBPS_FLAG_FORCE is set through xbps_set_flags(), the package
|
2010-01-23 07:07:19 +05:30
|
|
|
* (or packages) will be reconfigured even if its state is
|
|
|
|
* XBPS_PKG_STATE_INSTALLED.
|
2010-01-21 07:40:19 +05:30
|
|
|
*/
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
int
|
2009-08-21 15:01:26 +05:30
|
|
|
xbps_configure_all_pkgs(void)
|
|
|
|
{
|
|
|
|
prop_dictionary_t d;
|
|
|
|
prop_object_t obj;
|
|
|
|
prop_object_iterator_t iter;
|
2009-08-25 09:33:02 +05:30
|
|
|
const char *pkgname, *version;
|
2009-08-21 15:01:26 +05:30
|
|
|
int rv = 0;
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
if ((d = xbps_regpkgdb_dictionary_get()) == NULL)
|
2009-11-26 07:52:50 +05:30
|
|
|
return errno;
|
2009-08-21 15:01:26 +05:30
|
|
|
|
|
|
|
iter = xbps_get_array_iter_from_dict(d, "packages");
|
2009-11-26 07:52:50 +05:30
|
|
|
if (iter == NULL) {
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-08-21 15:01:26 +05:30
|
|
|
|
|
|
|
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
|
|
|
rv = xbps_configure_pkg(pkgname, version, true, false);
|
|
|
|
if (rv != 0)
|
2009-08-21 15:01:26 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
prop_object_iterator_release(iter);
|
2009-11-26 07:52:50 +05:30
|
|
|
out:
|
2010-11-19 18:10:13 +05:30
|
|
|
xbps_regpkgdb_dictionary_release();
|
2009-08-21 15:01:26 +05:30
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
int
|
2010-11-19 18:10:13 +05:30
|
|
|
xbps_configure_pkg(const char *pkgname,
|
|
|
|
const char *version,
|
|
|
|
bool check_state,
|
2009-12-09 20:44:35 +05:30
|
|
|
bool update)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
|
|
|
prop_dictionary_t pkgd;
|
2010-11-06 11:14:00 +05:30
|
|
|
const char *lver, *rootdir = xbps_get_rootdir();
|
2009-08-17 22:37:20 +05:30
|
|
|
char *buf;
|
2010-11-19 18:10:13 +05:30
|
|
|
int rv = 0, flags = xbps_get_flags();
|
2009-08-17 22:37:20 +05:30
|
|
|
pkg_state_t state = 0;
|
|
|
|
bool reconfigure = false;
|
|
|
|
|
|
|
|
assert(pkgname != NULL);
|
|
|
|
|
2009-08-21 15:01:26 +05:30
|
|
|
if (check_state) {
|
2010-11-19 18:10:13 +05:30
|
|
|
rv = xbps_get_pkg_state_installed(pkgname, &state);
|
|
|
|
if (rv != 0)
|
|
|
|
return EINVAL;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-08-21 15:01:26 +05:30
|
|
|
if (state == XBPS_PKG_STATE_INSTALLED) {
|
|
|
|
if ((flags & XBPS_FLAG_FORCE) == 0)
|
|
|
|
return 0;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-08-21 15:01:26 +05:30
|
|
|
reconfigure = true;
|
|
|
|
} else if (state != XBPS_PKG_STATE_UNPACKED)
|
|
|
|
return EINVAL;
|
2009-08-25 09:33:02 +05:30
|
|
|
|
2010-01-21 07:40:19 +05:30
|
|
|
pkgd = xbps_find_pkg_dict_installed(pkgname, false);
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(pkgd, "version", &lver);
|
2009-08-25 09:33:02 +05:30
|
|
|
prop_object_release(pkgd);
|
|
|
|
} else {
|
|
|
|
lver = version;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
printf("%sonfiguring package %s-%s...\n",
|
2009-08-25 09:33:02 +05:30
|
|
|
reconfigure ? "Rec" : "C", pkgname, lver);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
buf = xbps_xasprintf(".%s/metadata/%s/INSTALL",
|
|
|
|
XBPS_META_PATH, pkgname);
|
|
|
|
if (buf == NULL)
|
2010-11-19 18:10:13 +05:30
|
|
|
return ENOMEM;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-11-26 07:52:50 +05:30
|
|
|
if (chdir(rootdir) == -1) {
|
2010-11-19 18:10:13 +05:30
|
|
|
xbps_dbg_printf("%s: [configure] chdir to '%s' returned %s\n",
|
|
|
|
pkgname, rootdir, strerror(errno));
|
2009-11-26 07:52:50 +05:30
|
|
|
free(buf);
|
2010-11-19 18:10:13 +05:30
|
|
|
return EINVAL;
|
2009-11-26 07:52:50 +05:30
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
if (access(buf, X_OK) == 0) {
|
|
|
|
if (xbps_file_exec(buf, "post",
|
|
|
|
pkgname, lver, update ? "yes" : "no", NULL) != 0) {
|
|
|
|
free(buf);
|
|
|
|
xbps_dbg_printf("%s: [configure] post INSTALL "
|
|
|
|
"action returned %s\n", pkgname, strerror(errno));
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (errno != ENOENT) {
|
|
|
|
free(buf);
|
|
|
|
return errno;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
|
|
|
|
return xbps_set_pkg_state_installed(pkgname, XBPS_PKG_STATE_INSTALLED);
|
|
|
|
}
|