#!/bin/bash
# 
# Braindead script to verify that all X-SEC-VCL-variables are part of
# VARIABLES.

if [ ! -f VARIABLES ]; then
	echo 1>&2 "No VARIABLES-file found. Bailing."
	exit 1;
fi

RET=0

for a in `grep --exclude=variables.vcl 'X-SEC-' *vcl modules/*vcl | sed 's/.*X-SEC/X-SEC/;s/\s.*//;s/\;\s*$//' | sort | uniq`; do 
	if ! grep -q $a VARIABLES; then
		echo >&2 "Variable $a found in a module, but not in VARIABLES! Unsafe."
		grep $a *vcl modules/*vcl | cat 1>&2
		if [ "x$a" = "xX-SEC-Info" ]; then
			echo >&2 "Are you sure you didn't mean X-SEC-RuleInfo?"
		fi
		RET=1;
	fi
done

exit $RET
