Je dispose sur mon serveur de plusieurs blogs Wordpress dans des répertoires différents. Voyant déjà la chose arriver, je me demandais comment simplifier la mise à jour de tous les blogs d'un coup, afin de ne pas y passer 3 jours à chaques fois.
J'ai tout d'abord pensé à faire un lien symbolique vers un repertoire common/wordpress/ mais plusieurs problèmes se posaient à moi (modification du fichier wp-config.php pour l'adapter à chaque sites, etc). Le problème de modifier le fichier, c'est que cette modification est a effectuer à chaque mise à jours. Pas top !
L'autre méthode auarit été l'utilisation du plugin Instant Upgrade de Wordpress. Le problème est qu'il aurait fallu cliquer sur la mise à jour dans chaque blog.
Encore trop fastidieux pour moi ! ^^
La méthode que j'ai choisi d'utiliser et l'utilisation d'un script shell, ou vous indiquez les repertoires ou mettre wordpress à jour, et vous n'avez plus qu'à appeler wordpress avec comme paramètre la version à mettre à jour. Il s'occupera du reste ! :)
Voici le code :
#!/bin/bash
# Shell script (BASH) to update listed blogs to a new version of WordPress
# (Ce script permet de faire une mise à jour vers la derniere version
# FRANCAISE de Wordpress sur les différents blogs indiqués)
#
# In order to run this script, you must have following tools installed:
# - /usr/bin/wget
# - /bin/tar
# - /bin/gzip
#
# Installation
# Customize the script according to your need. You need to setup :
# - the list of your blogs, separated by space (break line, tab works too)
# - The owner user of the blogs (generally www-data)
# - The owner group of the blogs (generally www-data)
#
# Execution
# This script must be executed with one parameters, the new version of
# wordpress, like ./wordpress_update.sh 2.6.2
#
# WARNING :
# This script delete all the content in your blogs, except wp-content/*
# and wp-config.php. If your update directory is in an other directory
# than wp-content/uploads, you will have to modify the script to
# adapt it at your configuration !
#
# --------------------------------------------------------------------
# This is a free shell script under GNU GPL version 2.0 or above
# Copyright (C) 2005 ReFlectiv project.
# Feedback/comment/suggestions : http://www.reflectiv.net/
# -------------------------------------------------------------------------
# List of blogs with absolute path, separated by space, tab or break line
BLOGS_PATH="/var/www/domain1/blog/ /var/www/domain2/blog/
/var/www/domain3/www/ /var/www/domain4/www/";
# Owner user
WP_UID="www-data";
# Owner group
WP_GID="www-data";
# Only change if your UNIX stores bin in diffrent location
WGET="/usr/bin/wget";
TAR="/bin/tar";
#######################################################################
# Do not change anything below
#######################################################################
clear
echo "--------------------------------------------------------------------------------";
echo "------------------------------ Updating Wordpress ------------------------------";
echo "--------------------------------------------------------------------------------";
# Testing differents elements needed for the good work of this script.
if [ $# != 1 ]; then
echo "You need to specify one parameter";
echo "(The version number of Wordpress, like 2.6.2";
exit 1;
fi
if [ ! -x $WGET ]; then
echo $WGET" command not found, please contact the administrator.";
exit 1;
fi
if [ ! -x $TAR ]; then
echo $TAR" command not found, please contact the administrator.";
exit 1;
fi
LATESTWP="wordpress-"$1"-fr_FR.tar.gz"
echo "Downloading the file '"$LATESTWP"'";
$WGET -q http://fr.wordpress.org/$LATESTWP
# An error occured while downloading the archive
if [ ! -f $LATESTWP ]; then
echo $LATESTWP" does not seem to be downloaded ?!";
exit 1;
fi
echo "Extracting "$LATESTWP;
$TAR -xzf $LATESTWP &> /dev/null;
# An error occured while extracting the archive
if [ ! $? -eq 0 ]; then
rm -f $LATESTWP;
echo "An error occured when extracting '"$LATESTWP"'";
exit 1;
fi
# For each blogs
for BLOG in $BLOGS_PATH
do
echo "Updating blog "$BLOG" with the new version of Wordpress ("$1")";
# Deleting current files
WPLISTS=`ls $BLOG`;
for WPFILE in $WPLISTS; do
if [[ $WPFILE != "wp-config.php" && $WPFILE != "wp-content" ]]; then
rm -rf $BLOG$WPFILE;
fi
done
# We copy the new version to the current blog
cp -Ru "wordpress/"* $BLOG
# And we gave the corrects rights for the folder
chown -R $WP_UID:$WP_GID $BLOG
done
# We delete the archive and the folder created by the archive extraction
rm -rf "wordpress/" $LATESTWP;
echo "--------------------------------------------------------------------------------";
echo "------------------------------ Updating Finished -------------------------------";
echo "------------------------------------------------------------------------------";
echo "";
echo "";
exit 0;
Ce code est fonctionnel pour moi, mais peut-être qu'avant de le valider, vous devriez le tester sur des répertoires de tests, afin de ne pas détruire votre installation !
Sachez que tous les fichiers & dossiers dans chaque blogs sont supprimés sauf wp-config.php et wp-content/ (tel qu'indiqué dans la doc de Wordpress pour la mise à jour !).
N'hésitez pas à proposer des mises à jours, des améliorations et à reporter des bugs éventuels ! :)