Last active
July 16, 2021 21:31
-
-
Save sarahg/b2945ee0157eb0b9b23ca204b4221c0b to your computer and use it in GitHub Desktop.
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 | |
# USAGE | |
# This script checks all sites in a Pantheon org for a given WordPress plugin. | |
# This may be useful in the event of an urgent security release. | |
# To run this, copy the file to your local machine and run the following commands: | |
# chmod +x checkOrgSitesForPlugin.sh | |
# ./checkOrgSitesForPlugin.sh plugin-slug | |
# Example: ./checkOrgSitesForPlugin.sh woo-gutenberg-products-block | |
# Un-comment line 15 and paste your Org ID there, or set it as an environment variable. | |
# You can find your Org ID by running: "terminus org:list" | |
# PANTHEON_ORG_ID="some-long-string-of-characters" | |
FIND_PLUGIN=${1} | |
# Get WordPress sites with a paid site plan. | |
PAID_WP_SITES="$(terminus org:site:list $PANTHEON_ORG_ID --filter="plan_name!=sandbox&&framework=wordpress" --format=list --field=Name)" | |
# Check each site to see if it has the given plugin. | |
while read -r SITENAME; do | |
PLUGINS="$(terminus wp "${SITENAME}".dev -- plugin list --field=name < /dev/null)" | |
for PLUGIN in $PLUGINS; do | |
if [[ "$PLUGIN" == "$FIND_PLUGIN" ]]; then | |
echo "🚨 $SITENAME is running $FIND_PLUGIN" | |
# Un-comment the following if you want to actually run the plugin update right meow: | |
# terminus connection:set "${SITENAME}".dev sftp | |
# terminus wp "${SITENAME}".dev -- plugin update "${FIND_PLUGIN}" --format=summary < /dev/null | |
# terminus env:commit "${SITENAME}".dev --message="Updated ${FIND_PLUGIN}" | |
# Un-comment this part if you want to push to Test: | |
# terminus env:deploy "${SITENAME}".test | |
# terminus env:clear-cache "${SITENAME}".test | |
# terminus wp "${SITENAME}".test -- core update-db < /dev/null | |
# And un-comment this if you want to make a database backup and push to Live: | |
# terminus backup:create "${SITENAME}".live --element=db | |
# terminus env:deploy "${SITENAME}".live | |
# terminus env:clear-cache "${SITENAME}".live | |
# terminus wp "${SITENAME}".live -- core update-db < /dev/null | |
fi | |
done | |
done <<< "$PAID_WP_SITES" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment