Drupal provision local development

This is a script that Kelly Beck(kpolymorphic) and I have put together for making a local development checkout of Drupal 5 or 6. After installing Drupal locally countless times this script really does saves some time. It is pretty specific about the setup of your local setup, but you might find it useful anyways. I may even decide to create a deprovision script, but first I think I will write another script that handles a local Drupal install from an svn repository. If you have questions about what setup I am using feel free to ask in the comments.
Enjoy!

  #!/usr/bin/env bash
  # Drupal CVS provisioning script using XAMPP

  if [ "$1" == "" ]; then
  echo
  echo "Usage: provision_drupal.sh \$1){drupal version} \$2){domain name} \$3){database user} \$4){database name}"
  echo
  exit
  fi
 
  drupal_version="${1}";
  domain_name="${2}";
  database_user="${3}";
  database_name="${4}";
  vhost_template='/Users/jonathan/Sites/data/etc/vhosts/vhost_template.txt';
  vhost_dir='/Users/jonathan/Sites/data/etc/vhosts';
  base_logroot_dir='/Users/jonathan/Sites';
  base_docroot_dir='/Users/jonathan/Sites';
  site_root_dir="${base_docroot_dir}/${domain_name}";
  site_logroot_dir="${base_logroot_dir}/${domain_name}/logs";
  site_docroot_dir="${base_docroot_dir}/${domain_name}/htdocs";
  apache_user="nobody";
  base_url='.jonathan.local';
 
  # Figure out which version of Drupal to install.
  if [[ "$drupal_version" == '6' ]]; then
      VERSION='DRUPAL-6-9';
  elif [[ "$drupal_version" == '5' ]]; then
      VERSION='DRUPAL-5-15';
  else
      echo 'Only the following are the following options are avaliable:';
      echo ' [5]';
      echo ' [6]';
      exit 1;
  fi
 
  # Checkout Drupal
  if [[ -z "$domain_name" ||  -z "$VERSION" ]]; then
      echo 'You must supply a sitename';
      else
          if [[ -z "$database_user" || -z "$database_name" ]]; then
              echo 'You must supply a database user and database name';
              exit 1;
          else
              echo "Attempting to create the database schema ${database_name} ...";
              if mysql -u${database_user} -e "CREATE DATABASE ${database_name}" -p
              then
                  echo -n 'success!';
                  echo
              else
                  echo 'there was a problem creating the database... exiting';
                  exit 1;
              fi
          fi
 
          echo "provisioning space...";
          if [ -d $site_docroot_dir ]; then
              echo 'site directory already exists, exiting';
              exit;
          else
              echo "creating $site_docroot_dir ..."
              if mkdir -p $site_docroot_dir
              then
                  echo -n "success!"
                  echo
              else
                  echo "could not create $site_docroot_dir ... exiting"
                  exit 1;
              fi
 
              echo "creating $site_logroot_dir ..."
              if mkdir -p $site_logroot_dir
              then
                  echo -n "success!"
                  echo
              else
                  echo "could not create $site_logroot_dir ... exiting"
                  exit 1;
              fi
          fi
 
          echo 'Checking out Drupal';
          cd ${site_root_dir} && cvs -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal checkout -d htdocs -r ${VERSION} drupal >> /dev/null
          #rsync -rv --exclude '.svn' ${site_root_dir}/svnroot/  $site_docroot_dir/
          mkdir ${site_docroot_dir}/sites/${domain_name}${base_url}
          if [[ "$drupal_version" = '5' ]]; then
              cp ${site_docroot_dir}/sites/default/settings.php ${site_docroot_dir}/sites/${domain_name}${base_url}/settings.php
              sudo chown $apache_user ${site_docroot_dir}/sites/${domain_name}${base_url}/settings.php
              else
              cp ${site_docroot_dir}/sites/default/default.settings.php ${site_docroot_dir}/sites/${domain_name}${base_url}/settings.php
              sudo chown $apache_user ${site_docroot_dir}/sites/${domain_name}${base_url}/settings.php
          fi
          mkdir ${site_docroot_dir}/sites/${domain_name}${base_url}/files
          sudo chown $apache_user ${site_docroot_dir}/sites/${domain_name}${base_url}/files
          echo 'Creating host file';
          sudo sh -c "echo \"127.0.0.1 \t ${domain_name}${base_url}\" >> /etc/hosts"
          echo 'Creating vhost';
          cp $vhost_template ${vhost_dir}/${domain_name}.conf;
          sed -i '' -e "s:@@@SITENAME@@@:${domain_name}:g" ${vhost_dir}/${domain_name}.conf;
          echo "Site Complete. Restart Apache and Please visit http://${domain_name}${base_url}/install.php ";
          echo 'Restarting Apache';
          sudo sh -c '/Applications/xampp/xamppfiles/mampp restartapache' >> /dev/null
          exit 0;
  fi

qr code for http://grndlvl.com/content/blog/2009/2/drupal-provision-local-development