From ad1209a73b16f66c108056471da7703e4d57c8b0 Mon Sep 17 00:00:00 2001
From: Htylol <dixperm909@yandex.ru>
Date: Thu, 26 Sep 2024 03:18:19 +0500
Subject: [PATCH] Update edit_db_from_gui

---
 data_from_portwine/scripts/functions_helper | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/data_from_portwine/scripts/functions_helper b/data_from_portwine/scripts/functions_helper
index ddc59962..76e6bdf9 100755
--- a/data_from_portwine/scripts/functions_helper
+++ b/data_from_portwine/scripts/functions_helper
@@ -1933,17 +1933,9 @@ edit_db_from_gui () {
     if [[ -n "$PORTWINE_DB_FILE" ]] \
     && [[ -f "$PORTWINE_DB_FILE" ]]
     then
-        for mod_db in $@ ; do
-            if ! grep "export ${mod_db}=" "${PORTWINE_DB_FILE}" &>/dev/null
-            then echo "export ${mod_db}=\"${!mod_db}\"" >> "${PORTWINE_DB_FILE}"
-            elif grep "export ${mod_db}=" "${PORTWINE_DB_FILE}" | grep -v "#" &>/dev/null
-            then
-                if [[ "$(grep "export ${mod_db}=" "${PORTWINE_DB_FILE}" | grep -v "#")" != "export ${mod_db}=\"${!mod_db}\"" ]]
-                then sed -ri "s|^export ${mod_db}=.*|export ${mod_db}=\"${!mod_db}\"|" "${PORTWINE_DB_FILE}"
-                fi
-            elif [[ "$(grep "export ${mod_db}=" "${PORTWINE_DB_FILE}")" != "export ${mod_db}=${!mod_db}" ]]
-            then sed -ri "s|.*export ${mod_db}=.*|export ${mod_db}=\"${!mod_db}\"|g" "${PORTWINE_DB_FILE}"
-            fi
+        for mod_db in "$@" ; do
+            grep -q "export ${mod_db}=" "${PORTWINE_DB_FILE}" || echo "export ${mod_db}=\"${!mod_db}\"" >> "${PORTWINE_DB_FILE}"
+            sed -i "s|^export ${mod_db}=.*|export ${mod_db}=\"${!mod_db}\"|" "${PORTWINE_DB_FILE}"
         done
     fi
     return 0