1 #email="dlugolecki.rafal@gmail.com"
2 sql_user = rdlugoleck_${name}
3 # this allows me to evaluate pwgen result to value
4 $(eval sql_password := $(shell pwgen -1 -s 50))
5 apache_sites = '/etc/apache2/sites-available'
6 project_dir = `pwd`/${name}
8 host_conf = ${name}.conf
11 echo "Usage: prj-site OPERATION NAME [type] "
13 echo " operation Operation on project; possible values:"
14 echo " create - creates project stubs according to type"
18 echo " type Type of project; possible values:"
23 create: create-directories create-permissions create-vhost create-$(type) enable
24 cd ${name} && echo ${name} > README && git init && git add . && git commit -a -m 'Initial commit'
25 echo "[+] ${type} ${name} project has been created. Make sure that you have added: '${host}' to your /etc/hosts file"
30 echo "> Creating project directory: ${name}"
33 create-directories: $(project_dir)
34 echo "> Creating directory: ${project_dir}/www"
35 mkdir ${project_dir}/www
37 create-permissions: create-directories
38 echo "> Setting group permissions of {project}/www to www-data, need root permissions to do that."
39 sudo chgrp -R www-data ${project_dir}/www
41 ${apache_sites}/${host_conf}:
42 echo "> Creating project's site configuration"
43 sudo cp ${apache_sites}/dummy.conf ${apache_sites}/${host_conf}
45 create-vhost: ${apache_sites}/${host_conf}
46 sudo sed -e "s/dummy/${name}/g" -i ${apache_sites}/${host_conf}
47 sudo sed -e "s@/var/www/${name}@${project_dir}/www@" -i ${apache_sites}/${host_conf}
49 sudo service apache2 reload
52 echo "> Removing directory ${project_dir}/www"
53 sudo rm -r ${project_dir}/www
54 echo "> Removing directory: ${project_dir}"
55 sudo rm -r ${project_dir}
58 if test -f ${apache_sites}/${host_conf}; then \
59 echo "> Removing apache configuration file"; \
60 sudo rm ${apache_sites}/${host_conf}; \
63 enable: enable-${type}
64 echo "[+] Enabling ${name}"
65 if test -f ${apache_sites}/${host_conf}; then \
66 echo "> Enabling project's vhost..."; \
67 sudo a2ensite ${host}; \
68 sudo service apache2 reload; \
70 echo "> Enabling failed. Check your project configuration"; \
75 disable: disable-${type}
76 echo "[+] Disabling ${name}"
77 if test -h /etc/apache2/sites-enabled/${host}; then \
78 echo "> Disabling project's vhost..."; \
79 sudo a2dissite ${host}; \
80 sudo service apache2 reload; \
85 purge: disable purge-${type} remove-vhost remove-directories
86 echo "[+] Project ${name} has been removed"
92 cgi: create-directories
93 echo "[+] CGI installation begins..."
94 echo "AddHandler cgi-script cgi" > ${project_dir}/www/.htaccess
95 echo "Options +ExecCGI" >> ${project_dir}/www/.htaccess
97 symfony2: create-directories create-vhost
98 echo "[+] Symfony installation begins..."
99 echo "> Recreating ${project_dir} for symfony2 specifics"
101 curl -s http://getcomposer.org/installer | php
102 php composer.phar create-project symfony/framework-standard-edition ${project_dir}/ --prefer-dist
103 mv composer.phar ${project_dir}/
104 cd ${project_dir} && php composer.phar install
105 chmod -R 777 ${project_dir}/app/cache
106 chmod -R 777 ${project_dir}/app/logs
107 sudo sed -e "s@${project_dir}/www@${project_dir}/web@" -i ${apache_sites}/${host_conf}
109 create-drupal: create-directories
110 echo "[+] Drupal installation begins..."
111 cd ${project_dir}/www && drush dl drupal
112 mv ${project_dir}/www/drupal*/* ${project_dir}/www/drupal*/.gitignore ${project_dir}/www/drupal*/.htaccess ${project_dir}/www/
113 rm -r ${project_dir}/www/drupal*
114 # sudo mysql --defaults-file=/etc/mysql/debian.cnf -e "create user '$sql_user'@'localhost' identified by '$sql_user';"
115 sudo mysql --defaults-file=/etc/mysql/debian.cnf -e "GRANT ALL PRIVILEGES ON ${sql_user}.* TO '${sql_user}'@'localhost' WITH GRANT OPTION;"
116 sudo mysql --defaults-file=/etc/mysql/debian.cnf -e "SET PASSWORD FOR '${sql_user}'@'localhost' = PASSWORD('${sql_password}');"
117 sudo mysql --defaults-file=/etc/mysql/debian.cnf -e "FLUSH PRIVILEGES;"
118 echo -n "--db-url=mysql://${sql_user}:${sql_password}@localhost/${sql_user}" > /tmp/drupal_options
119 echo -n " --account-mail='${email}'" >> /tmp/drupal_options
120 echo -n " --site-name=${name}" >> /tmp/drupal_options
121 echo -n " --clean-url=true" >> /tmp/drupal_options
122 echo -n " -y minimal" >> /tmp/drupal_options
123 echo "These are parameters with which drupal configuration will be called:"
125 echo " drush si `cat /tmp/drupal_options`\n"
127 cd ${project_dir}/www && cat /tmp/drupal_options | xargs drush si
128 cd ${project_dir}/www && drush en seven toolbar shortcut -y
129 cd ${project_dir}/www && drush vset admin_theme seven
132 echo "> Removing SQL user"
133 sudo mysql --defaults-file=/etc/mysql/debian.cnf -e "DROP USER '${sql_user}'@'localhost';"
134 echo "> Removing SQL database"
135 sudo mysql --defaults-file=/etc/mysql/debian.cnf -e "DROP DATABASE ${sql_user};"
137 .PHONY: help disable purge