Created
August 9, 2016 16:59
-
-
Save kamermans/b9ffacc7afb239630d1ad59f8d93ea6c to your computer and use it in GitHub Desktop.
# Recursively list all of the Varnish VCL config files that are included via "include" statements.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
# list_varnish_includes.sh | |
# Recursively list all of the Varnish VCL config files that are included via "include" statements. | |
# This scripts should work in Varnish 2-4+ | |
# Author: Steve Kamerman | |
if [[ $# -ne 1 ]]; then | |
echo "Usage: ./$(basename $0) <path_to_config.vcl>" >&2 | |
exit 2 | |
fi | |
CONFIG="$1" | |
BASE_FILE=$(basename $CONFIG) | |
BASE_DIR=$(cd $(dirname $CONFIG) && pwd) | |
ERRORS=0 | |
showIncludesRecursive() { | |
local BASE_FILE=$1 | |
local BASE_DIR=$2 | |
if [[ ! -f "$BASE_DIR/$BASE_FILE" ]]; then | |
echo "Error: base config file does not exist: $BASE_FILE" >&2 | |
echo "Please provide the relative or absolute path to a Varnish VCL config" >&2 | |
exit 1 | |
fi | |
echo $BASE_FILE | |
for FILE in $(cd $BASE_DIR && grep "^ *include" "$BASE_FILE" | cut -d'"' -f2); do | |
if [[ ! -f "$BASE_DIR/$FILE" ]]; then | |
echo "Error: Missing include file: $FILE" >&2 | |
ERRORS=$(( $ERRORS + 1 )) | |
continue | |
fi | |
showIncludesRecursive "$FILE" "$BASE_DIR" | |
done | |
} | |
showIncludesRecursive "$BASE_FILE" "$BASE_DIR" | |
if [[ $ERRORS -gt 0 ]]; then | |
echo "Some errors were reported!" >&2 | |
exit 2 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment