#!/bin/bash
if [ $# = "0" ]; then
echo "newdrupal47: usage: newdrupal47 sitename db_user"
exit 1;
fi
# You may want to set HOST to be your box's domain name
HOST='localhost'
DB_USER='root'
# If second argument is nonzero we were given a db_user;
# use it instead of defaulting to root
if [ -n "$2" ]; then
DB_USER=$2
fi
# This is the location of an SQL file to run after the Drupal
# database has been given to MySQL. I use it to insert one
# line into the user roles table and one line into the user
# table, thus establishing the admin user.
LOCAL_SQL=~/newdrupal47.sql
# This is the location of your htdocs directory.
DIR="/Library/WebServer/Documents"
echo "Changing directory to $DIR"
cd $DIR
echo "Retrieving Drupal 4.7 branch..."
# Pull down drupal 4.7
cvs -z3 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal checkout -r DRUPAL-4-7 drupal
echo "Configuring..."
# Rename the drupal site from "drupal" to whatever the first parameter was,
# e.g. newdrupal47 drupaltest results in a directory named drupaltest
mv $DIR/drupal $DIR/$1
# Make a copy of the default settings folder and name it localhost
# You may want to substitute your machine's DNS name
cp -R $DIR/$1/sites/default $DIR/$1/sites/$HOST
MYSQL_LOC=`which mysql`
if [ -x $MYSQL_LOC ]; then
echo "Enter the database password for user '$DB_USER'"
echo -n "Password: "
read -s PASS
# set local database connection
# -i means edit file in-place
# we search only lines 85-90 in the settings file
sed -i '' 85,90s#username:password@localhost/databasename#$DB_USER:$PASS@localhost/$1# $DIR/$1/sites/$HOST/settings.php
# set the base url
sed -i '' 108,110s#www.example.com#$HOST/$1# $DIR/$1/sites/$HOST/settings.php
echo "Creating database..."
mysqladmin -u$DB_USER -p$PASS create $1
$MYSQL_LOC -u$DB_USER -p$PASS $1 < $DIR/$1/database/database.4.1.mysql
echo "Checking for local configuration..."
if [ -r $LOCAL_SQL ]; then
echo "Found local configuration; executing SQL"
$MYSQL_LOC -u$DB_USER -p$PASS $1 < $LOCAL_SQL
fi
fi
echo "Done"
#opens Safari to the new site on OS X
open http://$HOST/$1