freebsd-update: refuse to operate on a pkgbase system

FreeBSD-update is not compatible with packaged base.

PR:		282252
Reviewed by:	bapt, markj (earlier)
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D47341

(cherry picked from commit cf1aba2857c1ec59c9a34d363cb18a61ffa34a10)

freebsd-update: improve pkgbase check

The previous version used a case-insensitive match (default for -x).
The presence of packages like freebsd-git-devtools and freebsd-ftpd
would falsely trigger the packaged base check.

Instead, just use `pkg which /usr/bin/uname` as a packaged base
indication.  pkg uses /usr/bin/uname to determine ABI, so we can rely on
it existing.  If it comes from a package then packaged base is in use.

Also, extend the check to all freebsd-update commands.  It is easier to
just disallow all commands, and easier to test.

Reported by: Mark Millard
Reviewed by: manu
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D47378

(cherry picked from commit 856e158dc4aa5e43f0f15fcd3089fc0d71861b0e)
This commit is contained in:
Ed Maste 2024-10-30 15:15:13 -04:00
parent fe019d5e44
commit 094a5146df

View file

@ -1046,6 +1046,26 @@ IDS_check_params () {
fetch_setup_verboselevel
}
# Packaged base and freebsd-update are incompatible. Exit with an error if
# packaged base is in use.
check_pkgbase()
{
# Packaged base requires that pkg is bootstrapped.
if ! pkg -c ${BASEDIR} -N >/dev/null 2>/dev/null; then
return
fi
# uname(1) is used by pkg to determine ABI, so it should exist.
# If it comes from a package then this system uses packaged base.
if ! pkg -c ${BASEDIR} which /usr/bin/uname >/dev/null; then
return
fi
cat <<EOF
freebsd-update is incompatible with the use of packaged base. Please see
https://wiki.freebsd.org/PkgBase for more information.
EOF
exit 1
}
#### Core functionality -- the actual work gets done here
# Use an SRV query to pick a server. If the SRV query doesn't provide
@ -3541,6 +3561,9 @@ export LC_ALL=C
# Clear environment variables that may affect operation of tools that we use.
unset GREP_OPTIONS
# Disallow use with packaged base.
check_pkgbase
get_params $@
for COMMAND in ${COMMANDS}; do
cmd_${COMMAND}