Skip to content
Snippets Groups Projects
start.sh 7.62 KiB
Newer Older
  • Learn to ignore specific revisions
  • function l3dComposer {
      php /usr/local/bin/.l3dComposer.php
    }
    
    
    jurgenhaas's avatar
    jurgenhaas committed
    function permissions {
      chmod -R g+w .
    }
    
    
      if [[ -f "${HOME}/.env" ]]; then
        # shellcheck disable=SC2046
        # shellcheck disable=SC2002
        export $(cat ${HOME}/.env | xargs) > /dev/null 2>&1
      fi
    
        # shellcheck disable=SC2046
        # shellcheck disable=SC2002
    
        export $(cat .env | xargs) > /dev/null 2>&1
      fi
    
      rm .* > /dev/null 2>&1
    }
    
    function restoreEnvFile {
    
      if [[ "${COMPOSE_PROJECT_NAME}" == "." ]]; then
        return
      fi
    
      if [[ -n ${PHP_VERSION} ]]; then
        echo "PHP_VERSION=${PHP_VERSION}" >>.env
      fi
      if [[ -n ${COMPOSE_PROJECT_NAME} ]]; then
        echo "COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME}" >>.env
      fi
    
      if [[ -n ${COMPOSER_DOWNGRADE} ]]; then
        echo "COMPOSER_DOWNGRADE=${COMPOSER_DOWNGRADE}" >>.env
      fi
    
        # shellcheck disable=SC2046
        # shellcheck disable=SC2094
        # shellcheck disable=SC2002
    
        env -i $(cat .env | xargs) >.env
      fi
    }
    
    function create {
    
      if [[ -f ".init_site.json" ]]; then
        mv .init_site.json /tmp/init_site.json
      fi
    
        composer create-project "${PROJECT}" ./ --no-interaction --repository "${REPOSITORY}"
    
        composer create-project "${PROJECT}" ./ --no-interaction
    
    jurgenhaas's avatar
    jurgenhaas committed
      permissions
    
        # Start container
        a d4d up
        sleep 2
        drush --no-interaction si ${SITE_INSTALL_ARGS}
    
        # Init site config values
        if [[ -f "drush/Commands/dev_modules/dev_modules.info.yml" ]]; then
          if [[ -f "/tmp/init_site.json" ]]; then
            mv /tmp/init_site.json web/.init_site.json
            drush site:init .init_site.json
            rm web/.init_site.json
    
        # Dump database
        if [[ $L3D_DUMP_DB -eq 1 ]]; then
          git ignore "/*.sql"
          drush sql:dump --result-file ../db.sql
        fi
    
        drush -y cex
        # shellcheck disable=SC2035
        git add *
        git add .*
        git commit -am "After site install"
    
        # Push to remote git repository
        if [[ -n ${L3D_GIT_REMOTE} ]]; then
          git remote add origin "$L3D_GIT_REMOTE"
          git push -u origin main
        fi
    
        # Cleanup
        if [[ $L3D_CLEANUP -eq 1 ]]; then
          docker compose stop
          docker compose rm --force -v
    
    jurgenhaas's avatar
    jurgenhaas committed
      composer create-project
      permissions
    
      echo "Lets start a new project here ..."
      echo ""
      echo "Options to start:"
    
      echo "    0   none: start with an empty container"
    
    jurgenhaas's avatar
    jurgenhaas committed
      echo "    1   LakeDrops Drupal 10 project template"
      echo "    2   LakeDrops Drupal 9 project template"
      echo "    3   LakeDrops Drupal 8 project template"
      echo "    4   drupal.org recommended project template (Drupal 10)"
      echo "    5   drupal.org recommended project template (Drupal 9)"
      echo "    6   Drupal's community project template (Drupal 8)"
      echo "    7   Custom project template"
      echo "    8   Existing git repository"
    
          read -p "Choose an option: " OPTION
          case ${OPTION} in
    
    jurgenhaas's avatar
    jurgenhaas committed
                PROJECT="lakedrops/d10-project"
    
                SITE_INSTALL_ARGS="--existing-config"
    
    jurgenhaas's avatar
    jurgenhaas committed
                PROJECT="lakedrops/d9-project"
                SITE_INSTALL_ARGS="--existing-config"
    
    jurgenhaas's avatar
    jurgenhaas committed
                PROJECT="lakedrops/d8-project"
                SITE_INSTALL_ARGS="config_installer"
    
    jurgenhaas's avatar
    jurgenhaas committed
                PROJECT="drupal/recommended-project:^10"
    
    jurgenhaas's avatar
    jurgenhaas committed
                PROJECT="drupal/recommended-project:^9"
                create
                break
                ;;
    
              6 )
                PROJECT="drupal-composer/drupal-project:8.x-dev"
                create
                break
                ;;
    
              7 )
    
                read -p "Custom project template: " PROJECT
    
                read -p "Repository URL (optional): " REPOSITORY
                create
                break
                ;;
    
    
    jurgenhaas's avatar
    jurgenhaas committed
              8 )
    
                read -p "Repository URL: " REPOSITORY
                if [[ -n "${REPOSITORY}" ]]; then
    
    function setupAhoy {
      if [[ ! -f .ahoy.yml ]]; then
        echo "ahoyapi: v2" >.ahoy.yml
    
        echo "commands:" >>.ahoy.yml
    
    jurgenhaas's avatar
    jurgenhaas committed
      if [[ ! -L .ahoy.l3d ]]; then
    
        ln -s /etc/ahoy .ahoy.l3d
    
      fi
      if [[ -f .gitignore ]]; then
    
        EXISTING=$(cat .gitignore | grep "^/.ahoy.l3d$")
    
        if [[ -z ${EXISTING} ]]; then
    
          echo "/.ahoy.l3d" >>.gitignore
    
      EXISTING=$(cat .ahoy.yml | grep "^  changelog:")
    
      if [[ -z ${EXISTING} ]]; then
        echo "  changelog:" >>.ahoy.yml
        echo "    imports:" >>.ahoy.yml
    
    jurgenhaas's avatar
    jurgenhaas committed
        echo "      - ./.ahoy.l3d/changelog.yml" >>.ahoy.yml
    
        echo "    usage: Changelog tools." >>.ahoy.yml
    
    if [[ -n ${PHP_VERSION} ]]; then
      echo "PHP_VERSION=${PHP_VERSION}" >>.env
    fi
    
    # Validate PHP version
    INSTALLED_PHP_VERSION=$(php -r "echo(substr(phpversion(),0,3));")
    if [[ "$INSTALLED_PHP_VERSION" != "$PHP_VERSION" ]]; then
    
      echo -e "\\033[31m ===================================================== \\033[0m"
    
      echo -e "\\033[31m ERROR: PHP $INSTALLED_PHP_VERSION installed but $PHP_VERSION expected !!! \\033[0m"
    
      echo -e "\\033[31m ===================================================== \\033[0m"
    
      if [[ "${COMPOSE_PROJECT_NAME}" != "." ]]; then
    
        echo -e "\\033[31m Killed the outdated container, please start again !!! \\033[0m"
        echo -e "\\033[31m ===================================================== \\033[0m"
    
        docker rm -f ${COMPOSE_PROJECT_NAME}_l3d
    
    if [[ "$COMPOSER_DOWNGRADE" == "1" ]]; then
      composer self-update --1
    fi
    
      if [[ -n ${PROJECT} ]]; then
        create
      elif [[ -n ${REPOSITORY} ]]; then
        clone
      else
        initialSetup
      fi
    
    if [[ -d /drupal/.idea ]]; then
      /usr/local/bin/.configIdea
    fi
    
    restoreEnvFile
    
    if [[ "${COMPOSE_PROJECT_NAME}" != "." ]]; then
      # Setup Ahoy
      setupAhoy
      # Configure Git Hook
      if [[ -d .git ]]; then
        if [[ ! -d .git/hooks ]]; then
          mkdir -p .git/hooks
        fi
        if [[ ! -f .git/hooks/post-checkout ]]; then
          echo "#!/bin/sh" > .git/hooks/post-checkout
          chmod +x .git/hooks/post-checkout
        fi
        OLDCOMMAND='docker exec '${COMPOSE_PROJECT_NAME}'_l3d /usr/local/bin/update-env'
        NEWCOMMAND='RUNNING=$(docker container ls --all -q -f name='${COMPOSE_PROJECT_NAME}'_l3d);if [ "x$RUNNING" != "x" ];then docker exec '${COMPOSE_PROJECT_NAME}'_l3d /usr/local/bin/update-env;fi'
        OLD_HOOK_DEFINED=$(grep "$OLDCOMMAND" .git/hooks/post-checkout)
        NEW_HOOK_DEFINED=$(grep "$NEWCOMMAND" .git/hooks/post-checkout)
        if [[ "x$OLD_HOOK_DEFINED" = "x" ]]; then
          echo "$NEWCOMMAND" >> .git/hooks/post-checkout
        elif [[ "x$NEW_HOOK_DEFINED" = "x" ]]; then
          OLDCOMMAND="${OLDCOMMAND//\//\\/}"
          sed -i -e "/${OLDCOMMAND}/d" .git/hooks/post-checkout
          echo "$NEWCOMMAND" >> .git/hooks/post-checkout
        fi
    
    
    if [[ -x "${L3DSHELL}" ]]; then
      ${L3DSHELL}
    else
      /usr/bin/fish
    fi