changeset 7:2712d249c371

Assert that the installed version number we get from "pkg query" is the same as the version in "pkg version"
author Franz Glasner <hg@dom66.de>
date Sun, 22 Oct 2017 14:36:16 +0200
parents 0d9a499e89e9
children 208545b92d43
files bin/check-ports
diffstat 1 files changed, 22 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/bin/check-ports	Thu Oct 19 08:54:24 2017 +0200
+++ b/bin/check-ports	Sun Oct 22 14:36:16 2017 +0200
@@ -4,8 +4,6 @@
 : ${FREEBSD_REPO:=FreeBSD}
 : ${PORTS_DIRECT_INSTALLED_REPO:=unknown-repository}
 
-installed_packages=$(pkg query '%n')
-
 get_remote_repo_versions() {
     _repo="$1"
 
@@ -19,6 +17,24 @@
     local_index_versions=$(pkg version -I -v)
 }
 
+assert_local_version() {
+    _name=$1
+    _version=$2
+    while read _n _v _r ; do
+	if [ ${_name} = ${_n} ] ; then
+	    if [ ${_version} != ${_v} ] ; then
+		return 1
+	    else
+		return 0
+	    fi
+	fi
+    done <<EOF223
+${installed_data}
+EOF223
+    return 2
+}
+
+installed_packages=$(pkg query '%n')
 installed_data="$(pkg query '%n %v %R' $installed_packages)"
 
 get_remote_repo_versions ${LOCAL_REPO}
@@ -29,6 +45,10 @@
     _installed_name=${lfqp%-*}
     _installed_version=${lfqp##*-}
     echo $lfqp ${_installed_name} ${_installed_version} ${llabel}
+    if ! assert_local_version ${_installed_name} ${_installed_version} ; then
+	echo "Assertion failed" >&2
+	exit 1
+    fi
 done <<EOF856661111299999
 ${local_index_versions}
 EOF856661111299999