@ -5,7 +5,7 @@ VERBOSE=2
DEBUG = 1
DEBUG = 1
pushd ../..
pushd ../..
export ROOT_DIR = $( readlink -m .)
ROOT_DIR = $( readlink -m .)
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Source external scripts
# Source external scripts
@ -13,24 +13,59 @@ export ROOT_DIR=$(readlink -m .)
. ./functions.sh
. ./functions.sh
. ./tests/assert/assert.sh
. ./tests/assert/assert.sh
head( ) {
header ( ) {
echo
echo
echo
echo
info "------------------------------------------------------------------------------"
info "------------------------------------------------------------------------------"
info " ${ 1 %% \\ n * } "
if ! [ " ${ 1 %% \\ n * } " = = " ${ 1 #* \\ n } " ] ; then
IFS = read -r title; info " ${ title } "
[ [ -z $TEST ] ] && echo -e " ${ bold } ${ green } ${ 1 #* \\ n } ${ reset } " || :
while IFS = read -r line; do
echo " ${ bold } ${ magenta } ${ line } ${ reset } "
done ;
echo
values SCRIPTSDIR
values DIST
values DISTS_VM
values TEMPLATE_FLAVOR
values TEMPLATE_FLAVOR_PREFIX
values TEMPLATE_FLAVOR_DIR
values TEMPLATE_OPTIONS
echo
}
declare -A VALUES = (
[ SCRIPTSDIR] = ""
[ DIST] = ""
[ DISTS_VM] = ""
[ TEMPLATE_FLAVOR] = ""
[ TEMPLATE_FLAVOR_DIR] = ""
[ TEMPLATE_FLAVOR_PREFIX] = ""
[ TEMPLATE_OPTIONS] = ""
)
values( ) {
[ [ -z $TEST ] ] && {
label = ${ 1 }
value = " ${ 1 } [@] "
value = " ${ !value } "
if [ " ${ VALUES [ $label ] } " = = " ${ value } " ] ; then
printf " ${ bold } ${ magenta } %-22s = ${ value } ${ reset } \n " " ${ label } " || :
else
printf " ${ bold } ${ black } %-22s = ${ value } ${ reset } \n " " ${ label } " || :
fi
fi
info "------------------------------------------------------------------------------"
VALUES[ $label ] = " ${ value } "
}
}
}
info( ) {
info( ) {
[ [ -z $TEST ] ] && echo -e " ${ bold } ${ blue } ${ 1 } ${ reset } " || :
[ [ -z $TEST ] ] && echo " ${ bold } ${ blue } ${ 1 } ${ reset } " || :
}
}
#debug() {
debug ( ) {
# [[ -z $TEST ]] && echo -e "${bold}${red}${1}${reset}" || :
[ [ -z $TEST ] ] && echo -e " ${ magenta } ${ 1 } ${ reset } " || :
#}
}
assertTest( ) {
assertTest( ) {
TEST = True
TEST = True
@ -46,122 +81,187 @@ assertEnd() {
printf " ${ reset } "
printf " ${ reset } "
}
}
# Defaults
export SCRIPTSDIR = "tests/template-flavors"
export DIST = "wheezy"
export TEMPLATE_FLAVOR = "whonix-gateway"
# Should be parses in functions!
export TEMPLATE_FLAVOR_PREFIX = ""
# Just use error to show text in red
head "=== Globals ==="
debug 'export SCRIPTSDIR="tests/template-flavors"'
debug 'export DIST="wheezy"'
debug 'export TEMPLATE_FLAVOR="whonix-gateway"'
debug 'export TEMPLATE_FLAVOR_PREFIX=""'
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
head " 1. With TEMPLATE_FLAVOR
# 1. With TEMPLATE_FLAVOR
\n export SCRIPTSDIR = tests/template-flavors \
# ------------------------------------------------------------------------------
\n export DIST = wheezy \
SCRIPTSDIR = "tests/template-flavors"
\n export TEMPLATE_FLAVOR = whonix-gateway \
DIST = "wheezy"
\n export TEMPLATE_FLAVOR_PREFIX = "
TEMPLATE_FLAVOR = "whonix-gateway"
TEMPLATE_FLAVOR_PREFIX = ""
header <<EOF
1. With TEMPLATE_FLAVOR
EOF
buildStep " $0 " "pre"
buildStep " $0 " "pre"
assertTest " buildStep $0 pre " "tests/template-flavors/wheezy+whonix-gateway/test_pre.sh"
assertTest " buildStep $0 pre " "tests/template-flavors/wheezy+whonix-gateway/test_pre.sh"
assertEnd
assertEnd
# ------------------------------------------------------------------------------
# 2. Without TEMPLATE_FLAVOR
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
head " 2. Without TEMPLATE_FLAVOR
TEMPLATE_FLAVOR = ""
\n export TEMPLATE_FLAVOR = "
export TEMPLATE_FLAVOR = ""
header <<EOF
2. Without TEMPLATE_FLAVOR
EOF
buildStep " $0 " "pre"
buildStep " $0 " "pre"
assertTest " buildStep $0 pre " "tests/template-flavors/test_pre.sh"
assertTest " buildStep $0 pre " "tests/template-flavors/test_pre.sh"
assertEnd
assertEnd
# ------------------------------------------------------------------------------
# 3. Template Options
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
head " 3. Template Options
TEMPLATE_FLAVOR = "whonix-gateway"
\n DISTS_VM = wheezy+whonix-gateway+gnome \
TEMPLATE_OPTIONS = ( 'gnome' 'kde' )
\n DISTS_VM = <DIST>+<TEMPLATE_FLAVOR>+<TEMPLATE_OPTIONS>+<TEMPLATE_OPTIONS> \
\n Options get seperated into TEMPLATE_OPTIONS seperated by spaces"
header <<EOF
#
3. Template Options
export TEMPLATE_FLAVOR = "whonix-gateway"
Options get seperated into TEMPLATE_OPTIONS seperated by spaces
export TEMPLATE_OPTIONS = ( 'gnome' 'kde' )
EOF
buildStep " $0 " "pre"
buildStep " $0 " "pre"
debug "Not supposed to find wheezy+whonix-gateway+kde"
debug "Not supposed to find wheezy+whonix-gateway+kde"
assertTest " buildStep $0 pre " "tests/template-flavors/wheezy+whonix-gateway/test_pre.sh\ntests/template-flavors/wheezy+whonix-gateway+gnome/test_pre.sh"
assertTest " buildStep $0 pre " "tests/template-flavors/wheezy+whonix-gateway/test_pre.sh\ntests/template-flavors/wheezy+whonix-gateway+gnome/test_pre.sh"
assertEnd
assertEnd
# ------------------------------------------------------------------------------
# 4. Template Options with custom prefix
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
head " 4. Template Options with custom prefix
TEMPLATE_FLAVOR_PREFIX = (
\n TEMPLATE_FLAVOR_PREFIX \
'wheezy+whonix-gateway:debian+'
\n export TEMPLATE_FLAVOR_PREFIX = ( \
'wheezy+whonix-workstation:debian+'
\n 'wheezy+whonix-gateway;debian+' \
\n 'wheezy+whonix-workstation;debian+' \
\n ) "
export TEMPLATE_FLAVOR_PREFIX = (
'wheezy+whonix-gateway;debian+'
'wheezy+whonix-workstation;debian+'
)
)
header <<EOF
4. Template Options with custom prefix
EOF
buildStep " $0 " "pre"
buildStep " $0 " "pre"
debug "Not supposed to find debian+whonix-gateway+kde"
debug "Not supposed to find debian+whonix-gateway+kde"
assertTest " buildStep $0 pre " "tests/template-flavors/debian+whonix-gateway/test_pre.sh\ntests/template-flavors/wheezy+whonix-gateway+gnome/test_pre.sh"
assertTest " buildStep $0 pre " "tests/template-flavors/debian+whonix-gateway/test_pre.sh\ntests/template-flavors/wheezy+whonix-gateway+gnome/test_pre.sh"
assertEnd
assertEnd
# ------------------------------------------------------------------------------
# 5. Template Options with NO prefix
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
head " 5. Template Options with NO prefix
TEMPLATE_FLAVOR_PREFIX = (
\n TEMPLATE_FLAVOR_PREFIX \
'wheezy+whonix-gateway:'
\n export TEMPLATE_FLAVOR_PREFIX = ( \
'wheezy+whonix-workstation:'
\n 'wheezy+whonix-gateway;' \
\n 'wheezy+whonix-workstation;' \
\n ) "
export TEMPLATE_FLAVOR_PREFIX = (
'wheezy+whonix-gateway;'
'wheezy+whonix-workstation;'
)
)
header <<EOF
5. Template Options with NO prefix
EOF
buildStep " $0 " "pre"
buildStep " $0 " "pre"
debug "Not supposed to find whonix-gateway+kde"
debug "Not supposed to find whonix-gateway+kde"
assertTest " buildStep $0 pre " "tests/template-flavors/whonix-gateway/test_pre.sh\ntests/template-flavors/wheezy+whonix-gateway+gnome/test_pre.sh"
assertTest " buildStep $0 pre " "tests/template-flavors/whonix-gateway/test_pre.sh\ntests/template-flavors/wheezy+whonix-gateway+gnome/test_pre.sh"
assertEnd
assertEnd
# ------------------------------------------------------------------------------
# 6. Custom template directory for options within \${SCRIPTSDIR}
# ------------------------------------------------------------------------------
unset TEMPLATE_FLAVOR_PREFIX
TEMPLATE_OPTIONS = ( 'gnome' )
TEMPLATE_FLAVOR_DIR = 'wheezy+whonix-gateway+gnome:${SCRIPTSDIR}/another_location/whonix_gnome'
header <<EOF
6. Custom template directory for options within \$ { SCRIPTSDIR}
NOTE: in config file you would need to use \$ \$ { SCRIPTSDIR} or whatever variable
and in a bash file use single 'quotes' around string and \$ { SCRIPTSDIR}
EOF
buildStep " $0 " "pre"
assertTest " buildStep $0 pre " "tests/template-flavors/wheezy+whonix-gateway/test_pre.sh\ntests/template-flavors/another_location/whonix_gnome/test_pre.sh"
assertEnd
# ------------------------------------------------------------------------------
# 7. Custom template directory
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
head " 6. Custom template directory
\n unset TEMPLATE_FLAVOR_PREFIX \
\n unset TEMPLATE_OPTIONS \
\n TEMPLATE_FLAVOR_DIR = wheezy+whonix-gateway; tests/template-flavors/another_location/whonix-gw"
unset TEMPLATE_FLAVOR_PREFIX
unset TEMPLATE_FLAVOR_PREFIX
unset TEMPLATE_OPTIONS
unset TEMPLATE_OPTIONS
TEMPLATE_FLAVOR_DIR = "wheezy+whonix-gateway;tests/template-flavors/another_location/whonix-gw"
TEMPLATE_FLAVOR_DIR = "wheezy+whonix-gateway:tests/template-flavors/another_location/whonix-gw"
header <<EOF
7. Custom template directory
EOF
buildStep " $0 " "pre"
buildStep " $0 " "pre"
assertTest " buildStep $0 pre " "tests/template-flavors/another_location/whonix-gw/test_pre.sh"
assertTest " buildStep $0 pre " "tests/template-flavors/another_location/whonix-gw/test_pre.sh"
assertEnd
assertEnd
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
head " 7. Custom template directory with space in name
# 8. Custom template directory with space in name
\n unset TEMPLATE_FLAVOR_PREFIX \
# ------------------------------------------------------------------------------
\n unset TEMPLATE_OPTIONS \
TEMPLATE_FLAVOR_DIR = "wheezy+whonix-gateway:tests/template-flavors/another_location/whonix gw"
\n TEMPLATE_FLAVOR_DIR = wheezy+whonix-gateway; tests/template-flavors/another_location/whonix gw"
TEMPLATE_FLAVOR_DIR = "wheezy+whonix-gateway;tests/template-flavors/another_location/whonix gw"
header <<EOF
8. Custom template directory with space in name
EOF
buildStep " $0 " "pre"
buildStep " $0 " "pre"
assertTest " buildStep $0 pre " "tests/template-flavors/another_location/whonix gw/test_pre.sh"
assertTest " buildStep $0 pre " "tests/template-flavors/another_location/whonix gw/test_pre.sh"
assertEnd
assertEnd
# ------------------------------------------------------------------------------
# 9. Custom template directory for options
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
head " 8. Custom template directory for options
\n unset TEMPLATE_FLAVOR_PREFIX \
\n unset TEMPLATE_OPTIONS \
\n TEMPLATE_FLAVOR_DIR = wheezy+whonix-gateway+gnome; tests/template-flavors/another_location/whonix_gnome"
unset TEMPLATE_FLAVOR_PREFIX
unset TEMPLATE_FLAVOR_PREFIX
export TEMPLATE_OPTIONS = ( 'gnome' )
TEMPLATE_OPTIONS = ( 'gnome' )
TEMPLATE_FLAVOR_DIR = "wheezy+whonix-gateway+gnome;tests/template-flavors/another_location/whonix_gnome"
TEMPLATE_FLAVOR_DIR = "wheezy+whonix-gateway+gnome:tests/template-flavors/another_location/whonix_gnome"
header <<EOF
9. Custom template directory for options
EOF
buildStep " $0 " "pre"
buildStep " $0 " "pre"
assertTest " buildStep $0 pre " "tests/template-flavors/wheezy+whonix-gateway/test_pre.sh\ntests/template-flavors/another_location/whonix_gnome/test_pre.sh"
assertTest " buildStep $0 pre " "tests/template-flavors/wheezy+whonix-gateway/test_pre.sh\ntests/template-flavors/another_location/whonix_gnome/test_pre.sh"
assertEnd
assertEnd
# ------------------------------------------------------------------------------
# 10. Template directory for options within $SCRIPTSDIR using short name filter
# ------------------------------------------------------------------------------
unset TEMPLATE_FLAVOR_PREFIX
unset TEMPLATE_FLAVOR_DIR
TEMPLATE_OPTIONS = ( 'proxy' )
TEMPLATE_FLAVOR_DIR = 'wheezy+proxy:${SCRIPTSDIR}/proxy'
header <<EOF
10. Template directory for options within $SCRIPTSDIR using short name filter
EOF
buildStep " $0 " "pre"
assertTest " buildStep $0 pre " "tests/template-flavors/wheezy+whonix-gateway/test_pre.sh\ntests/template-flavors/proxy/test_pre.sh"
assertEnd
# ------------------------------------------------------------------------------
# 11. Template directory for options within using VERY short name filter (+proxy)
# ------------------------------------------------------------------------------
unset TEMPLATE_FLAVOR_PREFIX
unset TEMPLATE_FLAVOR_DIR
TEMPLATE_OPTIONS = ( 'proxy' )
TEMPLATE_FLAVOR_DIR = '+proxy:${SCRIPTSDIR}/proxy'
header <<EOF
11. Template directory for options within using VERY short name filter ( +proxy)
EOF
buildStep " $0 " "pre"
assertTest " buildStep $0 pre " "tests/template-flavors/wheezy+whonix-gateway/test_pre.sh\ntests/template-flavors/proxy/test_pre.sh"
assertEnd
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
head " 9. Configuration Files
# 12. Configuration Files
\n Find packages.list for every template available"
# ------------------------------------------------------------------------------
TEMPLATE_FLAVOR_DIR = "wheezy+whonix-gateway;tests/template-flavors/another_location/whonix gw"
TEMPLATE_FLAVOR_DIR = "wheezy+whonix-gateway:tests/template-flavors/another_location/whonix gw"
TEMPLATE_OPTIONS = ( 'gnome' )
header <<EOF
12. Configuration Files
Find packages.list for every template available
EOF
getFileLocations filelist 'packages.list'
getFileLocations filelist 'packages.list'
for file in " ${ filelist [@] } " ; do
for file in " ${ filelist [@] } " ; do
echo " Configuration: ${ file } "
echo " Configuration: ${ file } "
@ -170,11 +270,17 @@ result="$(echo $(printf "'%s' " "${filelist[@]}"))"
assertTest " echo ${ result } " "tests/template-flavors/another_location/whonix gw/packages.list tests/template-flavors/wheezy+whonix-gateway+gnome/packages.list"
assertTest " echo ${ result } " "tests/template-flavors/another_location/whonix gw/packages.list tests/template-flavors/wheezy+whonix-gateway+gnome/packages.list"
assertEnd
assertEnd
# ------------------------------------------------------------------------------
# 13. Configuration Files - No Template
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
head " 10. Configuration Files - No Template
\n Find packages.list for every template available"
TEMPLATE_FLAVOR =
TEMPLATE_FLAVOR =
TEMPLATE_FLAVOR_DIR =
TEMPLATE_FLAVOR_DIR =
header <<EOF
13. Configuration Files - No Template
Find packages.list for every template available
EOF
getFileLocations filelist 'packages.list'
getFileLocations filelist 'packages.list'
for file in " ${ filelist [@] } " ; do
for file in " ${ filelist [@] } " ; do
echo " Configuration: ${ file } "
echo " Configuration: ${ file } "
@ -183,11 +289,17 @@ result="$(echo $(printf "'%s' " "${filelist[@]}"))"
assertTest " echo ${ result } " "tests/template-flavors/packages.list"
assertTest " echo ${ result } " "tests/template-flavors/packages.list"
assertEnd
assertEnd
# ------------------------------------------------------------------------------
# 14. Configuration Files - No Template - with suffix
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
head " 11. Configuration Files - No Template - with suffix
\n Find packages.list for every template available"
TEMPLATE_FLAVOR =
TEMPLATE_FLAVOR =
TEMPLATE_FLAVOR_DIR =
TEMPLATE_FLAVOR_DIR =
header <<EOF
14. Configuration Files - No Template - with suffix
Find packages.list for every template available
EOF
getFileLocations filelist 'packages.list' 'wheezy'
getFileLocations filelist 'packages.list' 'wheezy'
for file in " ${ filelist [@] } " ; do
for file in " ${ filelist [@] } " ; do
echo " Configuration: ${ file } "
echo " Configuration: ${ file } "
@ -197,17 +309,24 @@ assertTest "echo ${result}" "tests/template-flavors/packages_wheezy.list"
assertEnd
assertEnd
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
export INSTALLDIR = " ${ SCRIPTSDIR } /test_copy_location "
# 14. Copy files
head " 12. Copy files
# ------------------------------------------------------------------------------
\n Just test copying from here to ${ INSTALLDIR } "
TEMPLATE_FLAVOR = "whonix-gateway"
TEMPLATE_FLAVOR = "whonix-gateway"
TEMPLATE_FLAVOR_DIR = ""
TEMPLATE_FLAVOR_DIR = ""
TEMPLATE_OPTIONS = ""
TEMPLATE_OPTIONS = ""
INSTALLDIR = " ${ SCRIPTSDIR } /test_copy_location "
header <<EOF
14. Copy files
Just test copying from here to ${ INSTALLDIR }
INSTALLDIR = " ${ SCRIPTSDIR } /test_copy_location "
EOF
rm -rf " $INSTALLDIR " /*
rm -rf " $INSTALLDIR " /*
copyTree "files"
copyTree "files"
ls -l " $INSTALLDIR "
ls -l " $INSTALLDIR "
assertTest " ls $INSTALLDIR " "test1\ntest2\ntest3"
assertTest " ls $INSTALLDIR " "test1\ntest2\ntest3"
assertEnd
assertEnd
# Done
# Done
popd
popd