A set of bash scripts for "mass updating" sites on Pantheon using Terminus. These scripts are tooled for WordPress sites but can easily be repurposed for Drupal sites. While there is a Terminus Mass Update plugin, these scripts rely solely on base terminus commands; no additional plugins necessary. However, these scripts require setting ENVIRONMENT_VARIABLES to store "secrets". I chose to put them in a local file that is not included in this repository. You may view a reference to it in the scripts. Directions for setting the environment variables are provided below.
- requirement: terminus
- optional: Node.js and npm for installing a local version of standard-version
npm install
There are two sets of scripts in this repo, a set for updating multiple sites and a set for updating a single site. Each set of scripts consists of three scripts, each script addressing either the dev, test or live Pantheon Environments.
The following is a list of the scripts included and a brief description of what each does. These scripts should generally be run in the order listed below:
-
Update
devupdate-site-dev.shorupdate-sites-dev.sh
Update core<site>.<dev>:
-- check whether WordPress core updates are available.
-- set connection of all sites togitmode
-- apply upstream updates
-- reset connection of all sites tosftpmode
-- clear all caches
Apply WordPress theme and plugin updates:
-- update any plugins that need updating
-- update any themes that need updating
-- commit updates to the environment with a message
-- clear caches in the<site>.<dev>environment
-- open all<site>.<dev>environments in browser tabs for review -
Deploy from
<site>.<dev>to<site>.<test>:deploy-site-to-test.shordeploy-sites-to-test.sh
-- deploy sites to<site>.<test>with commit message
-- clear all caches
-- open all<site>.<test>environments in browser tabs for review -
Deploy from
<site>.<test>to<site>.<live>:deploy-site-to-live.shordeploy-sites-to-live.sh
Does exactly the same that Script 2 does, except deploys from<site>.<test>to<site>.<live>. -
Search and replace in database:
db-search-replace.sh(single-site only)
-- performs a WP-CLIsearch-replaceon the live database
-- runs in--dry-runmode by default — remove that flag to apply changes
-- requiresWP_SEARCHandWP_REPLACEto be set insecrets.sh
I use a local script named secrets.sh placed in the same directory as the scripts. This is where the environment variables are set. Each script directory includes a secrets.sh.example file — copy it and fill in your values:
cp scripts/multiple-sites/secrets.sh.example scripts/multiple-sites/secrets.sh
cp scripts/single-site/secrets.sh.example scripts/single-site/secrets.shThe PANTHEON_ORG environment variable used for updating multiple sites. Into your multiple-sites secrets.sh script, paste the following, using your own ORG UUID:
#!/bin/bash
# Stash ORG UUID
export PANTHEON_ORG="5234...9de8"The SITE_NAME environment variable is used for updating single sites. Into your single-site secrets.sh script, paste the following, using any portion of your single site's name:
#!/bin/bash
# Stash site name
export SITE_NAME="my-site-name"
# Required for db-search-replace.sh only
export WP_SEARCH="https://old-domain.com"
export WP_REPLACE="https://new-domain.com"chmod +x scripts/multiple-sites/*.sh
chmod +x scripts/single-site/*.shOnce the environment variables are set, the scripts should be run in the order described above.
# note: let each script complete before running the next
user@machine:~$ ./update-sites-dev.sh
user@machine:~$ ./deploy-sites-to-test.sh
user@machine:~$ ./deploy-sites-to-live.sh