2012-11-02 19:34:25 +05:30
|
|
|
/*-
|
2014-02-25 21:12:52 +05:30
|
|
|
* Copyright (c) 2011-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 <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <syslog.h>
|
2013-03-05 08:38:42 +05:30
|
|
|
#include <assert.h>
|
2013-06-20 16:01:02 +05:30
|
|
|
#include <xbps.h>
|
2012-11-02 19:34:25 +05:30
|
|
|
#include "defs.h"
|
|
|
|
|
2013-10-05 15:08:04 +05:30
|
|
|
int
|
2014-09-06 13:16:03 +05:30
|
|
|
state_cb(const struct xbps_state_cb_data *xscd, void *cbdata _unused)
|
2012-11-02 19:34:25 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_t pkgd;
|
2013-03-05 08:38:42 +05:30
|
|
|
const char *instver, *newver;
|
|
|
|
char *pkgname;
|
2013-10-05 15:08:04 +05:30
|
|
|
int rv = 0;
|
2014-06-04 13:09:02 +05:30
|
|
|
bool slog = false;
|
2012-11-02 19:34:25 +05:30
|
|
|
|
2014-06-04 13:09:02 +05:30
|
|
|
if ((xscd->xhp->flags & XBPS_FLAG_DISABLE_SYSLOG) == 0) {
|
|
|
|
slog = true;
|
2012-11-03 14:18:16 +05:30
|
|
|
openlog("xbps-install", LOG_CONS, LOG_USER);
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
switch (xscd->state) {
|
|
|
|
/* notifications */
|
|
|
|
case XBPS_STATE_TRANS_DOWNLOAD:
|
2012-11-16 21:25:35 +05:30
|
|
|
printf("\n[*] Downloading binary packages\n");
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case XBPS_STATE_TRANS_VERIFY:
|
2013-12-24 15:13:55 +05:30
|
|
|
printf("\n[*] Verifying package integrity\n");
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case XBPS_STATE_TRANS_RUN:
|
2012-11-16 21:25:35 +05:30
|
|
|
printf("\n[*] Running transaction tasks\n");
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case XBPS_STATE_TRANS_CONFIGURE:
|
2012-11-16 21:25:35 +05:30
|
|
|
printf("\n[*] Configuring unpacked packages\n");
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
2014-09-11 03:42:12 +05:30
|
|
|
case XBPS_STATE_PKGDB:
|
|
|
|
printf("[*] pkgdb upgrade in progress, please wait...\n");
|
|
|
|
break;
|
2012-11-02 19:34:25 +05:30
|
|
|
case XBPS_STATE_REPOSYNC:
|
2013-03-05 08:38:42 +05:30
|
|
|
printf("[*] Updating `%s' ...\n", xscd->arg);
|
2012-11-07 14:41:06 +05:30
|
|
|
break;
|
2012-11-02 19:34:25 +05:30
|
|
|
case XBPS_STATE_VERIFY:
|
2013-12-24 15:13:55 +05:30
|
|
|
printf("%s\n", xscd->desc);
|
2013-03-05 08:38:42 +05:30
|
|
|
break;
|
2012-11-02 19:34:25 +05:30
|
|
|
case XBPS_STATE_CONFIG_FILE:
|
|
|
|
if (xscd->desc != NULL)
|
|
|
|
printf("%s\n", xscd->desc);
|
|
|
|
break;
|
|
|
|
case XBPS_STATE_REMOVE:
|
2013-03-05 08:38:42 +05:30
|
|
|
printf("%s: removing ...\n", xscd->arg);
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case XBPS_STATE_CONFIGURE:
|
2013-03-05 08:38:42 +05:30
|
|
|
printf("%s: configuring ...\n", xscd->arg);
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
2013-03-07 13:54:04 +05:30
|
|
|
case XBPS_STATE_CONFIGURE_DONE:
|
2012-11-02 19:34:25 +05:30
|
|
|
/* empty */
|
|
|
|
break;
|
|
|
|
case XBPS_STATE_UNPACK:
|
2013-03-05 08:38:42 +05:30
|
|
|
printf("%s: unpacking ...\n", xscd->arg);
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case XBPS_STATE_INSTALL:
|
2014-07-03 12:03:37 +05:30
|
|
|
case XBPS_STATE_DOWNLOAD:
|
2012-11-19 16:59:47 +05:30
|
|
|
/* empty */
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case XBPS_STATE_UPDATE:
|
2013-03-05 08:38:42 +05:30
|
|
|
pkgname = xbps_pkg_name(xscd->arg);
|
|
|
|
assert(pkgname);
|
|
|
|
newver = xbps_pkg_version(xscd->arg);
|
|
|
|
pkgd = xbps_pkgdb_get_pkg(xscd->xhp, pkgname);
|
2013-12-25 15:42:03 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &instver);
|
|
|
|
printf("%s: updating to %s ...\n", instver, newver);
|
2013-03-05 08:38:42 +05:30
|
|
|
free(pkgname);
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
/* success */
|
|
|
|
case XBPS_STATE_REMOVE_FILE:
|
|
|
|
case XBPS_STATE_REMOVE_FILE_OBSOLETE:
|
2012-11-30 11:41:51 +05:30
|
|
|
if (xscd->xhp->flags & XBPS_FLAG_VERBOSE)
|
2012-11-02 19:34:25 +05:30
|
|
|
printf("%s\n", xscd->desc);
|
|
|
|
else {
|
|
|
|
printf("%s\n", xscd->desc);
|
|
|
|
printf("\033[1A\033[K");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XBPS_STATE_INSTALL_DONE:
|
2013-03-05 08:38:42 +05:30
|
|
|
printf("%s: installed successfully.\n", xscd->arg);
|
2014-06-04 13:09:02 +05:30
|
|
|
if (slog) {
|
2013-03-05 08:38:42 +05:30
|
|
|
syslog(LOG_NOTICE, "Installed `%s' successfully "
|
|
|
|
"(rootdir: %s).", xscd->arg,
|
2012-11-30 11:41:51 +05:30
|
|
|
xscd->xhp->rootdir);
|
2014-02-25 21:12:52 +05:30
|
|
|
}
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case XBPS_STATE_UPDATE_DONE:
|
2013-03-05 08:38:42 +05:30
|
|
|
printf("%s: updated successfully.\n", xscd->arg);
|
2014-06-04 13:09:02 +05:30
|
|
|
if (slog) {
|
2013-03-05 08:38:42 +05:30
|
|
|
syslog(LOG_NOTICE, "Updated `%s' successfully "
|
|
|
|
"(rootdir: %s).", xscd->arg,
|
2012-11-30 11:41:51 +05:30
|
|
|
xscd->xhp->rootdir);
|
2014-02-25 21:12:52 +05:30
|
|
|
}
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case XBPS_STATE_REMOVE_DONE:
|
2013-03-05 08:38:42 +05:30
|
|
|
printf("%s: removed successfully.\n", xscd->arg);
|
2014-06-04 13:09:02 +05:30
|
|
|
if (slog) {
|
2013-03-05 08:38:42 +05:30
|
|
|
syslog(LOG_NOTICE, "Removed `%s' successfully "
|
|
|
|
"(rootdir: %s).", xscd->arg,
|
2012-11-30 11:41:51 +05:30
|
|
|
xscd->xhp->rootdir);
|
2014-02-25 21:12:52 +05:30
|
|
|
}
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
2014-09-11 03:42:12 +05:30
|
|
|
case XBPS_STATE_PKGDB_DONE:
|
|
|
|
printf("The pkgdb file has been upgraded successfully, please reexec "
|
|
|
|
"the command again.\n");
|
|
|
|
break;
|
2013-11-18 20:35:46 +05:30
|
|
|
case XBPS_STATE_REPO_KEY_IMPORT:
|
|
|
|
printf("%s\n", xscd->desc);
|
|
|
|
printf("Fingerprint: %s\n", xscd->arg);
|
|
|
|
rv = yesno("Do you want to import this public key?");
|
|
|
|
break;
|
2014-07-27 14:54:49 +05:30
|
|
|
case XBPS_STATE_SHOW_INSTALL_MSG:
|
2014-09-16 13:26:00 +05:30
|
|
|
printf("%s: post-install message:\n", xscd->arg);
|
|
|
|
printf("========================================================================\n");
|
|
|
|
printf("%s", xscd->desc);
|
|
|
|
printf("========================================================================\n");
|
2014-07-27 14:54:49 +05:30
|
|
|
break;
|
2014-08-01 18:39:51 +05:30
|
|
|
case XBPS_STATE_UNPACK_FILE_PRESERVED:
|
|
|
|
printf("%s\n", xscd->desc);
|
|
|
|
break;
|
2012-11-02 19:34:25 +05:30
|
|
|
/* errors */
|
|
|
|
case XBPS_STATE_UNPACK_FAIL:
|
|
|
|
case XBPS_STATE_UPDATE_FAIL:
|
|
|
|
case XBPS_STATE_CONFIGURE_FAIL:
|
|
|
|
case XBPS_STATE_REMOVE_FAIL:
|
|
|
|
case XBPS_STATE_VERIFY_FAIL:
|
|
|
|
case XBPS_STATE_DOWNLOAD_FAIL:
|
|
|
|
case XBPS_STATE_REPOSYNC_FAIL:
|
|
|
|
case XBPS_STATE_CONFIG_FILE_FAIL:
|
|
|
|
xbps_error_printf("%s\n", xscd->desc);
|
2014-06-04 13:09:02 +05:30
|
|
|
if (slog) {
|
2012-11-02 19:34:25 +05:30
|
|
|
syslog(LOG_ERR, "%s", xscd->desc);
|
2014-02-25 21:12:52 +05:30
|
|
|
}
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case XBPS_STATE_REMOVE_FILE_FAIL:
|
|
|
|
case XBPS_STATE_REMOVE_FILE_HASH_FAIL:
|
|
|
|
case XBPS_STATE_REMOVE_FILE_OBSOLETE_FAIL:
|
|
|
|
/* Ignore errors due to not empty directories */
|
|
|
|
if (xscd->err == ENOTEMPTY)
|
2013-10-05 15:08:04 +05:30
|
|
|
return 0;
|
2012-11-02 19:34:25 +05:30
|
|
|
|
|
|
|
xbps_error_printf("%s\n", xscd->desc);
|
2014-06-04 13:09:02 +05:30
|
|
|
if (slog) {
|
2012-11-02 19:34:25 +05:30
|
|
|
syslog(LOG_ERR, "%s", xscd->desc);
|
2014-02-25 21:12:52 +05:30
|
|
|
}
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
default:
|
2014-07-02 14:29:25 +05:30
|
|
|
if (xscd->desc)
|
|
|
|
xbps_error_printf("%s\n", xscd->desc);
|
|
|
|
else
|
|
|
|
xbps_dbg_printf(xscd->xhp,
|
|
|
|
"%s: unknown state %d\n", xscd->arg, xscd->state);
|
|
|
|
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
}
|
2013-10-05 15:08:04 +05:30
|
|
|
|
|
|
|
return rv;
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|