Skip to content

Instantly share code, notes, and snippets.

@andrewwoods
Created October 10, 2018 03:49
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 andrewwoods/efae605e0f06cce7f99e31b78a23d99a to your computer and use it in GitHub Desktop.
Save andrewwoods/efae605e0f06cce7f99e31b78a23d99a to your computer and use it in GitHub Desktop.
WordPress Install Bash Script
#!/bin/bash
#
# Client website setup script
#
echo "Commencing WordPress trunk Setup"
DB_NAME="name_of_database"
DB_USER="database_username"
DB_PASS="database_password"
#
# Make a database, if we don't already have one
#
echo "Creating database (if it's not already there)"
mysql -u root --password=${DB_PASS} \
-e "CREATE DATABASE IF NOT EXISTS ${DB_NAME}"
mysql -u root --password=$DB_PASS \
-e "GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO ${DB_USER}@localhost IDENTIFIED BY '${DB_USER}';"
#
# Check for the presence of a `htdocs` folder.
# If `htdocs` folder doesn't exist, check out WordPress as that folder
#
if [ ! -d htdocs ]
then
echo "Checking out GitHub project"
git clone https://github.com/username/project.git htdocs
# Use WP CLI to create a `wp-config.php` file
wp core config --dbname="${DB_NAME}" \
--dbuser=${DB_USER} \
--dbpass=${DB_USER} \
--dbhost="localhost" \
--allow-root
# Use WP CLI to install WordPress
wp core install --url= \
--title="WordPress Trunk Auto" \
--admin_user=admin \
--admin_password=password \
--admin_email=demo@example.com \
--allow-root
#
# Change folder to the parent folder of `htdocs`
#
cd ..
else
echo "Updating Git Website"
# If the `htdocs` folder exists, then run SVN update
cd htdocs
git pull
cd ..
fi
#
# The Vagrant site setup script will restart Nginx for us
#
# Let the user know the good news
echo "WordPress client website now installed";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment