chore: initial wp-boilerplate project
This commit is contained in:
5
scripts/.lwsrc
Normal file
5
scripts/.lwsrc
Normal file
@@ -0,0 +1,5 @@
|
||||
#LOCAL_DOMAIN=example.${TLD-ledevsimple.ca}
|
||||
#REMOTE_DOMAIN=www.example.com
|
||||
#REMOTE_HOST=cpanel5.lewebsimple.ca
|
||||
#REMOTE_USER=example
|
||||
#REMOTE_PATH=/home/${REMOTE_USER}/public_html
|
||||
75
scripts/common.sh
Executable file
75
scripts/common.sh
Executable file
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
_DIR_=`dirname "$(readlink -f "$0")"`
|
||||
_FILE_=`basename $0`
|
||||
_LOG_=${SHELL_LOG:-/dev/null}
|
||||
_NOW_=`date +"%Y-%m-%d@%H:%M"`
|
||||
|
||||
# Helpers
|
||||
function CONFIRM {
|
||||
read -r -p "${1:-Are you sure?} [y/N] " response
|
||||
case "$response" in
|
||||
[yY][eE][sS]|[yY])
|
||||
true
|
||||
;;
|
||||
*)
|
||||
false
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function INFO {
|
||||
echo -e "\e[1;32m[${_FILE_}]\e[0m ${1}"
|
||||
}
|
||||
|
||||
function WARNING {
|
||||
echo -e "\e[1;33m[${_FILE_}]\e[0m ${1}"
|
||||
CONFIRM && return
|
||||
exit 1
|
||||
}
|
||||
|
||||
function ERROR {
|
||||
echo -e "\e[1;31m[${_FILE_}]\e[0m ${1}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
function TIME_START {
|
||||
t1=`date +%s.%N`
|
||||
}
|
||||
|
||||
function TIME_STOP {
|
||||
t2=`date +%s.%N`
|
||||
dt=`echo "$t2 - $t1" | bc -l`
|
||||
dt=`echo "scale=2; $dt / 1" | bc -l`
|
||||
echo "Done in ${dt}s"
|
||||
}
|
||||
|
||||
# Default configuration
|
||||
if [ -f "${_DIR_}/.lwsrc" ]; then
|
||||
source ${_DIR_}/.lwsrc
|
||||
else
|
||||
ERROR "Config not found! Please create ${_DIR_}/.lwsrc"
|
||||
fi
|
||||
|
||||
# Check configuration
|
||||
if [ -z "${REMOTE_DOMAIN}" ]; then
|
||||
ERROR "Please configure REMOTE_DOMAIN in ${_DIR_}/.lwsrc"
|
||||
fi
|
||||
if [ -z "$REMOTE_HOST" ] || [ -z "$REMOTE_USER" ] || [ -z "$REMOTE_PATH" ]; then
|
||||
ERROR "Please configure REMOVE_HOST / REMOVE_USER / REMOTE_PATH in ${_DIR_}/.lwsrc"
|
||||
fi
|
||||
|
||||
# Change to project root directory
|
||||
cd ${_DIR_}/..
|
||||
|
||||
# Determine local domain
|
||||
if [ -z "${LOCAL_DOMAIN}" ]; then
|
||||
LOCAL_DOMAIN=${REMOTE_DOMAIN#www.}
|
||||
LOCAL_DOMAIN="${LOCAL_DOMAIN%%.*}.${TLD-ledevsimple.ca}"
|
||||
fi
|
||||
if [ -z "${LOCAL_DOMAIN}" ]; then
|
||||
ERROR "Could not determine local domain. Please verify ${_DIR_}/.lwsrc"
|
||||
fi
|
||||
|
||||
# Determine local protocol
|
||||
LOCAL_PROTOCOL="${LOCAL_PROTOCOL-https}"
|
||||
63
scripts/post-create.sh
Executable file
63
scripts/post-create.sh
Executable file
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
PROJECT=${PWD##*/}
|
||||
DB_NAME="wp_${PROJECT/-/_}"
|
||||
GIT_URL="https://gitea.websimple.com/wp-sites/${PROJECT}.git"
|
||||
GIT_ORIGIN="ssh://git@gitea.websimple.com:222/wp-sites/${PROJECT}.git"
|
||||
|
||||
# Portable in-place sed: use GNU sed's -i -e or BSD/macOS sed's -i '' -e
|
||||
sed_inplace() {
|
||||
local expr="$1"
|
||||
shift || return
|
||||
|
||||
# Detect macOS (Darwin) via uname -s; treat everything else as GNU-like sed
|
||||
local os
|
||||
os="$(uname -s 2>/dev/null || echo Unknown)"
|
||||
|
||||
for f in "$@"; do
|
||||
if [ "$os" = "Darwin" ]; then
|
||||
# macOS/BSD sed requires an explicit empty extension to avoid creating backups
|
||||
sed -i '' -e "$expr" "$f"
|
||||
else
|
||||
# GNU sed supports -i -e without creating backup files
|
||||
sed -i -e "$expr" "$f"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Rename project
|
||||
sed_inplace "s/wp-boilerplate/${PROJECT}/g" .cpanel.yml .gitignore composer.json
|
||||
|
||||
# Initialize git repository
|
||||
git init
|
||||
git remote add origin ${GIT_ORIGIN}
|
||||
git fetch origin || error_code=$?
|
||||
if [ "${error_code-0}" -eq 0 ]; then
|
||||
git checkout main -f
|
||||
rm -rf wp-content/mu-plugins/*
|
||||
rm -rf wp-content/plugins/*
|
||||
rm -rf wp-content/themes/*
|
||||
git reset --hard
|
||||
composer install
|
||||
else
|
||||
git remote remove origin
|
||||
git add -A
|
||||
git commit -am 'chore: initial wp-boilerplate project'
|
||||
fi
|
||||
|
||||
# Create database
|
||||
mysql -e "CREATE DATABASE IF NOT EXISTS ${DB_NAME}"
|
||||
|
||||
# Download / configure / install WordPress
|
||||
wp core download --force --skip-content
|
||||
wp core config --dbname=${DB_NAME}
|
||||
|
||||
# Require Composer vendor/autoload.php in wp-config.php
|
||||
VENDOR_AUTOLOAD="if ( file_exists( 'vendor/autoload.php' ) ) { require_once 'vendor/autoload.php'; }"
|
||||
if ! grep -Fq "${VENDOR_AUTOLOAD}" wp-config.php; then
|
||||
sed_inplace "2s|^|${VENDOR_AUTOLOAD}\n|" wp-config.php
|
||||
fi
|
||||
|
||||
# Done
|
||||
echo "Site ready at ${LOCAL_PROTOCOL-https}://${PROJECT}.${TLD-ledevsimple.ca}"
|
||||
59
scripts/update-local.sh
Executable file
59
scripts/update-local.sh
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
source "`dirname $0`/common.sh"
|
||||
|
||||
# Backup database
|
||||
#INFO "Backing up database..."
|
||||
#DB_FILE="${LOCAL_DOMAIN}-${_NOW_}-before-update.sql"
|
||||
#TIME_START
|
||||
#wp db export ${DB_FILE} > ${_LOG_} 2>&1
|
||||
#TIME_STOP
|
||||
|
||||
# Synchronize uploads
|
||||
INFO "Synchronizing uploads..."
|
||||
TIME_START
|
||||
rsync -ave "ssh -p 2222" ${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_PATH}/wp-content/uploads/ wp-content/uploads/ --exclude node_modules --delete > ${_LOG_} 2>&1
|
||||
TIME_STOP
|
||||
|
||||
# Synchronize database
|
||||
INFO "Synchronizing database..."
|
||||
DB_FILE="${REMOTE_DOMAIN}-${_NOW_}.sql"
|
||||
TIME_START
|
||||
ssh -p 2222 ${REMOTE_USER}@${REMOTE_HOST} "cd ${REMOTE_PATH} && wp --allow-root --skip-plugins --skip-themes db export ${DB_FILE}" > ${_LOG_} 2>&1
|
||||
ssh -p 2222 ${REMOTE_USER}@${REMOTE_HOST} "cat ${REMOTE_PATH}/${DB_FILE}" | wp db import - > ${_LOG_} 2>&1
|
||||
ssh -p 2222 ${REMOTE_USER}@${REMOTE_HOST} "rm -f ${REMOTE_PATH}/${DB_FILE}" > ${_LOG_} 2>&1
|
||||
TIME_STOP
|
||||
|
||||
# Replace domain
|
||||
INFO "Replacing domain ${REMOTE_DOMAIN} => ${LOCAL_DOMAIN}..."
|
||||
TIME_START
|
||||
wp --skip-plugins --skip-themes search-replace "https://${REMOTE_DOMAIN}" "${LOCAL_PROTOCOL}://${LOCAL_DOMAIN}" --all-tables > ${_LOG_} 2>&1
|
||||
TIME_STOP
|
||||
|
||||
# Deactivate plugins
|
||||
INFO "Deactivating plugins..."
|
||||
TIME_START
|
||||
wp --skip-plugins --skip-themes plugin deactivate \
|
||||
cookie-law-info \
|
||||
ithemes-security-pro \
|
||||
wp-offload-ses \
|
||||
> ${_LOG_} 2>&1 || true \
|
||||
TIME_STOP
|
||||
|
||||
# Activate plugins
|
||||
INFO "Activating plugins..."
|
||||
TIME_START
|
||||
wp --skip-plugins --skip-themes plugin install --activate \
|
||||
disable-emails \
|
||||
loco-translate \
|
||||
wp-mail-logging \
|
||||
> ${_LOG_} 2>&1 || true \
|
||||
TIME_STOP
|
||||
|
||||
# Flush permalinks
|
||||
INFO "Flushing permalinks..."
|
||||
TIME_START
|
||||
wp rewrite flush --hard > ${_LOG_} 2>&1
|
||||
TIME_STOP
|
||||
|
||||
INFO "Local development site ready: ${LOCAL_PROTOCOL}://${LOCAL_DOMAIN}"
|
||||
Reference in New Issue
Block a user