Here's a complete (untested) hack that does about what you said. If you're comfortable in php then use that. Pseudo script:
#!/usr/bin/env php
<?php
echo "Site setup v0.0\n";
if($argc != 2){
echo "Usage:\n script sitename\n";
}
//set vars
$sitename = $argv[1];
$src_folder = "/path/to/some/folder";
$template_db ="template_site";
//copy files
`mkdir $sitename`;
`cp -R $src_folder $sitename`;
//copy template db
$dblink = mysql_connect("localhost");
if(!mysql_query($dblink, "CREATE DATABASE site_$sitename; USE site_$sitename;"))exit(-1);
$r = mysql_query($dblink, "SHOW TABLES FROM $template_db");
while($row = mysql_fetch_array($r)){
$table = $row[0];
mysql_query($dblink, "CREATE TABLE $table AS SELECT $template_db.$table");
}
//conf and restart apache
$f = fopen("httpd.conf","a");//open for append
fwrite("<VirtualHost $sitename> bla bla </VirtualHost>");
fclose($f);
`sudo apachectl -k restart`; //you'll be asked for a password here
//open in browser
`open http://$sitename/`; //on mac anyway...
?>
Make the file executable with
chmod +x filename
Remember that to run scripts in the current folder you need to add ./
. Like
./scriptname sitename
Also note the slanted quotes ` <- They start a shell command. The first line is called a shebang-line (yes like that old 80s band, or what was it..) and tells a shell what to use to execute the file. (Env is a utility program that kinda finds other programs, in this case php. Good if you want to run the script in systems where php has different install locations.)
Also please note that this script is just pseudo code—it does not work! Don't run it before modifying it!