Generalize checking APT/APK package versions

pull/64/head
Michele Locati 2019-12-19 10:14:38 +01:00
parent 0a514973a5
commit c1807e9cfc
No known key found for this signature in database
GPG Key ID: 98B7CE2E7234E28B
1 changed files with 57 additions and 8 deletions

View File

@ -647,6 +647,52 @@ installRequiredPackages () {
esac esac
} }
# Get the version of an installed APT/APK package
#
# Arguments:
# $1: the name of the installed package
#
# Output:
# The numeric part of the package version, with from 1 to 3 numbers
#
# Example:
# 1
# 1.2
# 1.2.3
getInstalledPackageVersion() {
case "$(getDistro)" in
alpine)
apk info "$1" | head -n1 | cut -c $(( ${#1} + 2 ))- | grep -o -E '^[0-9]+(\.[0-9]+){0,2}'
;;
debian)
dpkg-query --showformat='${Version}' --show "$1" 2>/dev/null | grep -o -E '^[0-9]+(\.[0-9]+){0,2}'
;;
esac
}
# Compare two versions
#
# Arguments:
# $1: the first version
# $2: the second version
#
# Output
# -1 if $1 is less than $2
# 0 if $1 is the same as $2
# 1 if $1 is greater than $2
compareVersions() {
compareVersions_v1="$1.0.0"
compareVersions_v2="$2.0.0"
compareVersions_vMin="$(printf '%s\n%s' "${compareVersions_v1}" "${compareVersions_v2}" | sort -t '.' -n -k1,1 -k2,2 -k3,3 | head -n 1)"
if test "$compareVersions_vMin" != "$compareVersions_v1"; then
echo '1'
elif test "$compareVersions_vMin" = "$compareVersions_v2"; then
echo '0'
else
echo '-1'
fi
}
# Install a bundled PHP module given its handle # Install a bundled PHP module given its handle
# #
# Arguments: # Arguments:
@ -902,20 +948,23 @@ installPECLModule () {
fi fi
;; ;;
rdkafka) rdkafka)
installPECLModule_tmp=
case "$(getDistro)" in case "$(getDistro)" in
alpine) alpine)
# lowest version on alpine is 0.9 installPECLModule_tmp='librdkafka'
if test ! -z "$(apk search librdkafka | grep -E '^librdkafka-0.9')"; then
installPECLModule_actual="$2-3.1.3"
fi
;; ;;
debian) debian)
# lowest version on debian is 0.8 (jessie), 0.9 (stretch) installPECLModule_tmp='librdkafka++1'
if test ! -z "$(apt-cache show librdkafka++1 | grep -E -e '^Version: 0.9' -e '^Version: 0.8')"; then
installPECLModule_actual="$2-3.1.3"
fi
;; ;;
esac esac
if test -n "$installPECLModule_tmp"; then
installPECLModule_tmp="$(getInstalledPackageVersion "$installPECLModule_tmp")"
if test -n "$installPECLModule_tmp"; then
if test $(compareVersions "$installPECLModule_tmp" '0.11.0') -lt 0; then
installPECLModule_actual="$2-3.1.3"
fi
fi
fi
;; ;;
redis) redis)
if test $1 -le 506; then if test $1 -le 506; then