From: Rafał Długołęcki Date: Tue, 18 Jun 2013 22:45:34 +0000 (+0200) Subject: Added Makefile style script for creation of project templates. X-Git-Tag: 0.1 X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=52d9db960715399d67dcc5f67f25fccf95759b50;p=prj-utils.git Added Makefile style script for creation of project templates. --- diff --git a/prj-create-site b/prj-create-site new file mode 100755 index 0000000..884af6e --- /dev/null +++ b/prj-create-site @@ -0,0 +1,8 @@ +#!/bin/sh + +op="$1" +name="$2" +type="$3" + +make name=$name type=$type -s -f ~/prj/prj-utils/prj-create-site-make $op + diff --git a/prj-create-site-make b/prj-create-site-make new file mode 100755 index 0000000..8abaf52 --- /dev/null +++ b/prj-create-site-make @@ -0,0 +1,109 @@ +#email="dlugolecki.rafal@gmail.com" +sql_user = rdlugoleck_${name} +# this allows me to evaluate pwgen result to value +$(eval sql_password := $(shell pwgen -1 -s 50)) +apache_sites = '/etc/apache2/sites-available' +project_dir = `pwd`/${name} +host = ${name}.localhost + +help: + echo "Usage: prj-site OPERATION NAME [type] " + echo "Options:" + echo " type Type of project; possible values:" + echo " cgi" + echo " drupal" + echo " symfony2" + +create: directories permissions vhost $(type) + 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" + +$(project_dir): + echo "> Creating directory for project: ${name}" + mkdir ${project_dir} + +directories: $(project_dir) + echo "> Creating www directory ${project_dir}" + mkdir ${project_dir}/www + +permissions: 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}: + echo "> Creating project's site configuration" + sudo cp ${apache_sites}/dummy.localhost ${apache_sites}/${host} + +vhost: ${apache_sites}/${host} + sudo sed -e "s/dummy/${name}/g" -i ${apache_sites}/${host} + sudo sed -e "s@/var/www/${name}@${project_dir}/www@" -i ${apache_sites}/${host} + sudo a2ensite ${host} + sudo service apache2 reload + +clean: + echo "[+] Cleaning project" + if test -h /etc/apache2/sites-enabled/${host}; then \ + echo "> Disabling project's vhost..."; \ + sudo a2dissite ${host}; \ + sudo service apache2 reload; \ + fi + +purge: clean purge-${type} + echo "[+] Purging project" + if test -e ${apache_sites}/${host}; then \ + echo "> Removing apache configuration file"; \ + sudo rm ${apache_sites}/${host}; \ + fi; + if test -d ${project_dir}; then \ + echo "> Removing project directory"; \ + sudo rm -r ${project_dir}; \ + fi; + + +### Site types: +cgi: directories + echo "[+] CGI installation begins..." + echo "AddHandler cgi-script cgi" > ${project_dir}/www/.htaccess + echo "Options +ExecCGI" >> ${project_dir}/www/.htaccess + +symfony2: directories 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} + +drupal: 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 + +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 clean purge