Skip to content

Commit

Permalink
Upgrade to 1.2 - Now sets perms for phpsuexec systems. No longer trie…
Browse files Browse the repository at this point in the history
…s to create dbs on cPanel systems (cPanel API has changed). Bug fix.
  • Loading branch information
Scot Hacker committed Aug 26, 2011
1 parent db5a28d commit 2e9ec17
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 31 deletions.
11 changes: 9 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
WP-Mass-Tools v1.1
WP-Mass-Tools v1.2
Scot Hacker ([email protected])
http://birdhouse.org/software

*** These tools must be run by root - they are not for users of standard hosting accounts. ***

WP-Mass-Tools is a collection of tools (bash shell scripts) for managing lots of disparate WordPress installations on a single server. All installations are checked out via subversion, and their locations listed in a file. When upgrade time comes, a script is run to iterate through all registered sites, back up their databases just in case, and upgrade (svn sw) them to the new version.
WP-Mass-Tools is a collection of tools (bash shell scripts) for managing lots of disparate WordPress installations on a single server. The system assumes you're working on a cPanel-based server, but it can be easily modified to work on other systems instead. All installations are checked out via subversion, and their locations listed in a file. When upgrade time comes, a script is run to iterate through all registered sites, back up their databases just in case, and upgrade (svn sw) them to the new version.

HOW TO USE WP-MASS-TOOLS

Expand All @@ -19,6 +19,8 @@ sh /path/to/scripts/wp-create.sh

Simply follow the prompts. When it's done, it will spit out a new line, to be added to the bottom of wp-sites.sh. You must add the line to wp-sites.sh manually - it's not done automatically.

IMPORTANT FOR CPANEL ADMINISTRATORS: Because cPanel has changed the database creation API, this script no longer creates databases on cPanel systems. You'll need to create the database manually through cPanel, then run this script with matching credentials. If you can help modify this system to utilize the new cPanel APIs, please contribute code!


CHECK FOR PLUGIN COMPATIBILITY
If a major WP release has been made and you're worried about plugins breaking, you can use wp-mass-plugins.sh to spit out a list of all active plugins on all sites on the server. You can then compare the list to lists of known incompatible plugins on the internet.
Expand All @@ -39,5 +41,10 @@ sh /path/to/scripts/wp-mass-upgrade.sh | tee wpuplog.txt
and follow the prompts. You'll see the output live, but will also have a complete record of the process in wpuplog.txt, which you should page through later to make sure there aren't any unexpected errors (e.g. sometimes customers will move their directories around and you'll need to update the paths in your site array).


VERSION NOTES:

1.1 Updated to use array of sites in a separate file

1.2 No longer attempts to create the database on cPanel systems. Changes permissions modification to work on phpsuexec servers. In other words, it no longer changes ownership to user:nobody, but to user:user. Added protection against a situation - a bug - where if the array of sites had a blank line at the end, it would cd to / and start changing permissions!


28 changes: 16 additions & 12 deletions wp-create.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/bin/sh

# WP-Create 1.1 :: 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.
# WP-Create 1.2 :: Creates a new client WP installation via svn quickly.
# Use wp-mass-upgrade.sh to upgrade sites, i.e. One script to do quick WP svn checkouts,
# database setup, etc. and another to mass upgrade all WP installations on a server.
# See the readme for information on why this script no longer creates databases.

# 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 database (not currently doing this), 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-sites.sh
Expand All @@ -20,7 +21,7 @@
DBROOT="dppass"

# Full path to the svn binary on your system (use 'which svn' to obtain if not sure)
svnpath='/usr/local/bin/svn'
svnpath='/usr/bin/svn'

####################################################
# Gather data
Expand Down Expand Up @@ -90,7 +91,7 @@ $svnpath co http://svn.automattic.com/wordpress/tags/$wpver/ .

####################################################
# Create database, db user, set db privs via external .sql file

# Temporarily not working until cPanel db API problems are worked out.


cat <<EOT >$install_path/wp-db.sql
Expand All @@ -100,7 +101,8 @@ FLUSH PRIVILEGES;
EOT

# Feed the db
mysql -u root -p$DBROOT < $install_path/wp-db.sql
# This is temporarily commented out until the cPanel db API problems are worked out
# mysql -u root -p$DBROOT < $install_path/wp-db.sql

# Clean up
rm $install_path/wp-db.sql
Expand Down Expand Up @@ -141,18 +143,20 @@ require_once(ABSPATH.'wp-settings.php');
EOT

####################################################
# Create upload dir and set filesystem permissions
# Create upload dir and set filesystem permissions.
# Note that perms are set for phpsuexec systems - this
# will need to be tweaked if not using phpsuexec.
mkdir -p wp-content/uploads
chown -R $owner:$owner $install_path/
chmod -R 777 wp-content/uploads wp-content/themes

chown -R $owner:$owner *
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;

####################################################
# Report
echo
echo "Installation complete. Please visit http://$url to complete setup."
echo
echo "Add this line to wp-sites.sh (change number 23 when adding):"
echo "Add this line to wp-sites.sh:"
echo "\"$install_path|$url|$email|$owner\""
echo

36 changes: 20 additions & 16 deletions wp-mass-upgrade.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
# wp-mass-upgrade.sh v1.1
# wp-mass-upgrade.sh v1.2
# Batch-update WordPress .svn installations.
# Iterate over array of installations and split vars into components:
# path|URL|email|owner
Expand All @@ -11,7 +11,7 @@
scriptpath='/root/scripts/wp-mass-tools'

# Full path to the svn binary on your system (use 'which svn' to obtain if not sure)
svnpath='/usr/local/bin/svn'
svnpath='/usr/bin/svn'

mailpath='/bin/mail'

Expand Down Expand Up @@ -44,9 +44,8 @@ echo "Upgrading blogs to $ver"
echo

# Iterate through array, upgrading each
for blog in ${site[@]}
for blog in ${sites[@]}
do
#echo $blog
dir=$(echo $blog | cut -f1 -d\|)
url=$(echo $blog | cut -f2 -d\|)
email=$(echo $blog | cut -f3 -d\|)
Expand All @@ -57,8 +56,13 @@ do
echo "E-mail: $email"
echo "User: $owner"
echo

# Safeguard - in case the array of sites has a blank line at the end.
# Bail out before we start changing permissions on the wrong file!
if [[ $dir != */home/* ]]; then echo "Script is working in the wrong place - remove blank lines from your array. Exiting"; exit; fi

cd $dir

cd $dir

# Back up the existing db. We'll only keep one copy, overwriting the old.
if [ -f $dbname.sql.gz ]
Expand All @@ -67,29 +71,29 @@ do
fi

dbname=`grep -i "db_name" wp-config.php | sed s/define\(\'DB_NAME\',\ //g | sed s/\).*$//g | sed s/\'//g`
mysqldump $dbname > $dbname.sql
gzip $dbname.sql
chown -R $owner:$owner $dbname.sql.gz
mysqldump $dbname > $dbname.sql
gzip $dbname.sql
chown -R $owner:$owner $dbname.sql.gz
echo "Backed up database as $dbname.sql.gz."

# For the 2.x - 3.0 upgrade - back up the default theme directory in case site owner
# was using or had modified it - otherwise the svn update command will delete it!
if [ -d "wp-content/themes/default" ]
then
cp -r wp-content/themes/default wp-content/themes/default-bak
chown -R $owner:$owner * wp-content/themes/default-bak
fi

# OK, let's do the upgrade.
cd $dir
$svnpath sw $wptagurl .
# OK, let's do the upgrade.
cd $dir
$svnpath sw $wptagurl .
echo
echo "If no errors shown above, upgrade successful."
echo "Fixing permissions..."
chgrp nobody $dir
chown -R $owner:$owner *
chown -R $owner:nobody wp-content
chmod -R g+w wp-content/uploads
# Setting perms for phpusexec systems - tweak if on a non-phpsuexec system

chown -R $owner:$owner *
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
echo


Expand Down
2 changes: 1 addition & 1 deletion wp-sites.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Array of sites under svn control. This file is shared by wp-mass-upgrade.sh and wp-mass-plugins.sh
# format: "fullpath|URL|email|account"

site=(
sites=(
"/home/joe/public_html/myblog|example.org/myblog|[email protected]|joe"
"/home/jane/public_html|blahblah.com|[email protected]|jane"
"/home/elmo/public_html/blog|elmo.edu/blog|[email protected]|elmo"
Expand Down

0 comments on commit 2e9ec17

Please sign in to comment.