git: 2c06b824436d - main - pkgbootstrap: Build pkg if PORTSDIR exists
Date: Thu, 18 Sep 2025 19:25:02 UTC
The branch main has been updated by cperciva:
URL: https://cgit.FreeBSD.org/src/commit/?id=2c06b824436df6177545cc0f1603e5c3bfbf3365
commit 2c06b824436df6177545cc0f1603e5c3bfbf3365
Author: Colin Percival <cperciva@FreeBSD.org>
AuthorDate: 2025-09-18 19:21:29 +0000
Commit: Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2025-09-18 19:21:29 +0000
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
---
Makefile.inc1 | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/Makefile.inc1 b/Makefile.inc1
index cd0385ea32ac..d41741d15384 100644
--- a/Makefile.inc1
+++ b/Makefile.inc1
@@ -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}'