1 # Create a development environment for a given "name" on devwww/devdb
3 # Include common dev script.
6 # Usage: write_template "template" "path/to/destination"
7 function write_template {
8 sed -e "s/DB_NAME/${db_name}/g;s/NAME/${name}/g;s/SITE/${site}/g;s/DB_PASS/${db_pass}/g" "dev/${1}" > "${2}"
11 # Fail early if comment is omitted.
12 [ -z "${COMMENT-}" ] && echo "Comment is required." && exit 1
14 # Handle drupal.org vs. sub-domains properly
15 if [ ${site} == "drupal" ]; then
17 repository="drupal.org"
18 snapshot="/var/dumps/mysql/drupal_database_snapshot.reduce-current.sql.bz2"
19 elif [ ${site} == "drupal_7" ]; then
21 repository="drupal.org-7"
22 snapshot="/var/dumps/mysql/drupal_7_database_snapshot.reduce-current.sql.bz2"
24 # Strip any _ and following characters from ${site}, and add .drupal.org.
25 # Such as 'qa_7' -> 'qa.drupal.org'
26 fqdn="$(echo "${site}" | sed -e 's/_.*//').drupal.org"
27 # If ${site} has an underscore, use the following characters. Such as
28 # 'qa_7' -> 'qa.drupal.org-7'
29 repository="${fqdn}$(echo ${site} | sed -ne 's/.*_/-/p')"
30 snapshot="/var/dumps/mysql/${site}_database_snapshot.dev-current.sql.bz2"
33 # DrupalCon São Paulo 2012 and later have a common BZR repository.
34 if [ "${site}" == "saopaulo2012" -o "${site}" == "sydney2013" -o "${site}" == "portland2013" -o "${site}" == "europe2014" -o "${site}" == "northamerica2014" ]; then
35 repository="drupalcon-7"
38 # Sites migrated to D7.
39 if [ "${site}" == "association" -o "${site}" == "api" ]; then
40 repository="${repository}-7"
44 drush="drush -r ${web_path}/htdocs -y"
45 db_pass=$(pwgen -s 16 1)
47 [ -e "${web_path}" ] && echo "Project webroot already exists!" && exit 1
49 # Create the webroot and add comment file
50 mkdir -p "${web_path}/htdocs"
51 chown -R bender:developers "${web_path}"
52 echo "${COMMENT}" > "${web_path}/comment"
54 # Create the vhost config
55 write_template "vhost.conf.template" "${vhost_path}"
57 # Configure the database
58 mysql -e "CREATE DATABASE ${db_name};"
59 mysql -e "GRANT ALL ON ${db_name}.* TO '${db_name}'@'devwww.drupal.org' IDENTIFIED BY '${db_pass}';"
62 echo "Populating development environment with bzr checkout"
63 bzr checkout bzr+ssh://util.drupal.org/bzr/${repository} "${web_path}/htdocs"
65 # Add settings.local.php
66 write_template "settings.local.php.template" "${web_path}/htdocs/sites/default/settings.local.php"
68 # Strongarm the permissions
69 echo "Forcing proper permissions on ${web_path}"
70 find "${web_path}" -type d -exec chmod g+rwx {} +
71 find "${web_path}" -type f -exec chmod g+rw {} +
72 chgrp -R developers "${web_path}"
75 ssh util cat "${snapshot}" | bunzip2 | mysql "${db_name}"
76 # InnoDB handles the url alias table much faster.
77 echo "ALTER TABLE url_alias ENGINE InnoDB;" | ${drush} sql-cli
79 # Disable modules that don't work well in development (yet)
80 ${drush} pm-disable paranoia
81 ${drush} pm-disable civicrm
82 ${drush} pm-disable securepages
83 ${drush} pm-disable beanstalkd
85 # Link up the files directory
86 ln -s /media/${fqdn} "${web_path}/htdocs/$(${drush} status | sed -ne 's/^ *File directory path *: *\([^ ]*\).*$/\1/p')"
88 # Reload apache with new vhost
91 # Get ready for development
93 ${drush} vdel preprocess_css
94 ${drush} vdel preprocess_js
95 ${drush} pm-enable devel
96 ${drush} pm-enable views_ui
97 ${drush} pm-enable imagecache_ui
101 # Enable UC test gateway
102 ${drush} en test_gateway
103 ${drush} vset uc_payment_credit_gateway test_gateway
105 # Set up for potential bakery testing
106 ${drush} vdel bakery_slaves
107 ${drush} vset bakery_domain ".redesign.devdrupal.org"
108 if [ "${site}" == "drupal" ]; then
109 # Drupal.org sites are masters
110 ${drush} vset bakery_master "http://${name}-${site}.redesign.devdrupal.org/"
111 ${drush} vset bakery_key "$(pwgen -s 32 1)"
113 if [ "${bakery_master-}" ]; then
114 # Hook up to a Drupal.org
115 ${drush} vset bakery_master "http://${bakery_master}-drupal.redesign.devdrupal.org/"
116 drush_master="drush -r /var/www/dev/${bakery_master}-drupal.redesign.devdrupal.org/htdocs -l ${bakery_master}-drupal.redesign.devdrupal.org -y"
117 ${drush} vset bakery_key $(${drush_master} vget bakery_key | sed -ne 's/^.*"\(.*\)"/\1/p')
118 ${drush_master} bakery-add-slave "http://${name}-${site}.redesign.devdrupal.org/"
120 # Don't bother with bakery
121 ${drush} pm-disable bakery
126 ${drush} upwd bacon --password=bacon
128 # Prime any big caches
129 wget -O /dev/null http://${name}-${site}.redesign.devdrupal.org --user=drupal --password=drupal