Skip to content

Instantly share code, notes, and snippets.

@ginkgomzd
Last active March 13, 2020 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ginkgomzd/899aa993e4b095fc330c7b82dc68d6da to your computer and use it in GitHub Desktop.
Save ginkgomzd/899aa993e4b095fc330c7b82dc68d6da to your computer and use it in GitHub Desktop.
Makefile to on-board WP Engine sites for administration: set admin email and upgrade plugins, etc...
# # #
# Looks for ${PROJ_ROOT}conf/ssh_config.
# Export PROJ_ROOT or SSH_CONFIG
#
# Minimal orchestration through filtering of HOST_LIST
# by a prefix/suffix in ssh Host aliases specified in ENV.
# Defaults to 'stage'
#
# Targets with 'all-' prefix execute commands against all
# hosts in HOST_LIST.
#
# Many commands use HOST (esp ssh)
#
# Check individual commands for other variables used.
# Use the source, Luke.
#
# # #
SSH_CONFIG ?= ${PROJ_ROOT}conf/ssh_config
ssh = ssh -F ${SSH_CONFIG} ${HOST}
# filter HOST_LIST by ENV sub-string
ENV ?= stage
HOST_LIST = $(shell ${list-hosts} | grep -e ${ENV} )
list-hosts = grep Host\ ${SSH_CONFIG} | cut -d ' ' -f 2
DO_ALL_VERBOSE ?=
do-all = $(foreach host,${HOST_LIST}, $(MAKE) $(if ${DO_ALL_VERBOSE},,--quiet) HOST=${host} $(subst all-,,$@) ; )
wp = wp --skip-plugins --skip-themes
user-create = $(wp) user create --porcelain ${USER_LOGIN} ${USER_EMAIL} --display_name=\"${USER_FULL_NAME}\"
user-update = $(wp) user update ${USER_LOGIN}
$(info SELECTED HOST:: ${HOST})
list-users:
$(ssh) '$(wp) user list'
list-hosts: FILTER ?= \w
list-hosts:
@${list-hosts} | grep -e '${FILTER}'
get-shell:
@$(ssh)
dp-rmt: --cmd ?= wp user list
do-rmt:
$(ssh) '${--cmd}'
get-link:
$(eval site_url = $(shell $(ssh) '$(wp) option get siteurl --skip-plugins --skip-themes' ) )
$(info $(strip ${site_url})/wp-admin)
all-get-link:
@$(do-all)
# # #
# Jobs
create-admin:
-$(ssh) '$(user-create)'
$(ssh) '$(user-update) --role=administrator --user_pass="${USER_PASS}"'
all-create-admin:
$(do-all)
set-admin-email:
$(ssh) '$(wp) option set admin_email cdeutsch@allrise.org'
@$(eval LIFESPAN = $(shell date -d 'Sep 15, 2020' +%s ))
$(ssh) '$(wp) option set admin_email_lifespan ${LIFESPAN}'
all-set-admin-email:
$(do-all)
update-plugins:
@# not using $$(wp) on purpose to avoid --skip-plugins
$(ssh) 'wp plugin update --all'
all-update-plugins:
$(do-all)
find-plugins:
@# grep generates an error if none-found, so make should ignore:
-$(ssh) '$(wp) plugin list --status=active' | grep -e '${FILTER}'
all-find-plugins:
$(do-all)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment