-
-
Save wturnerharris/27211cfec94831a9a2a22c594fec857e to your computer and use it in GitHub Desktop.
Enables a2ensite functionality in OSX for Apache virtual hosts
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 | |
######################################### | |
# | |
# This script enables apache virtual hosts | |
# by creating symlinks in | |
# | |
# /private/etc/apache2/sites-enabled | |
# | |
# that point to vhost conf files in | |
# | |
# /private/etc/apache2/sites-available | |
# | |
# | |
# NOTE: The analogue of this script is | |
# | |
# a2dsite | |
# | |
######################################### | |
# | |
# Test for no arguments, then display the | |
# instructions | |
# | |
if [ $# -eq 0 ]; then | |
echo " | |
usage: a2ensite [config file name] | |
example: a2ensite 000-default | |
A symbolic link for the the virtual host | |
configuration file specified in the argument | |
will be created in the sites-enabled folder, | |
pointing to the configuration file in the | |
sites-available folder. | |
The following folders must exist: | |
/private/etc/apache2/sites-available | |
/private/etc/apache2/sites-enabled | |
"; | |
exit 1; | |
fi | |
# | |
# Require root password | |
# | |
if [[ $UID != 0 ]]; then | |
echo "Requesting permissions..."; | |
sudo "$0" "$@"; | |
exit $?; | |
fi; | |
# | |
# | |
# | |
conf=$1; | |
# | |
# Source folder for hard vhost files | |
# | |
src="/private/etc/apache2/sites-available/"; | |
# | |
# Source folder for symlink vhost files | |
# | |
dst="/private/etc/apache2/sites-enabled/"; | |
# | |
# Test for necessary conf folders | |
# | |
! test -d $src && { echo "The required folder does not exist: $src"; exit 1; } | |
! test -d $dst && { echo "The required folder does not exist: $dst"; exit 1; } | |
# | |
# Set full path to config files | |
# | |
dest_conf_file=$dst$conf".conf"; | |
src_conf_file=$src$conf".conf"; | |
# | |
# Is this file already enabled | |
# | |
test -f $dest_conf_file && { echo "$conf is already enabled"; exit 1; } | |
# | |
# Does this file exist | |
# | |
! test -f $src_conf_file && { echo "This site does not exist."; exit 1; } | |
# | |
# Create a symbolic link to the source config file | |
# | |
if ln -s $src_conf_file $dest_conf_file; then | |
echo "The site $conf has been enabled."; | |
sudo apachectl restart; | |
exit 0; | |
fi; | |
exit 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment