#!/bin/sh ################################################################################ # quick and dirty script by D'Arcy Norman # more info at: # http://www.darcynorman.net/2006/07/20/drupal-shared-hosting-site-installer # # version: 0.1 # modified: July 21, 2006 ################################################################################ ################################################################################ # customize these variables to match your configuration ################################################################################ # the installed Drupal codebase to use for all sites. # this doesn't have to be in a web-accessable location, as we'll be symlinking to it DRUPAL_DIR=/Library/WebServer/drupal # where do you want the new Drupal sites to be linked to? SITE_DIRECTORY=/Library/WebServer/Documents/ # default Drupal site notation description of the URL prefix for the site. # in this case, the sites will all go in "http://blogs.mysite.com/SITENAME" # so, in Drupal site notation, that becomes "blogs.mysite.com." SITE_PREFIX='blogs.mysite.com.' # for the new database, what db name prefix would you like to use? # this makes it easier to manage a whole LOT of databases in a list... DB_PREFIX='drupal_' # which .sql file to use as the site database template? can use your own mysqldump if so desired DRUPAL_DATABASE_TEMPLATE=$DRUPAL_DIR/database/database.4.1.mysql # MySQL account info. # this account needs to have CREATE, INSERT, SELECT, and UPDATE privs (at least). MYSQL_USER='username_goes_here' MYSQL_PASSWORD='password_goes_here' ################################################################################ # Don't edit any of this unless you know what you're doing. # of course, if you know what you're doing, by all means please edit away... ################################################################################ SHORT_NAME=$1 echo "creating site: $SHORT_NAME" echo "creating web directory" ln -s $DRUPAL_DIR $SITE_DIRECTORY$SHORT_NAME DB_NAME=$DB_PREFIX$SHORT_NAME echo "creating database: $DB_NAME" mysqladmin -u $MYSQL_USER -p$MYSQL_PASSWORD create $DB_NAME echo "populating database using template: $DRUPAL_DATABASE_TEMPLATE" mysql -u $MYSQL_USER -p$MYSQL_PASSWORD $DB_NAME < $DRUPAL_DATABASE_TEMPLATE echo "creating drupal site directory, and fixing permissions on files subdirectory" cp -R $DRUPAL_DIR'/sites/template' $DRUPAL_DIR'/sites/'$SITE_PREFIX$SHORT_NAME chmod -R 777 $DRUPAL_DIR'/sites/'$SITE_PREFIX$SHORT_NAME'/files' echo "configuring settings.php file for site" for file in `grep -l "database_name_goes_here" $DRUPAL_DIR/sites/$SITE_PREFIX$SHORT_NAME/settings.php`; do sed 's/database_name_goes_here/'$DB_NAME'/g' $file >/tmp/$$ && mv /tmp/$$ $file sed 's/file_directory_path_goes_here/'$SITE_PREFIX$SHORT_NAME'/g' $file >/tmp/$$ && mv /tmp/$$ $file done echo "done."