I'm a really bad blogger. First, I never write. Secondly, I never write about new stuffs. I have my reason and to be honest, I've seen too many very good article so I had to realise, it's not going to be a tech blog. I'm really curious about how my coming MacBook affects to my reading habit. I've got a lot of hope in it. And another big news for me. I'll be a proud cat holder? Call me crazy but she will be my first child. (Besides that if her teacher says she is the smartest in the class - I won't believe it:) Anyway. To restart this stuff I intend to share a small Drupal site generator script with you.
What is the problem?
I'm a Drupal developer. I need to test modules before using it on production sites. I need to try out a lot of things. And the best for doing that is a Drupal sandbox. But it takes 1 or 2 minutes to create one. (At least for me.) ((It should be a Drupal install contest - yeah:))
Solution?
Create a sandbox once and pre-populate it when needs a new one.
Prepaire:
- Download the latest Drupal install: http://drupal.org/
- Install it in a directory called: drupal_sandbox
- Install all the modules you want by default (contrib ones as well)
- Use the database name of: drupal_sandbox in the settings.php
- Tar the drupal_sandbox directory: tar -cvzf drupal_sandbox.tar.gz drupal_sandbox
- Create an sql dump: mysqldump -u YOURUSER --password=YOURPASS drupal_sandbox > drupal_sandbox.sql
The script:
#!/usr/bin/env bash
# Directory where the tar.gz and sql file lies
package_dir=~/download
# Base file name for the tar.gz and sql files
package_name=drupal_sandbox
# Your web root
www_dir=~/www
# Your MySQL user
mysql_pwd=YOURMYSQLUSER
mysql_user=YOURMYSQLPASSWORD
cd $www_dir
tar -xvzf $package_dir/$package_name.tar.gz
mv $package_name $1
cd $1/sites/default
mv settings.php settings.php.bckup
sed "s/$package_name/$1/g" settings.php.bckup > settings.php
mysql -u $mysql_user --password=$mysql_pwd -e "create database $1"
mysql -u $mysql_user --password=$mysql_pwd $1 < $package_dir/$package_name.sql
Usage:
Call the script with a parameter (the name of the new drupal site (directory & sql))
sh ./drupal_creator.sh drupal_site_for_testing
Thats it. I hope it works for you. On my environment its fine.
Good luck,
Peter
Nice one, been looking for something like this for ages.
ReplyDeleteI'm glad. But check this out:
ReplyDeletehttp://cvs.drupal.org/viewvc.py/drupal/drupal/CHANGELOG.txt?revision=1.321&view=markup
It is written for Drupal 7:
"- Installer: * Refactored the installer into an API that allows Drupal to be installed
via a command line script."