Last active
June 3, 2021 05:01
-
-
Save kevinmesiab/5404a839ce15b5f6e5e7 to your computer and use it in GitHub Desktop.
Enables a2ensite functionality in OSX for Apache virtual hosts
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/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.conf | |
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 | |
# | |
# | |
# | |
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; | |
src_conf_file=$src$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."; | |
exit 0; | |
fi; | |
exit 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment