Skip to content

Commit

Permalink
Auto-collate hosts to add from /srv/www/**/vvv-domains
Browse files Browse the repository at this point in the history
Write-out hosts to config/host-hosts for easy appending to host's /etc/hosts file
Prompt at end of provision script for hosts to add
  • Loading branch information
westonruter committed Jul 17, 2013
1 parent b06f308 commit ee604fb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
# We do have some default nginx configs that should be included
!/config/nginx-config/sites/default.conf

# Ignore file containing hosts which needs to get appended to system's hosts file
/config/host-hosts

# And we do have a default SQL file that should be included
!/database/init.sql

Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ Immediate goals for VVV include:
1. Start the Vagrant environment
* `vagrant up` - *omg magic happens*
* Be patient, this could take a while, especially on the first run.
1. Add a record to your local machine's hosts file
* `192.168.50.4 local.wordpress.dev local.wordpress-trunk.dev`
* On -nix systems you can use: (note that location of host file after the >> may vary) `sudo sh -c 'echo "192.168.50.4 local.wordpress.dev local.wordpress-trunk.dev" >>/private/etc/hosts'`
1. Add records to your local machine's hosts file, which are prompted at the end of `vagrant up` and which are located in `config/hosts-hosts`
* On -nix systems you can use: (note that location of host file after the >> may vary) `sudo sh -c 'cat config/hosts-hosts >>/private/etc/hosts'`
1. Visit `http://local.wordpress.dev/` in your browser for WordPress 3.5.1, `http://local.wordpress-trunk.dev` for WordPress trunk, or `http://192.168.50.4` for the default dashboard.

Fancy, yeah?
Expand Down
25 changes: 22 additions & 3 deletions provision/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,29 @@ else
fi
# Add any custom domains to the virtual machine's hosts file so that it
# is self aware. Enter domains space delimited as shown with the default.
DOMAINS='local.wordpress.dev local.wordpress-trunk.dev'
if ! grep -q "$DOMAINS" /etc/hosts
then echo "127.0.0.1 $DOMAINS" >> /etc/hosts

echo "# Hosts for varying-vagrant-vagrants:" > /srv/config/hosts-hosts
echo "# Make sure the following exist in your host machine's hosts file"
echo "# Full list will be located in config/hosts-hosts"
wp_domains='local.wordpress.dev local.wordpress-trunk.dev'
if ! grep -q "$wp_domains" /etc/hosts
then
echo "127.0.0.1 $wp_domains" >> /etc/hosts
fi
echo "$vagrant_ip $wp_domains" | tee -a /srv/config/hosts-hosts

# Look for additional domains defined in the sites
for site_domains_file in $(find /srv/www -type f -name 'vvv-domains')
do
cat $site_domains_file | sed '/^(#| *$)/d' | while read site_domain_line
do
if ! grep -q "$site_domain_line" /etc/hosts
then
echo "127.0.0.1 $site_domain_line" >> /etc/hosts
fi
echo "$vagrant_ip $site_domain_line" | tee -a /srv/config/hosts-hosts
done
done

end_seconds=`date +%s`
echo -----------------------------
Expand Down

0 comments on commit ee604fb

Please sign in to comment.