From 2e9ec179ff34fa7205443170d5ec100bf11eb718 Mon Sep 17 00:00:00 2001 From: Scot Hacker Date: Fri, 26 Aug 2011 15:31:56 -0700 Subject: [PATCH] Upgrade to 1.2 - Now sets perms for phpsuexec systems. No longer tries to create dbs on cPanel systems (cPanel API has changed). Bug fix. --- readme.txt | 11 +++++++++-- wp-create.sh | 28 ++++++++++++++++------------ wp-mass-upgrade.sh | 36 ++++++++++++++++++++---------------- wp-sites.sh | 2 +- 4 files changed, 46 insertions(+), 31 deletions(-) diff --git a/readme.txt b/readme.txt index cc28667..38c9415 100644 --- a/readme.txt +++ b/readme.txt @@ -1,10 +1,10 @@ -WP-Mass-Tools v1.1 +WP-Mass-Tools v1.2 Scot Hacker (shacker@birdhouse.org) 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 @@ -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. @@ -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! diff --git a/wp-create.sh b/wp-create.sh index c25681e..f47ec27 100644 --- a/wp-create.sh +++ b/wp-create.sh @@ -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 @@ -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 @@ -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 <$install_path/wp-db.sql @@ -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 @@ -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 diff --git a/wp-mass-upgrade.sh b/wp-mass-upgrade.sh index 9a5cdcb..8dae0f8 100644 --- a/wp-mass-upgrade.sh +++ b/wp-mass-upgrade.sh @@ -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 @@ -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' @@ -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\|) @@ -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 ] @@ -67,9 +71,9 @@ 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 @@ -77,19 +81,19 @@ do 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 diff --git a/wp-sites.sh b/wp-sites.sh index 34ecc21..57897cd 100644 --- a/wp-sites.sh +++ b/wp-sites.sh @@ -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|joe@example.org|joe" "/home/jane/public_html|blahblah.com|jane@blahblah.com|jane" "/home/elmo/public_html/blog|elmo.edu/blog|elmo@elmo.edu|elmo"