-
-
Save johanoloflindberg/5e5dccae7621a8b69b2bf538e310d08a to your computer and use it in GitHub Desktop.
Script to create new WordPress setup, using WP-CLI
This file contains hidden or 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 | |
# | |
# USE FOR LOCAL DEVELOPMENT ONLY!!! | |
# | |
EMAIL='[email protected]' | |
MYSQL=`which mysql` | |
echo -n "DB user/name for project (lowercase) [ENTER]:" | |
read DB | |
if [ -z "$DB" ]; then | |
echo "User must define a DB Name for your project." | |
exit; | |
fi | |
echo -n "Local URL eg. local.test.com [ENTER]:" | |
read URL | |
if [ -z "$URL" ]; then | |
echo "You must enter a valid url." | |
exit; | |
fi | |
echo -n "Theme slug [ENTER]:" | |
read THEME_SLUG | |
echo -n "Theme Name, like 'My Theme' [ENTER]:" | |
read THEME_NAME | |
# | |
# Start WP Installation | |
# | |
random-string() { | |
LENGTH=$1 | |
if [ -z "$LENGTH" ]; then | |
LENGTH='20' | |
fi | |
cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w $LENGTH | head -n 1 | |
} | |
# Generate random password (mac friendly) | |
PASS=`random-string 20` | |
PREFIX='' | |
# No prefix? Then just comment out the line below | |
PREFIX="--dbprefix=`random-string 6`_" | |
Q1="CREATE DATABASE IF NOT EXISTS $DB;" | |
Q2="GRANT ALL ON $DB.* TO '$DB'@'localhost' IDENTIFIED BY '$PASS';" | |
Q3="FLUSH PRIVILEGES;" | |
SQL="${Q1}${Q2}${Q3}" | |
if [ ! -d "htdocs" ]; then | |
# Create directory for new WP | |
mkdir htdocs | |
fi | |
cd htdocs | |
echo "SUDO password for adding /etc/hosts entry"; | |
# Add to our hosts file (saves adding it manually) | |
sudo -- sh -c -e "echo '127.0.0.1 $URL' >> /etc/hosts" | |
if [ -n "$(grep $URL /etc/hosts)" ] | |
then | |
echo "$URL was added succesfully \n $(grep $URL /etc/hosts)"; | |
else | |
echo "Failed to Add $URL, Try again!"; | |
fi | |
# Set up a login path for creating your dbs and users (must have global privileges) | |
# mysql_config_editor set --login-path=local --host=localhost --user=username --password | |
$MYSQL --login-path=local -e "$SQL" | |
echo "MYSQL user/db '$DB' created." | |
# Install latest WP | |
wp core download | |
wp core config --dbname="$DB" --dbuser="$DB" --dbpass="$PASS" $PREFIX | |
wp core install --url="$URL" --title='New WP Build' --admin_user='jason' --admin_password='local' --admin_email="$EMAIL" --skip-email | |
# Install & Active Plugins | |
# wp plugin install sucuri-scanner --activate | |
# wp plugin install wordpress-seo | |
wp plugin install autodescription | |
#wp plugin install google-sitemap-generator | |
wp plugin install advanced-custom-fields | |
wp plugin install regenerate-thumbnails | |
wp plugin install developer | |
# Install but leave inactive | |
# wp plugin install jetpack | |
#wp plugin install google-analytics-for-wordpress | |
# wp plugin install loginlockdown | |
# wp plugin install wp-retina-2x | |
wp plugin install wordpress-importer | |
# wp plugin install cookie-law-info | |
wp plugin install w3-total-cache | |
# Remove 'hello dolly' demo plugin | |
wp plugin delete hello | |
# Remove old default themes | |
wp theme delete twentyfifteen | |
wp theme delete twentythirteen | |
wp theme delete twentyfourteen | |
# Remove default posts, widgets, comments etc. | |
wp site empty --yes | |
wp scaffold _s "$THEME_SLUG" --theme_name="$THEME_NAME" --sassify | |
git clone https://github.com/roots/sage.git wp-content/themes/sage && rm -rf wp-content/themes/sage/.git | |
git clone https://github.com/roots/wp-password-bcrypt.git wp-content/mu-plugins/wp-password-bcrypt && rm -rf wp-content/mu-plugins/wp-password-bcrypt/.git | |
git clone https://github.com/roots/soil.git wp-content/plugins/soil && rm -rf wp-content/plugins/soil/.git | |
# Move the config a directory above | |
mv wp-config.php ../ | |
# Make uploads writable | |
chmod -R 777 wp-content/uploads | |
# Is the directory a git repo? If not, create one | |
cd .. | |
if [ ! -d ".git" ]; then | |
git init . | |
fi | |
# Making a dumping folder | |
mkdir etc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment