Fixed too long password for mysql. Fixed no enable-drupal target. Fixed no email...
[prj-utils.git] / prj-site-make
1 email="example@example.com"
2 apache_sites = '/etc/apache2/sites-available'
3 project_dir = `pwd`/${name}
4 host = ${name}
5 host_conf = ${name}.conf
6
7 help:
8         echo "Usage: prj-site OPERATION NAME [type] "
9         echo "Options:"
10         echo "   operation    Operation on project; possible values:"
11         echo "                    create - creates project stubs according to type"
12         echo "                    enable"
13         echo "                    disable"
14         echo "                    remove"
15         echo "   type         Type of project; possible values:"
16         echo "                    cgi"
17         echo "                    drupal"
18         echo "                    symfony2"
19
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" 
23
24 create-:
25
26 $(project_dir):
27         echo "> Creating project directory: ${name}"
28         mkdir ${project_dir}
29
30 create-directories: $(project_dir)
31         echo "> Creating directory: ${project_dir}/www"
32         mkdir ${project_dir}/www
33
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
37
38 ${apache_sites}/${host_conf}:
39         echo "> Creating project's site configuration"
40         sudo cp ${apache_sites}/dummy.conf ${apache_sites}/${host_conf}
41
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}
45         sudo a2ensite ${host}
46         sudo service apache2 reload
47
48 remove-directories:
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}
53
54 remove-vhost:
55         if test -f ${apache_sites}/${host_conf}; then \
56           echo "> Removing apache configuration file"; \
57           sudo rm ${apache_sites}/${host_conf}; \
58         fi;
59
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; \
66         else \
67           echo "> Enabling failed. Check your project configuration"; \
68         fi
69
70 enable-:
71
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; \
78         fi
79
80 disable-:
81
82 purge: disable purge-${type} remove-vhost remove-directories
83         echo "[+] Project ${name} has been removed"
84
85 purge-:
86
87
88 ### Site types:
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
93
94 symfony2: create-directories create-vhost
95         echo "[+] Symfony installation begins..."
96         echo "> Recreating ${project_dir} for symfony2 specifics"
97         rm -r ${project_dir}
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}
105
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:"
121         echo ""
122         echo "      drush si `cat /tmp/drupal_options`\n"
123         echo ""
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
127
128 enable-drupal:
129
130 purge-drupal:
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};"
135
136 .PHONY: help disable purge