From b70213b5c71b58f032bce1ead254669b1f4e6233 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Wed, 23 Oct 2013 14:23:48 +0000 Subject: [PATCH] Allow to bootstrap by doing pkg add ./a/path/to/a/pkg_package.txz Requested by: many MFC after: 3 days --- usr.sbin/pkg/pkg.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/usr.sbin/pkg/pkg.c b/usr.sbin/pkg/pkg.c index 44d841e7c9a..840f2a2f942 100644 --- a/usr.sbin/pkg/pkg.c +++ b/usr.sbin/pkg/pkg.c @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -297,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); @@ -311,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