1 email="example@example.com"
2 apache_sites = '/etc/apache2/sites-available'
3 project_dir = `pwd`/${name}
5 host_conf = ${name}.conf
8 echo "Usage: prj-site OPERATION NAME [type] "
10 echo " operation Operation on project; possible values:"
11 echo " create - creates project stubs according to type"
15 echo " type Type of project; possible values:"
20 create: create-directories create-permissions create-vhost create-$(type) enable
21 cd ${name} && echo ${name} > README && git init && git add . && git commit -a -m 'Initial commit'
22 echo "[+] ${type} ${name} project has been created. Make sure that you have added: '${host}' to your /etc/hosts file"
27 echo "> Creating project directory: ${name}"
30 create-directories: $(project_dir)
31 echo "> Creating directory: ${project_dir}/www"
32 mkdir ${project_dir}/www
34 create-permissions: create-directories
35 echo "> Setting group permissions of {project}/www to www-data, need root permissions to do that."
36 sudo chgrp -R www-data ${project_dir}/www
38 ${apache_sites}/${host_conf}:
39 echo "> Creating project's site configuration"
40 sudo cp ${apache_sites}/dummy.conf ${apache_sites}/${host_conf}
42 create-vhost: ${apache_sites}/${host_conf}
43 sudo sed -e "s/dummy/${name}/g" -i ${apache_sites}/${host_conf}
44 sudo sed -e "s@/var/www/${name}@${project_dir}/www@" -i ${apache_sites}/${host_conf}
46 sudo service apache2 reload
49 echo "> Removing directory ${project_dir}/www"
50 sudo rm -r ${project_dir}/www
51 echo "> Removing directory: ${project_dir}"
52 sudo rm -r ${project_dir}
55 if test -f ${apache_sites}/${host_conf}; then \
56 echo "> Removing apache configuration file"; \
57 sudo rm ${apache_sites}/${host_conf}; \
60 enable: enable-${type}
61 echo "[+] Enabling ${name}"
62 if test -f ${apache_sites}/${host_conf}; then \
63 echo "> Enabling project's vhost..."; \
64 sudo a2ensite ${host}; \
65 sudo service apache2 reload; \
67 echo "> Enabling failed. Check your project configuration"; \
72 disable: disable-${type}
73 echo "[+] Disabling ${name}"
74 if test -h /etc/apache2/sites-enabled/${host}; then \
75 echo "> Disabling project's vhost..."; \
76 sudo a2dissite ${host}; \
77 sudo service apache2 reload; \
82 purge: disable purge-${type} remove-vhost remove-directories
83 echo "[+] Project ${name} has been removed"
89 cgi: create-directories
90 echo "[+] CGI installation begins..."
91 echo "AddHandler cgi-script cgi" > ${project_dir}/www/.htaccess
92 echo "Options +ExecCGI" >> ${project_dir}/www/.htaccess
94 symfony2: create-directories create-vhost
95 echo "[+] Symfony installation begins..."
96 echo "> Recreating ${project_dir} for symfony2 specifics"
98 curl -s http://getcomposer.org/installer | php
99 php composer.phar create-project symfony/framework-standard-edition ${project_dir}/ --prefer-dist
100 mv composer.phar ${project_dir}/
101 cd ${project_dir} && php composer.phar install
102 chmod -R 777 ${project_dir}/app/cache
103 chmod -R 777 ${project_dir}/app/logs
104 sudo sed -e "s@${project_dir}/www@${project_dir}/web@" -i ${apache_sites}/${host_conf}
106 create-drupal: create-directories
107 echo "[+] Drupal installation begins..."
108 cd ${project_dir}/www && drush dl drupal
109 mv ${project_dir}/www/drupal*/* ${project_dir}/www/drupal*/.gitignore ${project_dir}/www/drupal*/.htaccess ${project_dir}/www/
110 rm -r ${project_dir}/www/drupal*
111 # sudo mysql --defaults-file=/etc/mysql/debian.cnf -e "create user '$sql_user'@'localhost' identified by '$sql_user';"
112 sudo mysql --defaults-file=/etc/mysql/debian.cnf -e "GRANT ALL PRIVILEGES ON ${sql_user}.* TO '${sql_user}'@'localhost' WITH GRANT OPTION;"
113 sudo mysql --defaults-file=/etc/mysql/debian.cnf -e "SET PASSWORD FOR '${sql_user}'@'localhost' = PASSWORD('${sql_password}');"
114 sudo mysql --defaults-file=/etc/mysql/debian.cnf -e "FLUSH PRIVILEGES;"
115 echo -n "--db-url=mysql://${sql_user}:${sql_password}@localhost/${sql_user}" > /tmp/drupal_options
116 echo -n " --account-mail='${email}'" >> /tmp/drupal_options
117 echo -n " --site-name=${name}" >> /tmp/drupal_options
118 echo -n " --clean-url=true" >> /tmp/drupal_options
119 echo -n " -y minimal" >> /tmp/drupal_options
120 echo "These are parameters with which drupal configuration will be called:"
122 echo " drush si `cat /tmp/drupal_options`\n"
124 cd ${project_dir}/www && cat /tmp/drupal_options | xargs drush si
125 cd ${project_dir}/www && drush en seven toolbar shortcut -y
126 cd ${project_dir}/www && drush vset admin_theme seven
131 echo "> Removing SQL user"
132 sudo mysql --defaults-file=/etc/mysql/debian.cnf -e "DROP USER '${sql_user}'@'localhost';"
133 echo "> Removing SQL database"
134 sudo mysql --defaults-file=/etc/mysql/debian.cnf -e "DROP DATABASE ${sql_user};"
136 .PHONY: help disable purge