Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add lvh.me to Mac OS X hosts file
#!/bin/bash
main() {
if [[ $(has_lvh_me) == 1 ]]; then
echo 'lvh.me is already specified in your hosts file'
else
add_lvh_me
echo 'lvh.me was added to your hosts file!'
fi
flush_dns_cache
}
has_lvh_me() {
if [[ $(find_lvh_in_hosts) -eq "1" ]]; then
echo 1
else
echo 0
fi
}
find_lvh_in_hosts() {
local has_lvh=`cat /etc/hosts | grep lvh.me | wc -l`
if [[ "$has_lvh" -gt "0" ]]; then
echo "1"
else
echo "0"
fi
}
add_lvh_me() {
sudo echo '127.0.0.1 lvh.me' >> /etc/hosts
}
flush_dns_cache() {
if [ `sysctl -n kern.osrelease | cut -d . -f 1` -lt 9 ]; then
lookupd -flushcache
else
dscacheutil -flushcache
fi
}
main
@mdespuits

This comment has been minimized.

Copy link
Owner Author

mdespuits commented May 3, 2012

The reason I created this was because somehow my lvh.me setup was destroyed in my /etc/hosts file, so this added it back in and made it all work again! (I think it may have had something to do with Pow, but I have not been able to confirm that).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.