Allow to bootstrap by doing pkg add ./a/path/to/a/pkg_package.txz

Requested by:	many
MFC after:	3 days
This commit is contained in:
Baptiste Daroussin 2013-10-23 14:23:48 +00:00
parent 081431ad8f
commit b70213b5c7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=256971

View File

@ -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>
@ -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