Skip to content

Instantly share code, notes, and snippets.

@jellybeansoup
Created March 25, 2014 14:46
Show Gist options
  • Save jellybeansoup/9763298 to your computer and use it in GitHub Desktop.
Save jellybeansoup/9763298 to your computer and use it in GitHub Desktop.
A shell script for easily setting up a Wordpress dev environment.
#!/bin/sh
# We need an install path
if [ $# != 1 ]; then
echo "Usage: wordpress.sh <install-path>"
exit 1
fi
# Fix the path if it's relative
given_path=$1
if [ ${given_path:0:1} != "\/" ]; then
#given_path=$(pwd)/$given_path
given_path=~/Development/Websites/$given_path
fi
echo "Installing Wordpress to '$given_path'..."
# If the folder exists, we fail
if [ -a "$given_path" ]; then
echo "Error: Cannot install Wordpress in existing folder"
exit 1
fi
# Move to this folder
mkdir -p $given_path
cd $given_path
# Get the wordpress install and unpack it
wget http://wordpress.org/latest.tar.gz
tar zxf $given_path/latest.tar.gz
# Move the unpacked files to where they belong
mv -f $given_path/wordpress/* $given_path
# Delete the temp files
rm -Rf $given_path/wordpress
rm -f $given_path/latest.tar.gz
# Set up the config file
prefix=$(echo "wp_${given_path##*/}_" | tr '[A-Z]' '[a-z]')
sed -e "s/database_name_here/js_wordpress/g" \
-e "s/username_here/js_wordpress/g" \
-e "s/password_here/js_wordpress/g" \
-e "s/put your unique phrase here/do_not_use_this_salt_in_production/g" \
-e "s/'wp_'/'$prefix'/g" \
-e "s/WP_DEBUG', false/WP_DEBUG', true/g" wp-config-sample.php > wp-config.php
# Now we're going to clone the theme repository
echo "To clone a theme repository, please provide the origin:"
read origin
if ! [ -z "$origin" ]; then
cd $given_path/wp-content/themes
git clone $origin
fi
# And finally, we're going to chmod everything
chmod -Rf 0777 $given_path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment