diff sbin/fjail @ 346:3b2935985c73

Prepare for some more future compatibility check on FreeBSD updates: implement _has_same_userland_version()
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 05 Dec 2022 09:37:53 +0100
parents 4a17b1f4c378
children 673505e96cea
line wrap: on
line diff
--- a/sbin/fjail	Sat Dec 03 21:46:04 2022 +0100
+++ b/sbin/fjail	Mon Dec 05 09:37:53 2022 +0100
@@ -136,6 +136,35 @@
 }
 
 
+#:
+#: Check whether a FreeBSD version at a given location matches the userland
+#: version of the host where the current process run.
+#:
+#: Args:
+#:   $1: the location where to check for
+#:
+#: Returns:
+#:   0 if the userland versions match, 1 otherwise
+#:
+#: Exit:
+#:   1 on fatal errors (e.g. /bin/freebsd-version not found or errors)
+#:
+_has_same_userland_version() {
+    local directory
+
+    local _host_version _directory_version
+
+    directory="$1"
+
+    _host_version=$(/bin/freebsd-version -u) || exit 1
+    _directory_version=$(chroot "${directory}" /bin/freebsd-version -u) || exit 1
+    if [ "${_host_version%%-*}" = "${_directory_version%%-*}" ]; then
+        return 0
+    fi
+    return 1
+}
+
+
 #
 # "datasets" -- create the ZFS dataset tree
 #