From 62703db0dfd426f01da19d91b6ca401e844424da Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Thu, 3 Jan 2019 16:45:03 +0100
Subject: [PATCH] #11 New script in the container to start a new project which
 gets executed automatically when working directory is empty

---
 Dockerfile        |  3 ++-
 l3d               |  8 ++++++-
 start-new-project | 61 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+), 2 deletions(-)
 create mode 100755 start-new-project

diff --git a/Dockerfile b/Dockerfile
index ed085ba..3ea3d8b 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -4,13 +4,14 @@ FROM registry.lakedrops.com/docker/gitlab-drupal-ci:php-${PHP_VERSION}
 
 LABEL com.example.vendor="LakeDrops" \
       maintainer="juergen.haas@lakedrops.com" \
-      version="1.2.0" \
+      version="1.2.1" \
       description="Drupal development environment from LakeDrops."
 
 ENV LAKEDROPS_DEV_ENV 1
 ENV LAKEDROPS_DEV_DC_OPTIONS " "
 
 ADD config.fish /etc/fish/
+ADD start-new-project /usr/local/bin/
 
 RUN echo "Install dorgflow" && \
     cd /var/opt && \
diff --git a/l3d b/l3d
index 50357a6..a3ff1f1 100755
--- a/l3d
+++ b/l3d
@@ -97,7 +97,13 @@ function start {
         --restart unless-stopped \
         registry.lakedrops.com/docker/l3d:php-${PHP_VERSION}
     fi
-    docker exec -it ${COMPOSE_PROJECT_NAME}_l3d /usr/bin/fish
+
+    EXISTING=$(ls -1)
+    if [[ -n "$EXISTING" ]]; then
+      docker exec -it ${COMPOSE_PROJECT_NAME}_l3d /usr/bin/fish
+    else
+      docker exec -it ${COMPOSE_PROJECT_NAME}_l3d /usr/local/bin/start-new-project
+    fi
   fi
 }
 
diff --git a/start-new-project b/start-new-project
new file mode 100755
index 0000000..7aca5de
--- /dev/null
+++ b/start-new-project
@@ -0,0 +1,61 @@
+#!/usr/bin/env bash
+
+EXISTING=$(ls -1)
+if [[ -n "$EXISTING" ]]; then
+  exit
+fi
+
+echo "Lets start a new project here ..."
+echo ""
+echo "Options to start:"
+echo "    1   LakeDrops Drupal 8 project template"
+echo "    2   Drupal's community project template"
+echo "    3   Existing git repository"
+echo ""
+echo ""
+
+function truncateCurrentDirectory {
+  if [[ -f ".env" ]]; then
+    export $(cat .env | xargs) > /dev/null 2>&1
+  fi
+  rm .* > /dev/null 2>&1
+}
+
+function create {
+  truncateCurrentDirectory
+  composer create-project ${PROJECT} . --no-interaction
+}
+
+while true; do
+    read -p "Choose an option: " OPTION
+    case ${OPTION} in
+
+        1 )
+          PROJECT="lakedrops/d8-project"
+          create
+          break
+          ;;
+
+        2 )
+          PROJECT="drupal-composer/drupal-project:8.x-dev"
+          create
+          break
+          ;;
+
+        3 )
+          read -p "Repository URL: " REPOSITORY
+          if [[ -n "${REPOSITORY}" ]]; then
+            truncateCurrentDirectory
+            git clone ${REPOSITORY} .
+            composer update
+            break
+          fi
+          ;;
+
+        * )
+          echo "Please try again."
+          ;;
+    esac
+done
+
+/usr/bin/fish
-- 
GitLab