Skip to content

Instantly share code, notes, and snippets.

@vl123
Last active April 26, 2017 09:02
Show Gist options
  • Save vl123/c2b0cd12e12c2f9763e38895b1703087 to your computer and use it in GitHub Desktop.
Save vl123/c2b0cd12e12c2f9763e38895b1703087 to your computer and use it in GitHub Desktop.
WP-CLI bash install script
#!/bin/bash
# functions
generate_password()
{
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n 1
}
# variables
SITE_URL_PART=".example.com"
DB_USER="dbuser"
DB_PASS="dbpassword"
DB_PREFIX="wp_"
WP_EMAIL="admin@localhost"
WP_USER="admin"
WP_PASS=$(generate_password)
THEMES_TO_REMOVE=("twentyfifteen" "twentysixteen")
PLUGINS_TO_REMOVE=("hello")
if [ $1 ]
then
SITE_URL_DOMAIN=$1$SITE_URL_PART
echo "Site domain: $SITE_URL_DOMAIN"
echo "WP login: $WP_USER"
echo "WP password: $WP_PASS"
wp core download --path=$1
cd $1/
wp core config --dbname=$1 --dbuser=$DB_USER --dbpass=$DB_PASS --dbprefix=$DB_PREFIX
wp db create
wp core install --url=$SITE_URL_DOMAIN --title=$1 --admin_user=$WP_USER --admin_password=$WP_PASS --admin_email=$WP_EMAIL --skip-email
# delete unused themes
for THEME_NAME in "${THEMES_TO_REMOVE[@]}"
do
wp theme delete $THEME_NAME
done
# delete unused plugins
for PLUGIN_NAME in "${PLUGINS_TO_REMOVE[@]}"
do
wp plugin delete $PLUGIN_NAME
done
# delete default post and page
wp post delete $(wp post list --post_type=page,post --format=ids) --force
# change settings
wp option set blog_public 0 # Discourage search engines from indexing this site
echo "That's all folks!"
else
echo "Usage: wp-install.sh sitename"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment