kneath (owner)

Forks

Revisions

gist: 18513 Download_button fork
public
Public Clone URL: git://gist.github.com/18513.git
Embed All Files: show embed
vhostit.sh #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/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