-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprovision.sh
executable file
·104 lines (84 loc) · 3.42 KB
/
provision.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env bash
##
# Provision a website using existing codebase.
#
# - Installs Drupal using SQLite database.
# - Enables modules
# - Serves site and generates one-time login link
#
# shellcheck disable=SC2015,SC2094,SC2002
set -eu
[ -n "${DEBUG:-}" ] && set -x
#-------------------------------------------------------------------------------
# Variables (passed from environment; provided for reference only).
#-------------------------------------------------------------------------------
# Webserver hostname.
WEBSERVER_HOST="${WEBSERVER_HOST:-localhost}"
# Webserver port.
WEBSERVER_PORT="${WEBSERVER_PORT:-8000}"
# Drupal profile to use when installing the site.
DRUPAL_PROFILE="${DRUPAL_PROFILE:-standard}"
#-------------------------------------------------------------------------------
# @formatter:off
note() { printf " %s\n" "${1}"; }
info() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[34m[INFO] %s\033[0m\n" "${1}" || printf "[INFO] %s\n" "${1}"; }
pass() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[32m[ OK ] %s\033[0m\n" "${1}" || printf "[ OK ] %s\n" "${1}"; }
fail() { [ "${TERM:-}" != "dumb" ] && tput colors >/dev/null 2>&1 && printf "\033[31m[FAIL] %s\033[0m\n" "${1}" || printf "[FAIL] %s\n" "${1}"; }
# @formatter:on
drush() { "build/vendor/bin/drush" -r "$(pwd)/build/web" -y "$@"; }
#-------------------------------------------------------------------------------
echo "==============================="
echo " 🚀 PROVISION "
echo "==============================="
echo
# Extension name, taken from .info file.
extension="$(basename -s .info.yml -- ./*.info.yml)"
[ "${extension}" == "*" ] && fail "ERROR: No .info.yml file found." && exit 1
extension_type="module"
if cat "${extension}.info.yml" | grep -Fq "type: theme"; then
extension_type="theme"
fi
# Database file path.
db_file="/tmp/site_${extension}.sqlite"
info "Installing Drupal into SQLite database ${db_file}."
db_status=$(drush status --field=db-status)
if [ "${db_status}" = "Connected" ]; then
drush sql:drop -y || true >/dev/null
fi
drush site-install "${DRUPAL_PROFILE}" -y --db-url="sqlite://localhost/${db_file}" --account-name=admin install_configure_form.enable_update_status_module=NULL install_configure_form.enable_update_status_emails=NULL
pass "Drupal installed."
drush status
info "Enabling extension ${extension}."
if [ "${extension_type}" = "theme" ]; then
drush theme:enable "${extension}" -y
else
drush pm:enable "${extension}" -y
fi
info "Clearing caches."
drush cr
info "Enabling suggested modules, if any."
drupal_suggests=$(cat composer.json | jq -r 'select(.suggest != null) | .suggest | keys[]' | sed "s/drupal\///" | cut -f1 -d":")
for drupal_suggest in $drupal_suggests; do
drush pm:enable "${drupal_suggest}" -y
done
pass "Suggested modules enabled."
info "Pre-warming caches."
curl -s "http://${WEBSERVER_HOST}:${WEBSERVER_PORT}" >/dev/null
echo
echo "==============================="
echo " 🚀 PROVISION COMPLETE ✅ "
echo "==============================="
echo
echo "Site URL: http://${WEBSERVER_HOST}:${WEBSERVER_PORT}"
echo -n "One-time login link: "
drush -l "http://${WEBSERVER_HOST}:${WEBSERVER_PORT}" uli --no-browser
echo
if [ -f ".ahoy.yml" ]; then
# shellcheck disable=SC2016
echo 'Run `ahoy` to see available commands.'
fi
if [ -f "Makefile" ]; then
# shellcheck disable=SC2016
echo 'Run `make` to see available commands.'
fi
echo