Modify version check during package upgrade 40/34940/6
authorPawel Wieczorek <p.wieczorek2@samsung.com>
Wed, 4 Feb 2015 11:11:19 +0000 (12:11 +0100)
committerPawel Wieczorek <p.wieczorek2@samsung.com>
Tue, 24 Feb 2015 15:02:32 +0000 (16:02 +0100)
Cynara has to determine its currently installed version during package
upgrade. Doing RPM queries from inside install-time scripts isn't
recommended. Necessary information is obtained from Cynara's version
information.

However, not all Cynara releases provided mechanism of reporting its
version. In case of lack of it, following fallback mechanism is
provided: version information is extracted from a name of a file that
Cynara depends on, which currently is
"<libdir>/libcynara-commons.so.<version>".

Change-Id: I5c9a2abf123d91a32513980e3f9c24112d59547c

packaging/cynara.spec

index 2eb9a23..bc51ae6 100644 (file)
@@ -225,9 +225,26 @@ if [ $? -eq 1 ]; then
 fi
 
 if [ $1 -gt 1 ] ; then
-    OLDVERSION="$(rpm -q --qf '%%{version}' %{name})"
-    %{_sbindir}/cynara/cynara-db-migration.sh upgrade -f ${OLDVERSION} -t %{version}
+    # upgrade
+    OLD_VERSION=""
+    VERSION_INDICATOR="$(ls %{_libdir}/libcynara-commons\.so\.*\.*\.*)"
+    if [ -z "${VERSION_INDICATOR}" ] ; then
+        # For releases which dropped "%{_libdir}/libcynara-commons\.so\.*" file
+        OLD_VERSION="$(/usr/bin/cynara --version)"
+    else
+        VERSION="${VERSION_INDICATOR##*so\.}"
+        SIGNIFICANT="${VERSION%\.*}"
+        if [ 0 -eq "${SIGNIFICANT%%\.*}" -a 5 -ge "${SIGNIFICANT##*\.}" ] ; then
+            # For releases which did not provide "--version" functionality
+            OLD_VERSION="${VERSION}"
+        else
+            OLD_VERSION="$(/usr/bin/cynara --version)"
+        fi
+    fi
+
+    %{_sbindir}/cynara/cynara-db-migration.sh upgrade -f ${OLD_VERSION} -t %{version}
 else
+    # install
     %{_sbindir}/cynara/cynara-db-migration.sh install -t %{version}
 fi