Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Conflicts:
	vvv
  • Loading branch information
Adam Silverstein committed May 8, 2014
2 parents 8b743d2 + a2ddb03 commit 949d67b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 39 deletions.
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@ This bash script makes it easy to spin up a new WordPress site using [Varying Va

## Installation

Place `vvv` in any folder included in your PATH environment variable. To add a folder to PATH:
Download the script and run `./vvv` from the directory the script is placed in.

1. Open `~/.bashrc` (or `~/.bash_profile`)
1. If `PATH` is not defined anywhere in the file, add this line:
To run the script from anywhere, you can place `vvv` in a folder included in your PATH environment variable.

export PATH=/path/to/folder:$PATH

Where `/path/to/folder` is the path to the folder containing the script.
1. Changes take effect in a new Terminal session.
1. To run the script from anywhere, open the file and uncomment the line at the top defining `path`. Set that to the root folder of VVV on your machine.
If you don't want to define the path each time you run the script, open the file and uncomment the line at the top defining `path`. Set that to the root folder of VVV on your machine.

## Usage

Expand All @@ -28,26 +23,29 @@ This lists all the sites currently in VVV's `www` folder.
Creating a site does the following:

* Halts Vagrant (if running)
* Creates a web root for the site in the `www` folder containing two files: `vvv-init.sh` and `vvv-hosts`
* `vvv-init.sh` tells Vagrant to create a database if one does not exist and download or update WordPress from trunk the next time Vagrant is provisioned
* Creates a web root for the site in the `www` folder containing three files: `vvv-init.sh`, `wp-cli.yml`, and `vvv-hosts`
* `vvv-init.sh` tells Vagrant to create a database if one does not exist and install the latest version of WordPress (via WP-CLI) the next time Vagrant is provisioned
* `wp-cli.yml` tells WP-CLI that WordPress is in the htdocs folder
* `vvv-hosts` contains the hosts entry to give your site a nice custom domain (the domain is set in the wizard)
* Creates a file in the `nginx-config` folder to handle server settings for your site
* Restarts Vagrant with `vagrant up --provision`

Provisioning Vagrant takes a couple of minutes, but this is a crucial step as it checks out WordPress trunk into your site's htdocs directory.
Provisioning Vagrant takes a couple of minutes, but this is a crucial step as it downloads WordPress into your site's htdocs directory and runs the installation. If you want to skip provisioning and install WordPress manually, you can run the new site's `vvv-init.sh` file directly in the Vagrant shell.

#### `vvv new|create|make [site] [filesonly]`

Adding the `filesonly` parameter to this command will do everything in the list above except restart Vagrant. This is useful for testing the script quickly (as provisioning Vagrant takes a while).
Adding the `filesonly` parameter to this command will do everything in the list above except restart Vagrant. This is useful for testing the script quickly, or if you're creating multiple sites (as provisioning Vagrant takes a while).

### `vvv delete|rm|teardown [site]`

Deleting a site does the following:

* Halts Vagrant (if running)
* Deletes the site's web root (which deletes the `vvv-init.sh` and `vvv-hosts` files as well)
* Deletes the site's web root (which deletes the `vvv-init.sh`, `wp-cli.yml`, and `vvv-hosts` files as well)
* Deletes the file in the `nginx-config` folder pertaining to the site

Note that it does not delete the site's database.

## Questions?

Ping me on Twitter at [@alisothegeek](http://twitter.com/alisothegeek).
45 changes: 19 additions & 26 deletions vvv
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ if [[ $action = 'new' || $action = 'make' || $action = 'create' || $action = 'de
path=`pwd`
else
while [ -z $path ]; do
echo -n "VVV local root: "
read path
read -e -p "VVV install directory: " path

# Make sure directory is actually a VVV root
if [ ! -e "$path/Vagrantfile" ]; then
Expand All @@ -115,6 +114,7 @@ if [[ $action = 'new' || $action = 'make' || $action = 'create' || $action = 'de
done
fi
fi
path=${path%/}
fi

# =============================================================================
Expand Down Expand Up @@ -144,8 +144,7 @@ if [[ $action = 'new' || $action = 'make' || $action = 'create' ]]; then
unset site
fi
while [ -z $site ]; do
echo -n "Name of new site directory: "
read site
read -e -p "Name of new site directory: " site

if [ -z $site ]; then
cecho "You must enter a directory name." red
Expand All @@ -165,18 +164,9 @@ if [[ $action = 'new' || $action = 'make' || $action = 'create' ]]; then
domain="$site.dev"
fi

# Get WordPress version
echo -n "WordPress version (svn tag) to use (leave blank for trunk): "
read version
if [ -z $version ]; then
installversion="trunk"
else
installversion="tags/$version"
fi

# Inform the user of what's about to happen and give them a chance to back out
# =============================================================================
echo -e "\nAbout to perform the following:\n\n* Halt Vagrant (if running)\n* Create directory $site in $path/www\n* Create files vvv-init.sh and vvv-hosts in directory $site\n* Create file $site.conf in $path/config/nginx-config/sites"
echo -e "\nAbout to perform the following:\n\n* Halt Vagrant (if running)\n* Create directory $site in $path/www\n* Create files vvv-init.sh, wp-cli.yml, and vvv-hosts in directory $site\n* Create file $site.conf in $path/config/nginx-config/sites"
if [[ -z $files_only || $files_only != 'filesonly' ]]; then
echo -e "* Run \`vagrant up --provision\` to initialize site"
fi
Expand All @@ -203,22 +193,25 @@ if [[ $action = 'new' || $action = 'make' || $action = 'create' ]]; then
# Create site folder with vvv-init.sh file
# =============================================================================
cd $path/www
echo -en "Creating site directory and vvv-init.sh file... "
mkdir $site; cd $site
echo -en "Creating site directory, wp-cli.yml, and vvv-init.sh file... "
mkdir $site && cd $site

printf "path: htdocs" > wp-cli.yml

printf "echo \"Creating database $site (if it does not exist)...\"\n"\
printf "echo \"Creating database '$site' (if it does not exist)...\"\n\n"\
"mysql -u root --password=root -e \"CREATE DATABASE IF NOT EXISTS \\\`$db_name\\\`\"\n"\
"mysql -u root --password=root -e \"GRANT ALL PRIVILEGES ON \\\`$db_name\\\`.* TO wp@localhost IDENTIFIED BY 'wp';\"\n"\
"mysql -u root --password=root -e \"GRANT ALL PRIVILEGES ON \\\`$db_name\\\`.* TO wp@localhost IDENTIFIED BY 'wp';\"\n\n"\
"if [ ! -d \"htdocs\" ]; then\n"\
"\techo 'Checking out WordPress $version in $site/htdocs...'\n"\
"\tsvn checkout http://svn.automattic.com/wordpress/$installversion/ htdocs\n"\
"\tcd htdocs\n"\
"\techo 'Installing WordPress in $site/htdocs...'\n"\
"\tmkdir ./htdocs\ncd ./htdocs\n"\
"\twp core download --allow-root\n"\
"\twp core config --dbname=\"$db_name\" --dbuser=wp --dbpass=wp --dbhost=\"localhost\" --allow-root\n"\
"\twp core install --url=$domain --title=\"$site - WordPress $version\" --admin_user=admin --admin_password=password --admin_email=demo@example.com --allow-root\n"\
"\tcd ..\n"\
"\twp core install --url=$domain --title=\"$site - A WordPress Site\" --admin_user=admin --admin_password=password --admin_email=demo@example.com --allow-root\n"\
"\t\tcd -\n"\
"else\n"\
"\techo 'Updating WordPress $version in $site/htdocs...'\n"\
"\tsvn up htdocs\n"\
"\techo 'Updating WordPress in $site/htdocs...'\n"\
"\twp core update --allow-root\n"\
"\twp core update-db --allow-root\n"\
"fi\n" > vvv-init.sh

done_text
Expand Down Expand Up @@ -332,7 +325,7 @@ elif [[ $action = 'teardown' || $action = 'delete' || $action = 'rm' ]]; then
elif [[ $action = 'list' ]]; then

cd $path/www
find . -type d -print0 -maxdepth 1 -mindepth 1 | while IFS= read -d '' filename; do
find . -maxdepth 1 -mindepth 1 -type d -print0 | while IFS= read -d '' filename; do
filename=${filename:2}
if [[ $filename != 'default' && $filename != 'phpcs' && $filename != 'wp-cli' ]]; then
echo $filename
Expand Down

0 comments on commit 949d67b

Please sign in to comment.