-
Notifications
You must be signed in to change notification settings - Fork 10
/
install-project.sh
executable file
·90 lines (59 loc) · 2.63 KB
/
install-project.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
set -e
# ---------------------------------------------------------------------------- #
# #
# Install Drupal 8. #
# #
# Readme more: https://github.com/drupal-composer/drupal-project #
# #
# ---------------------------------------------------------------------------- #
WORKING_DIR="$(pwd)"
SCRIPT_PATH="$(dirname ${0})"
SCRIPT_PATH="$(cd ${SCRIPT_PATH} && pwd)"
PROJECT_ROOT="$(cd ${SCRIPT_PATH}/.. && pwd)"
hash docker 2> /dev/null
if [ "${?}" -ne 0 ]; then
echo "docker command not found."
exit 1
fi
hash docker-compose 2> /dev/null
if [ "${?}" -ne 0 ]; then
echo "docker-compose command not found."
exit 1
fi
if [ ! -f "${PROJECT_ROOT}/.env" ]; then
cp "${PROJECT_ROOT}/.env.sample" "${PROJECT_ROOT}/.env"
fi
php_container_exists() {
local PROJECT_ROOT="${1}"
echo "$(cd ${PROJECT_ROOT} && docker-compose -f docker-compose.yml ps php 2> /dev/null | grep _php_ | awk '{ print $1 }')"
}
php_container_running() {
local CONTAINER="${1}"
echo "$(docker exec ${CONTAINER} date 2> /dev/null)"
}
PHP_CONTAINER="$(php_container_exists ${PROJECT_ROOT})"
if [ -z "${PHP_CONTAINER}" ]; then
read -p "PHP service could not be found. Would you like to start the containers? [Y/n]: " ANSWER
if [ "${ANSWER}" == "n" ]; then
exit
fi
cd "${PROJECT_ROOT}"
docker-compose -f docker-compose.yml up -d
PHP_CONTAINER="$(php_container_exists ${PROJECT_ROOT})"
echo "Waiting for PHP service to come up..."
sleep 30
elif [ -z "$(php_container_running ${PHP_CONTAINER})" ]; then
read -p "PHP service is not running. Would you like to start the containers? [Y/n]: " ANSWER
if [ "${ANSWER}" == "n" ]; then
exit
fi
cd "${PROJECT_ROOT}"
docker-compose -f docker-compose.yml up -d
echo "Waiting for PHP service to come up..."
sleep 30
fi
docker exec -it "${PHP_CONTAINER}" bash -c "rm -rf /usr/local/apache2/htdocs/web"
docker exec -it "${PHP_CONTAINER}" bash -c "composer create-project drupal-composer/drupal-project:8.x-dev /usr/local/apache2/htdocs --stability dev --no-interaction"
docker exec -it "${PHP_CONTAINER}" bash -c "cd /usr/local/apache2/htdocs/web && echo y | ../vendor/drush/drush/drush site-install standard --db-url=mysql://root:root@db/drupal --account-mail=admin@example.com --account-name=admin --account-pass=admin --site-mail=admin@example.com --site-name=Drupalstack"
cd "${WORKING_DIR}"