debian: honor verbose; fixed bug where base package.list was not being used

pull/1/head
Jason Mehring 10 years ago
parent d8138a8f44
commit 422dcc9c24

@ -1,6 +1,9 @@
#!/bin/bash
# vim: set ts=4 sw=4 sts=4 et :
# XXX
set -e
################################################################################
# Global functions
################################################################################
@ -72,20 +75,40 @@ fi
# ------------------------------------------------------------------------------
# Display messages in color
# ------------------------------------------------------------------------------
# Only output text under certain conditions
output() {
case ${VERBOSE} in
0)
true "${1}"
;;
1)
echo -e "${1}"
;;
2)
# Don't echo if -x is set since it will already be displayed via true
[[ ${-/x} != $- ]] || echo -e "${1}"
true "${1}"
;;
*)
true "${1}"
;;
esac
}
info() {
[[ -z ${TEST} ]] && echo -e "${bold}${blue}INFO: ${1}${reset}" || :
output "${bold}${blue}INFO: ${1}${reset}" || :
}
debug() {
[[ -z ${TEST} ]] && echo -e "${bold}${green}DEBUG: ${1}${reset}" || :
output "${bold}${green}DEBUG: ${1}${reset}" || :
}
warn() {
[[ -z ${TEST} ]] && echo -e "${stout}${yellow}WARNING: ${1}${reset}" || :
output "${stout}${yellow}WARNING: ${1}${reset}" || :
}
error() {
[[ -z ${TEST} ]] && echo -e "${bold}${red}ERROR: ${1}${reset}" || :
output "${bold}${red}ERROR: ${1}${reset}" || :
}
# ------------------------------------------------------------------------------
@ -254,7 +277,7 @@ templateFile() {
local file="$1"
local suffix="$2"
local template_flavor="$3"
local template_dir="$(templateDir ${template_flavor})"
local template_dir="$(templateDir "${template_flavor}")"
splitPath "${file}" path_parts
@ -277,9 +300,17 @@ buildStepExec() {
script="$(templateFile "${filename}" "${suffix}" "${template_flavor}")"
if [ -f "${script}" ]; then
[[ -n ${TEST} ]] && echo "${script}" || echo "${bold}${under}INFO: Currently running script: ${script}${reset}"
#if [ -f "${script}" ]; then
if [ -f "${script}" ] && [ ! ${GLOBAL_CACHE[$script]+_} ]; then
# Test module expects raw output back only used to asser test results
if [[ -n ${TEST} ]]; then
echo "${script}"
else
output "${bold}${under}INFO: Currently running script: ${script}${reset}"
fi
# Cache $script
GLOBAL_CACHE[$script]=1
# Execute $script
"${script}"
fi
@ -308,12 +339,17 @@ copyTreeExec() {
pushd "${target_dir}"
{
setfacl --restore="${source_dir}/.facl" 2>/dev/null ||:
rm -f .facl
}
popd
fi
}
callTemplateFunction() {
# Reset Cache
unset GLOBAL_CACHE
declare -A -g GLOBAL_CACHE
local calling_script="$1"
local calling_arg="$2"
local functionExec="$3"
@ -335,6 +371,12 @@ callTemplateFunction() {
"${calling_arg}" \
"${option}"
done
# If template_flavor exists, also check on base distro
if [ -n "${template_flavor}" ]; then
${functionExec} "${calling_script}" \
"${calling_arg}"
fi
}
# ------------------------------------------------------------------------------
@ -350,7 +392,9 @@ getFileLocations() {
#files=( $(callTemplateFunction "${filename}" "${suffix}" "${function}") )
#setArrayAsGlobal files $return_global_var
files=$(callTemplateFunction "${filename}" "${suffix}" "${function}")
# XXX
#files=$(callTemplateFunction "${filename}" "${suffix}" "${function}")
files="$(callTemplateFunction "${filename}" "${suffix}" "${function}")"
IFS_orig="${IFS}}"; IFS=$'\n'
files=( "${files}" )
@ -402,4 +446,4 @@ copyTree() {
}
# $0 is module that sourced vars.sh
echo "${bold}${under}INFO: Currently running script: ${0}${reset}"
output "${bold}${under}INFO: Currently running script: ${0}${reset}"

@ -112,7 +112,7 @@ EOF
exit 1
fi
for package_list in "${packages_list[@]}"; do
for package_list in ${packages_list[@]}; do
debug "Installing extra packages from: ${package_list}"
DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
xargs chroot ${INSTALLDIR} apt-get -y --force-yes install < "${package_list}"

@ -1,8 +1,7 @@
#!/bin/bash
# vim: set ts=4 sw=4 sts=4 et :
VERBOSE=2
DEBUG=1
VERBOSE=1
pushd ../..
ROOT_DIR=$(readlink -m .)
@ -45,27 +44,24 @@ declare -A VALUES=(
)
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
#printf "${bold}${black}%s=\"${value}\"${reset}\n" "${label}" || :
VALUES[$label]="${value}"
}
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 "${bold}${blue}${1}${reset}" || :
output "${bold}${blue}${1}${reset}" || :
}
debug() {
[[ -z ${TEST} ]] && echo -e "${magenta}${1}${reset}" || :
output "${magenta}${1}${reset}" || :
}
assertTest(){
@ -97,7 +93,7 @@ header <<EOF
1. With TEMPLATE_FLAVOR
EOF
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\ntests/template-flavors/test_pre.sh"
assertEnd
@ -137,7 +133,7 @@ header <<EOF
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"
assertTest "buildStep $0 pre" "tests/template-flavors/wheezy+whonix-gateway/test_pre.sh\ntests/template-flavors/wheezy+whonix-gateway+gnome/test_pre.sh\ntests/template-flavors/test_pre.sh"
assertEnd
@ -159,7 +155,7 @@ header <<EOF
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"
assertTest "buildStep $0 pre" "tests/template-flavors/debian+whonix-gateway/test_pre.sh\ntests/template-flavors/wheezy+whonix-gateway+gnome/test_pre.sh\ntests/template-flavors/test_pre.sh"
assertEnd
@ -181,7 +177,7 @@ header <<EOF
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"
assertTest "buildStep $0 pre" "tests/template-flavors/whonix-gateway/test_pre.sh\ntests/template-flavors/wheezy+whonix-gateway+gnome/test_pre.sh\ntests/template-flavors/test_pre.sh"
assertEnd
@ -278,7 +274,7 @@ 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"
assertTest "buildStep $0 pre" "tests/template-flavors/wheezy+whonix-gateway/test_pre.sh\ntests/template-flavors/proxy/test_pre.sh\ntests/template-flavors/test_pre.sh"
assertEnd
@ -297,7 +293,7 @@ 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"
assertTest "buildStep $0 pre" "tests/template-flavors/wheezy+whonix-gateway/test_pre.sh\ntests/template-flavors/proxy/test_pre.sh\ntests/template-flavors/test_pre.sh"
assertEnd
@ -387,7 +383,7 @@ for file in "${filelist[@]}"; do
echo "Configuration: ${file}"
done
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 tests/template-flavors/packages.list"
assertEnd

Loading…
Cancel
Save