Skip to content

Instantly share code, notes, and snippets.

@cyxou
Last active January 3, 2017 08:27
Show Gist options
  • Save cyxou/84038d5ff7127ce87828e3ba490f6763 to your computer and use it in GitHub Desktop.
Save cyxou/84038d5ff7127ce87828e3ba490f6763 to your computer and use it in GitHub Desktop.
Script that automatically updates plugins of WordPress hosted on Openshift. Inspired by http://www.websightdesigns.com/posts/view/wordpress-update-script
#!/bin/sh
if [ -d "./.openshift/plugins/" ]; then
webroot=$(pwd)
# folder plugins
for i in $(find $webroot/.openshift/plugins/ -maxdepth 1 -mindepth 1 -type d)
do
f=$(basename $i)
cd "$webroot/.openshift/plugins/"
if [ -f "./$f/readme.txt" ]; then
currpluginv=$(awk 'FNR>=1&&FNR<=10' ./$f/readme.txt | grep -E Stable.+\: | awk '{print $3}')
elif [ -f "./$f/README.txt" ]; then
currpluginv=$(awk 'FNR>=1&&FNR<=10' ./$f/README.txt | grep -E Stable.+\: | awk '{print $3}')
fi
echo -e "Current \e[48;5;21m$f\e(B\e[m version: \e[48;5;21m$currpluginv\e(B\e[m"
# Get the plugin readme file and use that to determine the latest stable release.
if curl --output /dev/null --silent --head --fail "http://plugins.svn.wordpress.org/$f/trunk/readme.txt"; then
curl --silent -o $f-readme.txt http://plugins.svn.wordpress.org/$f/trunk/readme.txt
pluginv=$(awk 'FNR>=1&&FNR<=10' $f-readme.txt | grep -E Stable.+\: | awk '{print $3}')
echo -e "Latest \e[48;5;21m$f\e(B\e[m version: \e[48;5;52m$currpluginv\e(B\e[m"
else
pluginv='.'
fi
# Do not update plugins for which we could not determine version.
if [[ "$currpluginv" = "$pluginv" ]] || [[ "$pluginv" == "trunk" ]] || [[ "$pluginv" == ".trunk" ]] || [[ "$pluginv" == "." ]]; then
updateplugin=false
echo -e "Skipping \e[48;5;21m$f\e(B\e[m plugin\n"
elif [[ ! "$currpluginv" = "$pluginv" ]]; then
updateplugin=true
else
updateplugin=false
fi
if [[ "$updateplugin" == "true" ]]; then
echo "Trying to download the $f plugin..."
# Check if plugin zip is available for download.
if curl --output /dev/null --silent --head --fail "http://downloads.wordpress.org/plugin/$f.$pluginv.zip"; then
wget -q "http://downloads.wordpress.org/plugin/$fi.$pluginv.zip"
rm -rf $f
unzip -o "$f.$pluginv.zip"
if [ -f "$f.$pluginv.zip" ]; then
rm -f "$f.$pluginv.zip"
fi
# Commit the changes
git add -A $f
git commit -m "Update $f to v$pluginv"
else
echo -e "\e[48;5;21mFailed to download the $f.$pluginv.zip\e(B\e[m zip. Update it manually\e(B\e[m"
fi
fi
if [ -f "$f-readme.txt" ]; then
rm $f-readme.txt
fi
done
fi
@cyxou
Copy link
Author

cyxou commented Jan 3, 2017

Update of 03.01.2017

  • Script won't update a plugin if it's version is trunk or could not be determined.
  • Script will download only the versioned zip of plugins (i.e woocommerce.2.6.11.zip)in order not to install a beta version under the not versioned zip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment