-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-wp-theme-from-github.sh
50 lines (47 loc) · 2.49 KB
/
update-wp-theme-from-github.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/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/independ/public_html/wordpress/wp-content/themes" # NO trailing slash
THEME_NAME="independent-publisher" # The final directory name for the theme
GITHUB_ZIP_URL="https://github.com/raamdev/independent-publisher/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-master" # The name of the directory the GitHub zip file is extracted to
CHOWN_USER="independ" # The name of the user who should own these files
CHOWN_GROUP="independ" # The name of the group who should own these files
GITHUB_ZIP_FILENAME_LATEST="master.zip.latest"
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
echo "Fetching remote code for local installation..."
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