Why is pkg(7) not jail-aware?

Just a curiousity, but today I realized that the pkg(7) bootstrapper doesn't understand jails:

Code:
pkg -j newjail -N > /dev/null 2>&1 || {
  echo "bootstrapping 'pkg' in jail 'newjail'"
  pkg -j newjail
}

Somewhat tangential, pkg(7) seems to act correctly on the -y flag, but then claims to not understand it:

Code:
# jexec newjail sh
# pkg -y
Bootstrapping pkg from pkg+https://pkg.FreeBSD.org/FreeBSD:14:amd64/latest, please wait...
Verifying signature with trusted certificate pkg.freebsd.org.2013102301... done
[newjail.example.edu] Installing pkg-2.0.5...
[newjail.example.ed] Extracting pkg-2.0.5: 100%
pkg: illegal option -- y
pkg: Invalid argument provided

It's a small use case, granted, but it would be nice to be able to:

Code:
pkg -j newjail -N > /dev/null 2>&1 || {
  echo "bootstrapping 'pkg' in jail 'newjail'"
  pkg -yj newjail
}
 
Somewhat tangential, pkg(7) seems to act correctly on the -y flag, but then claims to not understand it:
-y is an option for some of the subcommands, not pkg(7) itself.

Code:
SYNOPSIS
     pkg [-d] command ...
     pkg add [-dfy] [-r reponame] pkg.txz
     pkg -N
     pkg [-46d] bootstrap [-fy] [-r reponame]

pkg add -y .... and pkg bootstrap -y ... are valid, pkg -y .... is not. Same is true for pkg(8), some subcommands have the -y option (pkg-delete(8), pkg-install(8), etc), not pkg(8) itself.
 
-y is an option for some of the subcommands, not pkg(7) itself.
Well, it's "undocumented." It does seem to work, insofar as one doesn't have to confirm the operation. But point taken, relying on undocumented behaviour isn't a best practice.

pkg add -y .... and pkg bootstrap -y ... are valid, pkg -y .... is not. Same is true for pkg(8), some subcommands have the -y option (pkg-delete(8), pkg-install(8), etc), not pkg(8) itself.

Fwiw, pkg bootstrap ... is also not jail-aware:

Code:
# pkg bootstrap -j3
pkg already bootstrapped at /usr/local/sbin/pkg
# pkg -j3 bootstrap 
pkg already bootstrapped at /usr/local/sbin/pkg
# jexec 3 pkg bootstrap
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]:
 
Yes, pkg(7) isn't. But you can use pkg(8) on the host to bootstrap pkg(8) in the jail, because pkg(8) is jail aware. Or jexec(8) pkg(7) inside a jail.

# pkg -j3 bootstrap pkg already bootstrapped at /usr/local/sbin/pkg
Try /usr/local/sbin/pkg -j3 bootstrap instead. The problem you're running into is that /usr/sbin/pkg is first in the path, so it gets executed. It captures the bootstap subcommand. Any other subcommand is passed to /usr/local/sbin/pkg (if it exists).
 
pkg man page has no mention of -y flag (but some pkg-* commands do). Does pkg -N -c /path/to/jail help?
No, sadly it doesn't do anything about installing pkg(8) into the jail. Plus it's a little tedious to have to map a jail name or number to the path. Can be done, sure, but it's not as easy as
Code:
-j <jail-id>
 
Yes, pkg(7) isn't. But you can use pkg(8) on the host to bootstrap pkg(8) in the jail, because pkg(8) is jail aware. Or jexec(8) pkg(7) inside a jail.


Try /usr/local/sbin/pkg -j3 bootstrap instead. The problem you're running into is that /usr/sbin/pkg is first in the path, so it gets executed. It captures the bootstap subcommand. Any other subcommand is passed to /usr/local/sbin/pkg.
Thank you! That does work, although -f is also needed:
Code:
# /usr/local/sbin/pkg -j3 bootstrap
pkg(8) already installed, use -f to force.
# /usr/local/sbin/pkg -j3 bootstrap -f
pkg(8) is already installed. Forcing reinstallation through pkg(7).
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y
Bootstrapping pkg from pkg+https://pkg.FreeBSD.org/FreeBSD:14:amd64/latest, please wait...
Verifying signature with trusted certificate pkg.freebsd.org.2013102301... done
[newjail.example.edu] Installing pkg-2.0.5...
[newjail.example.edu] Extracting pkg-2.0.5: 100%
 
Back
Top
OSZAR »