Moved qubes-extra-files to its own directory as a sub-template (proxy) as its only needed for proxies

Removed call from qubes_installation scripts for proxy files.  will now be added by sub-template
Renamed extra-whonix-files to files
Modifies functions.sh to allow for very short proxy names and custom directories that will be dist independent
pull/1/head
Jason Mehring 10 years ago
parent 6f9860fb17
commit 0b341f4fb2

@ -148,8 +148,8 @@ templateFlavorPrefix() {
local template_flavor=${1-$(templateFlavor)}
for element in "${TEMPLATE_FLAVOR_PREFIX[@]}"
do
if [ "${element%;*}" == "${DIST}+${template_flavor}" ]; then
echo ${element#*;}
if [ "${element%:*}" == "${DIST}+${template_flavor}" ]; then
echo ${element#*:}
return
fi
done
@ -159,10 +159,16 @@ templateFlavorPrefix() {
templateDir() {
local template_flavor=${1-$(templateFlavor)}
for element in "${TEMPLATE_FLAVOR_DIR[@]}"
do
if [ "${element%;*}" == "$(templateFlavorPrefix ${template_flavor})${template_flavor}" ]; then
echo ${element#*;}
# (wheezy+whonix-gateway / wheezy+whonix-gateway+gnome[+++] / wheezy+gnome )
if [ "${element%:*}" == "$(templateFlavorPrefix ${template_flavor})${template_flavor}" ]; then
eval echo -e ${element#*:}
return
# Very short name compare (+proxy)
elif [ "${element:0:1}" == "+" -a "${element%:*}" == "+${template_flavor}" ]; then
eval echo -e ${element#*:}
return
fi
done
@ -206,6 +212,7 @@ buildStepExec() {
if [ -f "${script}" ]; then
[[ -n $TEST ]] && echo "${script}" || echo "${bold}${under}INFO: Currently running script: ${script}${reset}"
# Execute $script
"${script}"
fi
@ -250,9 +257,15 @@ callTemplateFunction() {
for option in ${TEMPLATE_OPTIONS[@]}
do
# Long name (wheezy+whonix-gateway+proxy)
${functionExec} "${calling_script}" \
"${calling_arg}" \
"$(templateFlavor)+${option}"
# Short name (wheezy+proxy)
${functionExec} "${calling_script}" \
"${calling_arg}" \
"${option}"
done
}

@ -182,15 +182,6 @@ EOF
# Need a xen log directory or xen scripts will fail
# --------------------------------------------------------------------------
mkdir -p -m 0700 "$INSTALLDIR/var/log/xen"
# --------------------------------------------------------------------------
# Copy over any extra files that may be needed that are located in
# $SCRIPT_DIR/extra-qubes-files
# --------------------------------------------------------------------------
debug "Copy extra files..."
copyTree "extra-qubes-files"
touch "$INSTALLDIR/tmp/.prepared_qubes"
fi
# ------------------------------------------------------------------------------

@ -279,7 +279,7 @@ if ! [ -f "$INSTALLDIR/tmp/.prepared_whonix" ]; then
# Copy over any extra files
# XXX: Moved to 02_install_groups_packages_installed.sh
# ------------------------------------------------------------------------------
copyTree "extra-whonix-files"
copyTree "files"
# --------------------------------------------------------------------------
# Install Whonix system

@ -45,11 +45,13 @@ if [ -L "$INSTALLDIR/etc/resolv.conf" ]; then
popd
fi
# ------------------------------------------------------------------------------
# Copy over any extra files
# XXX: Moved to 02_install_groups_packages_installed.sh
# ------------------------------------------------------------------------------
#copyTree "extra-whonix-files"
# --------------------------------------------------------------------------
# Copy over any extra files that may be needed that are located in
# --------------------------------------------------------------------------
debug "Copy extra Qubes related files..."
copyTree "extra-qubes-files"
touch "$INSTALLDIR/tmp/.prepared_qubes"
# ------------------------------------------------------------------------------
# Cleanup Whonix Installation

@ -0,0 +1,4 @@
#!/bin/sh
# vim: set ts=4 sw=4 sts=4 et :
:

@ -5,7 +5,7 @@ VERBOSE=2
DEBUG=1
pushd ../..
export ROOT_DIR=$(readlink -m .)
ROOT_DIR=$(readlink -m .)
# ------------------------------------------------------------------------------
# Source external scripts
@ -13,24 +13,59 @@ export ROOT_DIR=$(readlink -m .)
. ./functions.sh
. ./tests/assert/assert.sh
head() {
header() {
echo
echo
info "------------------------------------------------------------------------------"
info "${1%%\\n*}"
if ! [ "${1%%\\n*}" == "${1#*\\n}" ]; then
[[ -z $TEST ]] && echo -e "${bold}${green}${1#*\\n}${reset}" || :
fi
info "------------------------------------------------------------------------------"
IFS= read -r title; info "${title}"
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
VALUES[$label]="${value}"
}
}
info() {
[[ -z $TEST ]] && echo -e "${bold}${blue}${1}${reset}" || :
[[ -z $TEST ]] && echo "${bold}${blue}${1}${reset}" || :
}
#debug() {
# [[ -z $TEST ]] && echo -e "${bold}${red}${1}${reset}" || :
#}
debug() {
[[ -z $TEST ]] && echo -e "${magenta}${1}${reset}" || :
}
assertTest(){
TEST=True
@ -46,122 +81,187 @@ assertEnd() {
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
\n export SCRIPTSDIR=tests/template-flavors \
\n export DIST=wheezy \
\n export TEMPLATE_FLAVOR=whonix-gateway \
\n export TEMPLATE_FLAVOR_PREFIX="
# 1. With TEMPLATE_FLAVOR
# ------------------------------------------------------------------------------
SCRIPTSDIR="tests/template-flavors"
DIST="wheezy"
TEMPLATE_FLAVOR="whonix-gateway"
TEMPLATE_FLAVOR_PREFIX=""
header <<EOF
1. With TEMPLATE_FLAVOR
EOF
buildStep "$0" "pre"
assertTest "buildStep $0 pre" "tests/template-flavors/wheezy+whonix-gateway/test_pre.sh"
assertEnd
# ------------------------------------------------------------------------------
# 2. Without TEMPLATE_FLAVOR
# ------------------------------------------------------------------------------
head " 2. Without TEMPLATE_FLAVOR
\n export TEMPLATE_FLAVOR= "
export TEMPLATE_FLAVOR=""
TEMPLATE_FLAVOR=""
header <<EOF
2. Without TEMPLATE_FLAVOR
EOF
buildStep "$0" "pre"
assertTest "buildStep $0 pre" "tests/template-flavors/test_pre.sh"
assertEnd
# ------------------------------------------------------------------------------
# 3. Template Options
# ------------------------------------------------------------------------------
head " 3. Template Options
\n DISTS_VM = wheezy+whonix-gateway+gnome \
\n DISTS_VM = <DIST>+<TEMPLATE_FLAVOR>+<TEMPLATE_OPTIONS>+<TEMPLATE_OPTIONS> \
\n Options get seperated into TEMPLATE_OPTIONS seperated by spaces"
#
export TEMPLATE_FLAVOR="whonix-gateway"
export TEMPLATE_OPTIONS=('gnome' 'kde')
TEMPLATE_FLAVOR="whonix-gateway"
TEMPLATE_OPTIONS=('gnome' 'kde')
header <<EOF
3. Template Options
Options get seperated into TEMPLATE_OPTIONS seperated by spaces
EOF
buildStep "$0" "pre"
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"
assertEnd
# ------------------------------------------------------------------------------
# 4. Template Options with custom prefix
# ------------------------------------------------------------------------------
head " 4. Template Options with custom prefix
\n TEMPLATE_FLAVOR_PREFIX \
\n export TEMPLATE_FLAVOR_PREFIX=( \
\n 'wheezy+whonix-gateway;debian+' \
\n 'wheezy+whonix-workstation;debian+' \
\n)"
export TEMPLATE_FLAVOR_PREFIX=(
'wheezy+whonix-gateway;debian+'
'wheezy+whonix-workstation;debian+'
TEMPLATE_FLAVOR_PREFIX=(
'wheezy+whonix-gateway:debian+'
'wheezy+whonix-workstation:debian+'
)
header <<EOF
4. Template Options with custom prefix
EOF
buildStep "$0" "pre"
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"
assertEnd
# ------------------------------------------------------------------------------
# 5. Template Options with NO prefix
# ------------------------------------------------------------------------------
head " 5. Template Options with NO prefix
\n TEMPLATE_FLAVOR_PREFIX \
\n export TEMPLATE_FLAVOR_PREFIX=( \
\n 'wheezy+whonix-gateway;' \
\n 'wheezy+whonix-workstation;' \
\n)"
export TEMPLATE_FLAVOR_PREFIX=(
'wheezy+whonix-gateway;'
'wheezy+whonix-workstation;'
TEMPLATE_FLAVOR_PREFIX=(
'wheezy+whonix-gateway:'
'wheezy+whonix-workstation:'
)
header <<EOF
5. Template Options with NO prefix
EOF
buildStep "$0" "pre"
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"
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_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"
assertTest "buildStep $0 pre" "tests/template-flavors/another_location/whonix-gw/test_pre.sh"
assertEnd
# ------------------------------------------------------------------------------
head " 7. Custom template directory with space in name
\n unset TEMPLATE_FLAVOR_PREFIX \
\n unset TEMPLATE_OPTIONS \
\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"
# 8. Custom template directory with space in name
# ------------------------------------------------------------------------------
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"
assertTest "buildStep $0 pre" "tests/template-flavors/another_location/whonix gw/test_pre.sh"
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
export TEMPLATE_OPTIONS=('gnome')
TEMPLATE_FLAVOR_DIR="wheezy+whonix-gateway+gnome;tests/template-flavors/another_location/whonix_gnome"
TEMPLATE_OPTIONS=('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"
assertTest "buildStep $0 pre" "tests/template-flavors/wheezy+whonix-gateway/test_pre.sh\ntests/template-flavors/another_location/whonix_gnome/test_pre.sh"
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
\n Find packages.list for every template available"
TEMPLATE_FLAVOR_DIR="wheezy+whonix-gateway;tests/template-flavors/another_location/whonix gw"
# 12. Configuration Files
# ------------------------------------------------------------------------------
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'
for file in "${filelist[@]}"; do
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"
assertEnd
# ------------------------------------------------------------------------------
# 13. Configuration Files - No Template
# ------------------------------------------------------------------------------
head "10. Configuration Files - No Template
\n Find packages.list for every template available"
TEMPLATE_FLAVOR=
TEMPLATE_FLAVOR_DIR=
header <<EOF
13. Configuration Files - No Template
Find packages.list for every template available
EOF
getFileLocations filelist 'packages.list'
for file in "${filelist[@]}"; do
echo "Configuration: ${file}"
@ -183,11 +289,17 @@ result="$(echo $(printf "'%s' " "${filelist[@]}"))"
assertTest "echo ${result}" "tests/template-flavors/packages.list"
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_DIR=
header <<EOF
14. Configuration Files - No Template - with suffix
Find packages.list for every template available
EOF
getFileLocations filelist 'packages.list' 'wheezy'
for file in "${filelist[@]}"; do
echo "Configuration: ${file}"
@ -197,17 +309,24 @@ assertTest "echo ${result}" "tests/template-flavors/packages_wheezy.list"
assertEnd
# ------------------------------------------------------------------------------
export INSTALLDIR="${SCRIPTSDIR}/test_copy_location"
head "12. Copy files
\n Just test copying from here to ${INSTALLDIR}"
# 14. Copy files
# ------------------------------------------------------------------------------
TEMPLATE_FLAVOR="whonix-gateway"
TEMPLATE_FLAVOR_DIR=""
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"/*
copyTree "files"
ls -l "$INSTALLDIR"
assertTest "ls $INSTALLDIR" "test1\ntest2\ntest3"
assertEnd
# Done
popd

Loading…
Cancel
Save