changeset 95:e8c422379abb

Do package checks only for jails with compatible (i.e. "equal") userland versions with the host
author Franz Glasner <fzglas.hg@dom66.de>
date Thu, 12 Sep 2019 09:34:02 +0200
parents c9fb9e920a32
children 252223b1cff6
files bin/fpkg
diffstat 1 files changed, 45 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/bin/fpkg	Mon Sep 09 09:43:13 2019 +0200
+++ b/bin/fpkg	Thu Sep 12 09:34:02 2019 +0200
@@ -68,6 +68,31 @@
 : ${UPDATE_FLAGS:=}
 : ${UPGRADE_FLAGS:=}
 : ${SIGN:='===> '}
+: ${SKIPSIGN:='-----> '}
+
+
+has_same_userland_version() {
+    : 'Check whether the jail `_jail` has the same FreeBSD userland version
+    as the host the the current process runs.
+
+    Args:
+        _jail: the running jail to check for
+
+    Returns:
+        0 if the userland versions match, 1 otherwise
+
+    '
+    local _jail _host_version _jail_version
+
+    _jail="$1"
+
+    _host_version=$(/bin/freebsd-version -u) || exit 1
+    _jail_version=$(jexec -l "${_jail}" /bin/freebsd-version -u) || exit 1
+    if [ "${_host_version%%-*}" = "${_jail_version%%-*}" ]; then
+        return 0
+    fi
+    return 1
+}
 
 
 command_audit() {
@@ -79,7 +104,11 @@
     for _j in $(jls -N | awk '{if(NR>1)print $1}' | sort); do
         echo ""
         echo "${SIGN}JAIL: ${_j}"
-        pkg -j "${_j}" audit ${AUDIT_FLAGS}
+        if has_same_userland_version "${_j}"; then
+            pkg -j "${_j}" audit ${AUDIT_FLAGS}
+        else
+            echo "${SKIPSIGN}SKIPPED because of different userland"
+        fi
     done
 }
 
@@ -93,7 +122,11 @@
     for _j in $(jls -N | awk '{if(NR>1)print $1}' | sort); do
         echo ""
         echo "${SIGN}JAIL: ${_j}"
-        pkg -j "${_j}" update ${UPDATE_FLAGS}
+        if has_same_userland_version "${_j}"; then
+            pkg -j "${_j}" update ${UPDATE_FLAGS}
+        else
+            echo "${SKIPSIGN}SKIPPED because of different userland"
+        fi
     done
 }
 
@@ -107,7 +140,11 @@
     for _j in $(jls -N | awk '{if(NR>1)print $1}' | sort); do
         echo ""
         echo "${SIGN}JAIL: ${_j}"
-        pkg -j "${_j}" upgrade ${UPGRADE_FLAGS}
+        if has_same_userland_version "${_j}"; then
+            pkg -j "${_j}" upgrade ${UPGRADE_FLAGS}
+        else
+            echo "${SKIPSIGN}SKIPPED because of different userland"
+        fi
     done
 }
 
@@ -121,7 +158,11 @@
     for _j in $(jls -N | awk '{if(NR>1)print $1}' | sort); do
         echo ""
         echo "${SIGN}JAIL: ${_j}"
-        pkg -j "${_j}" upgrade -n ${UPGRADE_FLAGS}
+        if has_same_userland_version "${_j}"; then
+            pkg -j "${_j}" upgrade -n ${UPGRADE_FLAGS}
+        else
+            echo "${SKIPSIGN}SKIPPED because of different userland"
+        fi
     done
 }