From 54b6cc7ec139eb5f75071c7a2cfd7e8cf81ed9aa Mon Sep 17 00:00:00 2001 From: Juan RP Date: Mon, 24 Sep 2012 12:03:47 +0200 Subject: [PATCH] xbps-{bin,repo}: add -B flag to set default repo if xbps.conf not found. (cherry picked from commit 75eac1a1426040a833e0b10e208f2e55fa359532) --- NEWS | 3 +++ bin/xbps-bin/main.c | 11 ++++++++--- bin/xbps-bin/xbps-bin.8 | 5 ++++- bin/xbps-repo/main.c | 11 ++++++++--- bin/xbps-repo/xbps-repo.8 | 5 ++++- configure | 2 +- include/xbps_api.h | 7 +++++++ lib/initend.c | 24 +++++++++++++++++------- 8 files changed, 52 insertions(+), 16 deletions(-) diff --git a/NEWS b/NEWS index 307fdf9c..f01ca774 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,8 @@ xbps-0.17 (???): + * xbps-bin(8), xbps-repo(8): added a new flag -B to set default repository + to install packages, in case xbps.conf couldn't be found. + * xbps-create(8): a new utility to create XBPS binary packages; package files must be installed to a directory prior to executing this utility. diff --git a/bin/xbps-bin/main.c b/bin/xbps-bin/main.c index 82e51ca9..a9699008 100644 --- a/bin/xbps-bin/main.c +++ b/bin/xbps-bin/main.c @@ -47,6 +47,7 @@ usage(bool fail) "Usage: xbps-bin [options] target [arguments]\n\n" "[options]\n" " -A Enable Automatic installation (shown as orphan)\n" + " -B repo Set as default repository if xbps.conf not found.\n" " -C file Full path to configuration file\n" " -c cachedir Full path to cachedir, to store downloaded binpkgs\n" " -d Debug mode shown to stderr\n" @@ -111,23 +112,26 @@ main(int argc, char **argv) struct xferstat xfer; struct list_pkgver_cb lpc; struct sigaction sa; - const char *rootdir, *cachedir, *conffile, *option; + const char *rootdir, *cachedir, *conffile, *option, *defrepo; int i, c, flags, rv; bool rsync, yes, reqby_force, force_rm_with_deps, recursive_rm; bool reinstall, show_download_pkglist_url, dry_run; size_t maxcols; - rootdir = cachedir = conffile = option = NULL; + rootdir = cachedir = conffile = option = defrepo = NULL; flags = rv = 0; reqby_force = rsync = yes = dry_run = force_rm_with_deps = false; recursive_rm = reinstall = show_download_pkglist_url = false; - while ((c = getopt(argc, argv, "AC:c:dDFfhMno:Rr:SVvy")) != -1) { + while ((c = getopt(argc, argv, "AB:C:c:dDFfhMno:Rr:SVvy")) != -1) { switch (c) { case 'A': flags |= XBPS_FLAG_INSTALL_AUTO; break; + case 'B': + defrepo = optarg; + break; case 'C': conffile = optarg; break; @@ -210,6 +214,7 @@ main(int argc, char **argv) xh.cachedir = cachedir; xh.conffile = conffile; xh.flags = flags; + xh.repository = defrepo; if (flags & XBPS_FLAG_VERBOSE) xh.unpack_cb = unpack_progress_cb_verbose; else diff --git a/bin/xbps-bin/xbps-bin.8 b/bin/xbps-bin/xbps-bin.8 index 53e38c7d..b06630c9 100644 --- a/bin/xbps-bin/xbps-bin.8 +++ b/bin/xbps-bin/xbps-bin.8 @@ -1,4 +1,4 @@ -.Dd June 5, 2012 +.Dd September 24, 2012 .Os Void GNU/Linux .Dt xbps-bin 8 .Sh NAME @@ -36,6 +36,9 @@ and .Em update targets. Targetted packages and its required dependencies will be matched. +.It Fl B Ar repository +If a configuration file cannot be found, this repository will be used as +as primary source to install packages. .It Fl C Ar conffile Full path to the XBPS configuration file. By default set to .Pa /etc/xbps/xbps.conf . diff --git a/bin/xbps-repo/main.c b/bin/xbps-repo/main.c index 3684698e..d5368281 100644 --- a/bin/xbps-repo/main.c +++ b/bin/xbps-repo/main.c @@ -44,6 +44,7 @@ usage(bool fail) fprintf(stdout, "Usage: xbps-repo [options] target [arguments]\n\n" "[options]\n" + " -B repo Set as default repository if xbps.conf not found.\n" " -C file Full path to configuration file\n" " -c cachedir Full path to cachedir to store downloaded binpkgs\n" " -d Debug mode shown to stderr\n" @@ -92,13 +93,16 @@ main(int argc, char **argv) struct xferstat xfer; struct repo_search_data rsd; prop_dictionary_t pkgd; - const char *rootdir, *cachedir, *conffile, *option; + const char *rootdir, *cachedir, *conffile, *option, *defrepo; int flags = 0, c, rv = 0; - rootdir = cachedir = conffile = option = NULL; + rootdir = cachedir = conffile = option = defrepo = NULL; - while ((c = getopt(argc, argv, "C:c:dho:r:V")) != -1) { + while ((c = getopt(argc, argv, "B:C:c:dho:r:V")) != -1) { switch (c) { + case 'B': + defrepo = optarg; + break; case 'C': conffile = optarg; break; @@ -144,6 +148,7 @@ main(int argc, char **argv) xh.rootdir = rootdir; xh.cachedir = cachedir; xh.conffile = conffile; + xh.repository = defrepo; if ((rv = xbps_init(&xh)) != 0) { xbps_error_printf("xbps-repo: couldn't initialize library: %s\n", diff --git a/bin/xbps-repo/xbps-repo.8 b/bin/xbps-repo/xbps-repo.8 index 439cd5a2..ac7954fd 100644 --- a/bin/xbps-repo/xbps-repo.8 +++ b/bin/xbps-repo/xbps-repo.8 @@ -1,4 +1,4 @@ -.Dd July 31, 2012 +.Dd September 24, 2012 .Os Void GNU/Linux .Dt xbps-repo 8 .Sh NAME @@ -18,6 +18,9 @@ repositories, list repositories, search for packages and show information of a binary package in repository pool, among other things. .Sh OPTIONS .Bl -tag -width Fl +.It Fl B Ar repository +If a configuration file cannot be found, this repository will be used as +as primary source to install packages. .It Fl C Ar conffile Full path to the XBPS configuration file. By default set to .Pa /etc/xbps/xbps.conf . diff --git a/configure b/configure index 1298be99..85e54360 100755 --- a/configure +++ b/configure @@ -444,7 +444,7 @@ int main(void) { return 0; } EOF -if $XCC -lprop _$func.c -o _$func 2>/dev/null; then +if ! $XCC -lprop _$func.c -o _$func 2>/dev/null; then PROPLIB=yes echo "USE_EXTERNAL_PROPLIB = 1" >>$CONFIG_MK echo "LDFLAGS += -lz -lpthread -lprop" >>$CONFIG_MK diff --git a/include/xbps_api.h b/include/xbps_api.h index 6173f529..c7b03842 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -528,6 +528,13 @@ struct xbps_handle { char *cachedir_priv; char *metadir_priv; char *un_machine; + /* + * @var repository + * + * Default repository to be used if a configuration file + * couldn't be found. + */ + const char *repository; /** * @var conffile * diff --git a/lib/initend.c b/lib/initend.c index 39bb1329..6f30216a 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -131,15 +131,25 @@ xbps_init(struct xbps_handle *xhp) if ((rv = cfg_parse(xhp->cfg, xhp->conffile)) != CFG_SUCCESS) { if (rv == CFG_FILE_ERROR) { - if (errno != ENOENT) { - /* - * Don't error out if config file not found. - * We'll use defaults without any repo or - * virtual packages. - */ + /* + * Don't error out if config file not found. + * If a default repository is set, use it; otherwise + * use defaults (no repos and no virtual packages). + */ + if (errno != ENOENT) return rv; - } + xhp->conffile = NULL; + if (xhp->repository) { + char *buf; + + buf = xbps_xasprintf("repositories = { %s }", + xhp->repository); + assert(buf); + if ((rv = cfg_parse_buf(xhp->cfg, buf)) != 0) + return rv; + free(buf); + } } else if (rv == CFG_PARSE_ERROR) { /* * Parser error from configuration file.