Skip to content

Instantly share code, notes, and snippets.

@mattkenefick
Created August 7, 2014 20:32
Show Gist options
  • Save mattkenefick/f2244f64f777349e9da3 to your computer and use it in GitHub Desktop.
Save mattkenefick/f2244f64f777349e9da3 to your computer and use it in GitHub Desktop.
Hate Wordpress Less - Install / Setup Script
#!/bin/bash
set -e
#
# @package Wordpress Commands
# @authors Matt Kenefick (matt@polymermallard.com)
# @date 2014-08-07 16:27:36
#
# Install the most recent version of Wordpress to your current directory.
# Connect to your local MySQL, check if DB exists, if not, create.
#
# I generally like having a folder containing commands like these hooked
# into my PATH. That way you can run "install-wordpress.sh" from any directory
# and get started in no time.
#
function install_wordpress {
# Fetch
wget http://wordpress.org/latest.tar.gz
# Unpack
tar xfz latest.tar.gz
# Move
mv wordpress/* .
# Cleanup
rmdir wordpress/
rm -f latest.tar.gz
}
mysql_exec () {
mysql -u$MYSQL_USER -p$MYSQL_PASS -h$MYSQL_HOST -se "$1"
}
# Start
while true; do
read -p "Install new Wordpress @ $PWD? [y/n] " yn
case $yn in
[Yy]* ) install_wordpress; break;;
[Nn]* ) break;;
* ) echo -e "Ignoring install.\n"; break; ;;
esac
done
# MySQL data
read -p "MySQL User: " MYSQL_USER
MYSQL_USER=${MYSQL_USER:-root}
read -p "MySQL Pass: " MYSQL_PASS
MYSQL_PASS=${MYSQL_PASS:-password}
read -p "MySQL Host: " MYSQL_HOST
MYSQL_HOST=${MYSQL_HOST:-localhost}
read -p "MySQL DB: " MYSQL_DB
MYSQL_DB=${MYSQL_DB:-new_wordpress}
echo "MySQL: $MYSQL_USER@$MYSQL_HOST $MYSQL_DB";
# Test Connection
DBS=$(mysql -u$MYSQL_USER -p$MYSQL_PASS -h$MYSQL_HOST -se "show databases");
if ! echo $DBS | grep $MYSQL_DB; then
mysql_exec "create database $MYSQL_DB";
mysql_exec "grant usage on *.* to $MYSQL_USER@$MYSQL_HOST identified by '$MYSQL_PASS'";
mysql_exec "grant all privileges on $MYSQL_DB.* to $MYSQL_USER@$MYSQL_HOST"
else
echo "Selected database '$MYSQL_DB' already exists. Exiting...";
fi
# Create your config file
cp wp-config-sample.php wp-config.php
perl -pi -e "s/username_here/$MYSQL_USER/g" wp-config.php
perl -pi -e "s/password_here/$MYSQL_PASS/g" wp-config.php
perl -pi -e "s/database_name_here/$MYSQL_DB/g" wp-config.php
# Create and control your uploads folder
mkdir wp-content/uploads
chmod 0777 wp-content/uploads
# Exit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment