#!/bin/bash # Virtual Host addition template for Justcurl.com # # Template assumes you'll have a www and non-www subdomain. # Included separate server blocks for rewrite purposes if needed # as well as a basic SSL installation # # @author : Lindsey Anderson # @date : 06/03/2014 # # @license: apache_vhost_installer.template is a part of JustCurl # # JustCurl is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # JustCurl is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with JustCurl. If not, see . # # @url : http://justcurl.com/ # Ensure we're root before the script is run if [[ "$EUID" -ne 0 ]]; then echo "You must run this script as root" 1>&2 exit 1 fi if [ -f /etc/redhat-release ]; then DISTRO="REDHAT" if [ -f /etc/httpd/vhost.d/mdisk.org.conf ]; then echo "Virtual host for mdisk.org already exists." exit 1 fi elif [ -f /etc/debian_version ]; then DISTRO="DEBIAN" if [ ! -f /etc/apache2/sites-enabled/mdisk.org ]; then if [ -f /etc/apache2/sites-available/mdisk.org ]; then echo "Virtual host for mdisk.org already exists." exit 1 fi else echo "Virtual host for mdisk.org already exists." exit 1 fi else echo "This isn't Debian or Redhat!" echo "Send me an email at lindsey.anderson@rackspace.com with more information about your OS." exit 1 fi PIFS=$IFS export DATA=$(cat < ServerName mdisk.org ServerAlias www.mdisk.org ### Content is loaded from your Document Root DocumentRoot /var/www/vhosts/mdisk.org/public_html/mdisk.org # RewriteEngine On # RewriteCond %{HTTP_HOST} ^mdisk.org # RewriteRule ^(.*)$ http://www.mdisk.org [R=301,L] Options -Indexes +FollowSymLinks -Multiviews AllowOverride All Order deny,allow Allow from all ENDOFTEMPLATE ) # Log directories change based on the implementation of Apache if [[ "$DISTRO" == "REDHAT" ]]; then export DATA=${DATA}$(cat < ## # To install the SSL certificate, please place the certificates in the following files: # >> SSLCertificateFile /etc/pki/tls/certs/mdisk.org.crt # >> SSLCertificateKeyFile /etc/pki/tls/private/mdisk.org.key # >> SSLCACertificateFile /etc/pki/tls/certs/mdisk.org.CA.crt # # After these files have been created, and ONLY AFTER, then run this and reload Apache: # # To remove these comments and use the virtual host, use the following: # VI - :25,\$ s/^#//g # RedHat Bash - sed -i '25,\$ s/^#//g' /etc/httpd/vhost.d/mdisk.org.conf && service httpd reload # Debian Bash - sed -i '25,\$ s/^#//g' /etc/apache2/sites-available/mdisk.org && service apache2 reload ## # # ServerName mdisk.org # ServerAlias www.mdisk.org # DocumentRoot /var/www/vhosts/mdisk.org/public_html/mdisk.org # # Options -Indexes +FollowSymLinks -MultiViews # AllowOverride All # # Order deny,allow # Allow from all # # ENDOFTEMPLATE ) if [[ "$DISTRO" == "REDHAT" ]]; then export DATA=${DATA}$(cat < # SSLOptions +StdEnvVars # # # BrowserMatch \"MSIE [2-6]\" \\ # nokeepalive ssl-unclean-shutdown \\ # downgrade-1.0 force-response-1.0 \\ # BrowserMatch \"MSIE [17-9]\" ssl-unclean-shutdown # ENDOFTEMPLATE ) # Create our virtual host if [[ "$DISTRO" == "REDHAT" ]]; then if [ ! -d /etc/httpd/vhost.d ]; then mkdir -p /etc/httpd/vhost.d && echo "include vhost.d/*.conf" >> /etc/httpd/conf/httpd.conf fi echo "$DATA" > /etc/httpd/vhost.d/mdisk.org.conf mkdir -p /var/www/vhosts/mdisk.org/public_html/mdisk.org # {% if data['reload'] %} service httpd reload DOMAIN=$(cat /etc/httpd/vhost.d/mdisk.org.conf | grep ServerName | grep -v "#") DOCROOT=$(cat /etc/httpd/vhost.d/mdisk.org.conf | grep Doc | grep -v "#") VLOCATION=$(echo /etc/httpd/vhost.d/mdisk.org.conf) echo "*************************************************************" echo ">> $DOMAIN " echo ">> $DOCROOT " echo ">> $VLOCATION " echo "*************************************************************" # {% endif %} elif [[ "$DISTRO" == "DEBIAN" ]]; then echo "$DATA" > /etc/apache2/sites-available/mdisk.org mkdir -p /var/www/vhosts/mdisk.org/public_html/mdisk.org a2ensite mdisk.org && # {% if data['reload'] %} service apache2 reload DOMAIN=$(cat /etc/apache2/sites-available/mdisk.org | grep ServerName | grep -v "#") DOCROOT=$(cat /etc/apache2/sites-available/mdisk.org | grep Doc | grep -v "#") VLOCATION=$(echo /etc/apache2/sites-available/mdisk.org) echo "*************************************************************" echo ">> $DOMAIN " echo ">> $DOCROOT " echo ">> $VLOCATION " echo "*************************************************************" # {% endif %} fi exit 0