#!/bin/sh 

# format,
#   runall clean
#   runall setup
#   runall run

progname=$(basename $0)
pwd=`pwd`

if [ $# -eq 0 ]; then
    echo "Usage: $progname (clean|setup|run)" >&2;
    exit 1
fi

ABAC_PROVER_PATH=`which abac_prover_yap | sed 's/\/abac_prover_yap//'`
export ABAC_PROVER_PATH

if [ "$1" = "clean" ]; then
    rm -rf allout.tmp 
    rm -rf ENC_PRIVATE.PEM PFILE
    for i in `ls -1 `; do
        if [ -d $i ]; then
            printf "\n ==> CLEANING on %s\n" "$i" >& 2 ;
            cd $i
            rm -rf */*.der */*.pem */pfile */*.tmp
            rm -rf */*.cn */*.sha */*.log */creds_dump
            rm -rf *.der *.pem pfile *.tmp
            cd $pwd
        fi
    done
elif [ "$1" = "setup" ]; then
    echo "dumdum" > PFILE
    echo ">>>>  generate a encrypted private key ..."
    echo "passphrase is ==> dumdum"
    openssl genrsa -des3 -out ENC_PRIVATE.PEM -passout file:PFILE
    for i in `ls -1 `; do
        if [ -d $i ]; then
            printf "\n ==> SETUP on %s\n" "$i"  >& 2;
            cd $i
            ./setup
            cd $pwd
        fi
    done
elif [ "$1" = "run" ] ; then
    for i in `ls -1 `; do
        if [ -d $i ]; then
            printf "\n ==> RUN on %s\n" "$i" ;
            cd $i
            ./run_test
            cd $pwd
        fi
    done
fi 
