2012-11-02 19:34:25 +05:30
|
|
|
/*-
|
2020-04-29 17:42:10 +05:30
|
|
|
* Copyright (c) 2011-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 <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
|
2018-07-18 07:54:26 +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;
|
2020-02-09 00:01:29 +05:30
|
|
|
char pkgname[XBPS_NAME_SIZE];
|
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;
|
2015-10-29 11:46:49 +05:30
|
|
|
openlog("xbps-install", 0, LOG_USER);
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
switch (xscd->state) {
|
|
|
|
/* notifications */
|
|
|
|
case XBPS_STATE_TRANS_DOWNLOAD:
|
2019-06-19 00:47:44 +05:30
|
|
|
printf("\n[*] Downloading 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;
|
2019-06-16 21:10:31 +05:30
|
|
|
case XBPS_STATE_TRANS_FILES:
|
|
|
|
printf("\n[*] Collecting package files\n");
|
|
|
|
break;
|
2012-11-02 19:34:25 +05:30
|
|
|
case XBPS_STATE_TRANS_RUN:
|
2019-06-19 00:47:44 +05:30
|
|
|
printf("\n[*] Unpacking packages\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:
|
2020-02-21 13:38:22 +05:30
|
|
|
printf("[*] Updating repository `%s' ...\n", xscd->arg);
|
2012-11-07 14:41:06 +05:30
|
|
|
break;
|
2015-09-02 22:26:20 +05:30
|
|
|
case XBPS_STATE_TRANS_ADDPKG:
|
|
|
|
if (xscd->xhp->flags & XBPS_FLAG_VERBOSE)
|
|
|
|
printf("%s\n", xscd->desc);
|
|
|
|
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;
|
2019-06-16 21:10:31 +05:30
|
|
|
case XBPS_STATE_FILES:
|
|
|
|
printf("%s\n", xscd->desc);
|
|
|
|
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:
|
2020-02-09 00:01:29 +05:30
|
|
|
if (!xbps_pkg_name(pkgname, sizeof(pkgname), xscd->arg)) {
|
|
|
|
abort();
|
|
|
|
}
|
2013-03-05 08:38:42 +05:30
|
|
|
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);
|
2015-01-28 14:18:20 +05:30
|
|
|
if (slog) {
|
|
|
|
syslog(LOG_NOTICE, "%s: updating to %s ... "
|
|
|
|
"(rootdir: %s)\n", instver, newver,
|
|
|
|
xscd->xhp->rootdir);
|
|
|
|
}
|
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 */
|
2021-06-24 21:03:26 +05:30
|
|
|
case XBPS_STATE_TRANS_FAIL:
|
2012-11-02 19:34:25 +05:30
|
|
|
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:
|
2019-06-16 21:10:31 +05:30
|
|
|
case XBPS_STATE_FILES_FAIL:
|
2012-11-02 19:34:25 +05:30
|
|
|
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:
|
2019-03-23 02:13:52 +05:30
|
|
|
/* Ignore errors due to not empty directories or directories being a mount point */
|
|
|
|
if (xscd->err == ENOTEMPTY || xscd->err == EBUSY)
|
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)
|
2015-10-30 19:17:25 +05:30
|
|
|
printf("%s\n", xscd->desc);
|
2014-07-02 14:29:25 +05:30
|
|
|
else
|
2022-12-24 18:16:33 +05:30
|
|
|
xbps_dbg_printf("%s: unknown state %d\n", xscd->arg, xscd->state);
|
2014-07-02 14:29:25 +05:30
|
|
|
|
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
|
|
|
}
|