cryptonas/validation/validate.sh
lars 5cf24ebede changed some setting names (CHROOTSTART and BUILDDIR)
removed the "revert" feature (too complicated and rarely used)
moved some settings to etc-defaults.d/cbox-dev.conf to allow local changes
2005-08-24 12:01:59 +00:00

159 lines
4.8 KiB
Bash
Executable file

#!/bin/sh
#
# do a validation
#
# use "--help" for a list of possible actions
#
set -eu
# get the path of a configuration file - local configuration files
# supersede default files
# parameter: base name of the configuration file
function get_config_file()
{
[ -e "$LOCALCONF_DIR/$1" ] && echo "$LOCALCONF_DIR/$1" && return 0
[ -e "$DEFAULTCONF_DIR/$1" ] && echo "$DEFAULTCONF_DIR/$1" && return 0
echo "configuration file ($1) not found!" >&2
exit 1
}
# the base directory of your local development files
ROOT_DIR=$(dirname "$0")/..
# the template (default) configuration directory
DEFAULTCONF_DIR="$ROOT_DIR/etc-defaults.d"
# your local configuration directory (existing files supersede the defaults)
LOCALCONF_DIR="$ROOT_DIR/etc-local.d"
############# include local configuration ##############
if [ -e "$(get_config_file cbox-dev.conf)" ]
then source "$(get_config_file cbox-dev.conf)"
else echo "local cbox-dev.conf ($(get_config_file cbox-dev.conf)) does not exist!" >&2
exit 1
fi
#################### some functions ####################
function error_die()
{
echo "$2" >&2
exit $1
}
function do_single()
# Parameter: "test case dir" "output directory for results"
{
local TESTNAME=$(basename $1)
curl --insecure --silent --output "${2}/${TESTNAME}.html" --config "$1/input.curl"
# there is no status in certain cases - e.g. for error 404
if [ -e "${2}/${TESTNAME}.html" ]
then sed "1,/CBOX-STATUS-begin/d; /CBOX-STATUS-end/,\$d" "${2}/${TESTNAME}.html" >"${2}/${TESTNAME}.status"
# the diff option "-B" is required, because the status output of
# the cryptobox.pl script contains some blank lines
diff -NB "${2}/${TESTNAME}.status" "$1/output" >"${2}/${TESTNAME}.diff" || true
rm "${2}/${TESTNAME}.status"
fi
cp "$1/description" "${2}/${TESTNAME}.desc"
}
function do_series()
# parameter: name of the test case
{
[ -d "$VALIDATE_REPORT_DIR/$1" ] && rm -r "$VALIDATE_REPORT_DIR/$1"
mkdir -p "$VALIDATE_REPORT_DIR/$1"
find "$VALIDATE_TEST_CASES_DIR/$1" -type d -maxdepth 1 -mindepth 1 | grep -v "/\.[^/]*$" | sort | while read a
do do_single "$a" "$VALIDATE_REPORT_DIR/$1"
done
create_summary "$VALIDATE_REPORT_DIR/$1" >"$VALIDATE_REPORT_DIR/$1/summary.html"
tar czf "$VALIDATE_REPORT_DIR/${1}-results.tar.gz" -C "$VALIDATE_REPORT_DIR" "$1"
#echo "$VALIDATE_REPORT_DIR/${1}-results.tar.gz"
}
create_summary()
# parameter: directory of results
{
cat "$VALIDATE_SUMMARY_TEMPLATE_DIR/header"
find "$1" -type f -name \*.desc -maxdepth 1 | sort | while read a
do TESTNAME=$(basename ${a%.desc})
TESTDESCRIPTION=$(cat $a)
sed "s#_TESTNAME_#$TESTNAME#g; s/_TESTDESCRIPTION_/$TESTDESCRIPTION/" "$VALIDATE_SUMMARY_TEMPLATE_DIR/single_header"
local DIFF_FILE=${a%.desc}.diff
if [ -s "$DIFF_FILE" ]
then cat "$VALIDATE_SUMMARY_TEMPLATE_DIR/result-error"
sed 's#$#<br/>#' "$DIFF_FILE"
else cat "$VALIDATE_SUMMARY_TEMPLATE_DIR/result-ok"
echo "no differences found"
# remove empty diff
[ -e "$DIFF_FILE" ] && rm "$DIFF_FILE"
fi
cat "$VALIDATE_SUMMARY_TEMPLATE_DIR/single_footer"
# remove description file
rm "$a"
done
cat "$VALIDATE_SUMMARY_TEMPLATE_DIR/footer"
}
import_style()
# get the stylesheet file and images
# change the stylesheet link
{
[ -d "VALIDATE_REPORT_DIR/img" ] && rm -r "$VALIDATE_REPORT_DIR/img"
mkdir -p "$VALIDATE_REPORT_DIR/img"
[ -e "$VALIDATE_REPORT_DIR/cryptobox.css" ] && rm "$VALIDATE_REPORT_DIR/cryptobox.css"
wget -q -O "$VALIDATE_REPORT_DIR/cryptobox.css" http://$VALIDATE_HOST_ADDRESS/cryptobox.css
# extract image file names
grep "url(img/" "$VALIDATE_REPORT_DIR/cryptobox.css" | sed 's#^.*url(img/\(.*\)).*$#\1#' | while read a
do wget -q -O "$VALIDATE_REPORT_DIR/img/$a" "http://$VALIDATE_HOST_ADDRESS/img/$a"
done
# change the stylesheet link in every html file in REPORT_DIR
find "$VALIDATE_REPORT_DIR" -type f -name \*.html | while read a
do sed -i '#link rel="stylesheet"#s#href="/cryptobox.css"#href="../cryptobox.css"#g' "$a"
done
}
ACTION="--help"
[ $# -gt 0 ] && ACTION=$1
case "$ACTION" in
list )
find "$VALIDATE_TEST_CASES_DIR" -type d -maxdepth 1 -mindepth 1 | grep -v "/\.[^/]*$" | sort | while read a
do echo $(basename "$a")
done
;;
check )
[ $# -ne 2 ] && error_die 1 "Syntax: $(basename $0) check NAME"
CASE_DIR="$VALIDATE_TEST_CASES_DIR/$2"
[ ! -d "$VALIDATE_CASE_DIR" ] && error_die 2 "the test case was not found ($VALIDATE_CASE_DIR)!"
do_series "$2"
import_style
;;
check_all )
"$0" list | sort | while read a
do echo -n "Validating $a ..."
"$0" check "$a"
echo
echo -n "Waiting 20 seconds ..."
sleep 20
echo
done
;;
* )
echo "Syntax of $(basename $0)"
echo -e "\t list \t\t - show a list of available test cases"
echo -e "\t check NAME \t - execute a test case"
echo -e "\t check_all \t - execute all test cases"
echo -e "\t help \t\t - this syntax information"
echo
;;
esac