From e6fbcf7db06a2741fc7772b4b431c33e71a76abc Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob@robotics.uk.to>
Date: Fri, 30 Sep 2016 22:50:16 +0100
Subject: [PATCH] Don't reinstall apps which have been removed during updates

---
 src/freedombone-app-gnusocial  |  1 +
 src/freedombone-utils-selector | 55 ++++++++++++++++++++++++++++++++--
 2 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/src/freedombone-app-gnusocial b/src/freedombone-app-gnusocial
index ebe8fb979..67e43d11c 100755
--- a/src/freedombone-app-gnusocial
+++ b/src/freedombone-app-gnusocial
@@ -360,6 +360,7 @@ function remove_gnusocial {
     remove_onion_service microblog ${MICROBLOG_ONION_PORT}
     sed -i '/install_gnusocial/d' $COMPLETION_FILE
     sed -i '/GNU Social /d' $COMPLETION_FILE
+    remove_app gnusocial
 }
 
 function install_gnusocial_main {
diff --git a/src/freedombone-utils-selector b/src/freedombone-utils-selector
index 0cfdb6bfc..2755e53d1 100755
--- a/src/freedombone-utils-selector
+++ b/src/freedombone-utils-selector
@@ -40,6 +40,9 @@ APPS_CHOSEN=()
 # A list of the names of installed apps
 APPS_INSTALLED_NAMES=()
 
+# file containing a list of removed apps
+REMOVED_APPS_FILE=/root/removed
+
 function app_variants {
     filename=$1
     variants_line=$(cat ${filename} | grep "VARIANTS=")
@@ -57,6 +60,40 @@ function item_in_array {
     return 1
 }
 
+function remove_app {
+    app_name=$1
+    if [ ! -f $REMOVED_APPS_FILE ]; then
+        touch $REMOVED_APPS_FILE
+    fi
+    if ! grep -Fxq "$app_name" $REMOVED_APPS_FILE; then
+        echo "$app_name" >> $REMOVED_APPS_FILE
+    fi
+}
+
+function app_is_removed {
+    app_name="$1"
+    if [ ! -f $REMOVED_APPS_FILE ]; then
+        echo "0"
+        return
+    fi
+
+    if ! grep -Fxq "$app_name" $REMOVED_APPS_FILE; then
+        echo "0"
+    else
+        echo "1"
+    fi
+}
+
+function reinstall_app {
+    app_name=$1
+    if [ ! -f $REMOVED_APPS_FILE ]; then
+        return
+    fi
+    if [[ $(app_is_removed $app_name) == "1" ]]; then
+        sed -i "/${app_name}/d" $REMOVED_APPS_FILE
+    fi
+}
+
 function app_is_installed {
     app_name="$1"
 
@@ -213,6 +250,7 @@ function remove_apps {
         if [[ ${APPS_INSTALLED[$app_index]} == "1" ]]; then
             if [[ ${APPS_CHOSEN[$app_index]} == "0" ]]; then
                 echo $"Removing application: ${a}"
+                remove_app ${a}
                 remove_${a}
                 echo $"${a} was removed"
             fi
@@ -246,9 +284,20 @@ function install_apps {
     do
         if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then
             if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then
-                echo $"Installing application: ${a}"
-                install_${a}
-                echo $"${a} was installed"
+                if [ ${is_interactive} ]; then
+                    reinstall_app ${a}
+                    echo $"Installing application: ${a}"
+                    install_${a}
+                    echo $"${a} was installed"
+                else
+                    if [[ $(app_is_removed ${a}) == "0" ]]; then
+                        echo $"Installing application: ${a}"
+                        install_${a}
+                        echo $"${a} was installed"
+                    else
+                        echo $"${a} has been removed and so will not be reinstalled"
+                    fi
+                fi
             fi
         fi
         app_index=$[app_index+1]
-- 
GitLab