Newer
Older

jurgenhaas
committed
#!/bin/bash
function l3dComposer {
php /usr/local/bin/.l3dComposer.php
}
function readEnv {

jurgenhaas
committed
if [[ -f ".env" ]]; then
# shellcheck disable=SC2046
# shellcheck disable=SC2002

jurgenhaas
committed
export $(cat .env | xargs) > /dev/null 2>&1
fi
}
function truncateCurrentDirectory {
readEnv

jurgenhaas
committed
rm .* > /dev/null 2>&1
}
function restoreEnvFile {
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 [[ -f ".env" ]]; then
# shellcheck disable=SC2046
# shellcheck disable=SC2094
# shellcheck disable=SC2002

jurgenhaas
committed
env -i $(cat .env | xargs) >.env
fi
}
function create {

jurgenhaas
committed
if [[ -f ".init_site.json" ]]; then
mv .init_site.json /tmp/init_site.json
fi

jurgenhaas
committed
truncateCurrentDirectory
if [[ -n ${REPOSITORY} ]]; then

jurgenhaas
committed
composer create-project "${PROJECT}" ./ --no-interaction --repository "${REPOSITORY}"
else

jurgenhaas
committed
composer create-project "${PROJECT}" ./ --no-interaction
fi
l3dComposer

jurgenhaas
committed
restoreEnvFile
if [[ -f "docker-compose.yml" ]]; then
if [[ -f "web/profiles/contrib/config_installer/config_installer.info.yml" ]]; then
# Start container
a d4d up
sleep 2
drush --no-interaction si config_installer
# Init site config values
if [[ -f "drush/Commands/dev_modules/dev_modules.info.yml" ]]; then

jurgenhaas
committed
if [[ -f "/tmp/init_site.json" ]]; then

jurgenhaas
committed
mv /tmp/init_site.json web/.init_site.json
drush site:init .init_site.json
rm web/.init_site.json
fi
fi
# 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"

jurgenhaas
committed
# Push to remote git repository
if [[ -n ${L3D_GIT_REMOTE} ]]; then
git remote add origin "$L3D_GIT_REMOTE"

jurgenhaas
committed
fi
# Cleanup
if [[ $L3D_CLEANUP -eq 1 ]]; then
docker-compose stop
docker-compose rm --force -v
fi
fi
fi
if [[ $L3D_EXIT -eq 1 ]]; then
exit
fi

jurgenhaas
committed
}
function clone {
truncateCurrentDirectory
git clone "${REPOSITORY}" .
l3dComposer
composer update
restoreEnvFile
}
function initialSetup {

jurgenhaas
committed
echo "Lets start a new project here ..."
echo ""
echo "Options to start:"
echo " 0 none: start with an empty container"

jurgenhaas
committed
echo " 1 LakeDrops Drupal 8 project template"
echo " 2 Drupal's community project template"
echo " 3 Custom project template"
echo " 4 Existing git repository"

jurgenhaas
committed
echo ""
echo ""
while true; do
# shellcheck disable=SC2162

jurgenhaas
committed
read -p "Choose an option: " OPTION
case ${OPTION} in
restoreEnvFile
l3dComposer

jurgenhaas
committed
1 )
PROJECT="lakedrops/d8-project"
create
break
;;
2 )
PROJECT="drupal-composer/drupal-project:8.x-dev"
create
break
;;
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

jurgenhaas
committed
read -p "Repository URL: " REPOSITORY
if [[ -n "${REPOSITORY}" ]]; then
clone

jurgenhaas
committed
break
fi
;;
* )
echo "Please try again."
;;
esac
done
}
readEnv
EXISTING=$(ls -1)
if [[ -z "$EXISTING" ]]; then
if [[ -n ${PROJECT} ]]; then
create
elif [[ -n ${REPOSITORY} ]]; then
clone
else
initialSetup
fi
else
l3dComposer

jurgenhaas
committed
fi
if [[ -d /drupal/.idea ]]; then
/usr/local/bin/.configIdea
fi

jurgenhaas
committed
if [[ -x "${L3DSHELL}" ]]; then
${L3DSHELL}
restoreEnvFile