2 # Bootstrap a Drupal project
4 # Copyright (C) 2017 Antonio Ospite <ao2@ao2.it>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 usage: drin $(basename $0 .sh) [--devel|-h|--help]
25 Bootstrap a Drupal project, using settings from a 'bootstrap.conf' file.
28 --devel install drupal/devel and use a settings.local.php file
29 -h, --help display this usage message and exit
45 echo "Error: Unknown option '${1}'" 1>&2
57 declare -p ACCOUNT_NAME
58 declare -p ACCOUNT_PASS
59 declare -p ACCOUNT_MAIL
63 declare -p SITE_BASE_PATH
65 declare -p TRUSTED_HOSTS
67 declare -p WEB_SERVER_GROUP
69 [ "x$INSTALLATION_PROFILE" = "x" ] && { echo "INSTALLATION_PROFILE not specified, using the \"standard\" profile!"; INSTALLATION_PROFILE="standard"; }
71 if [ "x$MYSQL_ROOT_PASSWORD" = "x" ];
73 read -s -p "MySQL root password: " MYSQL_ROOT_PASSWORD
77 SITE_LOCAL_PATH="${PWD}/web"
79 command -v composer &> /dev/null || { echo "Aborting, 'composer' not available." 1>&2; exit 1; }
80 command -v git &> /dev/null || { echo "Aborting, 'git' not available." 1>&2; exit 1; }
82 [ -d "$SITE_LOCAL_PATH" ] || composer install
84 # TODO check if the commands are available
85 DRUSH="${PWD}/vendor/bin/drush"
86 DRUPAL_CONSOLE="${PWD}/vendor/bin/drupal"
88 [ -x "$DRUSH" ] || { echo "Aborting, '$DRUSH' not available." 1>&2; exit 1; }
89 [ -x "$DRUPAL_CONSOLE" ] || { echo "Aborting, '$DRUPAL_CONSOLE' not available." 1>&2; exit 1; }
91 # This becomes unnecessary if the installation profile gets pulled in by
92 # composer.json, like suggested in
93 # https://github.com/drupal-composer/drupal-project/issues/249
94 if ! echo $INSTALLATION_PROFILE | egrep -q "^(minimal|standard)$";
96 if [ -d $SITE_LOCAL_PATH/profiles/$INSTALLATION_PROFILE ];
98 echo "Installation profile '$INSTALLATION_PROFILE' already there."
100 cp -a $INSTALLATION_PROFILE $SITE_LOCAL_PATH/profiles
104 pushd "$SITE_LOCAL_PATH"
106 $DRUSH --verbose --yes \
109 --db-su-pw="$MYSQL_ROOT_PASSWORD" \
110 --db-url="mysql://${DB_USER}:${DB_PASS}@localhost/${DB_NAME}" \
111 --site-name="$SITE_NAME" \
112 --site-mail="$SITE_MAIL" \
113 --account-name="$ACCOUNT_NAME" \
114 --account-pass="$ACCOUNT_PASS" \
115 --account-mail="$ACCOUNT_MAIL" \
116 "$INSTALLATION_PROFILE"
118 if $DRUSH pm-info --fields=status locale | grep -q enabled;
120 # This is necessary for multi-language sites, it fixes some issues like:
121 # "The Translation source field needs to be installed."
122 $DRUSH --yes entity-updates
124 # Update translations of contrib modules
125 $DRUSH --yes locale-update
128 # This fixes permissions when installing under $HOME/public_html/
129 chmod 775 sites/default/files
130 sudo chgrp -R "$WEB_SERVER_GROUP" sites/default/files
132 [ -d ../config/sync ] && sudo chgrp -R "$WEB_SERVER_GROUP" ../config/sync
135 sed -i "s@# RewriteBase /drupal\$@RewriteBase ${SITE_BASE_PATH}@" .htaccess
137 chmod 644 sites/default/settings.php
139 # Add some basic settings to settings.php
140 if ! grep -q "^\\\$settings\['trusted_host_patterns'\] =" sites/default/settings.php;
142 echo "\$settings['trusted_host_patterns'] = [" >> sites/default/settings.php
143 for host in "${TRUSTED_HOSTS[@]}"
145 echo " '^${host}\$'," >> sites/default/settings.php
147 echo "];" >> sites/default/settings.php
150 if [ "$DEVEL_MODE" = "true" ];
152 # NOTE: don't run composer under web/ but in the project dir
153 composer --working-dir=../ require drupal/devel
154 $DRUSH --yes en devel
156 chmod 755 sites/default
157 cp sites/example.settings.local.php sites/default/settings.local.php
158 chmod 444 sites/default/settings.local.php
159 chmod 555 sites/default
161 if ! grep -q "^include \$app_root . '/' . \$site_path . '/settings.local.php';" sites/default/settings.php;
163 echo "include \$app_root . '/' . \$site_path . '/settings.local.php';" >> sites/default/settings.php
167 chmod 444 sites/default/settings.php
169 # If using a git checkout of Drupal core, set up a diff alias.
171 # This is useful because the Automated Test infrastructure of drupal.org does
172 # not expect patches to be created from a split core directory.
175 git -C core/ config --local alias.core-diff "diff --src-prefix=a/core/ --dst-prefix=b/core/"
176 echo "Added a 'git core-diff' to the drupal/core repository clone."
177 echo "This command helps creating core patches ready for upstream."