Wenn man einen virtuellen oder dedizierten Root-Server hat, kann man ein kleines Bash-Script benutzen, um mehrere WordPress-Installationen automatisch zu aktualisieren. Das ganze passiert natürlich auf der Kommandozeile (bash).
Ich wollte das die ganze Zeit schon gemacht haben, aber jetzt hab ich mich doch mal hingesetzt. (Danke, Morris. ;-))
Ich weiß nicht, wie viele Leute mit mehreren WP-Installationen unterwegs sind, die zwar über eine Shell, jedoch nicht über Root-Zugang verfügen. Bei Bedarf kann ich das Script aber für den Gebrauch als eingeschränkter Benutzer anpassen.
#!/bin/bash
# Copyright (c) 2007 Alex Guensche
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
# where are working data stored
WORKDIR="/root/wpupgrade/"
# a file with the absolute path to the WordPress installation and the URL
# to the website, both separated only by an equation mark, no other characters
# example lines in that file:
# /var/www/example.org/htdocs/blog/=http://example.org/blog/
# /var/www/localhost/htdocs/=http://127.0.0.1/
WPDIRS_FILE="${WORKDIR}installations"
# derive the affected WP installations from that file
WPDIRS=$(cat ${WPDIRS_FILE})
# WordPress website
WORDPRESS="http://www.wordpress.org/"
# path to latest version
LATEST="latest.tar.gz"
# script to call in order to finish the upgrade
UPGRADESCRIPT="wp-admin/upgrade.php?step=1"
# get it on
cd ${WORKDIR}
# remove old versions
[ -e "wordpress" ] && rm -r wordpress
[ -e "latest.tar.gz" ] && rm latest.tar.gz
# get latest version, unpack and prepare
wget ${WORDPRESS}${LATEST}
tar -xzf $LATEST
rm -r wordpress/wp-content
rm -r wordpress/wp-config-sample.php
[ -d "languages" ] && cp -r languages wordpress/wp-includes
# upgrade each webhost
for i in ${WPDIRS}; do
DIR=$(echo $i | cut -f 1 -d "=")
WEBSITE=$(echo $i | cut -f 2 -d "=")
USER=$(ls -l ${DIR}/wp-config.php | cut -f 3 -d ' ')
GROUP=$(ls -l ${DIR}/wp-config.php | cut -f 4 -d ' ')
echo "Upgrading WP installation in ${DIR} for host ${WEBSITE}..."
echo -n "Do you have backups and want to continue? [y/N] "
read DOITBABY
[ "${DOITBABY}" == "y" ] || exit
cd $DIR;
echo "Upgrading..." >> index.html
mv wp-content wordpress_content
mv wp-config.php wordpress_config.php
rm -r wp-* xmlrpc.php index.php
cp -r ${WORKDIR}/wordpress/* .
mv wordpress_content wp-content
mv wordpress_config.php wp-config.php
wget "${WEBSITE}${UPGRADESCRIPT}" -O -
chown -R ${USER}:${GROUP} ${DIR}
rm index.html
echo "Upgrade for ${DIR} finished."
done
Alles anzeigen
Benutzung:
- Als Root anmelden und nach /root/ wechseln
- Ein Verzeichnis namens wpupgrade anlegen
- In das Verzeichnis wpupgrade wechseln und das obige Script dort speichern
- Das Script mit chmod +x ausführbar machen
- Empfohlen: Ein Verzeichnis languages mit allen benötigten Sprachdateien anlegen
- Eine Datei installations anlegen, in das zeilenweise der absolute Verzeichnispfad sowie die Web-URL getrennt durch ein Gleichheitszeichen eingegeben werden (keine Leer- oder sonstige Zeichen!). Bspw.:
Wenn man dann das obige Script ausführt, werden alle in installations aufgeführten Dateien automatisch aktualisiert. :-)
Achtung: Keine Gewähr für gar nix! Vorher Backups machen!