From 827081f8a280742ff7309515f476002717c18c1b Mon Sep 17 00:00:00 2001 From: Takashi Yoshi Date: Fri, 7 Dec 2018 17:32:43 +0100 Subject: [PATCH] [type/__package_pkg_openbsd/explorer/pkg_version] Fix version extraction The earlier code stripped away all non-numeric parts of the version number. E.g. "5.6.38p0" would be trimmed to "5.6.38" --- .../type/__package_pkg_openbsd/explorer/pkg_version | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cdist/conf/type/__package_pkg_openbsd/explorer/pkg_version b/cdist/conf/type/__package_pkg_openbsd/explorer/pkg_version index 212f0d96..71fccb42 100755 --- a/cdist/conf/type/__package_pkg_openbsd/explorer/pkg_version +++ b/cdist/conf/type/__package_pkg_openbsd/explorer/pkg_version @@ -19,7 +19,7 @@ # along with cdist. If not, see . # # -# Retrieve the status of a package - parsed dpkg output +# Retrieve the status of a package - parsed pkg_info output # if [ -f "$__object/parameter/name" ]; then @@ -28,5 +28,10 @@ else name="$__object_id" fi -#TODO: Is there a better way? -pkg_info | grep "^$name-[0-9]" | sed 's|.*\(-[0-9][0-9.]*\).*|\1|' | sed 's/-//' +# Extract version number from pkg_info. +# Refer to packages-specs(7) for more information regarding the format. + +# ATTENTION: If $name is just a stem (e.g. "php" or "python"), there may be +# multiple results. pkg_info prints a line for each version. + +pkg_info -q -I "inst:$name" | sed -e 's/^\([^-]*-\)*\([0-9][^-]*\).*$/\2/'