#!/bin/bash script_name=`basename $0` script_dir=`dirname $0` tmp_dir=/tmp/nupyf-tests function print_usage { echo "" echo "Usage:" echo " $script_name [-h] [-f] [-i <input_dir>] [-a <acl_file>] <testcase> <testname>" echo "" echo "Options:" echo " -h : Prints this help." echo " -i <input_dir> : Directory where taking expects files to add (by default $tmp_dir)." echo " -a <acl_file> : File containing the ACLs used for this test (if not given, use the already existing file if it exits)." echo " -f : force test overwriting if the acl file or expect directory already exist." echo "" echo "Arguments:" echo " <testcase> : a testcase is a subdirectory included in the $script_dir. This subdirectory must have been created manually and contain a desc.xml file." echo " <testname> : the base of the name of the test to add. By example, 'foo' will give an 'acls_foo.xml' ACL file and a 'expect_foo/' subdirectory." } input_dir= acl_file= force=1 while getopts "hfi:a:" flag do case "$flag" in 'h') print_usage; exit 0;; 'f') force=0;; 'i') input_dir=$OPTARG;; 'a') acl_file=$OPTARG;; '?') echo "Bad option: $flag"; print_usage; exit 1;; esac done shift $(($OPTIND-1)) if [ $# != 2 ] then echo "Wrong number of arguments, see usage..." print_usage exit 2 else testcase=$1 testname=$2 fi output_acl="$script_dir/$testcase/acls_$testname.xml" output_expect="$script_dir/$testcase/expect_$testname" # Checking -i option if [ "$input_dir" ] then if [ ! -d "$input_dir" ] then echo "Bad -i option: must be a directory containing the results of a nupyf process." print_usage exit 3 fi else if [ ! -d "$tmp_dir" ] then echo "-i option is not given, but $tmp_dir does not exist." print_usage exit 3 fi input_dir=$tmp_dir fi # Checking <testcase> argument if [ ! -d "$script_dir/$testcase" ] then echo "Bad <testcase> argument: '$testcase' ; must be a subdirectory of '$script_dir'." print_usage exit 3 fi if [ ! -e "$script_dir/$testcase/desc.xml" ] then echo "The file '$script_dir/$testcase/desc.xml' is expected to be a valid testcase." print_usage exit 3 fi # Checking ACL file existence if [ $force = 1 -a -e $output_acl -a "$acl_file" ] then echo "The resulting ACL file already exists: $output_acl; maybe should you use the -f option." print_usage exit 3 fi # Checking -a option if [ "$acl_file" ] then if [ ! -f $acl_file ] then echo "-a option: file not found: $acl_file." print_usage exit 3 fi else if [ ! -f $output_acl ] then echo "-a option not given: the file '$output_acl' must exist." print_usage exit 3 fi acl_file=$output_acl fi # Checking expected result directory existence (must be the last check) if [ -e $output_expect ] then if [ $force = 1 ] then echo "The resulting expect_dir already exists: $output_expect; maybe should you use the -f option." print_usage exit 3 fi rm -rf $output_expect fi # Copying ACL file cp $acl_file $output_acl.new mv -f $output_acl.new $output_acl # Copying expected result mkdir $output_expect cp -v $input_dir/* $output_expect/ echo Done.