From 55446a0bf859abeae55e4c4a624e5feb80278a4a Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob@freedombone.net>
Date: Sat, 31 Mar 2018 13:46:34 +0100
Subject: [PATCH] Remove directory if it already exists

---
 src/freedombone-app-bludit | 29 ++++++++++++++---------------
 src/freedombone-template   | 30 +++++++++++++++---------------
 2 files changed, 29 insertions(+), 30 deletions(-)

diff --git a/src/freedombone-app-bludit b/src/freedombone-app-bludit
index 974844a5c..871655e08 100755
--- a/src/freedombone-app-bludit
+++ b/src/freedombone-app-bludit
@@ -217,23 +217,22 @@ function install_bludit {
     apt-get -yq install php-gettext php-curl php-gd php-mysql git curl
     apt-get -yq install memcached php-memcached php-intl exiftool libfcgi0ldbl
 
-    if [ ! -d "/var/www/$BLUDIT_DOMAIN_NAME" ]; then
-        mkdir "/var/www/$BLUDIT_DOMAIN_NAME"
+    if [ -d "/var/www/$BLUDIT_DOMAIN_NAME/htdocs" ]; then
+        rm -rf "/var/www/$BLUDIT_DOMAIN_NAME/htdocs"
     fi
-    if [ ! -d "/var/www/$BLUDIT_DOMAIN_NAME/htdocs" ]; then
-        if [ -d /repos/bludit ]; then
-            mkdir "/var/www/$BLUDIT_DOMAIN_NAME/htdocs"
-            cp -r -p /repos/bludit/. "/var/www/$BLUDIT_DOMAIN_NAME/htdocs"
-            cd "/var/www/$BLUDIT_DOMAIN_NAME/htdocs" || exit 324687356
-            git pull
-        else
-            git_clone $BLUDIT_REPO "/var/www/$BLUDIT_DOMAIN_NAME/htdocs"
-        fi
 
-        if [ ! -d "/var/www/$BLUDIT_DOMAIN_NAME/htdocs" ]; then
-            echo $'Unable to clone bludit repo'
-            exit 87525
-        fi
+    if [ -d /repos/bludit ]; then
+        mkdir "/var/www/$BLUDIT_DOMAIN_NAME/htdocs"
+        cp -r -p /repos/bludit/. "/var/www/$BLUDIT_DOMAIN_NAME/htdocs"
+        cd "/var/www/$BLUDIT_DOMAIN_NAME/htdocs" || exit 324687356
+        git pull
+    else
+        git_clone $BLUDIT_REPO "/var/www/$BLUDIT_DOMAIN_NAME/htdocs"
+    fi
+
+    if [ ! -d "/var/www/$BLUDIT_DOMAIN_NAME/htdocs" ]; then
+        echo $'Unable to clone bludit repo'
+        exit 87525
     fi
 
     cd "/var/www/$BLUDIT_DOMAIN_NAME/htdocs" || exit 36587356
diff --git a/src/freedombone-template b/src/freedombone-template
index 8a5d7ded6..f367a83c3 100755
--- a/src/freedombone-template
+++ b/src/freedombone-template
@@ -593,27 +593,28 @@ if [[ "$app_php" == 'yes' ]]; then
     echo '    apt-get -yq install memcached php-memcached php-intl exiftool libfcgi0ldbl'
     echo ''
 fi
-echo "    if [ ! -d \"/var/www/\$${app_name_upper}_DOMAIN_NAME\" ]; then"
-echo "        mkdir \"/var/www/\$${app_name_upper}_DOMAIN_NAME\""
+
+echo "    if [ -d \"/var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs\" ]; then"
+echo "        rm -rf \"/var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs\""
 echo '    fi'
-echo "    if [ ! -d \"/var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs\" ]; then"
-echo "        if [ -d /repos/${app_name} ]; then"
-echo "            mkdir \"/var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs\""
+
+echo "      if [ -d /repos/${app_name} ]; then"
+echo "          mkdir \"/var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs\""
 if [ ! "$app_dir" ]; then
-    echo "            cp -r -p /repos/${app_name}/. \"/var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs\""
-    echo "            cd \"/var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs\" || exit 324687356"
+    echo "          cp -r -p /repos/${app_name}/. \"/var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs\""
+    echo "          cd \"/var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs\" || exit 324687356"
 else
-    echo "            cp -r -p /repos/${app_name}/. \"${app_dir}\""
-    echo "            cd \"${app_dir}\" || exit 36487365"
+    echo "          cp -r -p /repos/${app_name}/. \"${app_dir}\""
+    echo "          cd \"${app_dir}\" || exit 36487365"
 fi
-echo '            git pull'
-echo '        else'
+echo '          git pull'
+echo '      else'
 if [ ! "$app_dir" ]; then
-    echo "            git_clone \$${app_name_upper}_REPO \"/var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs\""
+    echo "          git_clone \$${app_name_upper}_REPO \"/var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs\""
 else
-    echo "            git_clone \$${app_name_upper}_REPO \"${app_dir}\""
+    echo "          git_clone \$${app_name_upper}_REPO \"${app_dir}\""
 fi
-echo '        fi'
+echo '      fi'
 echo ''
 if [ ! "$app_dir" ]; then
     echo "        if [ ! -d \"/var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs\" ]; then"
@@ -623,7 +624,6 @@ fi
 echo "            echo \$'Unable to clone ${app_name} repo'"
 echo '            exit 87525'
 echo '        fi'
-echo '    fi'
 echo ''
 if [ ! "$app_dir" ]; then
     echo "    cd \"/var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs\" || exit 36587356"
-- 
GitLab