vhost-stack/bin/vhost-varnish-update-sites.sh
2022-08-22 13:22:16 -07:00

55 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
#
# vhost-stack
# https://git.stack-source.com/msb/vhost-stack
# Copyright (c) 2022 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
# 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 "Makes sure all existing varnish configs are loaded."
echo ""
echo "usage: $thisfilename [-h]"
echo ""
echo " -h Print this help."
echo ""
echo " The varnish config is broken down in to individual"
echo " configurations for each virtualhost. Each config has"
echo " to be included by the master sites.vcl. This tool makes"
echo " sure all existing virtualhost varnish configs are"
echo " properly included in sites.vcl, and removes includes"
echo " for varnish virtualhost configs that have been deleted."
exit
}
# check for -h
if [ -n "$1" ]; then
if [ $1 == "-h" ]; then
help
exit
fi
fi
if [ ! -f /etc/varnish/sites.d/example.com.vcl ]; then
echo "ERROR: example.vlc does not exist"
exit 1
fi
sitesArray=(`ls -1 /etc/varnish/sites.d/`)
truncate -s 0 /etc/varnish/sites.vcl
for site in "${sitesArray[@]}"
do
echo include \"sites.d/$site\"\; >> /etc/varnish/sites.vcl
done
exit 0