Created
December 30, 2014 17:06
-
-
Save raamdev/9b2d67a6b24a1cd718b6 to your computer and use it in GitHub Desktop.
Updates a WordPress theme with the latest code from GitHub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ------------------------------------------------------------------- | |
# | |
# This script updates a WordPress theme with the latest code from | |
# GitHub. You can set it to run as a cronjob to automatically update | |
# a WordPress theme with the latest code from the master branch (or | |
# any branch that you want). | |
# | |
# Be sure to chmod +x this file so that it can be executed via Cron. | |
# | |
# Example cronjob to run this script every 30 minutes: | |
# 0,30 * * * * /home/independ/update-wp-theme-from-github.sh | |
# | |
# Author: Raam Dev <raam@raamdev.com> | |
# ------------------------------------------------------------------- | |
THEMES_DIR="/home/raamorg/public_html/wordpress/wp-content/themes" # NO trailing slash | |
THEME_NAME="independent-publisher-child" # The final directory name for the theme | |
GITHUB_ZIP_URL="https://github.com/raamdev/independent-publisher-child/archive/master.zip" # URL to the zip file on GitHub that contains the latest code | |
GITHUB_ZIP_FILENAME="master.zip" # The name of the zip file that GitHub gives us | |
GITHUB_ZIP_EXTRACTED_DIR_NAME="independent-publisher-child-master" # The name of the directory the GitHub zip file is extracted to | |
CHOWN_USER="raamorg" # The name of the user who should own these files | |
CHOWN_GROUP="raamorg" # The name of the group who should own these files | |
GITHUB_ZIP_FILENAME_LATEST="master-child.zip.latest" | |
# -------------------------------------------- | |
# NO CHANGES NECESSARY BELOW THIS LINE | |
# -------------------------------------------- | |
cd $THEMES_DIR | |
/usr/bin/curl -o $GITHUB_ZIP_FILENAME -k -L $GITHUB_ZIP_URL | |
if [ -e $THEMES_DIR/$GITHUB_ZIP_FILENAME_LATEST ]; then | |
if diff $GITHUB_ZIP_FILENAME $GITHUB_ZIP_FILENAME_LATEST >/dev/null ; then | |
echo "Remote and local are identical; skipping update..." | |
exit # already have latest code; not need to update | |
else | |
echo "Remote is different than local; updating..." | |
rm -rf $THEME_NAME | |
/usr/bin/unzip $GITHUB_ZIP_FILENAME | |
mv $GITHUB_ZIP_EXTRACTED_DIR_NAME $THEME_NAME | |
mv $GITHUB_ZIP_FILENAME $GITHUB_ZIP_FILENAME_LATEST | |
chown -R $CHOWN_USER:$CHOWN_GROUP $THEMES_DIR/$GITHUB_ZIP_FILENAME_LATEST | |
chown -R $CHOWN_USER:$CHOWN_GROUP $THEMES_DIR/$THEME_NAME | |
fi | |
else | |
rm -rf $THEME_NAME | |
/usr/bin/unzip $GITHUB_ZIP_FILENAME | |
mv $GITHUB_ZIP_EXTRACTED_DIR_NAME $THEME_NAME | |
mv $GITHUB_ZIP_FILENAME $GITHUB_ZIP_FILENAME_LATEST | |
chown -R $CHOWN_USER:$CHOWN_GROUP $THEMES_DIR/$GITHUB_ZIP_FILENAME_LATEST | |
chown -R $CHOWN_USER:$CHOWN_GROUP $THEMES_DIR/$THEME_NAME | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment