pkgbootstrap: Build pkg if PORTSDIR exists

If we don't already have the pkg tool installed, we need to install it
before we can build packages for pkgbase.  (This arises in release
builds which run in clean chroots; most users will have pkg installed
already.)  Installing it from pkg.freebsd.org via "pkg bootstrap" runs
into two problems: First, it's an external dependency with security
implications; and second, there's a bootstrapping problem on new major
versions where pkg.freebsd.org does not have packages yet.

Instead, if we have a ports tree, use it to build pkg ourselves.

With hat:	re
MFC after:	6 hours
Sponsored by:	https://www.patreon.com/cperciva
This commit is contained in:
Colin Percival 2025-09-18 12:21:29 -07:00
parent d5984d5f29
commit 2c06b82443

View file

@ -1992,8 +1992,16 @@ PKG_ABI!= ${PKG_CMD} -o ABI_FILE=${PKG_ABI_FILE} config ABI
_pkgbootstrap: .PHONY
.if make(*package*) && !exists(${LOCALBASE}/sbin/pkg)
.if exists(${PORTSDIR}/ports-mgmt/pkg/Makefile)
env - UNAME_r=${UNAME_r} PATH=$$PATH \
make -C ${PORTSDIR}/ports-mgmt/pkg \
I_DONT_CARE_IF_MY_BUILDS_TARGET_THE_WRONG_RELEASE=1 \
BATCH=1 WRKDIRPREFIX=/tmp/ports DISTDIR=/tmp/distfiles \
all install clean
.else
@env ASSUME_ALWAYS_YES=YES pkg bootstrap
.endif
.endif
PKG_BIN_VERSION!=${PKG_CMD} --version </dev/null 2>/dev/null |\
awk -F. '/^[0-9.]+$$/ {print $$1 * 10000 + $$2 * 100 + $$3}'