From c26c423e18930e14064b6b1aea185bff2e04e5b4 Mon Sep 17 00:00:00 2001
From: dmitry <dmitry.puzyrkov@demlabs.net>
Date: Thu, 13 Jul 2023 23:39:53 +0700
Subject: [PATCH] [*] write dpkg-new cfg if minor vesion is ok

---
 os/debian/postinst | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/os/debian/postinst b/os/debian/postinst
index a34fa9167..f79eb82bb 100755
--- a/os/debian/postinst
+++ b/os/debian/postinst
@@ -1,10 +1,29 @@
 #!/bin/bash -e
 . /usr/share/debconf/confmodule
 
+
+
 DAP_CHAINS_NAME="cellframe"
 DAP_APP_NAME="$DAP_CHAINS_NAME-node"
 DAP_PREFIX="/opt/$DAP_APP_NAME"
 
+new_ver=$(dpkg-query --show --showformat='${Version}' $DAP_APP_NAME)
+old_ver="$2"
+
+echo "New version: $new_ver"
+echo "Old version: $old_ver"
+
+OLD_MINOR=( $( printf "%s\n"  "$old_ver" | cut -c 3-3 | sort -nr) )
+NEW_MINOR=( $( printf "%s\n"  "$new_ver" | cut -c 3-3 | sort -nr) )
+
+
+if (( NEW_MINOR > OLD_MINOR )); then
+    echo "Need update cellframe-node configs..."
+else
+    echo "No need to update cellframe-node configs, write as new"
+fi
+
+
 DAP_CFG_TPL="$DAP_PREFIX/share/configs/$DAP_APP_NAME.cfg.tpl"
 
 # Store write config to new if present smth
@@ -16,7 +35,13 @@ DAP_CFG="$DAP_PREFIX/etc/$DAP_APP_NAME.cfg"
 
 # Init node config
 if [ -e "$DAP_CFG" ]; then
-    DAP_CFG="$DAP_PREFIX/etc/$DAP_APP_NAME.cfg.dpkg-new"
+    if (( NEW_MINOR > OLD_MINOR )); then
+        echo "Need update cellframe-node.cfg ..."
+        DAP_CFG="$DAP_PREFIX/etc/$DAP_APP_NAME.cfg"
+    else
+        echo "No need to update cellframe-node.cfg, write as new"
+        DAP_CFG="$DAP_PREFIX/etc/$DAP_APP_NAME.cfg.dpkg-new"
+    fi
 else
     DAP_CFG="$DAP_PREFIX/etc/$DAP_APP_NAME.cfg"
 fi
@@ -175,8 +200,15 @@ if [ "$RET" = "true" ]; then
     DAP_CFG_NET="$DAP_PREFIX/etc/network/$NET_NAME.cfg"
     DAP_CFG_NET_TPL="$DAP_PREFIX/share/configs/network/$NET_NAME.cfg.tpl"
     DAP_NET_CFG=""
+
     if [ -e "$DAP_CFG_NET" ]; then
-        DAP_NET_CFG="$DAP_PREFIX/etc/network/$NET_NAME.cfg.dpkg-new"
+        if (( NEW_MINOR > OLD_MINOR )); then
+            echo "Need update Backbone.cfg ..."
+            DAP_NET_CFG="$DAP_PREFIX/etc/network/$NET_NAME.cfg"
+        else
+            echo "No need to update Backbone.cfg, write as new"
+            DAP_NET_CFG="$DAP_PREFIX/etc/network/$NET_NAME.cfg.dpkg.new"
+        fi
     else
         DAP_NET_CFG="$DAP_PREFIX/etc/network/$NET_NAME.cfg"
     fi
-- 
GitLab