Generalize checking APT/APK package versions
parent
0a514973a5
commit
c1807e9cfc
|
@ -647,6 +647,52 @@ installRequiredPackages () {
|
|||
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
|
||||
#
|
||||
# Arguments:
|
||||
|
@ -902,20 +948,23 @@ installPECLModule () {
|
|||
fi
|
||||
;;
|
||||
rdkafka)
|
||||
installPECLModule_tmp=
|
||||
case "$(getDistro)" in
|
||||
alpine)
|
||||
# lowest version on alpine is 0.9
|
||||
if test ! -z "$(apk search librdkafka | grep -E '^librdkafka-0.9')"; then
|
||||
installPECLModule_actual="$2-3.1.3"
|
||||
fi
|
||||
installPECLModule_tmp='librdkafka'
|
||||
;;
|
||||
debian)
|
||||
# lowest version on debian is 0.8 (jessie), 0.9 (stretch)
|
||||
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
|
||||
installPECLModule_tmp='librdkafka++1'
|
||||
;;
|
||||
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)
|
||||
if test $1 -le 506; then
|
||||
|
|
Loading…
Reference in New Issue