From e552a6f18f2cec88c376223faac3a693f4728d1f Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Mon, 16 Sep 2019 14:26:45 +0200
Subject: [PATCH] customer/bison/core#14 Make variable checks more explicit and
 cleanup code

---
 start.sh | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/start.sh b/start.sh
index 63f0bdb..45e34a5 100755
--- a/start.sh
+++ b/start.sh
@@ -2,6 +2,8 @@
 
 function readEnv {
   if [[ -f ".env" ]]; then
+    # shellcheck disable=SC2046
+    # shellcheck disable=SC2002
     export $(cat .env | xargs) > /dev/null 2>&1
   fi
 }
@@ -19,6 +21,9 @@ function restoreEnvFile {
     echo "COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME}" >>.env
   fi
   if [[ -f ".env" ]]; then
+    # shellcheck disable=SC2046
+    # shellcheck disable=SC2094
+    # shellcheck disable=SC2002
     env -i $(cat .env | xargs) >.env
   fi
 }
@@ -29,9 +34,9 @@ function create {
   fi
   truncateCurrentDirectory
   if [[ -n ${REPOSITORY} ]]; then
-    composer create-project ${PROJECT} . --no-interaction --repository ${REPOSITORY}
+    composer create-project "${PROJECT}" . --no-interaction --repository "${REPOSITORY}"
   else
-    composer create-project ${PROJECT} . --no-interaction
+    composer create-project "${PROJECT}" . --no-interaction
   fi
   restoreEnvFile
 
@@ -51,26 +56,26 @@ function create {
       fi
 
       # Dump database
-      if [[ -n ${L3D_DUMP_DB} ]]; then
+      if [[ $L3D_DUMP_DB -eq 1 ]]; then
         git ignore "/*.sql"
         drush sql:dump --result-file ../db.sql
       fi
 
       # Cleanup
-      if [[ -n ${L3D_CLEANUP} ]]; then
+      if [[ $L3D_CLEANUP -eq 1 ]]; then
         docker-compose stop
         docker-compose rm --force
       fi
     fi
   fi
-  if [[ -n ${L3D_EXIT} ]]; then
+  if [[ $L3D_EXIT -eq 1 ]]; then
     exit
   fi
 }
 
 function clone {
   truncateCurrentDirectory
-  git clone ${REPOSITORY} .
+  git clone "${REPOSITORY}" .
   composer update
   restoreEnvFile
 }
@@ -88,6 +93,7 @@ function initialSetup {
   echo ""
 
   while true; do
+      # shellcheck disable=SC2162
       read -p "Choose an option: " OPTION
       case ${OPTION} in
           0 )
@@ -108,13 +114,16 @@ function initialSetup {
             ;;
 
           3 )
+            # shellcheck disable=SC2162
             read -p "Custom project template: " PROJECT
+            # shellcheck disable=SC2162
             read -p "Repository URL (optional): " REPOSITORY
             create
             break
             ;;
 
           4 )
+            # shellcheck disable=SC2162
             read -p "Repository URL: " REPOSITORY
             if [[ -n "${REPOSITORY}" ]]; then
               clone
@@ -131,7 +140,7 @@ function initialSetup {
 
 readEnv
 EXISTING=$(ls -1)
-if [[ ! -n "$EXISTING" ]]; then
+if [[ -z "$EXISTING" ]]; then
   if [[ -n ${PROJECT} ]]; then
     create
   elif [[ -n ${REPOSITORY} ]]; then
-- 
GitLab