Last active
November 8, 2018 03:10
-
-
Save L422Y/d91320b20941392a46cce2427dd3d817 to your computer and use it in GitHub Desktop.
Script to automate updating a staged WordPress site from a local dev environment and clear caches
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 | |
# | |
# Author: Larry Williamson - [email protected] | |
# Script to automate updating a staged WordPress site from a local dev environment and clear PageSpeed | |
# and NGiNX fastcgi caches. Skips uploading node_modules. | |
# | |
# 1) Update WordPress (Understrap) version in style.css so browsers will refresh the new version | |
# 2) use lftp w/ sftp to reverse mirror files w/ 20 parallel connections (FAST.) | |
# 3) use SSH to remotely execute a cache clearing script | |
# Update these... | |
REMOTEUSER=ubuntu | |
REMOTEHOST=stage.remotehost.com | |
PRIVKEY=REMOTEHOST.pem | |
# And these... | |
# Path to the WordPress stylesheet w/ Version # in it | |
STYLEPATH="/Users/larry/Development/websites/remotehost.com/wordpress/wp-content/themes/remotehost/style.css" | |
# Local source directory | |
SOURCEDIR="/Users/larry/Development/websites/remotehost.com/wordpress" | |
# Remote Destination Directory | |
DESTDIR="/var/www/html" | |
# Onwards to the good stuff... no need to update anything else | |
perl -i -pe 's/^\sVersion:\s+\d+\.\d+\.\K(\d+)/ $1+1 /e' ${STYLEPATH} | |
lftp sftp://${REMOTEUSER}:@${REMOTEHOST} -e 'set sftp:connect-program "ssh -i ~/.ssh/'${PRIVKEY}'"; mirror -c -e -R --parallel=20 --verbose "'${SOURCEDIR}'" "'${DESTDIR}'" --exclude node_modules/;quit;' | |
ssh -t ${REMOTEUSER}@${REMOTEHOST} -i ~/.ssh/${PRIVKEY} "sudo -s; rm -rf /etc/nginx/cache; rm -rf /var/ngx_pagespeed_cache/*" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment