Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add code to allow pkg_status to also report on chroots and jails from the host system.
Matthew Seaman committed 11 years ago
commit e3ac39b0480f8369613b9df8553bfd8f14517445
parent 8fb732a
1 file changed +71 -6
modified scripts/periodic/400.status-pkg.in
@@ -9,6 +9,75 @@ if [ -r /etc/defaults/periodic.conf ]; then
fi
pkgcmd=@prefix@/sbin/pkg

+
status_pkg() {
+
    local pkgargs
+
    local rc
+

+
    pkgargs="$1"
+

+
    rc=$(${pkgcmd} ${pkgargs} version -v ${pkg_version_index} |
+
	sed -n -e '/up-to-date/d' \
+
	    -e 's/^\([^[:space:]]*\)[[:space:]]*[<>=!?][[:space:]]*\(.*\)$/\1 \2/p' |
+
	tee /dev/stderr |
+
	wc -l)
+

+
    return $rc
+
}
+

+
# Use $pkg_chroots to provide a default list of chroots, and
+
# $pkg_jails to provide a default list of jails (or '*' for all jails)
+
# for all pkg periodic scripts, or set $weekly_pkg_status_chroots and
+
# $weekly_pkg_status_jails for this script only.
+

+
status_pkg_all() {
+
    local rc
+
    local jails
+

+
    : ${weekly_status_pkg_chroots=$pkg_chroots}
+
    : ${weekly_status_pkg_jails=$pkg_jails}
+

+
    # We always show pkg status for the base system but only print a
+
    # banner line if we're also showing status for any chroots or
+
    # jails.
+

+
    if [ -n "${weekly_status_pkg_chroots}" -o \
+
	 -n "${weekly_status_pkg_jails}" ];
+
    then
+
	echo "Host system:"
+
    fi
+

+
    status_pkg ''
+
    [ $? -gt 1 ] && rc=1
+

+
    for c in $weekly_status_pkg_chroots ; do
+
	echo
+
	echo "chroot: $c"
+
	status_pkg "-c $c"
+
	[ $? -gt 1 ] && rc=1
+
    done
+

+
    case $weekly_status_pkg_jails in
+
	\*)
+
	    jails=$(jls -q -h name | sed -e 1d)
+
	    ;;
+
	'')
+
	    jails=
+
	    ;;
+
	*)
+
	    jails=$weekly_status_pkg_jails
+
	    ;;
+
    esac
+

+
    for j in $jails ; do
+
	echo
+
	echo "jail: $j"
+
	status_pkg "-j $j"
+
	[ $? -gt 1 ] && rc=1
+
    done
+

+
    return $rc
+
}
+

# On 9.x or lower, 400.status-pkg exists in the base system, but using
# the old pkg_tools commands.  Unfortunately it uses the same
# configuration variables, so allow the setting of
@@ -31,12 +100,8 @@ case "$weekly_status_pkg_enable" in
	    echo 'status-pkg is enabled but pkg is not used'
	    rc=2
	else
-
		rc=$(${pkgcmd} version -v ${pkg_version_index} |
-
			sed -n -e '/up-to-date/d' \
-
			-e 's/^\([^[:space:]]*\)[[:space:]]*[<>=!?][[:space:]]*\(.*\)$/\1 \2/p' |
-
			tee /dev/stderr |
-
			wc -l)
-
		[ $rc -gt 1 ] && rc=1
+
	    status_pkg_all
+
	    rc=$?
	fi
	;;
	*)