Created
June 3, 2013 12:28
-
-
Save djekl/5697792 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
## clear the output | |
#clear | |
echo "\n" | |
## auth the sudo command | |
sudo -p "Please enter you admin password: " whoami 1>/dev/null | |
if [ "$(sudo whoami)" != 'root' ]; then | |
echo "You entered an invalid password or you are not an admin/sudoer user!\n\nScript aborted" | |
exit 1; | |
fi | |
## get the current username | |
username=$(whoami) | |
## get parameters for hostname and document root | |
echo "\nHost name (e.g. dev.domain.com):" | |
read hostname | |
echo "\nDocument root (project directory '~/projects/'):" | |
read project | |
## print a nice spacer | |
echo "\n==================================\n" | |
## add entry to hosts file | |
sudo bash -c "echo '127.0.0.1 $hostname www.$hostname' >> /etc/hosts" | |
## add entry to vhosts file | |
sudo bash -c "echo \"<VirtualHost *:80> | |
ServerName $hostname | |
ServerAlias www.$hostname | |
DocumentRoot '/Users/$username/projects/$project/' | |
ErrorLog '/Users/$username/Documents/www_logs/$hostname/error.log' | |
CustomLog '/Users/$username/Documents/www_logs/$hostname/access.log' combined | |
SetEnv APP_ENVIRONMENT development | |
</VirtualHost> | |
\" >> /etc/apache2/extra/httpd-vhosts.conf" | |
## create the log folder as $username | |
mkdir -p /Users/$username/Documents/www_logs/$hostname | |
## set correct permissions | |
find "/Users/$username/projects/$project" -type d -exec chmod 757 {} \; | |
find "/Users/$username/projects/$project" -type f -exec chmod 644 {} \; | |
#chmod 755 "/Users/$username/projects/$project" | |
chmod 755 "/Users/$username/Documents/www_logs/$hostname" | |
## restart apache | |
sudo bash -c "apachectl restart" | |
## kill the sudo session | |
sudo -k | |
## inform user we are finished | |
echo "\n\nVirtualHost added for $hostname.\n\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment