Created
May 9, 2013 15:15
-
-
Save adamnorwood/5548102 to your computer and use it in GitHub Desktop.
A simple bash script for setting up a local directory and corresponding entry in /etc/hosts, suitable for use with Apache wildcard name-based virtual hosts. For example: 'newsite example.dev' creates a directory called /www/example.dev/ and also adds appropriate 127.0.0.1 / ::1 entries for example.dev to /etc/hosts (the latter step requires sudo).
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/bash | |
DIRECTORY="/www/$1" | |
DIR_CREATED=false | |
HOSTS_EDITED=false | |
if [ -d "$DIRECTORY" ]; then | |
echo "* Directory $DIRECTORY already exists, skipping this step." | |
else | |
mkdir $DIRECTORY | |
DIR_CREATED=true | |
echo "* Directory added: $DIRECTORY" | |
fi | |
if grep -Fq "$1" /etc/hosts; then | |
echo "* Site already exists in /etc/hosts, skipping this step." | |
else | |
echo -e "\n127.0.0.1\t$1\n::1\t\t$1" | sudo tee -a /etc/hosts > /dev/null | |
HOSTS_EDITED=true | |
echo "* Site added to /etc/hosts" | |
fi | |
if $DIR_CREATED || $HOSTS_EDITED; then | |
echo -e "\nSite added: http://$1/" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment