#!/bin/sh # WP-Create 1.0 :: Creates a new client WP installation via svn in 30 seconds. # Designed to be used in conjunction with wp-mass-upgrade.sh: http://birdhouse.org/software/2007/07/wp-mass-upgrade/ # i.e. One script to do quick WP svn checkouts, database setup, etc. and another to mass upgrade all WP installations on a server. # Scot Hacker :: http://birdhouse.org/blog # This script performs the following tasks: # * Gather installation info # * Create install dir and check out a copy of WordPress # * Create database, db user, set db privs via external .sql file # * Create WP config file # * Create upload dir and set filesystem permissions # * Generate array line for wp-mass-upgrade.sh # Final setup is done via browser # Database root pass - protect this script with chmod 700 !!! DBROOT="some-crazy-password" #################################################### # Gather data echo echo -n "WordPress version? "; read wpver echo -n "System account (e.g. fred) "; read owner echo -n "Install path (e.g. /home/fred/public_html/blog)? "; read install_path echo -n "URL (without http, e.g. somedomain.com/blog)? " ; read url echo -n "Owner email? "; read email echo -n "Database user? (n.b.: username will be prepended) "; read dbuser echo -n "Database name? (n.b.: username will be prepended) "; read dbname echo -n "Database pass? "; read dbpass # Modify the db and db account names as necessary for the server you're on. For # example this can be used to prepend "wp-" to the start of WordPress database # names, or to use cPanel db naming format. # For one server, we use the format wp-dbname # thedb=wp\-${dbname} # thedbacct=$dbuser # Concatenate db name and username in cPanel standard format # Weird quirk: In cPanel, the database name will not appear associated with the username in the # graphical control panel unless you escape the underscore in the database name in the GRANT # statement. So we have two variants for $thedb - one with the underscore escaped and the other not. # If you're not on a cPanel system, season to taste. thedb1=${owner}_${dbname} thedb2=${owner}\\_${dbname} thedbacct=${owner}_${dbuser} echo echo " Version: $wpver Owner: $owner Path: $install_path URL: http://$url Owner email: $email Database name: $thedb1 Database user: $thedbacct Database pass: $dbpass " # Verify echo echo -n "Is this correct? (y/n) " ; read correct if [ $correct != "y" ]; then echo "Bzzzzt. Start over." exit; else echo echo "Installing WordPress..." echo fi #################################################### # Create install dir and check out a copy of WordPress if [ ! -d $install_path ]; then mkdir -p $install_path fi cd $install_path svn co http://svn.automattic.com/wordpress/tags/$wpver/ . #################################################### # Create database, db user, set db privs via external .sql file cat <$install_path/wp-db.sql CREATE DATABASE \`$thedb1\`; GRANT ALL ON \`$thedb2\`.* TO '$thedbacct'@'localhost' IDENTIFIED BY '$dbpass'; FLUSH PRIVILEGES; EOT # Feed the db mysql -u root -p$DBROOT < $install_path/wp-db.sql # Clean up rm $install_path/wp-db.sql #################################################### # Create WP config file cat <wp-config.php EOT #################################################### # Create upload dir and set filesystem permissions mkdir -p wp-content/uploads chown -R $owner:$owner * chmod -R 777 wp-content/uploads wp-content/themes #################################################### # Report echo echo "Installation complete. Please visit http://$url to complete setup." echo echo "Add this line to wp-mass-upgrade.sh (change number 23 when adding):" echo "site[23]=\"$install_path|$url|$email|$owner\"" echo