Skip to content

Instantly share code, notes, and snippets.

@crsnbrt
Last active August 8, 2016 03:33
Show Gist options
  • Save crsnbrt/55be3803919b841c6d48 to your computer and use it in GitHub Desktop.
Save crsnbrt/55be3803919b841c6d48 to your computer and use it in GitHub Desktop.
Script to generate instance of Wordpress from config file with wp-cli tools. Used in build/CI process to keep Wordpress core files of of your repo. Assumes your repo has "plugins/", "themes/", and "wp-config.json"
{
"version":"4.2.2",
"database":{
"dbhost":"127.0.0.1:3306",
"dbuser":"DB_USER",
"dbname":"DB_NAME",
"dbpass":"DB_PASS"
},
"plugins": [
{ "name":"wordpress-importer", "version": "0.6.1" }
]
}
#TODO: move this into the config
WP_ADMIN_UESR=user
WP_ADMIN_PASS=pass
WP_ADMIN_EMAIL=email
WP_TITLE=blog name
WP_URL=localhost
#php version
phpenv local 5.4
#install ruby dependencies
gem install compass
#install node dependencies
npm install
#install bower dependencies
bower install
#compile js and scss
gulp build
# create output dir for the bundle
mkdir -p ./output
# go into output dir
cd ./output
# get Wordpress cli tool http://wp-cli.org/
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
# Get json module for reading json config files
npm install -g json
# Get wordpress version to download
WP_VERSION=`cat ../wp-config.json | json version`
# Download instance of wordpress
php wp-cli.phar core download --version=$WP_VERSION
# Get wordpress database info
DB_USER=`cat ../wp-config.json | json database.dbuser`
DB_PASS=`cat ../wp-config.json | json database.dbpass`
DB_USER=${MYSQL_USER:-$DB_USER}
DB_PASS=${MYSQL_PASSWORD:-$DB_PASS}
DB_HOST=`cat ../wp-config.json | json database.dbhost`
DB_NAME=`cat ../wp-config.json | json database.dbname`
# setup config
php wp-cli.phar core config --dbhost=$DB_HOST --dbname=$DB_NAME --dbuser=$DB_USER --dbpass=$DB_PASS
# install wordpress
php wp-cli.phar core install --admin_user=$WP_ADMIN_UESR --admin_password=$WP_ADMIN_PASS --admin_email=$WP_ADMIN_EMAIL --title=$WP_TITLE --url=$WP_URL
#remove default plugins and themes
rm -r ./wp-content/plugins/*
rm -r ./wp-content/themes/*
# get plugins with versions to install
WP_PLUGINS=`cat ../wp-config.json | json plugins | json -a name version | tr '\n' ','`
IFS=','; plarr=($WP_PLUGINS)
# install each plugin
for key in "${!plarr[@]}"; do php wp-cli.phar plugin install ${plarr[$key]%% *} --version=${plarr[$key]##* } --force; done
# Copy custom themes into ./wp-content/themes/
cp -r ../themes/* ./wp-content/themes
# Copy custom puugins into ./wp-content/plugins/
cp -r ../plugins/* ./wp-content/plugins
# Remove wp-cli tool
rm wp-cli.phar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment