Add command line option for chrootdir, all pkg_add(8) operations will be

done inside of chroot(2) to chrootdir.  Added to help with sysinstall(8)
support of install to alternate root but possibly useful for setting up
jails, etc.

No objection from:	portmgr@
Style(9) abuse due to:	entire program violates style(9)
Approved by:		rwatson (mentor)
This commit is contained in:
Ken Smith 2004-03-01 21:58:21 +00:00
parent c15f03d381
commit e77e03a08a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=126465
2 changed files with 39 additions and 3 deletions

View file

@ -27,9 +27,10 @@ __FBSDID("$FreeBSD$");
#include "lib.h"
#include "add.h"
static char Options[] = "hvIRfnrp:SMt:";
static char Options[] = "hvIRfnrp:SMt:C:";
char *Prefix = NULL;
char *Chroot = NULL;
Boolean NoInstall = FALSE;
Boolean NoRecord = FALSE;
Boolean Remote = FALSE;
@ -129,6 +130,10 @@ main(int argc, char **argv)
AddMode = MASTER;
break;
case 'C':
Chroot = optarg;
break;
case 'h':
case '?':
default:
@ -210,6 +215,11 @@ main(int argc, char **argv)
warnx("only one package name may be specified with master mode");
usage();
}
/* Perform chroot if requested */
if (Chroot != NULL) {
if (chroot(Chroot))
errx(1, "chroot to %s failed", Chroot);
}
/* Make sure the sub-execs we invoke get found */
setenv("PATH",
"/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin",
@ -280,7 +290,7 @@ static void
usage()
{
fprintf(stderr, "%s\n%s\n",
"usage: pkg_add [-vInrfRMS] [-t template] [-p prefix]",
" pkg-name [pkg-name ...]");
"usage: pkg_add [-vInrfRMS] [-t template] [-p prefix] [-C chrootdir]",
" pkg-name [pkg-name ...]");
exit(1);
}

View file

@ -28,6 +28,7 @@
.Op Fl vInfrRMS
.Op Fl t Ar template
.Op Fl p Ar prefix
.Op Fl C Ar chrootdir
.Ar pkg-name Op Ar pkg-name ...
.Sh DESCRIPTION
The
@ -188,6 +189,31 @@ in the staging area, the location of which is read as a string
from stdin.
The complete packing list is also read from stdin,
and the contents then acted on as normal.
.It Fl C Ar chrootdir
Before doing any operations
.Xr chroot 2
to the
.Ar chrootdir
directory so that all package files, and the package database, are
installed to
.Ar chrootdir .
Note that
.Ar chrootdir
needs to be a fairly complete file system, including everything normally
needed by
.Xr pkg_add 8
to run.
This flag was added to help support operations done by
.Xr sysinstall 8
and is not expected to be useful for much else.
Be careful that
.Ar chrootdir
is properly configured and can not be modified by normal users,
versions of commands like
.Xr fetch 1
may be run inside
.Ar chrootdir
as a side-effect.
.El
.Pp
One or more