Skip to content

Instantly share code, notes, and snippets.

@crewstyle
Last active April 20, 2016 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crewstyle/a22b4af3e33fee817c3fd5392e65dde4 to your computer and use it in GitHub Desktop.
Save crewstyle/a22b4af3e33fee817c3fd5392e65dde4 to your computer and use it in GitHub Desktop.
WordPress updater bash script on remote server - #optimisation #bash #remote
#!/bin/bash
####################################################################
# WordPress updater script
#
# This script has been made to update WordPress sites quickly
# and works on remote server.
#
# It works with this simple command line:
# /path/to/wp-update.sh folder_name user:group
#
# Example, if we need to update the `wp-project` WP folder with
# its own rights:
#
# ssh remote-server
# cd /path/to/wp-project/parent/
# /path/to/wp-update.sh wp-project wp-project:www-data
#
# You'll see that a new folder - with the old files - has been created.
# It is useful if you need to get back other specific files and move them
# in the new updated WordPress folder.
####################################################################
# Temporary WordPress folder useful to download WP in it
WPUPDATE="wp-update"
# Suffix name to the old project docroot
OLDNAME="_old"
# Main function which make all the magic
function wpUpdate {
echo " "
echo " .-..-. "
echo " "
echo " "
echo " __ .-..-. "
echo " Whoot? -=(o '. "
echo " '.-.\ "
echo " /| \\ "
echo " .-..-. '| || "
echo " _\_):,_ "
echo " "
echo " "
echo " __---___--___---___--___---___--___ "
echo " "
echo "~~ WordPress update START ~~"
if [ -e "latest.tar.gz" ]; then
echo " "
echo "! Removing the old latest.tar.gz file..."
rm latest.tar.gz
fi
echo " "
echo "~ WordPress download latest archive"
wget http://wordpress.org/latest.tar.gz
if [ ! -d "$WPUPDATE" ]; then
echo "! Creating '$WPUPDATE' folder..."
mkdir $WPUPDATE
else
echo "! Removing all files in '$WPUPDATE' folder..."
rm -rf $WPUPDATE/*
fi
echo " "
echo "~ WordPress extraction in '$WPUPDATE' temporary folder"
tar xfz latest.tar.gz -C $WPUPDATE
rm latest.tar.gz
echo " "
echo "~ Removing new wp-content folder, readme.html and license.txt files"
rm -rf $WPUPDATE/wordpress/wp-content
rm $WPUPDATE/wordpress/license.txt $WPUPDATE/wordpress/readme.html
echo " "
echo "~ Moving wp-config.php and google site verification files"
mv $FOLDER_NAME/wp-config.php $WPUPDATE/wordpress/
mv $FOLDER_NAME/google*.html $WPUPDATE/wordpress/
echo " "
echo "~ Moving wp-content and robots.txt"
mv $FOLDER_NAME/wp-content $WPUPDATE/wordpress/
mv $FOLDER_NAME/robots.txt $WPUPDATE/wordpress/
echo " "
echo "~ Renaming old folder"
mv $FOLDER_NAME $FOLDER_NAME$OLDNAME
echo " "
echo "~ Renaming/moving new folder"
mv $WPUPDATE/wordpress $FOLDER_NAME
echo " "
echo "~ Change new folder's owner"
chown -R $USER_GRANT $FOLDER_NAME
echo " "
echo "You can now remove the old $FOLDER_NAME$OLDNAME folder if you want."
echo " "
echo "~~ WordPress update END ~~"
}
if [ $# -ne 2 ]; then
echo "USAGE : $0 folder_name user:group"
else
FOLDER_NAME=$1
USER_GRANT=$2
wpUpdate
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment