Use this script to quickly update to the latest version of WordPress.
- WordPress should be located in subdirectory of root (i.e.
site-root/wp
). - Requires WordPress to be a git submodule.
#!/bin/bash | |
# Use this script to update WordPress to the latest version. Keep in mind that | |
# this script will commit the new version automatically; therefore, only use | |
# this script for quick updates to production, not development. | |
# Change to WordPress directory. | |
cd "$(git rev-parse --show-toplevel)"/wp | |
# Get the current tag and run a conditional to see if we are on a tag or not. | |
current_tag=$( git name-rev --tags --name-only $(git rev-parse HEAD) ) | |
# No tag? Bail. | |
if [[ $current_tag == 'undefined' ]]; then | |
# Update complete message. | |
echo "You are not currently on any tag." | |
exit | |
fi | |
# We've made it this far, let's perform the update. | |
# Fetch the repo and tags. | |
git fetch && git fetch --tags | |
# Get the latest tag. | |
latest_tag=$( git tag | tail -1 ) | |
# If the latest tag is greater than the current tag, perform updates. Otherwise | |
# no updates are needed and we can bail. | |
if [[ $latest_tag > $current_tag ]]; then | |
# Clean and update WordPress. | |
git clean -f -d && git reset --hard HEAD && git checkout master && git pull && git fetch --tags && git checkout $latest_tag && cd "$(git rev-parse --show-toplevel)" | |
# Commit update. | |
git add wp && git commit -m "Update WordPress to $latest_tag" && git push | |
# Update complete message. | |
echo "Updated complete. WordPress is now at $latest_tag." | |
exit | |
else | |
# Update complete message. | |
echo "No update required. WordPress is at $current_tag." | |
exit | |
fi |