diff options
author | bapt <bapt@FreeBSD.org> | 2013-10-29 07:33:53 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2013-10-29 07:33:53 +0000 |
commit | 22acce6ad4bcdd38373f948bdaf4b2dff52e4943 (patch) | |
tree | a4dc1a314a9048d73cecca507572032d8f97e1b8 /usr.sbin/pkg/pkg.c | |
parent | e5d79eff87107912cdd11a112a074f5b40a6d963 (diff) | |
download | FreeBSD-src-22acce6ad4bcdd38373f948bdaf4b2dff52e4943.zip FreeBSD-src-22acce6ad4bcdd38373f948bdaf4b2dff52e4943.tar.gz |
MFC: r256968, r256971, r256978
Improve SRV records support for the pkg(8) bootstrap:
- order srv records by priorities
- for all entries of the same priority, order randomly respect the weight
- select the port where to fetch from respect the port provided in the SRV
record
Allow to bootstrap by doing pkg add ./a/path/to/a/pkg_package.txz
Approved by: re (glebius)
Diffstat (limited to 'usr.sbin/pkg/pkg.c')
-rw-r--r-- | usr.sbin/pkg/pkg.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/usr.sbin/pkg/pkg.c b/usr.sbin/pkg/pkg.c index 0aef3da..34ab26f 100644 --- a/usr.sbin/pkg/pkg.c +++ b/usr.sbin/pkg/pkg.c @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$"); #include <archive_entry.h> #include <err.h> #include <errno.h> +#include <fcntl.h> #include <fetch.h> #include <paths.h> #include <stdbool.h> @@ -191,8 +192,10 @@ bootstrap_pkg(void) } } - if (mirrors != NULL) + if (mirrors != NULL) { strlcpy(u->host, current->host, sizeof(u->host)); + u->port = current->port; + } remote = fetchXGet(u, &st, ""); if (remote == NULL) { @@ -295,7 +298,9 @@ int main(__unused int argc, char *argv[]) { char pkgpath[MAXPATHLEN]; + char pkgstatic[MAXPATHLEN]; bool yes = false; + int fd, ret; snprintf(pkgpath, MAXPATHLEN, "%s/sbin/pkg", getenv("LOCALBASE") ? getenv("LOCALBASE") : _LOCALBASE); @@ -309,6 +314,19 @@ main(__unused int argc, char *argv[]) if (argv[1] != NULL && strcmp(argv[1], "-N") == 0) errx(EXIT_FAILURE, "pkg is not installed"); + if (argc > 2 && strcmp(argv[1], "add") == 0 && + access(argv[2], R_OK) == 0) { + fd = open(argv[2], O_RDONLY); + if (fd == -1) + err(EXIT_FAILURE, "Unable to open %s", argv[2]); + + if ((ret = extract_pkg_static(fd, pkgstatic, MAXPATHLEN)) == 0) + ret = install_pkg_static(pkgstatic, argv[2]); + close(fd); + if (ret != 0) + exit(EXIT_FAILURE); + exit(EXIT_SUCCESS); + } /* * Do not ask for confirmation if either of stdin or stdout is * not tty. Check the environment to see if user has answer |