#!/bin/bash # # vhost-stack # https://git.stack-source.com/msb/vhost-stack # Copyright (c) 2022 Matthew Saunders Brown # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # load include file source $(dirname $0)/vhost.sh help() { thisfilename=$(basename -- "$0") echo "Disables Varnish config for specified domain (VirtualHost)." echo "" echo "usage: $thisfilename -d [-h]" echo "" echo " -h Print this help." echo " -d Domain name (VirtualHost) to disable Varnish for." echo "" echo " Varnish is proxied through Apache. This disables the" echo " Apache proxy to Varnish and removes the varnish config." exit } vhost:getoptions "$@" # check for domain (virtualhost) if [[ -z $domain ]]; then echo "domain is required" exit fi # grab macro line from virtualhost config if macro_vhost_line=`grep -m 1 "Use .*" /etc/apache2/sites-available/$domain.conf` ; then macro_name=`echo "$macro_vhost_line" | awk '{print $2}'` else echo "$domain is not configured with mod_macro" exit 1 fi # make sure Varnish is already enabled if [[ $macro_name =~ ^.*Varnish$ ]]; then # set new macro_name macro_name=`echo $macro_name | sed -e 's|Varnish$||'` vhost_enable="-d $domain -m $macro_name" else echo "Varnish is not enabled for $domain" exit 1 fi # check if VHost macro is for a Subdomain or Alias if [[ "$macro_name" == *"Subdomain"* ]] || [[ "$macro_name" == *"Alias"* ]]; then macro_var=`echo "$macro_vhost_line" | awk '{print $5}'` vhost_enable="$vhost_enable -o $macro_var" fi /usr/local/bin/vhost-enable.sh $vhost_enable if [[ -f /etc/varnish/sites.d/$domain ]]; then rm /etc/varnish/sites.d/$domain /usr/local/bin/vhost-varnish-update-sites.sh $vhost_enable fi