Do not delete placeholder multiple email address for deleted accounts.
[project/infrastructure.git] / dev / deploy.sh
1 # Create a development environment for a given "name" on devwww/devdb
2
3 # Include common dev script.
4 . dev/common.sh
5
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}"
9 }
10
11 # Fail early if comment is omitted.
12 [ -z "${COMMENT-}" ] && echo "Comment is required." && exit 1
13
14 # Handle drupal.org vs. sub-domains properly
15 if [ ${site} == "drupal" ]; then
16   fqdn="drupal.org"
17   repository="drupal.org-7"
18   snapshot="drupal_database_snapshot.reduce-current.sql.bz2"
19 else
20   # Strip any _ and following characters from ${site}, and add .drupal.org.
21   # Such as 'qa_7' -> 'qa.drupal.org'
22   fqdn="$(echo "${site}" | sed -e 's/_.*//').drupal.org"
23   # If ${site} has an underscore, use the following characters. Such as
24   # 'qa_7' -> 'qa.drupal.org-7'
25   repository="${fqdn}$(echo ${site} | sed -ne 's/.*_/-/p')"
26   snapshot="${site}_database_snapshot.dev-current.sql.bz2"
27 fi
28
29 # DrupalCon São Paulo 2012 and later have a common BZR repository.
30 if [ "${site}" == "sydney2013" -o "${site}" == "portland2013" -o "${site}" == "prague2013" -o "${site}" == "northamerica2014" ]; then
31   repository="drupalcon-7"
32 fi
33
34 # Sites migrated to D7.
35 if [ "${site}" == "association" -o "${site}" == "api" -o "${site}" == "infrastructure" ]; then
36   repository="${repository}-7"
37 fi
38
39 export TERM=dumb
40 drush="drush -r ${web_path}/htdocs -y"
41 db_pass=$(pwgen -s 16 1)
42
43 [ -e "${web_path}" ] && echo "Project webroot already exists!" && exit 1
44
45 # Create the webroot and add comment file
46 mkdir -p "${web_path}/htdocs"
47 chown -R bender:developers "${web_path}"
48 echo "${COMMENT}" > "${web_path}/comment"
49
50 # Create the vhost config
51 write_template "vhost.conf.template" "${vhost_path}"
52
53 # Configure the database
54 mysql -e "CREATE DATABASE ${db_name};"
55 mysql -e "GRANT ALL ON ${db_name}.* TO '${db_name}'@'devwww.drupal.org' IDENTIFIED BY '${db_pass}';"
56
57 # Checkout webroot 
58 echo "Populating development environment with bzr checkout"
59 bzr checkout bzr+ssh://bender-deploy@util.drupal.org/${repository} "${web_path}/htdocs"
60
61 # Add settings.local.php
62 write_template "settings.local.php.template" "${web_path}/htdocs/sites/default/settings.local.php"
63
64 # Strongarm the permissions
65 echo "Forcing proper permissions on ${web_path}"
66 find "${web_path}" -type d -exec chmod g+rwx {} +
67 find "${web_path}" -type f -exec chmod g+rw {} +
68 chgrp -R developers "${web_path}"
69
70 # Import database
71 rsync -v --copy-links --password-file ~/util.rsync.pass "rsync://devmysql@util.drupal.org/mysql-dev/${snapshot}" "${WORKSPACE}"
72 bunzip2 < "${WORKSPACE}/${snapshot}" | mysql "${db_name}"
73 ${drush} sql-cli <<END
74   -- InnoDB handles the url alias table much faster.
75   ALTER TABLE url_alias ENGINE InnoDB;
76   -- CiviCRM is needy.
77   UPDATE system SET status = 0 WHERE name = 'civicrm';
78 END
79
80 # Run any pending updates.
81 ${drush} updatedb
82
83 # Disable modules that don't work well in development (yet)
84 ${drush} pm-disable paranoia
85 ${drush} pm-disable beanstalkd
86
87 # Link up the files directory
88 ln -s /media/${fqdn} "${web_path}/htdocs/$(${drush} status | sed -ne 's/^ *File directory path *: *\([^ ]*\).*$/\1/p')"
89
90 # Reload apache with new vhost
91 restart_apache
92
93 # Get ready for development
94 ${drush} vset cache 0
95 ${drush} vdel preprocess_css
96 ${drush} vdel preprocess_js
97 ${drush} pm-enable devel
98 ${drush} pm-enable views_ui
99 ${drush} pm-enable imagecache_ui
100
101 # Set up for potential bakery testing
102 ${drush} vdel bakery_slaves
103 ${drush} vset bakery_domain ".redesign.devdrupal.org"
104 if [ "${site}" == "drupal" ]; then
105   # Drupal.org sites are masters
106   ${drush} vset bakery_master "https://${name}-${site}.redesign.devdrupal.org/"
107   ${drush} vset bakery_key "$(pwgen -s 32 1)"
108 else
109   if [ "${bakery_master-}" ]; then
110     # Hook up to a Drupal.org
111     ${drush} vset bakery_master "https://${bakery_master}-drupal.redesign.devdrupal.org/"
112     drush_master="drush -r /var/www/dev/${bakery_master}-drupal.redesign.devdrupal.org/htdocs -l ${bakery_master}-drupal.redesign.devdrupal.org -y"
113     ${drush} vset bakery_key $(${drush_master} vget bakery_key | sed -ne 's/^.*"\(.*\)"/\1/p')
114     ${drush_master} bakery-add-slave "https://${name}-${site}.redesign.devdrupal.org/"
115   else
116     # Don't bother with bakery
117     ${drush} pm-disable bakery
118   fi
119 fi
120
121 # Set up test user
122 ${drush} upwd bacon --password=bacon
123
124 # Prime any big caches
125 wget --no-check-certificate -O /dev/null https://${name}-${site}.redesign.devdrupal.org --user=drupal --password=drupal