aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/pkg/pkg.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/pkg/pkg.c')
-rw-r--r--usr.sbin/pkg/pkg.c47
1 files changed, 44 insertions, 3 deletions
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) {