Created
March 28, 2015 15:49
-
-
Save sxalexander/c35cb9f2cef8e9636fc2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# DESCRIPTION Setup wildcard domains using dnsmasq so *.doc is automatically sent to a running boot2docker vm | |
# MAINTAINER sxalexander@gmail.com | |
# See: | |
# https://echo.co/blog/never-touch-your-local-etchosts-file-os-x-again | |
# https://gist.github.com/r10r/5108046 | |
# http://passingcuriosity.com/2013/dnsmasq-dev-osx/ | |
# check for homebrew | |
if ! command -v brew >/dev/null; then | |
echo "Homebrew is not installed. Aborting..."; | |
exit 1 | |
fi | |
# check for dnsmasq | |
brew list -1 | grep -Fqx "dnsmasq" | |
if [[ $? -ne 0 ]]; then | |
echo "dnsmasq is not installed. Aborting..."; | |
exit 1 | |
fi | |
# check for boot2docker running | |
if ! boot2docker ip &>/dev/null; then | |
echo "boot2docker is not running. Please start it and try again: 'boot2docker up'" | |
exit 1 | |
fi | |
# make folder for dynamic domains. NOTE: this requires a directive of `conf-dir=/usr/local/etc/dnsmasq.d/` to be set in dnsmasq.conf | |
[ -d $(brew --prefix)/etc/dnsmasq.d/ ] || mkdir -p $(brew --prefix)/etc/dnsmasq.d | |
# add a new conf file to instruct dnsmasq to ANSWER all requests to a *.doc domain with the boot2docker ip | |
echo "address=/.doc/$(boot2docker ip)\nlocal=/doc/" > $(brew --prefix)/etc/dnsmasq.d/doc.conf | |
# echo "address=/.doc/127.0.0.1\nlocal=/doc/" > $(brew --prefix)/etc/dnsmasq.d/doc.conf | |
# instruct OS X to CHECK dnsmasq locally for all *.doc top level domain requests | |
[ -d /etc/resolver ] || mkdir -v /etc/resolver | |
sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/doc' | |
# restart | |
sudo launchctl stop homebrew.mxcl.dnsmasq | |
sudo launchctl start homebrew.mxcl.dnsmasq | |
sudo discoveryutil mdnsflushcache |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment