Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Shell Script to add Vhost.Run as root, takes one param: Directory to add, and extra optional param as subdirectory written as /subdirectory where / is folder root.ex: sudo bash newSite.sh [-h | -c | -m ] <nameOfNewsite> [subDirectory DocumentRoot] To run as commands, place files in your /usr/local folder without the .sh extensions, and then just sudo zf5 [sitename]

View colors.sh
1 2 3 4 5 6 7 8 9 10 11
#!/bin/sh
# Define colors
red="\033[33;31m"
green="\033[33;32m"
yellow="\033[33;33m"
blue="\033[33;34m"
magenta="\033[33;35m"
gray="\033[33;30m"
cyan="\033[33;36m"
reset="\033[33;0m"
View colors.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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
#!/bin/sh
 
##############################
## This script assumes ##
## that you've set up ##
## apache like debian: ##
## http://apple.stackexchange.com/questions/37241/how-to-configure-local-apache-virtual-hosts
##############################
 
##############################
## ##
## SETTINGS ##
## ##
##############################
 
##
username="kbater" #Computer Username
pathToSite="/Users/${username}/Dev/"
pathToVhosts="/etc/apache2/sites-enabled/"
pathToHosts="/etc/hosts"
pubDir="dist"
sitePostfix=".dev"
pubPostfix=".pub"
 
 
#Logging Options
individualLogs=true; #True or False
#If the above bool is false, uncomment the following line and comment out the others
#pathToMasterLog="/path/to/apache/log"
pathToLogFolder="${pathToSite}${siteName}"
 
################################
################################
 
#Check for flags:
#
# -c : disable colors
# -h : show help dialogs
# -m : don't make the directory
#
 
colors=true
makeDir=true
optCount=0
 
while getopts ":hcmc:" opt; do
let optCount=optCount+1
case $opt in
c)
colors=false
;;
h)
printf "Usage: sudo newSite.sh [-h|-c|-m] <Site Name> [subDirectory for Apache]\nWhere -h displays Help, -c disables colors, and -m disables making new directory\n";
exit 0
;;
m)
makeDir=false
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
 
 
#Separate Args from Opts
argArray=("$@")
 
arg1=$optCount
arg2=arg1+1
 
siteName=${argArray[arg1]};
subDir=${argArray[arg2]};
 
# Import Colors Script if not flagged for no-colors
if [ ${colors} == true ]; then
source colors
fi
 
## Run The Script
 
 
 
 
# Create a new directory, blank file, and OWN IT
#sucess tracks the progress of the script, because if one completes it won't kill anything, you'll just get errors,
#but then it checks before continuing the script for errors.
# Only performs this block if user doesn't set the -n flag.
echo "${green}Creating New Directory at ${reset}${pathToSite}${siteName}";
if [ ${makeDir} == true ]; then
success=0
mkdir ${pathToSite}${siteName}
let success=success+$?
chown -R ${username} ${pathToSite}${siteName}
let success=success+$?
 
if [ ${success} -ne "0" ]; then
echo -e "${red}Couldn't create new Directory at ${reset}${pathToSite}${siteName}. Script Failed.${reset}"
exit 1
fi
fi
 
 
# Create a new entry in the Apache virtual hosts file.
echo "${green}Adding Entry into ${reset}${pathToVhosts}"
 
printf "<VirtualHost *:80>\n DocumentRoot \"${pathToSite}${siteName}${subDir}\"\n ServerName ${siteName}${sitePostfix}\n ErrorLog \"${pathToLogFolder}apache-error.log\"\n</VirtualHost>\n\n<VirtualHost *:80>\n DocumentRoot \"${pathToSite}${siteName}/${pubDir}\"\n ServerName ${siteName}${pubPostfix}\n ErrorLog \"${pathToLogFolder}apache-error.log\"\n</VirtualHost>" >> ${pathToVhosts}vhost-${siteName}${sitePostfix}
 
if [ "$?" -ne "0" ]; then
echo "${red}Appending to ${reset}${pathToVhosts} ${red} could not happen. Script Failed.${reset}"
rm ${pathToVhosts}vhost-${siteName}${sitePostfix}
rmdir ${pathToSite}/${siteName}
exit 1
fi
 
 
# Add an entry to the /etc/hosts file and restart Apache
echo "${green}Adding Entry into ${reset}${pathToHosts}"
sudo printf "\n127.0.0.1\t${siteName}.dev" >> ${pathToHosts}
 
if [ "$?" -ne "0" ]; then
echo "${red}Appending to ${reset}${pathToHosts} ${red}could not happen. Script Failed.${reset}"
rm ${pathToVhosts}vhost-${siteName}${sitePostfix}
rmdir ${pathToSite}${siteName}
exit 1
fi
 
# Restart Apache
echo "${green}Restarting Apache.${reset}"
apachectl restart >/dev/null
 
 
#clean Exit
echo "${green}#########################################################################"
echo ""
echo "${green}## ${yellow}Successfully added ${siteName}${sitePostfix} as a virtual server!${green}"
echo ""
echo "${green}#########################################################################${reset}"
 
return 0
View colors.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
#!/bin/sh
 
site=$1
 
#import Colors
source colors
 
#Check for Arg
if [ site == "" ]; then
echo "${red}Usage: ${yellow}ff5 <siteName>${reset}"
exit 1
fi
 
#Run NewSite.sh
source newSite -c $site "/src"
 
#Check to make sure that NewSite executed properly
if [ $? -ne 0 ]; then
exit $?
fi
 
echo "${yellow}Changing Directory to ${reset}${pathToSite}${siteName}"
cd ${pathToSite}${siteName}
 
 
#Run as sudo with the -u flag so that bower doesn't get upset.
sudo -u ${username} yo ase
 
sudo -u ${username} grunt make
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.