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
Fixes: cf1aba2857 ("freebsd-update: refuse to operate on a pkgbase system")
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D47378
This commit is contained in:
Ed Maste
2024-10-31 22:13:44 -04:00
parent 5e5e4e1cf0
commit 856e158dc4
+7 -6
View File
@@ -1107,12 +1107,13 @@ check_pkgbase()
if ! pkg -c ${BASEDIR} -N >/dev/null 2>/dev/null; then if ! pkg -c ${BASEDIR} -N >/dev/null 2>/dev/null; then
return return
fi fi
# Presence of FreeBSD-* package(s) indicates packaged base. # uname(1) is used by pkg to determine ABI, so it should exist.
if ! pkg -c ${BASEDIR} info -q -x '^FreeBSD' 2>/dev/null; then # If it comes from a package then this system uses packaged base.
if ! pkg -c ${BASEDIR} which /usr/bin/uname >/dev/null; then
return return
fi fi
cat <<EOF cat <<EOF
FreeBSD-update is incompatible with the use of packaged base. Please see freebsd-update is incompatible with the use of packaged base. Please see
https://wiki.freebsd.org/PkgBase for more information. https://wiki.freebsd.org/PkgBase for more information.
EOF EOF
exit 1 exit 1
@@ -3536,7 +3537,6 @@ cmd_cron () {
# Fetch files for upgrading to a new release. # Fetch files for upgrading to a new release.
cmd_upgrade () { cmd_upgrade () {
check_pkgbase
finalize_components_config ${COMPONENTS} finalize_components_config ${COMPONENTS}
upgrade_check_params upgrade_check_params
upgrade_check_kmod_ports upgrade_check_kmod_ports
@@ -3571,7 +3571,6 @@ cmd_updatesready () {
# Install downloaded updates. # Install downloaded updates.
cmd_install () { cmd_install () {
check_pkgbase
finalize_components_config ${COMPONENTS} finalize_components_config ${COMPONENTS}
install_check_params install_check_params
install_create_be install_create_be
@@ -3580,7 +3579,6 @@ cmd_install () {
# Rollback most recently installed updates. # Rollback most recently installed updates.
cmd_rollback () { cmd_rollback () {
check_pkgbase
finalize_components_config ${COMPONENTS} finalize_components_config ${COMPONENTS}
rollback_check_params rollback_check_params
rollback_run || exit 1 rollback_run || exit 1
@@ -3617,6 +3615,9 @@ export LC_ALL=C
# Clear environment variables that may affect operation of tools that we use. # Clear environment variables that may affect operation of tools that we use.
unset GREP_OPTIONS unset GREP_OPTIONS
# Disallow use with packaged base.
check_pkgbase
get_params $@ get_params $@
for COMMAND in ${COMMANDS}; do for COMMAND in ${COMMANDS}; do
cmd_${COMMAND} cmd_${COMMAND}