Skip to content

Instantly share code, notes, and snippets.

@bipinu
Forked from kevinmesiab/a2ensite
Last active May 21, 2019 05:47
Show Gist options
  • Save bipinu/7edd083db14f1c2f30d8 to your computer and use it in GitHub Desktop.
Save bipinu/7edd083db14f1c2f30d8 to your computer and use it in GitHub Desktop.
#!/bin/bash
#########################################
#
# This script enables apache virtual hosts
# by creating symlinks in
#
# /etc/apache2/sites-enabled
#
# that point to vhost conf files in
#
# /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:
/etc/apache2/sites-available
/etc/apache2/sites-enabled
";
exit 1;
fi
#
#
#
conf=$1;
#
# Source folder for hard vhost files
#
src="/etc/apache2/sites-available/";
#
# Source folder for symlink vhost files
#
dst="/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