Last active
March 16, 2021 17:23
-
-
Save knowler/fe28bf66a3359fcdc65d491ecc6f91ba 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 | |
# Regolith aka Un-Bedrock | |
# "But what if we need to hand it off to another agency?" No more! | |
# This script converts a Bedrock site to a normal WordPress structure. | |
# Run it from the root of a Bedrock project. | |
# Created by Nathan Knowler and Daniel Roe | |
echo "Converting Bedrock to a normal WordPress file structure..." | |
# Get site name | |
site=${PWD##*/} | |
# Set destination name | |
dest=../$site-wordpress | |
# Set .env | |
env=./.env | |
# Copy WordPress | |
cp -a ./web/wp $dest | |
# Copy app content | |
cp -a ./web/app $dest/wp-content | |
# Backup current database | |
wp db export $dest/$site-backup.sql | |
# Change Bedrock URLs | |
wp search-replace '/app/' '/wp-content/' | |
wp search-replace '\/app\/' '\/wp-content\/' | |
# Export DB | |
wp db export $dest/$site.sql | |
# Restore DB backup | |
wp db import $dest/$site-backup.sql | |
# Remove DB backup | |
rm $dest/$site-backup.sql | |
# Create wp-config.php | |
cp $dest/wp-config-sample.php $dest/wp-config.php | |
dest_config=$dest/wp-config.php | |
# Copy over basic WP database settings | |
# On macOS sed is broken-ish. Use gnu-sed instead. | |
# brew install gnu-sed | |
# echo 'alias sed=gsed\nexport LC_ALL=en_US.UTF-8' >> .bash_profile | |
source $env | |
sed -i "s/database_name_here/${DB_NAME}/g" $dest_config | |
sed -i "s/username_here/${DB_USER}/g" $dest_config | |
sed -i "s/password_here/${DB_PASSWORD}/g" $dest_config | |
if [ ! -z "$DB_HOST" ]; then | |
sed -i "s/localhost/${DB_HOST}/g" $dest_config | |
fi | |
# Copy over any other .env settings | |
# On macOS use gxargs included in findutils. | |
# brew install findutils | |
# echo 'alias xargs=gxargs' >> .bash_profile | |
for line in $(grep -v '^#' .env | xargs -d '\n') | |
do | |
varname=$(echo ${line} | sed -e 's/\(.*\)=.*/\1/g') | |
value=$(echo ${line} | sed -e "s/.*\=\('\(.*\)'\$\)\|\(.*\=\(.*\)\$\)/\4/g") | |
if [ -z "$value" ]; then | |
value=$(echo ${line} | sed -e "s/.*\=\('\(.*\)'\$\)\|\(.*\=\(.*\)\$\)/\2/g") | |
fi | |
if [ "$varname" != 'WP_SITEURL' ] && [ "$varname" != 'DB_NAME' ] && [ "$varname" != 'DB_USER' ] && [ "$varname" != 'DB_PASSWORD' ] && [ "$varname" != 'DB_HOST' ] && [ "$varname" != 'WP_SITEURL' ]; then | |
echo "define('${varname}', '${value}');" >> $dest_config | |
fi | |
done | |
# Compress | |
zip -qr $site.zip $dest | |
mv $site.zip .. | |
# Clean up | |
rm -rf $dest | |
# Sassiness | |
echo "That was *really* easy. Output is zipped in directory above." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment