git: d76ef58d566c - main - freebsd-update: Correctly check if pkg(8) is present

From: Zhenlei Huang <zlei_at_FreeBSD.org>
Date: Thu, 23 May 2024 04:11:14 UTC
The branch main has been updated by zlei:

URL: https://cgit.FreeBSD.org/src/commit/?id=d76ef58d566ccf203b21a1c8fea55985f355d4d2

commit d76ef58d566ccf203b21a1c8fea55985f355d4d2
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2024-05-23 04:10:17 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2024-05-23 04:10:17 +0000

    freebsd-update: Correctly check if pkg(8) is present
    
    On systems without pkg(8) installed, `command -v pkg` will return
    success and falsely report that pkg(8) is present. Fix that by checking
    via the `pkg -N` form.
    
    This is missing from the final revision of D39695.
    
    Reported by:    delphij
    Reviewed by:    fernape, delphij
    Fixes:          bc0c6c9cf3a9 freebsd-update: Add check for kernel modules
    Differential Revision:  https://reviews.freebsd.org/D45292
---
 usr.sbin/freebsd-update/freebsd-update.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/usr.sbin/freebsd-update/freebsd-update.sh b/usr.sbin/freebsd-update/freebsd-update.sh
index fb9924ee60eb..1456601edf26 100644
--- a/usr.sbin/freebsd-update/freebsd-update.sh
+++ b/usr.sbin/freebsd-update/freebsd-update.sh
@@ -667,7 +667,7 @@ upgrade_check_kmod_ports() {
 	local report
 	local w
 
-	if ! command -v pkg >/dev/null; then
+	if ! pkg -N 2>/dev/null; then
 		echo "Skipping kernel modules check. pkg(8) not present."
 		return
 	fi