2021-04-04 13:28:22 -07:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# vhost-stack
|
|
|
|
# https://git.stack-source.com/msb/vhost-stack
|
|
|
|
# MIT License Copyright (c) 2021 Matthew Saunders Brown
|
|
|
|
|
2021-04-04 14:15:16 -07:00
|
|
|
# load include file
|
|
|
|
source $(dirname $0)/vhost.sh
|
2021-04-04 13:28:22 -07:00
|
|
|
|
|
|
|
# varnish-disable.sh virtualhost
|
|
|
|
|
|
|
|
# check for and set virtualhost
|
|
|
|
if [ -n "$1" ]; then
|
|
|
|
virtualhost=$1
|
|
|
|
else
|
|
|
|
echo "virtualhost not set"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# grab macro line from virtualhost config
|
|
|
|
if macro_vhost_line=`grep -m 1 "Use .*" /etc/apache2/sites-available/$virtualhost.conf` ; then
|
|
|
|
macro_name=`echo "$macro_vhost_line" | awk '{print $2}'`
|
|
|
|
else
|
|
|
|
echo "$virtualhost 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="$macro_name $virtualhost"
|
|
|
|
else
|
|
|
|
echo "Varnish is not enabled for $virtualhost"
|
|
|
|
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 $macro_var"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# uncomment to flush varnish cache
|
|
|
|
# systemctl is-active --quiet varnish && systemctl reload --quiet varnish
|
|
|
|
|
|
|
|
echo /usr/local/bin/vhost-enable.sh $vhost_enable
|