From b7806f57d548abd034c4ec4baf3ff2f95e14d6bc Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob@freedombone.net>
Date: Wed, 1 Aug 2018 20:34:00 +0100
Subject: [PATCH] Install web admin after apps

---
 src/freedombone                |  1 +
 src/freedombone-installer      |  6 +++++
 src/freedombone-utils-setup    |  3 ---
 src/freedombone-utils-webadmin | 48 +++++++++++++++++++---------------
 4 files changed, 34 insertions(+), 24 deletions(-)

diff --git a/src/freedombone b/src/freedombone
index a737a0614..f1eea0f9a 100755
--- a/src/freedombone
+++ b/src/freedombone
@@ -358,6 +358,7 @@ setup_utils
 setup_email
 setup_web
 setup_apps "$command_options"
+install_web_admin
 setup_final
 
 echo ''
diff --git a/src/freedombone-installer b/src/freedombone-installer
index 057c11efc..51b27f613 100755
--- a/src/freedombone-installer
+++ b/src/freedombone-installer
@@ -93,7 +93,9 @@ do
                 fi
 
                 # Do the initial setup which includes email
+                touch "$webadmin_install_dir/.running_install_command"
                 /usr/local/bin/freedombone -c "$CONFIGURATION_FILE"
+                rm "$webadmin_install_dir/.running_install_command"
             fi
 
             if grep -q 'install_final' "$COMPLETION_FILE"; then
@@ -151,6 +153,10 @@ do
                     rm -rf "$INSTALL_DIR/tempwebadmin"
                 fi
 
+                if [ -f "$webadmin_install_dir/.running_install_command" ]; then
+                    rm "$webadmin_install_dir/.running_install_command"
+                fi
+
                 # restart the web server
                 systemctl restart nginx
             fi
diff --git a/src/freedombone-utils-setup b/src/freedombone-utils-setup
index 9610c1654..63b671fa7 100755
--- a/src/freedombone-utils-setup
+++ b/src/freedombone-utils-setup
@@ -1174,9 +1174,6 @@ function setup_web {
 
     function_check install_web_server_access_control
     install_web_server_access_control
-
-    function_check install_web_admin
-    install_web_admin
 }
 
 function upgrade_apps {
diff --git a/src/freedombone-utils-webadmin b/src/freedombone-utils-webadmin
index 31abcb995..75dc75908 100755
--- a/src/freedombone-utils-webadmin
+++ b/src/freedombone-utils-webadmin
@@ -92,14 +92,16 @@ function web_admin_create_users {
     users_file="$webadmin_install_dir/users.html"
 
     if [ -f "$webadmin_install_dir/.setupscreenactive" ]; then
-        if [ -f "$users_file" ]; then
-            rm "$users_file"
-        fi
-        if [ ! -d "$INSTALL_DIR/tempwebadmin" ]; then
-            mkdir -p "$INSTALL_DIR/tempwebadmin"
+        if [ ! -f "$webadmin_install_dir/.running_install_command" ]; then
+            if [ -f "$users_file" ]; then
+                rm "$users_file"
+            fi
+            if [ ! -d "$INSTALL_DIR/tempwebadmin" ]; then
+                mkdir -p "$INSTALL_DIR/tempwebadmin"
+            fi
+            mv "$webadmin_install_dir/userprofile_"*.html "$INSTALL_DIR/tempwebadmin"
+            return
         fi
-        mv "$webadmin_install_dir/userprofile_"*.html "$INSTALL_DIR/tempwebadmin"
-        return
     fi
 
     ADMIN_USER=$(get_completion_param "Admin user")
@@ -175,14 +177,16 @@ function web_admin_create_add_apps {
 
     appslist_add_filename="$webadmin_install_dir/apps_add.html"
     if [ -f "$webadmin_install_dir/.setupscreenactive" ]; then
-        if [ -f "$appslist_add_filename" ]; then
-            rm "$appslist_add_filename"
-        fi
-        if [ ! -d "$INSTALL_DIR/tempwebadmin" ]; then
-            mkdir -p "$INSTALL_DIR/tempwebadmin"
+        if [ ! -f "$webadmin_install_dir/.running_install_command" ]; then
+            if [ -f "$appslist_add_filename" ]; then
+                rm "$appslist_add_filename"
+            fi
+            if [ ! -d "$INSTALL_DIR/tempwebadmin" ]; then
+                mkdir -p "$INSTALL_DIR/tempwebadmin"
+            fi
+            mv "$webadmin_install_dir/app_add_"*.html "$INSTALL_DIR/tempwebadmin"
+            return
         fi
-        mv "$webadmin_install_dir/app_add_"*.html "$INSTALL_DIR/tempwebadmin"
-        return
     fi
 
     read_config_param DDNS_PROVIDER
@@ -335,14 +339,16 @@ function web_admin_create_installed_apps {
 
     appslist_filename="$webadmin_install_dir/apps.html"
     if [ -f "$webadmin_install_dir/.setupscreenactive" ]; then
-        if [ -f "$appslist_filename" ]; then
-            rm "$appslist_filename"
-        fi
-        if [ ! -d "$INSTALL_DIR/tempwebadmin" ]; then
-            mkdir -p "$INSTALL_DIR/tempwebadmin"
+        if [ ! -f "$webadmin_install_dir/.running_install_command" ]; then
+            if [ -f "$appslist_filename" ]; then
+                rm "$appslist_filename"
+            fi
+            if [ ! -d "$INSTALL_DIR/tempwebadmin" ]; then
+                mkdir -p "$INSTALL_DIR/tempwebadmin"
+            fi
+            mv "$webadmin_install_dir/app_"*.html "$INSTALL_DIR/tempwebadmin"
+            return
         fi
-        mv "$webadmin_install_dir/app_"*.html "$INSTALL_DIR/tempwebadmin"
-        return
     fi
 
     appslist_template_filename="$webadmin_install_dir/apps_template.html"
-- 
GitLab