Last active
October 4, 2022 15:29
-
-
Save jacobmc/09e73d26dac265880787b81d238d33f4 to your computer and use it in GitHub Desktop.
Bash Script for starting an updates feature for a Bedrock WordPress site
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 | |
read -p "Have you pulled the latest changes? (y/N)" pulled | |
## Exit if user has not pulled latest changes | |
if [ "$pulled" != "y" ]; then | |
echo "exiting..." | |
exit | |
fi | |
# Check for untracked or changed files | |
untracked=`git ls-files --exclude-standard --others` | |
changed=`git diff --name-only` | |
# If there are changed or untracked files, abort | |
if [ ! -z "$untracked" -o ! -z "$changed" ]; then | |
echo ERROR: There are uncommitted changes in this repository. | |
echo exiting... | |
exit | |
fi | |
wp theme list --skip-plugins | |
wp plugin list --skip-plugins | |
read -p "Do you wish to continue? (y/N)" continue | |
## Exit if user does not wish to continue | |
if [ "$continue" != "y" ]; then | |
echo "exiting..." | |
exit | |
fi | |
git flow feature start updates | |
# Capture all premium plugins that aren't in the WP repo | |
premium_plugins=("woocommerce-shipment-tracking" "woocommerce-shipping-fedex" "woocommerce-shipping-ups" "woocommerce-shipping-usps") | |
premium_plugins+=("wordpress-seo-premium") | |
plugins_dir="web/app/plugins/" | |
# Loop through all plugin directories | |
for d in web/app/plugins/*/; do | |
# Checks to make sure file is not a symlink | |
if [[ ! -L "${d%/}" ]]; then | |
# Get plugin folder name | |
plugin_dir=${d#"$plugins_dir"} | |
plugin_dir=${plugin_dir%"/"} | |
is_premium=false | |
for p in ${premium_plugins[@]}; do | |
if [ $plugin_dir == $p ]; then | |
is_premium=true | |
fi | |
done | |
# Check if plugin is premium, only update non-premium plugins | |
if [ "$is_premium" = true ]; then | |
manual_plugins+=( "$plugin_dir" ) | |
else | |
wp plugin update $plugin_dir --dry-run --skip-plugins | |
# Check for untracked or changed files again | |
untracked=`git ls-files --exclude-standard --others` | |
changed=`git diff --name-only` | |
if [ ! -z "$untracked" -o ! -z "$changed" ]; then | |
git add $d | |
git commit -m "Updated $plugin_dir" | |
fi | |
fi | |
fi | |
done | |
# List premium plugins for easy reference | |
if [ ${#manual_plugins[@]} -eq 0 ]; then | |
echo "All plugins updated" | |
else | |
echo "" | |
echo "The following plugins will need to be updated manually:" | |
printf '%s\n' ${manual_plugins[*]} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't forget to make the script executable with
chmod 755 run-updates.sh