From owner-dev-commits-src-branches@freebsd.org Sat Feb 20 19:29:57 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 9F210552029; Sat, 20 Feb 2021 19:29:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DjdnK43N4z4ZxD; Sat, 20 Feb 2021 19:29:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7D9E5248DF; Sat, 20 Feb 2021 19:29:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 11KJTvUc053476; Sat, 20 Feb 2021 19:29:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 11KJTvET053475; Sat, 20 Feb 2021 19:29:57 GMT (envelope-from git) Date: Sat, 20 Feb 2021 19:29:57 GMT Message-Id: <202102201929.11KJTvET053475@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 6cf4aaf763ca - stable/13 - pkg(7): add an -r reponame option for bootstrap and add MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 6cf4aaf763ca0fb35d77e00d1daede803038bbf0 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Feb 2021 19:29:57 -0000 The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=6cf4aaf763ca0fb35d77e00d1daede803038bbf0 commit 6cf4aaf763ca0fb35d77e00d1daede803038bbf0 Author: Kyle Evans AuthorDate: 2021-02-12 00:58:26 +0000 Commit: Kyle Evans CommitDate: 2021-02-20 19:29:30 +0000 pkg(7): add an -r reponame option for bootstrap and add This is limited to bootstrap/add because some real pkg(8) commands have -r flags with an incompatible meaning/usage, e.g., pkg-audit. pkg(7) will still commence the search as it has, but it will ignore any repo objects without the given name so that overrides and whatnot still work as expected. The use of it for add is noted in the manpage; notably, that the signature config for that repository will be used over global config if it's specified. i.e., pkg(7) should assume that the given pkg did come from that repository and treat it appropriately. (cherry picked from commit 18418e1936b59c34a9c4a02a1ba5fe0d00dde1b3) --- usr.sbin/pkg/config.c | 24 +++++++++++++++--------- usr.sbin/pkg/config.h | 2 +- usr.sbin/pkg/pkg.7 | 37 +++++++++++++++++++++++++++++++------ usr.sbin/pkg/pkg.c | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 91 insertions(+), 19 deletions(-) diff --git a/usr.sbin/pkg/config.c b/usr.sbin/pkg/config.c index aaa9010b295d..3a5434639d6d 100644 --- a/usr.sbin/pkg/config.c +++ b/usr.sbin/pkg/config.c @@ -324,7 +324,7 @@ cleanup: * etc... */ static void -parse_repo_file(ucl_object_t *obj) +parse_repo_file(ucl_object_t *obj, const char *requested_repo) { ucl_object_iter_t it = NULL; const ucl_object_t *cur; @@ -339,13 +339,17 @@ parse_repo_file(ucl_object_t *obj) if (cur->type != UCL_OBJECT) continue; + if (requested_repo != NULL && strcmp(requested_repo, key) != 0) + continue; + config_parse(cur, CONFFILE_REPO); } } static int -read_conf_file(const char *confpath, pkg_conf_file_t conftype) +read_conf_file(const char *confpath, const char *requested_repo, + pkg_conf_file_t conftype) { struct ucl_parser *p; ucl_object_t *obj = NULL; @@ -369,7 +373,7 @@ read_conf_file(const char *confpath, pkg_conf_file_t conftype) if (conftype == CONFFILE_PKG) config_parse(obj, conftype); else if (conftype == CONFFILE_REPO) - parse_repo_file(obj); + parse_repo_file(obj, requested_repo); } ucl_object_unref(obj); @@ -379,7 +383,7 @@ read_conf_file(const char *confpath, pkg_conf_file_t conftype) } static int -load_repositories(const char *repodir) +load_repositories(const char *repodir, const char *requested_repo) { struct dirent *ent; DIR *d; @@ -403,8 +407,10 @@ load_repositories(const char *repodir) repodir, repodir[strlen(repodir) - 1] == '/' ? "" : "/", ent->d_name); - if (access(path, F_OK) == 0 && - read_conf_file(path, CONFFILE_REPO)) { + if (access(path, F_OK) != 0) + continue; + if (read_conf_file(path, requested_repo, + CONFFILE_REPO)) { ret = 1; goto cleanup; } @@ -418,7 +424,7 @@ cleanup: } int -config_init(void) +config_init(const char *requested_repo) { char *val; int i; @@ -459,7 +465,7 @@ config_init(void) localbase = getlocalbase(); snprintf(confpath, sizeof(confpath), "%s/etc/pkg.conf", localbase); - if (access(confpath, F_OK) == 0 && read_conf_file(confpath, + if (access(confpath, F_OK) == 0 && read_conf_file(confpath, NULL, CONFFILE_PKG)) goto finalize; @@ -477,7 +483,7 @@ config_init(void) } STAILQ_FOREACH(cv, c[REPOS_DIR].list, next) - if (load_repositories(cv->value)) + if (load_repositories(cv->value, requested_repo)) goto finalize; finalize: diff --git a/usr.sbin/pkg/config.h b/usr.sbin/pkg/config.h index f1a2aa227f16..afcd728abd92 100644 --- a/usr.sbin/pkg/config.h +++ b/usr.sbin/pkg/config.h @@ -58,7 +58,7 @@ typedef enum { CONFFILE_REPO, } pkg_conf_file_t; -int config_init(void); +int config_init(const char *); void config_finish(void); int config_string(pkg_config_key, const char **); int config_bool(pkg_config_key, bool *); diff --git a/usr.sbin/pkg/pkg.7 b/usr.sbin/pkg/pkg.7 index c672306ac08d..b92f5c9820cd 100644 --- a/usr.sbin/pkg/pkg.7 +++ b/usr.sbin/pkg/pkg.7 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd December 31, 2020 +.Dd February 7, 2021 .Dt PKG 7 .Os .Sh NAME @@ -36,6 +36,7 @@ .Nm add .Op Fl f +.Op Fl r Ar reponame .Op Fl y .Ao Pa pkg.txz Ac .Nm @@ -44,6 +45,7 @@ add .Op Fl 4 | Fl 6 bootstrap .Op Fl f +.Op Fl r Ar reponame .Op Fl y .Sh DESCRIPTION .Nm @@ -68,7 +70,7 @@ is not installed yet, it will be fetched, have its signature verified, installed, and then have the original command forwarded to it. If already installed, the command requested will be forwarded to the real .Xr pkg 8 . -.It Nm Li add Oo Fl f Oc Oo Fl y Oc Ao Pa pkg.txz Ac +.It Nm Li add Oo Fl f Oc Oo Fl r Ar reponame Oc Oo Fl y Oc Ao Pa pkg.txz Ac Install .Xr pkg 8 from a local package instead of fetching from remote. @@ -83,13 +85,19 @@ If the .Fl y flag is specified, no confirmation will be asked when bootstrapping .Xr pkg 8 . +.Pp +If a +.Ar reponame +has been specified, then the signature configuration for that repository will be +used. .It Nm Fl N Do not bootstrap, just determine if .Xr pkg 8 is actually installed or not. Returns 0 and the number of packages installed if it is, otherwise 1. -.It Nm Oo Fl 4 | Fl 6 Oc Li bootstrap Oo Fl f Oc Oo Fl y Oc +.It Nm Oo Fl 4 | Fl 6 Oc Li bootstrap Oo Fl f Oc \ +Oo Fl r Ar reponame Oc Oo Fl y Oc Attempt to bootstrap and do not forward anything to .Xr pkg 8 after it is installed. @@ -110,14 +118,30 @@ If the .Fl y flag is specified, no confirmation will be asked when bootstrapping .Xr pkg 8 . +.Pp +If a +.Ar reponame +has been specified, then the configuration for that repository will be used. .El .Sh CONFIGURATION Configuration varies in whether it is in a repository configuration file or the global configuration file. +The default repository configuration for +.Fx +is stored in +.Pa /etc/pkg/FreeBSD.conf , +and additional repository configuration files will be searched for in +.Ev REPOS_DIR , +or +.Pa /usr/local/etc/pkg/repos +if it is unset. .Pp -Repository configuration can be stored in -.Pa /etc/pkg/FreeBSD.conf -in the following format: +For bootstrapping, +.Nm +will process all repositories that it finds and use the last enabled repository +by default. +.Pp +Repository configuration is stored in the following format: .Bd -literal -offset indent FreeBSD: { url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest", @@ -127,6 +151,7 @@ FreeBSD: { enabled: yes } .Ed +.Pp .Bl -tag -width signature_type -compact .It url Refer to diff --git a/usr.sbin/pkg/pkg.c b/usr.sbin/pkg/pkg.c index 788fdb39ebb9..5e424cf83034 100644 --- a/usr.sbin/pkg/pkg.c +++ b/usr.sbin/pkg/pkg.c @@ -1045,7 +1045,7 @@ int main(int argc, char *argv[]) { char pkgpath[MAXPATHLEN]; - const char *pkgarg; + const char *pkgarg, *repo_name; bool activation_test, add_pkg, bootstrap_only, force, yes; signed char ch; const char *fetchOpts; @@ -1058,6 +1058,7 @@ main(int argc, char *argv[]) fetchOpts = ""; force = false; pkgarg = NULL; + repo_name = NULL; yes = false; struct option longopts[] = { @@ -1070,7 +1071,7 @@ main(int argc, char *argv[]) snprintf(pkgpath, MAXPATHLEN, "%s/sbin/pkg", getlocalbase()); - while ((ch = getopt_long(argc, argv, "-:fyN46", longopts, NULL)) != -1) { + while ((ch = getopt_long(argc, argv, "-:fr::yN46", longopts, NULL)) != -1) { switch (ch) { case 'f': force = true; @@ -1087,6 +1088,46 @@ main(int argc, char *argv[]) case '6': fetchOpts = "6"; break; + case 'r': + /* + * The repository can only be specified for an explicit + * bootstrap request at this time, so that we don't + * confuse the user if they're trying to use a verb that + * has some other conflicting meaning but we need to + * bootstrap. + * + * For that reason, we specify that -r has an optional + * argument above and process the next index ourselves. + * This is mostly significant because getopt(3) will + * otherwise eat the next argument, which could be + * something we need to try and make sense of. + * + * At worst this gets us false positives that we ignore + * in other contexts, and we have to do a little fudging + * in order to support separating -r from the reponame + * with a space since it's not actually optional in + * the bootstrap/add sense. + */ + if (add_pkg || bootstrap_only) { + if (optarg != NULL) { + repo_name = optarg; + } else if (optind < argc) { + repo_name = argv[optind]; + } + + if (repo_name == NULL || *repo_name == '\0') { + fprintf(stderr, + "Must specify a repository with -r!\n"); + exit(EXIT_FAILURE); + } + + if (optarg == NULL) { + /* Advance past repo name. */ + optreset = 1; + optind++; + } + } + break; case 1: // Non-option arguments, first one is the command if (command == NULL) { @@ -1126,7 +1167,7 @@ main(int argc, char *argv[]) if (activation_test) errx(EXIT_FAILURE, "pkg is not installed"); - config_init(); + config_init(repo_name); if (add_pkg) { if (pkgarg == NULL) {