email="example@example.com" apache_sites = '/etc/apache2/sites-available' project_dir = `pwd`/${name} host = ${name} host_conf = ${name}.conf help: echo "Usage: prj-site OPERATION NAME [type] " echo "Options:" echo " operation Operation on project; possible values:" echo " create - creates project stubs according to type" echo " enable" echo " disable" echo " remove" echo " type Type of project; possible values:" echo " cgi" echo " drupal" echo " symfony2" create: create-directories create-permissions create-vhost create-$(type) enable cd ${name} && echo ${name} > README && git init && git add . && git commit -a -m 'Initial commit' echo "[+] ${type} ${name} project has been created. Make sure that you have added: '${host}' to your /etc/hosts file" create-: $(project_dir): echo "> Creating project directory: ${name}" mkdir ${project_dir} create-directories: $(project_dir) echo "> Creating directory: ${project_dir}/www" mkdir ${project_dir}/www create-permissions: create-directories echo "> Setting group permissions of {project}/www to www-data, need root permissions to do that." sudo chgrp -R www-data ${project_dir}/www ${apache_sites}/${host_conf}: echo "> Creating project's site configuration" sudo cp ${apache_sites}/dummy.conf ${apache_sites}/${host_conf} create-vhost: ${apache_sites}/${host_conf} sudo sed -e "s/dummy/${name}/g" -i ${apache_sites}/${host_conf} sudo sed -e "s@/var/www/${name}@${project_dir}/www@" -i ${apache_sites}/${host_conf} sudo a2ensite ${host} sudo service apache2 reload remove-directories: echo "> Removing directory ${project_dir}/www" sudo rm -r ${project_dir}/www echo "> Removing directory: ${project_dir}" sudo rm -r ${project_dir} remove-vhost: if test -f ${apache_sites}/${host_conf}; then \ echo "> Removing apache configuration file"; \ sudo rm ${apache_sites}/${host_conf}; \ fi; enable: enable-${type} echo "[+] Enabling ${name}" if test -f ${apache_sites}/${host_conf}; then \ echo "> Enabling project's vhost..."; \ sudo a2ensite ${host}; \ sudo service apache2 reload; \ else \ echo "> Enabling failed. Check your project configuration"; \ fi enable-: disable: disable-${type} echo "[+] Disabling ${name}" if test -h /etc/apache2/sites-enabled/${host}; then \ echo "> Disabling project's vhost..."; \ sudo a2dissite ${host}; \ sudo service apache2 reload; \ fi disable-: purge: disable purge-${type} remove-vhost remove-directories echo "[+] Project ${name} has been removed" purge-: ### Site types: cgi: create-directories echo "[+] CGI installation begins..." echo "AddHandler cgi-script cgi" > ${project_dir}/www/.htaccess echo "Options +ExecCGI" >> ${project_dir}/www/.htaccess symfony2: create-directories create-vhost echo "[+] Symfony installation begins..." echo "> Recreating ${project_dir} for symfony2 specifics" rm -r ${project_dir} curl -s http://getcomposer.org/installer | php php composer.phar create-project symfony/framework-standard-edition ${project_dir}/ --prefer-dist mv composer.phar ${project_dir}/ cd ${project_dir} && php composer.phar install chmod -R 777 ${project_dir}/app/cache chmod -R 777 ${project_dir}/app/logs sudo sed -e "s@${project_dir}/www@${project_dir}/web@" -i ${apache_sites}/${host_conf} create-drupal: create-directories echo "[+] Drupal installation begins..." cd ${project_dir}/www && drush dl drupal mv ${project_dir}/www/drupal*/* ${project_dir}/www/drupal*/.gitignore ${project_dir}/www/drupal*/.htaccess ${project_dir}/www/ rm -r ${project_dir}/www/drupal* # sudo mysql --defaults-file=/etc/mysql/debian.cnf -e "create user '$sql_user'@'localhost' identified by '$sql_user';" sudo mysql --defaults-file=/etc/mysql/debian.cnf -e "GRANT ALL PRIVILEGES ON ${sql_user}.* TO '${sql_user}'@'localhost' WITH GRANT OPTION;" sudo mysql --defaults-file=/etc/mysql/debian.cnf -e "SET PASSWORD FOR '${sql_user}'@'localhost' = PASSWORD('${sql_password}');" sudo mysql --defaults-file=/etc/mysql/debian.cnf -e "FLUSH PRIVILEGES;" echo -n "--db-url=mysql://${sql_user}:${sql_password}@localhost/${sql_user}" > /tmp/drupal_options echo -n " --account-mail='${email}'" >> /tmp/drupal_options echo -n " --site-name=${name}" >> /tmp/drupal_options echo -n " --clean-url=true" >> /tmp/drupal_options echo -n " -y minimal" >> /tmp/drupal_options echo "These are parameters with which drupal configuration will be called:" echo "" echo " drush si `cat /tmp/drupal_options`\n" echo "" cd ${project_dir}/www && cat /tmp/drupal_options | xargs drush si cd ${project_dir}/www && drush en seven toolbar shortcut -y cd ${project_dir}/www && drush vset admin_theme seven enable-drupal: purge-drupal: echo "> Removing SQL user" sudo mysql --defaults-file=/etc/mysql/debian.cnf -e "DROP USER '${sql_user}'@'localhost';" echo "> Removing SQL database" sudo mysql --defaults-file=/etc/mysql/debian.cnf -e "DROP DATABASE ${sql_user};" .PHONY: help disable purge