2012-11-02 19:34:25 +05:30
|
|
|
/*-
|
2020-04-29 17:42:10 +05:30
|
|
|
* Copyright (c) 2008-2019 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 <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
|
2013-06-20 16:01:02 +05:30
|
|
|
#include <xbps.h>
|
2012-11-02 19:34:25 +05:30
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
static void __attribute__((noreturn))
|
|
|
|
usage(bool fail)
|
|
|
|
{
|
|
|
|
fprintf(stdout,
|
|
|
|
"Usage: xbps-install [OPTIONS] [PKGNAME...]\n\n"
|
|
|
|
"OPTIONS\n"
|
2020-04-21 00:55:14 +05:30
|
|
|
" -A, --automatic Set automatic installation mode\n"
|
|
|
|
" -C, --config <dir> Path to confdir (xbps.d)\n"
|
|
|
|
" -c, --cachedir <dir> Path to cachedir\n"
|
|
|
|
" -d, --debug Debug mode shown to stderr\n"
|
|
|
|
" -D, --download-only Download packages and check integrity, nothing else\n"
|
|
|
|
" -f, --force Force package re-installation\n"
|
|
|
|
" If specified twice, all files will be overwritten.\n"
|
|
|
|
" -h, --help Show usage\n"
|
|
|
|
" -i, --ignore-conf-repos Ignore repositories defined in xbps.d\n"
|
|
|
|
" -I, --ignore-file-conflicts Ignore detected file conflicts\n"
|
|
|
|
" -U, --unpack-only Unpack packages in transaction, do not configure them\n"
|
|
|
|
" -M, --memory-sync Remote repository data is fetched and stored\n"
|
|
|
|
" in memory, ignoring on-disk repodata archives\n"
|
|
|
|
" -n, --dry-run Dry-run mode\n"
|
|
|
|
" -R, --repository <url> Add repository to the top of the list\n"
|
|
|
|
" This option can be specified multiple times\n"
|
|
|
|
" -r, --rootdir <dir> Full path to rootdir\n"
|
|
|
|
" --reproducible Enable reproducible mode in pkgdb\n"
|
|
|
|
" -S, --sync Sync remote repository index\n"
|
|
|
|
" -u, --update Update target package(s)\n"
|
|
|
|
" -v, --verbose Verbose messages\n"
|
|
|
|
" -y, --yes Assume yes to all questions\n"
|
|
|
|
" -V, --version Show XBPS version\n");
|
2012-11-02 19:34:25 +05:30
|
|
|
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2013-03-07 16:01:55 +05:30
|
|
|
static void
|
2018-07-18 07:54:26 +05:30
|
|
|
unpack_progress_cb(const struct xbps_unpack_cb_data *xpd, void *cbdata UNUSED)
|
2013-03-07 16:01:55 +05:30
|
|
|
{
|
|
|
|
if (xpd->entry == NULL || xpd->entry_total_count <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
printf("%s: unpacked %sfile `%s' (%" PRIi64 " bytes)\n",
|
|
|
|
xpd->pkgver,
|
|
|
|
xpd->entry_is_conf ? "configuration " : "", xpd->entry,
|
|
|
|
xpd->entry_size);
|
|
|
|
}
|
|
|
|
|
2013-11-18 20:35:46 +05:30
|
|
|
static int
|
2018-07-18 07:54:26 +05:30
|
|
|
repo_import_key_cb(struct xbps_repo *repo, void *arg UNUSED, bool *done UNUSED)
|
2013-11-18 20:35:46 +05:30
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
|
2014-09-07 13:04:33 +05:30
|
|
|
if ((rv = xbps_repo_key_import(repo)) != 0)
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("Failed to import pubkey from %s: %s\n",
|
2013-11-18 20:35:46 +05:30
|
|
|
repo->uri, strerror(rv));
|
|
|
|
|
2014-09-07 13:04:33 +05:30
|
|
|
return rv;
|
2013-11-18 20:35:46 +05:30
|
|
|
}
|
|
|
|
|
2012-11-02 19:34:25 +05:30
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2019-06-21 19:27:25 +05:30
|
|
|
const char *shortopts = "AC:c:DdfhIiMnR:r:SuUVvy";
|
2012-11-02 19:34:25 +05:30
|
|
|
const struct option longopts[] = {
|
|
|
|
{ "automatic", no_argument, NULL, 'A' },
|
|
|
|
{ "config", required_argument, NULL, 'C' },
|
|
|
|
{ "cachedir", required_argument, NULL, 'c' },
|
|
|
|
{ "debug", no_argument, NULL, 'd' },
|
2019-06-21 19:27:25 +05:30
|
|
|
{ "download-only", no_argument, NULL, 'D' },
|
2012-11-02 19:34:25 +05:30
|
|
|
{ "force", no_argument, NULL, 'f' },
|
|
|
|
{ "help", no_argument, NULL, 'h' },
|
2014-11-21 15:26:41 +05:30
|
|
|
{ "ignore-conf-repos", no_argument, NULL, 'i' },
|
2019-06-21 18:51:58 +05:30
|
|
|
{ "ignore-file-conflicts", no_argument, NULL, 'I' },
|
2014-11-27 15:12:05 +05:30
|
|
|
{ "memory-sync", no_argument, NULL, 'M' },
|
2012-11-02 19:34:25 +05:30
|
|
|
{ "dry-run", no_argument, NULL, 'n' },
|
|
|
|
{ "repository", required_argument, NULL, 'R' },
|
|
|
|
{ "rootdir", required_argument, NULL, 'r' },
|
2013-01-31 15:14:33 +05:30
|
|
|
{ "sync", no_argument, NULL, 'S' },
|
2015-06-03 14:45:11 +05:30
|
|
|
{ "unpack-only", no_argument, NULL, 'U' },
|
2012-11-02 19:34:25 +05:30
|
|
|
{ "update", no_argument, NULL, 'u' },
|
|
|
|
{ "verbose", no_argument, NULL, 'v' },
|
|
|
|
{ "version", no_argument, NULL, 'V' },
|
|
|
|
{ "yes", no_argument, NULL, 'y' },
|
2019-12-29 15:08:55 +05:30
|
|
|
{ "reproducible", no_argument, NULL, 1 },
|
2012-11-02 19:34:25 +05:30
|
|
|
{ NULL, 0, NULL, 0 }
|
|
|
|
};
|
2012-12-14 16:28:30 +05:30
|
|
|
struct xbps_handle xh;
|
2012-11-02 19:34:25 +05:30
|
|
|
struct xferstat xfer;
|
2014-11-06 14:28:04 +05:30
|
|
|
const char *rootdir, *cachedir, *confdir;
|
2013-02-02 16:00:42 +05:30
|
|
|
int i, c, flags, rv, fflag = 0;
|
2020-04-23 09:33:56 +05:30
|
|
|
bool syncf, yes, force, drun, update;
|
2019-06-21 22:49:09 +05:30
|
|
|
int maxcols, eexist = 0;
|
2012-11-02 19:34:25 +05:30
|
|
|
|
2014-11-06 14:28:04 +05:30
|
|
|
rootdir = cachedir = confdir = NULL;
|
2012-11-02 19:34:25 +05:30
|
|
|
flags = rv = 0;
|
2020-04-23 09:33:56 +05:30
|
|
|
syncf = yes = force = drun = update = false;
|
2012-11-02 19:34:25 +05:30
|
|
|
|
2013-09-18 20:15:05 +05:30
|
|
|
memset(&xh, 0, sizeof(xh));
|
|
|
|
|
2012-11-02 19:34:25 +05:30
|
|
|
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
|
|
|
|
switch (c) {
|
2019-12-29 15:08:55 +05:30
|
|
|
case 1:
|
|
|
|
flags |= XBPS_FLAG_INSTALL_REPRO;
|
|
|
|
break;
|
2012-11-02 19:34:25 +05:30
|
|
|
case 'A':
|
|
|
|
flags |= XBPS_FLAG_INSTALL_AUTO;
|
|
|
|
break;
|
|
|
|
case 'C':
|
2014-11-06 14:28:04 +05:30
|
|
|
confdir = optarg;
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
cachedir = optarg;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
flags |= XBPS_FLAG_DEBUG;
|
|
|
|
break;
|
2019-06-21 19:27:25 +05:30
|
|
|
case 'D':
|
|
|
|
flags |= XBPS_FLAG_DOWNLOAD_ONLY;
|
|
|
|
break;
|
2012-11-02 19:34:25 +05:30
|
|
|
case 'f':
|
2013-02-02 16:00:42 +05:30
|
|
|
fflag++;
|
|
|
|
if (fflag > 1)
|
|
|
|
flags |= XBPS_FLAG_FORCE_UNPACK;
|
2020-04-23 09:33:56 +05:30
|
|
|
force = true;
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
usage(false);
|
|
|
|
/* NOTREACHED */
|
2019-06-21 18:51:58 +05:30
|
|
|
case 'I':
|
|
|
|
flags |= XBPS_FLAG_IGNORE_FILE_CONFLICTS;
|
|
|
|
break;
|
2014-11-21 15:26:41 +05:30
|
|
|
case 'i':
|
|
|
|
flags |= XBPS_FLAG_IGNORE_CONF_REPOS;
|
|
|
|
break;
|
2014-11-27 15:12:05 +05:30
|
|
|
case 'M':
|
|
|
|
flags |= XBPS_FLAG_REPOS_MEMSYNC;
|
|
|
|
break;
|
2012-11-02 19:34:25 +05:30
|
|
|
case 'n':
|
|
|
|
drun = true;
|
|
|
|
break;
|
|
|
|
case 'R':
|
2015-01-10 16:29:31 +05:30
|
|
|
xbps_repo_store(&xh, optarg);
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
rootdir = optarg;
|
|
|
|
break;
|
2013-01-31 15:14:33 +05:30
|
|
|
case 'S':
|
2014-10-05 01:35:33 +05:30
|
|
|
syncf = true;
|
2012-11-02 19:34:25 +05:30
|
|
|
break;
|
2015-06-03 14:45:11 +05:30
|
|
|
case 'U':
|
|
|
|
flags |= XBPS_FLAG_UNPACK_ONLY;
|
|
|
|
break;
|
2012-11-02 19:34:25 +05:30
|
|
|
case 'u':
|
|
|
|
update = true;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
flags |= XBPS_FLAG_VERBOSE;
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
printf("%s\n", XBPS_RELVER);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
case 'y':
|
|
|
|
yes = true;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage(true);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
}
|
2014-10-05 01:35:33 +05:30
|
|
|
if ((!update && !syncf) && (argc == optind))
|
2012-11-02 19:34:25 +05:30
|
|
|
usage(true);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize libxbps.
|
|
|
|
*/
|
|
|
|
xh.state_cb = state_cb;
|
|
|
|
xh.fetch_cb = fetch_file_progress_cb;
|
|
|
|
xh.fetch_cb_data = &xfer;
|
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));
|
2013-12-16 16:16:39 +05:30
|
|
|
if (cachedir)
|
2014-11-06 14:28:04 +05:30
|
|
|
xbps_strlcpy(xh.cachedir, cachedir, sizeof(xh.cachedir));
|
|
|
|
if (confdir)
|
|
|
|
xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir));
|
2012-11-02 19:34:25 +05:30
|
|
|
xh.flags = flags;
|
|
|
|
if (flags & XBPS_FLAG_VERBOSE)
|
2013-03-07 16:01:55 +05:30
|
|
|
xh.unpack_cb = unpack_progress_cb;
|
2012-11-02 19:34:25 +05:30
|
|
|
|
|
|
|
if ((rv = xbps_init(&xh)) != 0) {
|
|
|
|
xbps_error_printf("Failed to initialize libxbps: %s\n",
|
|
|
|
strerror(rv));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
maxcols = get_maxcols();
|
|
|
|
|
2013-11-18 20:35:46 +05:30
|
|
|
/* Sync remote repository data and import keys from remote repos */
|
2014-10-05 01:35:33 +05:30
|
|
|
if (syncf && !drun) {
|
2013-06-10 13:58:39 +05:30
|
|
|
if ((rv = xbps_rpool_sync(&xh, NULL)) != 0)
|
2013-01-31 15:14:33 +05:30
|
|
|
exit(rv);
|
2013-11-18 20:35:46 +05:30
|
|
|
rv = xbps_rpool_foreach(&xh, repo_import_key_cb, NULL);
|
|
|
|
if (rv != 0)
|
|
|
|
exit(rv);
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
|
|
|
|
2014-10-05 01:35:33 +05:30
|
|
|
if (syncf && !update && (argc == optind))
|
2013-02-20 14:28:31 +05:30
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
|
2020-01-25 17:35:46 +05:30
|
|
|
if (!(xh.flags & XBPS_FLAG_DOWNLOAD_ONLY) && !drun) {
|
|
|
|
if ((rv = xbps_pkgdb_lock(&xh)) != 0) {
|
2023-02-09 15:24:36 +05:30
|
|
|
xbps_error_printf("Failed to lock the pkgdb: %s\n", strerror(rv));
|
2020-01-25 17:35:46 +05:30
|
|
|
exit(rv);
|
|
|
|
}
|
2014-02-23 12:53:14 +05:30
|
|
|
}
|
|
|
|
|
2019-06-21 22:49:09 +05:30
|
|
|
eexist = optind;
|
|
|
|
|
2012-11-02 19:54:48 +05:30
|
|
|
if (update && (argc == optind)) {
|
2012-11-02 19:34:25 +05:30
|
|
|
/* Update all installed packages */
|
|
|
|
rv = dist_upgrade(&xh, maxcols, yes, drun);
|
2012-11-02 19:54:48 +05:30
|
|
|
} else if (update) {
|
2012-11-02 19:34:25 +05:30
|
|
|
/* Update target packages */
|
|
|
|
for (i = optind; i < argc; i++) {
|
2020-04-23 09:33:56 +05:30
|
|
|
rv = update_pkg(&xh, argv[i], force);
|
2019-06-21 14:36:45 +05:30
|
|
|
if (rv == EEXIST) {
|
|
|
|
/* pkg already updated, ignore */
|
|
|
|
rv = 0;
|
2019-06-21 22:49:09 +05:30
|
|
|
eexist++;
|
2016-02-05 15:57:40 +05:30
|
|
|
} else if (rv != 0) {
|
2015-01-10 23:41:31 +05:30
|
|
|
xbps_end(&xh);
|
2012-12-14 16:28:30 +05:30
|
|
|
exit(rv);
|
2014-02-23 12:53:14 +05:30
|
|
|
}
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
2019-06-21 22:49:09 +05:30
|
|
|
if (eexist == argc)
|
2019-06-27 11:32:19 +05:30
|
|
|
goto out;
|
2019-06-21 22:49:09 +05:30
|
|
|
|
2012-11-02 19:34:25 +05:30
|
|
|
rv = exec_transaction(&xh, maxcols, yes, drun);
|
2012-11-02 19:54:48 +05:30
|
|
|
} else if (!update) {
|
2012-11-02 19:34:25 +05:30
|
|
|
/* Install target packages */
|
|
|
|
for (i = optind; i < argc; i++) {
|
2020-04-23 09:33:56 +05:30
|
|
|
rv = install_new_pkg(&xh, argv[i], force);
|
2019-06-21 14:36:45 +05:30
|
|
|
if (rv == EEXIST) {
|
|
|
|
/* pkg already installed, ignore */
|
|
|
|
rv = 0;
|
2019-06-21 22:49:09 +05:30
|
|
|
eexist++;
|
2014-08-23 11:32:40 +05:30
|
|
|
} else if (rv != 0) {
|
2015-01-10 23:41:31 +05:30
|
|
|
xbps_end(&xh);
|
2012-12-14 16:28:30 +05:30
|
|
|
exit(rv);
|
2014-02-23 12:53:14 +05:30
|
|
|
}
|
2012-11-02 19:34:25 +05:30
|
|
|
}
|
2019-06-21 22:49:09 +05:30
|
|
|
if (eexist == argc)
|
2019-06-27 11:32:19 +05:30
|
|
|
goto out;
|
2019-06-21 22:49:09 +05:30
|
|
|
|
2012-11-02 19:34:25 +05:30
|
|
|
rv = exec_transaction(&xh, maxcols, yes, drun);
|
|
|
|
}
|
|
|
|
|
2019-06-27 11:32:19 +05:30
|
|
|
out:
|
2015-01-10 23:41:31 +05:30
|
|
|
xbps_end(&xh);
|
2012-11-02 19:34:25 +05:30
|
|
|
exit(rv);
|
|
|
|
}
|