Created
October 22, 2008 01:55
-
-
Save kneath/18513 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 | |
# VHostit | |
# Simple bash script to add a virtual host to apache & your hosts file on OS X | |
# | |
# Installation | |
# Throw vhostit.sh somewhere in your path. I like to copy it to /usr/local/bin/vhostit | |
# Usage | |
# `vhostit domain.tld` from within the directory you want to host. | |
# The domain.tld will be added to your hosts file and a VirtualHost added to your apache's httpd.conf\ | |
usage(){ | |
echo "vhostit by Kyle Neath (http://warpspire.com)" | |
echo "" | |
echo "Adds the current directory to your httpd & hosts file under the domain you choose" | |
echo "Assumes default OS X locations (/etc/hosts & /etc/apache2/httpd.conf)" | |
echo "" | |
echo "Usage $0 [domain]" | |
exit | |
} | |
case $1 in | |
-h) usage;; | |
--help) usage;; | |
esac | |
HOSTS_FILE="/etc/hosts" | |
HTTPD_FILE="/etc/apache2/httpd.conf" | |
if [ -n "$1" ]; then | |
NEW_HOSTS="127.0.0.1\t$1" | |
$(echo $NEW_HOSTS >> $HOSTS_FILE) | |
NEW_HTTPD="\n<VirtualHost *:80>\n\tServerName $1\n\tDocumentRoot \"$(pwd)\"\n\t<directory \"$(pwd)\">\n\t\tOrder allow,deny\n\t\tAllow from all\n\t</directory>\n</VirtualHost>" | |
$(echo $NEW_HTTPD >> $HTTPD_FILE) | |
$(apachectl restart) | |
else | |
usage; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment