route - See https://www.drupal.org/node/2382211${COLOR_ENDING}"
357 | fi
358 |
359 | for API_SGLOBALS in "${!SUPERGLOBALS[@]}"; do
360 | if [[ $(find "${VALID_PATH}" -type f ! -name "*.css" ! -name "*.js" | xargs grep "${API_SGLOBALS}") ]]; then
361 | echo -e "\tReplace ${RED}${API_SGLOBALS}()${COLOR_ENDING} by ${GREEN}${SUPERGLOBALS[${API_SGLOBALS}]}${COLOR_ENDING}"
362 | fi
363 | done
364 |
--------------------------------------------------------------------------------
/audit/system_audit.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Invoke the script from anywhere (e.g .bashrc alias)
4 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5 |
6 | # Required source files
7 | source "${DIR}"/common
8 | source "${DIR}"/functions.sh
9 |
10 | is_root
11 |
12 | PHP_APACHE="/etc/php5/apache2/php.ini"
13 | PHP_CLI="/etc/php5/cli/php.ini"
14 |
15 | MYSQL_MINIMUM="$(mysql -V | awk '{print $5}' | head -c 5)"
16 | PHP_MINIMUM="$(php -v | awk '{print $2}' | head -c 5)"
17 |
18 | DISABLE_FUNCTIONS="$(php -c ${PHP_CLI} -i | grep disable_functions | awk '{print $3$4}')"
19 | DATE_TIMEZONE="$(grep "date.timezone" ${PHP_APACHE} | awk '{print $3}' | tail -1)"
20 | DATE_TIMEZONE_CLI="$(grep "date.timezone" ${PHP_CLI} | awk '{print $3}' | tail -1)"
21 | TWIG_EXTENSION="$(grep "extension=twig.so" ${PHP_APACHE})"
22 | TWIG_EXTENSION_CLI="$(grep "extension=twig.so" ${PHP_CLI})"
23 | XDEBUG_NESTING="$(grep "xdebug.max_nesting_level" ${PHP_APACHE} | awk '{print $3}')"
24 | XDEBUG_NESTING_CLI="$(grep "xdebug.max_nesting_level" ${PHP_CLI} | awk '{print $3}')"
25 | APC_UPLOAD_PROGRESS="$(php -c ${PHP_CLI} -i | grep apc.rfc1867_name | awk '{print $3}')"
26 |
27 | # Minimum required MySQL version.
28 | if [[ "${MYSQL_MINIMUM}" < "5.5.3" ]]; then
29 | echo -e "Your MySQL version is too old (${MYSQL_MINIMUM}). Minimum requirement for Drupal 8 is PHP 5.5.3 ${RED}[ERROR]${COLOR_ENDING}"
30 | else
31 | echo -e "MySQL version is ${MYSQL_MINIMUM} ${GREEN}[OK]${COLOR_ENDING}"
32 | fi
33 |
34 | # Minimum required PHP version.
35 | if [[ "${PHP_MINIMUM}" < "5.4.2" ]]; then
36 | echo -e "Your PHP version is too old (${PHP_MINIMUM}). Minimum requirement for Drupal 8 is PHP 5.4.2 ${RED}[ERROR]${COLOR_ENDING}"
37 | else
38 | echo -e "PHP version is ${PHP_MINIMUM} ${GREEN}[OK]${COLOR_ENDING}"
39 | fi
40 |
41 | # Drush requires PHP's disable_functions to be empty, except for PHP 5.5 - See https://github.com/drush-ops/drush/pull/357
42 | if [[ "${DISABLE_FUNCTIONS}" == "novalue" ]]; then
43 | echo -e "PHP CLI's disable_functions are turned off ${GREEN}[OK]${COLOR_ENDING}"
44 | else
45 | echo -e "PHP CLI's disable_functions are turned on and might cause issues with Drush. ${RED}[ERROR]${COLOR_ENDING}"
46 | fi
47 |
48 | # date.timezone needs to be set.
49 | if [[ -z "${DATE_TIMEZONE}" ]] || [[ -z "${DATE_TIMEZONE_CLI}" ]]; then
50 | echo -e "PHP's date.timezone is not set. You should check your apache2 and CLI php.ini file settings. ${RED}[ERROR]${COLOR_ENDING}"
51 | else
52 | echo -e "PHP's date.timezone is set ${GREEN}[OK]${COLOR_ENDING}"
53 | fi
54 |
55 | # The Twig C extension should ideally be enabled.
56 | if [[ -z "${TWIG_EXTENSION}" ]] || [[ -z "${TWIG_EXTENSION_CLI}" ]]; then
57 | echo -e "The Twig C extension is not set. You should check your apache2 and CLI php.ini file settings or install the extension. See http://twig.sensiolabs.org/doc/installation.html#installing-the-c-extension. ${RED}[ERROR]${COLOR_ENDING}"
58 | else
59 | echo -e "The Twig C extension is set ${GREEN}[OK]${COLOR_ENDING}"
60 | fi
61 |
62 | # If XDebug is enabled, then check max_nesting_level.
63 | if [[ "${XDEBUG_NESTING}" -lt 256 ]] || [[ "${XDEBUG_NESTING_CLI}" -lt 256 ]]; then
64 | echo -e "PHP's xdebug.max_nesting_level should be set to 256 at a minimum. ${RED}[ERROR]${COLOR_ENDING}"
65 | else
66 | echo -e "PHP's xdebug.max_nesting_level is correctly set ${GREEN}[OK]${COLOR_ENDING}"
67 | fi
68 |
69 | # APC upload progress is recommended.
70 | if [[ -z "${APC_UPLOAD_PROGRESS}" ]]; then
71 | echo -e "APC upload progress is not correctly set. Please follow http://php.net/manual/apc.configuration.php#ini.apc.rfc1867 for instructions. ${RED}[ERROR]${COLOR_ENDING}"
72 | else
73 | echo -e "APC upload progress is correctly set ${GREEN}[OK]${COLOR_ENDING}"
74 | fi
75 |
--------------------------------------------------------------------------------
/misc/README.md:
--------------------------------------------------------------------------------
1 | Requirements
2 | ------------
3 |
4 | - Git clone HEAD from drupal.org
5 |
6 |
7 | $ git clone --branch 8.0.x http://git.drupal.org/project/drupal.git
8 |
9 |
10 | - Create a *HEAD* symbolic link in the *misc* directory so that the installer knows where to git pull changes from.
11 |
12 |
13 | $ cd /path/to/misc/dir ; ln -s /path/to/d8/repo HEAD
14 |
15 |
16 | Note: The *HEAD* directory name has been added to the .gitignore file so that it won't be deleted ever.
17 |
18 | misc/core-update.sh
19 | -----------------------
20 |
21 | - Checks if the current working directory contains a bootstrap.inc file
22 | - Preserves common files you might have modified (.htaccess, robots.txt, settings.php, services.yml)
23 | - Updates Drupal Core by leveraging advanced rsync options (e.g. --checksum)
24 | - Logs rsync output under /tmp/core-update-YYYY-MM-DD.log
25 |
--------------------------------------------------------------------------------
/misc/core-update.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Invoke the script from anywhere (e.g .bashrc alias)
4 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5 |
6 | # Colors
7 | GREEN="\033[0;32m"
8 | RED="\033[0;31m"
9 | BLUE="\033[94m"
10 | COLOR_ENDING="\033[0m"
11 |
12 | SOURCE="${DIR}/HEAD"
13 | DEST="${PWD}"
14 | FILES="composer.json composer.lock .csslintrc .editorconfig .eslintignore .eslintrc example.gitignore .gitattributes index.php README.txt web.config"
15 | SITES="development.services.yml example.settings.local.php example.sites.php README.txt"
16 | DEFAULT="default.settings.php default.services.yml"
17 | LOG="/tmp/core-update-$(date +%F).log"
18 |
19 | echo -e "${RED}###########################################################################${COLOR_ENDING}"
20 | echo -e "${RED}# WARNING! You're about to update Drupal. This might result in data loss! #${COLOR_ENDING}"
21 | echo -e "${RED}###########################################################################${COLOR_ENDING}"
22 |
23 | echo -e "Current working directory: ${PWD}\n"
24 |
25 | read -p "Are you sure? [Y/N] "
26 | if [[ ${REPLY} =~ ^[Nn]$ ]]; then
27 | echo -e "${GREEN}Back to the comfort zone. Aborting.${COLOR_ENDING}"
28 | exit 0
29 | elif [[ ${REPLY} =~ ^[Yy]$ ]]; then
30 | echo -e "${BLUE}Starting Drupal Core update...${COLOR_ENDING}"
31 | else
32 | echo "Sorry, the only accepted input characters are [Yy/Nn]. Aborting..."
33 | exit 0
34 | fi
35 |
36 | if [[ ! -f ${DEST}/core/includes/bootstrap.inc ]]; then
37 | echo "Oops! This doesn't look like a Drupal docroot. Aborting..."
38 | exit 0
39 | else
40 | echo -e "*\n**\n***\nDrupal Core update started: $(date)\n***\n**\n*" >> "${LOG}"
41 |
42 | echo "The below files will stay untouched:"
43 | echo -e "\t.htaccess"
44 | echo -e "\trobots.txt"
45 |
46 | if [[ -d ${DEST}/sites/default ]]; then
47 | for DEFAULT_FILE in ${DEFAULT}; do
48 | echo -e "\t${DEST}/sites/default/${DEFAULT_FILE}"
49 | done
50 | fi
51 |
52 | echo -e "\t/modules"
53 | echo -e "\t/profiles"
54 | echo -e "\t/themes"
55 |
56 | echo -e "\n#############################" >> "${LOG}" 2>&1
57 | echo "# Updating docroot files... #" >> "${LOG}" 2>&1
58 | echo -e "#############################\n" >> "${LOG}" 2>&1
59 | for FILE in ${FILES}; do
60 | rsync -azP --delete --checksum "${SOURCE}"/"${FILE}" "${DEST}"/"${FILE}" >> "${LOG}" 2>&1
61 | done
62 |
63 | echo -e "\n##############################" >> "${LOG}" 2>&1
64 | echo "# Updating core directory... #" >> "${LOG}" 2>&1
65 | echo -e "##############################\n" >> "${LOG}" 2>&1
66 | rsync -azP --delete --checksum "${SOURCE}"/core/ "${DEST}"/core/ >> "${LOG}" 2>&1
67 |
68 | echo -e "\n###############################" >> "${LOG}" 2>&1
69 | echo "# Updating sites directory... #" >> "${LOG}" 2>&1
70 | echo -e "###############################\n" >> "${LOG}" 2>&1
71 | for SITES_FILE in ${SITES}; do
72 | rsync -azP --delete --checksum "${SOURCE}"/sites/"${SITES_FILE}" "${DEST}"/sites/"${SITES_FILE}" >> "${LOG}" 2>&1
73 | done
74 |
75 | if [[ -d ${DEST}/sites/default ]]; then
76 | for DEFAULT_FILE in ${DEFAULT}; do
77 | rsync -azP --delete --checksum "${SOURCE}"/sites/default/"${DEFAULT_FILE}" "${DEST}"/sites/default/"${DEFAULT_FILE}" >> "${LOG}" 2>&1
78 | done
79 | fi
80 |
81 | # Ephemeral PHP dir cleanup
82 | if [[ -d ${DEST}/sites/default/files/php ]]; then
83 | rm -Rf "${DEST}"/sites/default/files/php
84 | fi
85 |
86 | echo -e "\n*\n**\n***\nDrupal Core update completed: $(date)\n***\n**\n*\n" >> "${LOG}"
87 | fi
88 |
89 | echo -e "${BLUE}Drupal Core update completed!${COLOR_ENDING}"
90 |
--------------------------------------------------------------------------------
/provisioning/.my.conf:
--------------------------------------------------------------------------------
1 | [client]
2 | host=localhost
3 | user=root
4 | password='root'
5 |
--------------------------------------------------------------------------------
/provisioning/.mydevdesktop.conf:
--------------------------------------------------------------------------------
1 | [client]
2 | host=localhost
3 | user=drupaluser
4 | password='root'
5 |
--------------------------------------------------------------------------------
/provisioning/README.md:
--------------------------------------------------------------------------------
1 | Requirements
2 | ------------
3 |
4 | - Git clone `8.0.x` from drupal.org
5 |
6 |
7 | $ git clone --branch 8.0.x http://git.drupal.org/project/drupal.git
8 |
9 |
10 | - Create a `HEAD` symbolic link in the *provisioning* directory so that the installer knows where to git pull changes from
11 |
12 |
13 | $ cd /path/to/provisioning/dir ; ln -s /path/to/d8/repo HEAD
14 |
15 |
16 | Note: The `HEAD` symlink has been added to the `.gitignore` file so that it won't be deleted ever.
17 |
18 | provisioning/install.sh
19 | -----------------------
20 |
21 | - Enable Apache's mod_rewrite if it is disabled
22 | - Allow you to customize the name of the new Drupal docroot
23 | - Git pull 8.0.x (HEAD) to make sure you're working with the latest dev release
24 | - Set up a new docroot with the correct permissions and requirements (settings.php, files dir...)
25 | - Create the required Apache vhost and tweak the hosts file accordingly
26 | - Create a MySQL database
27 | - Run the Drupal installer automatically and spin up the site in seconds
28 |
29 | The script assumes that your MySQL credentials are root/root and that you're downloading the latest Drupal 8 dev release to set up a new docroot under _/var/www/html_. Feel free to modify the script according to your preferences.
30 |
31 | $ install d8
32 |
33 | The `install.sh` script supports passing arguments to load a specific Drush make file. There's a make file named `dev.make` that ships with the repo. It loads some handy dev modules (devel, coder, webprofiler...) that most Drupal 8 developers will need. You can invoke it by passing `-d` as a second argument to the script.
34 |
35 | $ install d8 -d
36 |
37 | The other make file does NOT ship with the repo and you'll have to create it manually:
38 |
39 | * Place it under the `provisioning` directory
40 | * Name it `custom.make` for the install script to find it
41 |
42 | The intent of supporting a custom make file is that you can come up with your own requirements and quickly spin up a D8 instance with just what you need. That file has been added to `.gitignore` so that it won't be wiped at any point in time. You can invoke it by passing `-c` to the script.
43 |
44 | $ install d8 -c
45 |
46 | provisioning/delete.sh
47 | ----------------------
48 |
49 | Does the exact opposite and cleans up everything (docroot, DB, vhost, hosts entry).
50 |
51 | $ delete d8
52 |
53 |
54 | provisioning/functions.sh
55 | -------------------------
56 |
57 | Holds shared functions and feature-specific functions to keep the main files clean.
58 |
59 | provisioning/common
60 | -------------------
61 |
62 | Simple admin script to store common variables.
63 |
--------------------------------------------------------------------------------
/provisioning/common:
--------------------------------------------------------------------------------
1 | # Apache variables
2 | WEBROOT="/var/www/html"
3 | PERMS=`stat -c %U:%G ${WEBROOT}`
4 | SITES_AVAILABLE="/etc/apache2/sites-available"
5 | SITES_ENABLED="/etc/apache2/sites-enabled"
6 | APACHE_22_DEFAULT="default"
7 | APACHE_24_DEFAULT="000-default.conf"
8 | SUFFIX="local"
9 |
10 | GIT="${DIR}/HEAD"
11 |
12 | DRUSH=`which drush`
13 |
14 | # PHP variables
15 | PHP="php5-curl"
16 |
17 | # MySQL variables
18 | MYSQL=`which mysql`
19 | DB_HOST="localhost"
20 | DB_PORT="3306"
21 |
22 | # Misc variables
23 | HOMEDIR="/home/`stat -c %G ${WEBROOT}`"
24 | CREDS="admin"
25 |
26 | # Compatibility with Acquia Dev Desktop
27 | DD_CREDS="drupaluser"
28 |
29 | # Colors
30 | GREEN="\033[0;32m"
31 | RED="\033[0;31m"
32 | BLUE="\033[94m"
33 | COLOR_ENDING="\033[0m"
34 |
--------------------------------------------------------------------------------
/provisioning/delete.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Invoke the script from anywhere (e.g .bashrc alias)
4 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5 |
6 | # Required source files
7 | source "${DIR}"/common
8 | source "${DIR}"/functions.sh
9 |
10 | SITENAME=$1
11 |
12 | is_root
13 |
14 | warning
15 |
16 | docroot_selection
17 | deletion
18 |
19 | # Rebuild Drush command file cache to purge the alias
20 | ${DRUSH} -q cc drush
21 |
22 | echo -e "${GREEN}Successfully removed http://${SITENAME}.${SUFFIX}${COLOR_ENDING}"
23 |
--------------------------------------------------------------------------------
/provisioning/functions.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Shared functions
4 | is_root() {
5 | # Make sure only root can execute the script
6 | if [[ ! $(id -u) = 0 ]]; then
7 | echo -e "${RED}You are required to run this script as root or with sudo! Aborting...${COLOR_ENDING}"
8 | exit 1
9 | fi
10 | }
11 |
12 | # Deployment functions
13 |
14 | mod_rewrite() {
15 | # Enable mod_rewrite if needed
16 | if [[ ! -L /etc/apache2/mods-enabled/rewrite.load ]]; then
17 | echo "Enabling mod_rewrite..."
18 | a2enmod rewrite > /dev/null 2>&1
19 | service apache2 restart
20 | fi
21 | }
22 |
23 | curl() {
24 | # Install cURL if needed
25 | if [[ ! $(dpkg -s curl | head -n1 | awk '{print $2}') == 'curl' ]]; then
26 | echo 'Installing cURL...'
27 | apt-get install -qy curl
28 | fi
29 | }
30 |
31 |
32 | head_symlink() {
33 | # @todo: allow to install from checkout or archive.
34 | # Make sure the HEAD symbolic link exists
35 | if [[ ! -L ${DIR}/HEAD ]]; then
36 | echo "You need to create a HEAD symbolic link from your Drupal checkout in the provisioning directory..."
37 | exit 1
38 | fi
39 | }
40 |
41 | installer() {
42 | # @todo: implement --minimal parameter in the installer.
43 | if [[ ${OPTION} == "-d" ]] || [[ ${OPTION} == "-c" ]]; then
44 | SITENAME_UPPER=${OPTION}
45 | if [[ -z ${OPTION} ]]; then
46 | echo -n "What should be the name of the new Drupal docroot? "
47 | read SITENAME_UPPER
48 | fi
49 | elif [[ ${OPTION} == *-* ]]; then
50 | echo -e "${RED}Only -d (dev make file) or -c (custom make file) parameters are accepted! Aborting.${COLOR_ENDING}"
51 | exit 0
52 | else
53 |
54 | SITENAME_UPPER=${DOCROOT}
55 | if [[ -z ${DOCROOT} ]]; then
56 | echo -n "What should be the name of the new Drupal docroot? "
57 | read SITENAME_UPPER
58 | fi
59 | fi
60 |
61 | # Convert sitename to lowercase if needed.
62 | SITENAME="${SITENAME_UPPER,,}"
63 | }
64 |
65 | checkout() {
66 | # Abort if docroot exists. Else, copy from Git
67 | if [[ -d ${WEBROOT}/${SITENAME} ]]; then
68 | echo -e "${RED}The ${SITENAME} docroot already exists! Aborting.${COLOR_ENDING}"
69 | exit 0
70 | else
71 | echo "Pulling changes from upstream repo..."
72 | cd "${GIT}" && git pull -q
73 | cp -R "${GIT}"/ "${WEBROOT}"/"${SITENAME}"
74 | fi
75 | }
76 |
77 | composer_dependencies() {
78 | echo "Pulling composer dependencies..."
79 | cd "${WEBROOT}"/"${SITENAME}"
80 | composer install -q
81 | }
82 |
83 | settings_files() {
84 | echo "Creating settings.testing.php file..." # See https://www.drupal.org/node/2230005
85 | touch "${WEBROOT}"/"${SITENAME}"/sites/default/settings.testing.php
86 |
87 | echo "Creating services.yml file..."
88 | cp "${WEBROOT}"/"${SITENAME}"/sites/default/default.services.yml "${WEBROOT}"/"${SITENAME}"/sites/default/services.yml
89 | }
90 |
91 | settings_php() {
92 | echo "Creating settings.php file..."
93 | cp "${WEBROOT}"/"${SITENAME}"/sites/default/default.settings.php "${WEBROOT}"/"${SITENAME}"/sites/default/settings.php
94 |
95 | # Enable settings.local.php
96 | # @todo This is very fragile. Improve the detection even if lines change.
97 | sed -i '706,708 s/# //' "${WEBROOT}"/"${SITENAME}"/sites/default/settings.php
98 |
99 | echo "Adding configuration for trusted hostnames..."
100 | cat <> ${WEBROOT}/${SITENAME}/sites/default/settings.php
101 |
102 | \$settings['trusted_host_patterns'] = array(
103 | '^${SITENAME}\\.${SUFFIX}$',
104 | );
105 |
106 | EOT
107 |
108 | # Enable on-screen error reporting
109 | echo "\$config['system.logging']['error_level'] = 'verbose';" >> "${WEBROOT}"/"${SITENAME}"/sites/default/settings.php
110 | }
111 |
112 | twig_debugging() {
113 | echo "Turning on Twig debugging mode..."
114 | sed -i "s/debug: false/debug: true/g" "${WEBROOT}"/"${SITENAME}"/sites/default/services.yml
115 | sed -i "s/auto_reload: null/auto_reload: true/g" "${WEBROOT}"/"${SITENAME}"/sites/default/services.yml
116 | sed -i "s/cache: true/cache: false/g" "${WEBROOT}"/"${SITENAME}"/sites/default/services.yml
117 | }
118 |
119 | apache() {
120 | # Apache setup
121 | echo "Provisionning Apache vhost..."
122 |
123 | # First, determine if we're running Apache 2.2 or 2.4
124 | if [[ -f ${SITES_AVAILABLE}/${APACHE_22_DEFAULT} ]]; then
125 | cp "${SITES_AVAILABLE}"/"${APACHE_22_DEFAULT}" "${SITES_AVAILABLE}"/"${SITENAME}"
126 | # ServerName directive
127 | sed -i "3i\\\tServerName ${SITENAME}.${SUFFIX}" "${SITES_AVAILABLE}"/"${SITENAME}"
128 | # Modifying directives
129 | sed -i "s:/var/www:/${WEBROOT}/${SITENAME}:g" "${SITES_AVAILABLE}"/"${SITENAME}"
130 | # Make sure that Drupal's .htaccess clean URLs will work fine
131 | sed -i "s/AllowOverride None/AllowOverride All/g" "${SITES_AVAILABLE}"/"${SITENAME}"
132 |
133 | echo "Enabling site..."
134 | a2ensite "${SITENAME}" > /dev/null 2>&1
135 | else
136 | cp "${SITES_AVAILABLE}"/"${APACHE_24_DEFAULT}" "${SITES_AVAILABLE}"/"${SITENAME}".conf
137 | # ServerName directive
138 | sed -i "11i\\\tServerName ${SITENAME}.${SUFFIX}" "${SITES_AVAILABLE}"/"${SITENAME}".conf
139 | # ServerAlias directive
140 | sed -i "12i\\\tServerAlias ${SITENAME}.${SUFFIX}" "${SITES_AVAILABLE}"/"${SITENAME}".conf
141 | # vHost overrides
142 | sed -i "16i\\\t" "${SITES_AVAILABLE}"/"${SITENAME}".conf
143 | sed -i "17i\\\t\tOptions Indexes FollowSymLinks" "${SITES_AVAILABLE}"/"${SITENAME}".conf
144 | sed -i "18i\\\t\tAllowOverride All" "${SITES_AVAILABLE}"/"${SITENAME}".conf
145 | sed -i "19i\\\t\tRequire all granted" "${SITES_AVAILABLE}"/"${SITENAME}".conf
146 | sed -i "20i\\\t" "${SITES_AVAILABLE}"/"${SITENAME}".conf
147 |
148 | # Modifying directives
149 | sed -i "s:DocumentRoot /var/www/html:DocumentRoot ${WEBROOT}/${SITENAME}:g" "${SITES_AVAILABLE}"/"${SITENAME}".conf
150 | sed -i "s:Directory /var/www/:Directory ${WEBROOT}/${SITENAME}/:g" "${SITES_AVAILABLE}"/"${SITENAME}".conf
151 |
152 | # Custom logging
153 | sed -i "s:error.log:${SITENAME}-error.log:g" "${SITES_AVAILABLE}"/"${SITENAME}".conf
154 | sed -i "s:access.log:${SITENAME}-access.log:g" "${SITES_AVAILABLE}"/"${SITENAME}".conf
155 |
156 | echo "Enabling site..."
157 | a2ensite "${SITENAME}".conf > /dev/null 2>&1
158 | fi
159 |
160 | # Restart Apache to apply the new configuration
161 | service apache2 reload > /dev/null 2>&1
162 | }
163 |
164 | hosts_file() {
165 | echo "Adding hosts file entry..."
166 | sed -i "1i127.0.0.1\t${SITENAME}.${SUFFIX}" /etc/hosts
167 | }
168 |
169 | mysql() {
170 | # MySQL queries - See https://www.drupal.org/node/1314214
171 | DB_CREATE="CREATE DATABASE IF NOT EXISTS \`${SITENAME}\` DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_general_ci"
172 |
173 | # Custom DB queries if we're using Linux
174 | if [[ $(uname -s) == 'Linux' ]]; then
175 | DB_PERMS="GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES ON \`${SITENAME}\`.* TO '${CREDS}'@'${DB_HOST}' IDENTIFIED BY '${CREDS}'"
176 | SQL="${DB_CREATE};${DB_PERMS}"
177 |
178 | echo "Creating MySQL database..."
179 | $MYSQL --defaults-file="${DIR}"/.my.conf -e "${SQL}"
180 |
181 | # Custom DB queries if we're using a Mac
182 | elif [[ $(uname -s) == 'Darwin' ]]; then
183 | DB_PERMS="GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES ON \`${SITENAME}\`.* TO '${DD_CREDS}'@'${DB_HOST}' IDENTIFIED BY '${DD_CREDS}'"
184 | SQL="${DB_CREATE};${DB_PERMS}"
185 |
186 | echo "Creating MySQL database..."
187 | $MYSQL --defaults-file="${DIR}"/.mydevdesktop.conf -e "${SQL}"
188 | fi
189 | }
190 |
191 | drush_alias() {
192 | echo "Creating Drush alias..."
193 |
194 | cat <> ${HOMEDIR}/.drush/${SITENAME}.aliases.drushrc.php
195 | '${SITENAME}',
199 | 'env' => '${SUFFIX}',
200 | 'root' => '${WEBROOT}/${SITENAME}',
201 | 'uri' => '${SITENAME}.${SUFFIX}',
202 | );
203 |
204 | EOT
205 |
206 | echo "Setting Drush permissions..."
207 | # Drush
208 | chown "${PERMS}" "${HOMEDIR}"/.drush/"${SITENAME}".aliases.drushrc.php
209 | chmod 600 "${HOMEDIR}"/.drush/"${SITENAME}".aliases.drushrc.php
210 | chmod -R 777 "${HOMEDIR}"/.drush/cache/
211 | }
212 |
213 | drupal_install() {
214 | echo "Running Drupal installation..."
215 |
216 | cd "${WEBROOT}"/"${SITENAME}"/sites/default/
217 |
218 | # Custom installation if we're using Linux
219 | if [[ $(uname -s) == 'Linux' ]]; then
220 | ${DRUSH} site-install standard install_configure_form.update_status_module='array(FALSE,FALSE)' -qy --db-url=mysql://"${CREDS}":"${CREDS}"@"${DB_HOST}":"${DB_PORT}"/"${SITENAME}" --site-name="${SITENAME}" --site-mail="${CREDS}"@"${SITENAME}"."${SUFFIX}" --account-name="${CREDS}" --account-pass="${CREDS}" --account-mail="${CREDS}"@"${SITENAME}"."${SUFFIX}"
221 |
222 | # Custom installation if we're using a Mac
223 | elif [[ $(uname -s) == 'Darwin' ]]; then
224 | ${DRUSH} site-install standard install_configure_form.update_status_module='array(FALSE,FALSE)' -qy --db-url=mysql://"${DD_CREDS}"@"${DB_HOST}":"${DB_PORT}"/"${SITENAME}" --site-name="${SITENAME}" --site-mail="${CREDS}"@"${SITENAME}"."${SUFFIX}" --account-name="${CREDS}" --account-pass="${CREDS}" --account-mail="${CREDS}"@"${SITENAME}"."${SUFFIX}"
225 | fi
226 |
227 | # Now that Drupal is installed, rebuild Drush commandfile cache to load the alias.
228 | ${DRUSH} -q cc drush
229 | }
230 |
231 | dev_mode() {
232 | echo "Setting up development mode..."
233 | # Enable Simpletest
234 | cd ../ ; mkdir simpletest ; chmod -R 777 simpletest
235 | ${DRUSH} --root="${WEBROOT}"/"${SITENAME}" en -qy simpletest
236 | }
237 |
238 | make_file() {
239 | # Load the make file, if any. (-d = dev.make / -c = custom.make)
240 | while getopts ":dc" opt; do
241 | case $opt in
242 | d)
243 | echo "Loading the dev make file..." >&2
244 | # Drush doesn't place the modules at the right location so we're changing directory manually.
245 | cd "${WEBROOT}"/"${SITENAME}"
246 | ${DRUSH} make --no-core -qy "${DIR}"/dev.make --contrib-destination=.
247 | ;;
248 | c)
249 | echo "Loading custom make file..." >&2
250 | cd "${WEBROOT}"/"${SITENAME}"
251 | ${DRUSH} make --no-core -qy "${DIR}"/custom.make --contrib-destination=.
252 | ;;
253 | esac
254 | done
255 | }
256 |
257 | set_permissions() {
258 | echo "Setting correct permissions..."
259 | # Drupal
260 | chmod go-w "${WEBROOT}"/"${SITENAME}"/sites/default
261 | chmod go-w "${WEBROOT}"/"${SITENAME}"/sites/default/settings.php
262 | chmod go-w "${WEBROOT}"/"${SITENAME}"/sites/default/services.yml
263 | chmod 777 "${WEBROOT}"/"${SITENAME}"/sites/default/files/
264 | chmod -R 777 "${WEBROOT}"/"${SITENAME}"/sites/default/files/config_*/sync
265 | # Supposedly, the below perms are too open, but it's the only way I found to fix broken image styles.
266 | chmod 777 "${WEBROOT}"/"${SITENAME}"/sites/default/files/styles
267 | chown -R "${PERMS}" "${WEBROOT}"/"${SITENAME}"
268 | }
269 |
270 | site_check() {
271 | # Rebuilding Drupal caches
272 | ${DRUSH} --root="${WEBROOT}"/"${SITENAME}" cache-rebuild -q
273 |
274 | if [[ $(curl -sL -w "%{http_code} %{url_effective}\\n" "http://${SITENAME}.${SUFFIX}" -o /dev/null) ]]; then
275 | echo -e "${GREEN}Site is available at http://${SITENAME}.${SUFFIX}${COLOR_ENDING}"
276 | else
277 | echo -e "${RED}There has been a problem when accessing the site. Is Apache running?${COLOR_ENDING}"
278 | fi
279 | }
280 |
281 | # Deletion functions
282 |
283 | warning() {
284 | echo -e "${RED}############################################################${COLOR_ENDING}"
285 | echo -e "${RED}# WARNING! You're about to delete a site and all its data! #${COLOR_ENDING}"
286 | echo -e "${RED}############################################################${COLOR_ENDING}"
287 | }
288 |
289 | docroot_selection() {
290 | if [[ -z ${SITENAME} ]]; then
291 | echo -n "Which Drupal docroot should we delete? "
292 | read SITENAME
293 | fi
294 |
295 | read -p "Are you sure? [Y/N] "
296 | if [[ ${REPLY} =~ ^[Nn]$ ]]; then
297 | echo -e "${GREEN}Back to the comfort zone. Aborting.${COLOR_ENDING}"
298 | exit 0
299 | elif [[ ! ${REPLY} =~ ^[Yy]$ ]]; then
300 | echo "Sorry, the only accepted input characters are [Yy/Nn]. Aborting..."
301 | exit 0
302 | fi
303 | }
304 |
305 | deletion() {
306 | # Docroot exists
307 | if [[ ! -d ${WEBROOT}/${SITENAME} ]]; then
308 | echo -e "${GREEN}The ${SITENAME} docroot doesn't exist! Aborting.${COLOR_ENDING}"
309 | exit 0
310 | fi
311 |
312 | echo "Deleting Drupal docroot..."
313 | rm -Rf "${WEBROOT:?}"/"${SITENAME}"
314 |
315 | echo "Deleting Apache vHost..."
316 | a2dissite "${SITENAME}" > /dev/null 2>&1
317 | service apache2 reload > /dev/null 2>&1
318 |
319 | # First, determine if we're running Apache 2.2 or 2.4
320 | if [[ -f ${SITES_AVAILABLE}/${SITENAME} ]]; then
321 | rm -f "${SITES_AVAILABLE}"/"${SITENAME}"
322 | else
323 | rm -f "${SITES_AVAILABLE}"/"${SITENAME}".conf
324 | rm /var/log/apache2/"${SITENAME}"-access.log && rm /var/log/apache2/"${SITENAME}"-error.log
325 | fi
326 |
327 | echo "Deleting hosts file entry..."
328 | sed -i "/${SITENAME}.${SUFFIX}/d" /etc/hosts
329 |
330 | echo "Deleting database..."
331 | ${MYSQL} --defaults-file="${DIR}"/.my.conf -e "DROP DATABASE IF EXISTS \`$SITENAME\`"
332 |
333 | echo "Deleting Drush alias..."
334 | rm "${HOMEDIR}"/.drush/"${SITENAME}".aliases.drushrc.php
335 | }
336 |
--------------------------------------------------------------------------------
/provisioning/install.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Invoke the script from anywhere (e.g .bashrc alias)
4 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5 |
6 | # Required source files
7 | source "${DIR}"/common
8 | source "${DIR}"/functions.sh
9 |
10 | is_root
11 |
12 | DOCROOT=$1
13 | OPTION=$2
14 |
15 | # Requirements
16 | mod_rewrite
17 | curl
18 | head_symlink
19 |
20 | # Prepare deployment
21 | installer
22 | checkout
23 | composer_dependencies
24 |
25 | # Prepare Drupal files
26 | settings_files
27 | settings_php
28 | twig_debugging
29 |
30 | # Stack configuration
31 | apache
32 | hosts_file
33 | mysql
34 |
35 | # Drupal install
36 | drush_alias
37 | drupal_install
38 |
39 | # Local setup
40 | dev_mode
41 | make_file
42 | set_permissions
43 |
44 | site_check
45 |
--------------------------------------------------------------------------------
/scaffolding/README.md:
--------------------------------------------------------------------------------
1 | scaffolding/module.sh
2 | ---------------------
3 |
4 | - Create a directory structure with Dependency Injection support (Controller, Form, Plugin, Tests)
5 | - Create required default module files and CMI config directory
6 | - Fill in *.info.yml with basic details
7 |
8 | scaffolding/common
9 | ------------------
10 |
11 | Simple admin script to store common variables.
12 |
--------------------------------------------------------------------------------
/scaffolding/common:
--------------------------------------------------------------------------------
1 | # Colors
2 | GREEN="\033[0;32m"
3 | RED="\033[0;31m"
4 | BLUE="\033[94m"
5 | COLOR_ENDING="\033[0m"
--------------------------------------------------------------------------------
/scaffolding/functions.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Shared functions
4 | is_root() {
5 | # Make sure only root can execute the script
6 | if [[ ! $(id -u) = 0 ]]; then
7 | echo -e "${RED}You are required to run this script as root or with sudo! Aborting...${COLOR_ENDING}"
8 | exit 1
9 | fi
10 | }
11 |
--------------------------------------------------------------------------------
/scaffolding/module.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # @todo: https://drupal.org/node/2122201 (Route subscriber + service.yml file)
4 | # @todo: https://drupal.org/node/2122195 (Access check service.yml file)
5 |
6 | # Invoke the script from anywhere (e.g .bashrc alias)
7 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
8 |
9 | # Required source files
10 | source "${DIR}"/common
11 | source "${DIR}"/functions.sh
12 |
13 | is_root
14 |
15 | # Fill-in module details.
16 | NAME=$1
17 | DESCRIPTION=$2
18 | PACKAGE=$3
19 |
20 | if [[ -z $1 ]] && [[ -z $2 ]] && [[ -z $3 ]]; then
21 | echo -n "Module name (required): "
22 | read NAME
23 |
24 | echo -n "Description (required): "
25 | read DESCRIPTION
26 |
27 | echo -n "Package (optional): "
28 | read PACKAGE
29 | fi
30 |
31 | # Confirming path.
32 | while true; do
33 | read -p "Module scaffolding will be generated under $(pwd). Should we proceed? [Y/N] " ANSWER
34 | case ${ANSWER} in
35 | [Yy] )
36 | break;;
37 | [Nn] )
38 | read -p "Enter the new path: " NEW_PATH
39 | break;;
40 | * )
41 | echo -e "${RED}Sorry, you need to answer by Y/y (yes) or N/n (no).${COLOR_ENDING}"
42 | esac
43 | done
44 |
45 | # Change directory if needed.
46 | if [[ ! -z ${NEW_PATH} ]]; then
47 | cd "${NEW_PATH}"
48 | echo -e "${GREEN}New scaffolding path is ${NEW_PATH}${COLOR_ENDING}"
49 | else
50 | echo -e "${GREEN}Generating scaffolding under $(pwd)${COLOR_ENDING}"
51 | fi
52 |
53 | # Convert module name to lowercase.
54 | NAME_LOWER="${NAME,,}"
55 |
56 | # Create module directory.
57 | if [[ -d ${NAME_LOWER} ]]; then
58 | echo -e "${RED}${NAME_LOWER} directory already exists! Aborting...${COLOR_ENDING}"
59 | exit 1
60 | else
61 | echo -e "\tCreating ${NAME_LOWER} directory..."
62 | mkdir "${NAME_LOWER}"
63 | fi
64 |
65 | ############################
66 | # Configuration Management #
67 | ############################
68 |
69 | # Create the config directory
70 | if [[ -d ${NAME_LOWER}/config ]]; then
71 | echo -e "\t${BLUE}${NAME_LOWER}/config directory already exists! Skipping...${COLOR_ENDING}"
72 | else
73 | echo -e "\tCreating ${NAME_LOWER}/config directory..."
74 | mkdir "${NAME_LOWER}"/config
75 | mkdir "${NAME_LOWER}"/config/install
76 | fi
77 |
78 | # Offer to create a schema for the configuration files.
79 | while true; do
80 | read -p "Create Schema scaffolding for configuration files? [Y/N] " ANSWER
81 | case ${ANSWER} in
82 | [Nn] )
83 | break;;
84 | [Yy] )
85 |
86 | if [[ -d ${NAME_LOWER}/config/schema ]]; then
87 | echo -e "\t${BLUE}${NAME_LOWER}/config/schema directory already exists! Skipping...${COLOR_ENDING}"
88 | else
89 | echo -e "\tCreating ${NAME_LOWER}/config/schema directory..."
90 | mkdir "${NAME_LOWER}"/config/schema
91 | echo -e "${GREEN}Successfully created Schema scaffolding!${COLOR_ENDING}"
92 | fi
93 | break;;
94 | * )
95 | echo -e "${RED}Sorry, you need to answer by Y/y (yes) or N/n (no).${COLOR_ENDING}"
96 | esac
97 | done
98 |
99 | ########################
100 | # Dependency Injection #
101 | ########################
102 |
103 | # Offer to create a Controller.
104 | while true; do
105 | read -p "Create Controller scaffolding? [Y/N] " ANSWER
106 | case ${ANSWER} in
107 | [Nn] )
108 | break;;
109 | [Yy] )
110 | if [[ -d ${NAME_LOWER}/src ]]; then
111 | echo -e "\t${BLUE}${NAME_LOWER}/src directory already exists! Skipping...${COLOR_ENDING}"
112 | else
113 | echo -e "\tCreating ${NAME_LOWER}/src directory..."
114 | mkdir "${NAME_LOWER}"/src
115 | fi
116 |
117 | if [[ -d ${NAME_LOWER}/src/Controller ]]; then
118 | echo -e "\t${BLUE}${NAME_LOWER}/src/Controller directory already exists! Skipping...${COLOR_ENDING}"
119 | else
120 | echo -e "\tCreating ${NAME_LOWER}/src/Controller directory..."
121 | mkdir "${NAME_LOWER}"/src/Controller
122 | fi
123 |
124 | # Ensure module's first letter is uppercase.
125 | NAME_1ST_UP=$(sed 's/\(.\)/\U\1/' <<< "${NAME_LOWER}")
126 | touch "${NAME_LOWER}"/src/Controller/"${NAME_1ST_UP}"Controller.php
127 |
128 | # Generating ModuleController.php default values
129 | cat <> ${NAME_LOWER}/src/Controller/${NAME_1ST_UP}Controller.php
130 | > ${NAME_LOWER}/src/Access/${NAME_1ST_UP}AccessCheck.php
174 | > ${NAME_LOWER}/${NAME_LOWER}.info.yml
306 | name: ${NAME}
307 | type: module
308 | description: '${DESCRIPTION}.'
309 | core: 8.x
310 | EOT
311 |
312 | # Only add package if any was entered.
313 | if [[ ! -z ${PACKAGE} ]]; then
314 | sed -i "4ipackage: ${PACKAGE}" "${NAME_LOWER}"/"${NAME_LOWER}".info.yml
315 | fi
316 | fi
317 |
318 | if [[ ! -f ${NAME_LOWER}/${NAME_LOWER}.module ]]; then
319 | echo -e "\tCreating ${NAME_LOWER}.module..."
320 | touch "${NAME_LOWER}"/"${NAME_LOWER}".module
321 | echo "> "${NAME_LOWER}"/"${NAME_LOWER}".module
322 | fi
323 |
324 | if [[ ! -f ${NAME_LOWER}/${NAME_LOWER}.routing.yml ]]; then
325 | echo -e "\tCreating ${NAME_LOWER}.routing.yml..."
326 | touch "${NAME_LOWER}"/"${NAME_LOWER}".routing.yml
327 | fi
328 |
329 | if [[ ! -f ${NAME_LOWER}/${NAME_LOWER}.links.menu.yml ]]; then
330 | echo -e "\tCreating ${NAME_LOWER}.links.menu.yml..."
331 | touch "${NAME_LOWER}"/"${NAME_LOWER}".links.menu.yml
332 | fi
333 | if [[ ! -f ${NAME_LOWER}/${NAME_LOWER}.links.task.yml ]]; then
334 | echo -e "\tCreating ${NAME_LOWER}.links.task.yml..."
335 | touch "${NAME_LOWER}"/"${NAME_LOWER}".links.task.yml
336 | fi
337 |
338 | if [[ ! -f ${NAME_LOWER}/${NAME_LOWER}.links.action.yml ]]; then
339 | echo -e "\tCreating ${NAME_LOWER}.links.action.yml..."
340 | touch "${NAME_LOWER}"/"${NAME_LOWER}".links.action.yml
341 | fi
342 |
343 | if [[ ! -f ${NAME_LOWER}/${NAME_LOWER}.services.yml ]]; then
344 | echo -e "\tCreating ${NAME_LOWER}.services.yml..."
345 | touch "${NAME_LOWER}"/"${NAME_LOWER}".services.yml
346 | fi
347 |
348 | echo -e "${GREEN}Successfully generated module scaffolding!${COLOR_ENDING}"
349 |
--------------------------------------------------------------------------------