Tag for commit 79de4f1997
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQIcBAABAgAGBQJVBdfmAAoJEBu5sftaTG2tEu4QAJEn6s9JtTB2GS0ZOT4leLuJ
JHfYeqb7fV0H+kIgw2K6bpnwJJSAldcH/yPQosmZAC3Uc8ttYCvEZXbwaa8tJ70v
STau0iZ2HGSJg9leaflsAdfOvQVLJ2CPA1n1RUxXfvt0e81svTgEh3E3kTLL3oHV
g0vSdsNj3ZrQEBP/a+wD8I02u1oqwiuNPVo50lFJ/fTdT8emhlXMWEIDDvdwtRq9
R0NIeTXuoVsIls3tqay6tQm6X/ziqqT2MVYx2wRcO1PuM+lWNSA04OElZ9TvszE1
QXAAJEtNg3Veu3OSHL8a1FQJppb9CGJ9Nt+cZTodvTp+aJbZ4X3aaz7s7oSpaDs9
/hYZbB2rVl/As3T5XWyh0WEl+00eZYKhsiBk+WQSSzXeutFqFxY1TsrmISqJZ7AL
2lahSU5pHfmYOaPdnXoK1CnMoWBs6uVX5+sNrgH2ZEE85C1ppWgPfpQe6WcH7Qzs
QPLqwSAEilXv3S3LJBk+pWxco+kd4JLBeLqiEdZbbSO5r532owqVaJUiNqn7WocX
zW1ZTycvAR05AHjyult3VEJ+ZijYSoeSwtmMiV3NrqC1XNe4Vxz1axXgk/VjQHYq
qARytTfj4kQw4xp8REyuUhIZ+6ON2HAYxSWx0kE+hEINRxBw3nLMDn1D0u+aNFWg
S3xrj5JeNt9PfVQK2VGE
=wgtX
-----END PGP SIGNATURE-----
Merge tag 'jm_79de4f19'
Tag for commit 79de4f1997
# gpg: Signature made Sun Mar 15 20:05:10 2015 CET using RSA key ID 5A4C6DAD
# gpg: Good signature from "Jason Mehring (Qubes OS Signing Key) <nrgaway@gmail.com>"
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg: There is no indication that the signature belongs to the owner.
# Primary key fingerprint: E0E3 2283 FDCA C1A5 1007 8F27 1BB9 B1FB 5A4C 6DAD
* tag 'jm_79de4f19':
Updated tests to include tests for new features added to functions*.sh
Fixed templateName function where it was throwing an error that template name was too long, even though it should have been reported as okay
Added the ability for template files to be found side by side the original file which allows template flavor suffix to be added to package lists as well as most any other file type now.
This commit is contained in:
commit
a95bf3a95f
@ -6,6 +6,23 @@ set -e
|
||||
VERBOSE=${VERBOSE:-1}
|
||||
DEBUG=${DEBUG:-0}
|
||||
|
||||
containsFlavor() {
|
||||
flavor="${1}"
|
||||
retval=1
|
||||
|
||||
# Check the template flavor first
|
||||
if [ "${flavor}" == "${TEMPLATE_FLAVOR}" ]; then
|
||||
retval=0
|
||||
fi
|
||||
|
||||
# Check the template flavors next
|
||||
elementIn "${flavor}" ${TEMPLATE_OPTIONS[@]} && {
|
||||
retval=0
|
||||
}
|
||||
|
||||
return ${retval}
|
||||
}
|
||||
|
||||
templateFlavorPrefix() {
|
||||
local template_flavor=${1-${TEMPLATE_FLAVOR}}
|
||||
|
||||
@ -30,18 +47,31 @@ templateFlavorPrefix() {
|
||||
fi
|
||||
}
|
||||
|
||||
templateNameFixLength() {
|
||||
local template_name="${1}"
|
||||
local temp_name=(${template_name//+/ })
|
||||
local index=$(( ${#temp_name[@]}-1 ))
|
||||
|
||||
while [ ${#template_name} -ge 32 ]; do
|
||||
template_name=$(printf '%s' ${temp_name[0]})
|
||||
if [ $index -gt 0 ]; then
|
||||
template_name+=$(printf '+%s' ${temp_name[@]:1:index})
|
||||
fi
|
||||
(( index-- ))
|
||||
if [ $index -lt 1 ]; then
|
||||
template_name="${template_name:0:31}"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "${template_name}"
|
||||
}
|
||||
|
||||
templateNameDist() {
|
||||
local dist_name="${1}"
|
||||
template_name="$(templateName)" && dist_name="${template_name}"
|
||||
|
||||
# XXX: Temp hack to shorten name
|
||||
if [ ${#dist_name} -ge 32 ]; then
|
||||
if [ ${#template_name} -lt 32 ]; then
|
||||
dist_name="${template_name}"
|
||||
else
|
||||
dist_name="${dist_name:0:31}"
|
||||
fi
|
||||
fi
|
||||
# Automaticly correct name length if it's greater than 32 chars
|
||||
dist_name="$(templateNameFixLength ${template_name})"
|
||||
|
||||
# Remove and '+' characters from name since they are invalid for name
|
||||
dist_name="${dist_name//+/-}"
|
||||
@ -53,13 +83,13 @@ templateName() {
|
||||
retval=1 # Default is 1; mean no replace happened
|
||||
|
||||
# Only apply options if $1 was not passed
|
||||
if [ -n "${1}" ]; then
|
||||
if [ -n "${1}" ] || [ "X${TEMPLATE_OPTIONS}" == "X" ]; then
|
||||
local template_options=
|
||||
else
|
||||
local template_options="${TEMPLATE_OPTIONS// /+}"
|
||||
local template_options=$(printf '%s' ${TEMPLATE_OPTIONS[@]/#/+})
|
||||
fi
|
||||
|
||||
local template_name="$(templateFlavorPrefix ${template_flavor})${template_flavor}${template_options:++}${template_options}"
|
||||
local template_name="$(templateFlavorPrefix ${template_flavor})${template_flavor}${template_options}"
|
||||
|
||||
# If TEMPLATE_LABEL is not already an array, make it one
|
||||
if ! [[ "$(declare -p TEMPLATE_LABEL 2>/dev/null)" =~ ^declare\ -a.* ]] ; then
|
||||
@ -74,13 +104,6 @@ templateName() {
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${#template_name} -ge 32 ]; then
|
||||
error "Template name is greater than 31 characters: ${template_name}"
|
||||
error "Please set an alias"
|
||||
error "Exiting!!!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ${template_name}
|
||||
echo "$(templateNameFixLength ${template_name})"
|
||||
return $retval
|
||||
}
|
||||
|
56
functions.sh
56
functions.sh
@ -164,6 +164,19 @@ setArrayAsGlobal() {
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Checks if the passed element exists in passed array
|
||||
# $1: Element to check for
|
||||
# $2: Array to check for element in
|
||||
#
|
||||
# Returns 0 if True, or 1 if False
|
||||
# ------------------------------------------------------------------------------
|
||||
elementIn () {
|
||||
local element
|
||||
for element in "${@:2}"; do [[ "$element" == "$1" ]] && return 0; done
|
||||
return 1
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Spilts the path and returns an array of parts
|
||||
#
|
||||
@ -231,6 +244,15 @@ templateDir() {
|
||||
echo "${dir}"
|
||||
}
|
||||
|
||||
exists() {
|
||||
filename="${1}"
|
||||
if [ -e "${filename}" ]; then
|
||||
echo "${filename}"
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
templateFile() {
|
||||
local file="$1"
|
||||
local suffix="$2"
|
||||
@ -239,15 +261,35 @@ templateFile() {
|
||||
|
||||
splitPath "${file}" path_parts
|
||||
|
||||
# Append suffix to filename (before extension)
|
||||
if [ "${suffix}" ]; then
|
||||
file="${template_dir}/${path_parts[base]}_${suffix}${path_parts[dotext]}"
|
||||
else
|
||||
file="${template_dir}/${path_parts[base]}${path_parts[dotext]}"
|
||||
# No template flavor
|
||||
if [ "X{template_flavor}" == "X" ]; then
|
||||
if [ -e "${file}" ]; then
|
||||
echo "${file}"
|
||||
fi
|
||||
return
|
||||
fi
|
||||
|
||||
if [ -f "${file}" ]; then
|
||||
echo "${file}"
|
||||
# Locate file in directory named after flavor
|
||||
if [ "${suffix}" ]; then
|
||||
# Append suffix to filename (before extension)
|
||||
|
||||
# (../SCRIPTSDIR/minimal/packages_qubes_suffix.list)
|
||||
exists "${template_dir}/${path_parts[base]}_${suffix}${path_parts[dotext]}" || true
|
||||
|
||||
# (../SCRIPTSDIR/minimal/packages_qubes_minimal_suffix.list)
|
||||
exists "${template_dir}/${path_parts[base]}_${suffix}_${template_flavor}${path_parts[dotext]}" || true
|
||||
|
||||
# (../SCRIPTSDIR/packages_qubes_minimal_suffix.list)
|
||||
exists "${SCRIPTSDIR}/${path_parts[base]}_${suffix}_${template_flavor}${path_parts[dotext]}" || true
|
||||
else
|
||||
# (../SCRIPTSDIR/minimal/packages_qubes.list)
|
||||
exists "${template_dir}/${path_parts[base]}${path_parts[dotext]}" || true
|
||||
|
||||
# (../SCRIPTSDIR/minimal/packages_qubes_minimal.list)
|
||||
exists "${template_dir}/${path_parts[base]}_${template_flavor}${path_parts[dotext]}" || true
|
||||
|
||||
# (../SCRIPTSDIR/packages_qubes_minimal.list)
|
||||
exists "${SCRIPTSDIR}/${path_parts[base]}_${template_flavor}${path_parts[dotext]}" || true
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,8 @@ ROOT_DIR=$(readlink -m .)
|
||||
. ./functions.sh
|
||||
. ./tests/assert/assert.sh
|
||||
|
||||
set +e
|
||||
|
||||
header() {
|
||||
echo
|
||||
echo
|
||||
@ -217,7 +219,7 @@ header <<EOF
|
||||
7. Custom template directory
|
||||
EOF
|
||||
buildStep "$0" "pre"
|
||||
assertTest "buildStep $0 pre" "tests/template-flavors/another_location/whonix-gw/test_pre.sh\ntests/template-flavors/wheezy/test_pre.sh"
|
||||
assertTest "buildStep $0 pre" "tests/template-flavors/another_location/whonix-gw/test_pre.sh\ntests/template-flavors/wheezy/test_pre.sh\ntests/template-flavors/test_pre.sh"
|
||||
assertEnd
|
||||
|
||||
|
||||
@ -236,7 +238,7 @@ 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\ntests/template-flavors/wheezy/test_pre.sh"
|
||||
assertTest "buildStep $0 pre" "tests/template-flavors/another_location/whonix gw/test_pre.sh\ntests/template-flavors/wheezy/test_pre.sh\ntests/template-flavors/test_pre.sh"
|
||||
assertEnd
|
||||
|
||||
|
||||
@ -359,9 +361,48 @@ info "Template name: $(templateName)"
|
||||
assertTest "templateName" "debian-7"
|
||||
assertEnd
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# 15. Template Name - containsFlavor
|
||||
# ------------------------------------------------------------------------------
|
||||
SCRIPTSDIR="tests/template-flavors"
|
||||
DIST="wheezy"
|
||||
DISTS_VM=""
|
||||
TEMPLATE_FLAVOR="whonix-gateway"
|
||||
TEMPLATE_FLAVOR_PREFIX=""
|
||||
TEMPLATE_FLAVOR_DIR=""
|
||||
TEMPLATE_OPTIONS=('proxy' 'minimal' 'flash' 'gnome')
|
||||
TEMPLATE_LABEL=""
|
||||
|
||||
header <<EOF
|
||||
15. Template Name - containsFlavor
|
||||
containsFlavor flash
|
||||
containsFlavor whonix-gateway
|
||||
EOF
|
||||
assert_raises "containsFlavor flash"
|
||||
assert_raises "containsFlavor whonix-gateway"
|
||||
assertEnd
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# 15. Configuration Files
|
||||
# 16. Long Template Name
|
||||
# ------------------------------------------------------------------------------
|
||||
SCRIPTSDIR="tests/template-flavors"
|
||||
DIST="wheezy"
|
||||
DISTS_VM=""
|
||||
TEMPLATE_FLAVOR="tor-gateway"
|
||||
TEMPLATE_FLAVOR_PREFIX=""
|
||||
TEMPLATE_FLAVOR_DIR=""
|
||||
TEMPLATE_OPTIONS=""
|
||||
TEMPLATE_OPTIONS=('minimal' 'proxy' 'flash' 'gnome' 'standard')
|
||||
|
||||
header <<EOF
|
||||
16. Long Template Name
|
||||
EOF
|
||||
info "Template name: $(templateName)"
|
||||
assertTest "templateName" "wheezy+tor-gateway+minimal"
|
||||
assertEnd
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# 17. Configuration Files
|
||||
# ------------------------------------------------------------------------------
|
||||
SCRIPTSDIR="tests/template-flavors"
|
||||
DIST="wheezy"
|
||||
@ -375,7 +416,7 @@ TEMPLATE_FLAVOR_DIR=(
|
||||
TEMPLATE_OPTIONS=('gnome')
|
||||
|
||||
header <<EOF
|
||||
15. Configuration Files
|
||||
17. Configuration Files
|
||||
Find packages.list for every template available
|
||||
EOF
|
||||
getFileLocations filelist 'packages.list'
|
||||
@ -388,7 +429,7 @@ assertEnd
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# 16. Configuration Files - No Template
|
||||
# 18. Configuration Files - No Template
|
||||
# ------------------------------------------------------------------------------
|
||||
SCRIPTSDIR="tests/template-flavors"
|
||||
DIST="wheezy"
|
||||
@ -399,7 +440,7 @@ TEMPLATE_FLAVOR_DIR=""
|
||||
TEMPLATE_OPTIONS=('gnome')
|
||||
|
||||
header <<EOF
|
||||
16. Configuration Files - No Template
|
||||
18. Configuration Files - No Template
|
||||
Find packages.list for every template available
|
||||
EOF
|
||||
getFileLocations filelist 'packages.list'
|
||||
@ -412,7 +453,7 @@ assertEnd
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# 17. Configuration Files - No Template - with suffix
|
||||
# 19. Configuration Files - No Template - with suffix
|
||||
# ------------------------------------------------------------------------------
|
||||
SCRIPTSDIR="tests/template-flavors"
|
||||
DIST="wheezy"
|
||||
@ -423,7 +464,7 @@ TEMPLATE_FLAVOR_DIR=""
|
||||
TEMPLATE_OPTIONS=('gnome')
|
||||
|
||||
header <<EOF
|
||||
17. Configuration Files - No Template - with suffix
|
||||
19. Configuration Files - No Template - with suffix
|
||||
Find packages.list for every template available
|
||||
EOF
|
||||
getFileLocations filelist 'packages.list' 'wheezy'
|
||||
@ -435,7 +476,7 @@ assertTest "echo ${result}" "tests/template-flavors/packages_wheezy.list"
|
||||
assertEnd
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# 18. Copy files
|
||||
# 20. Copy files
|
||||
# ------------------------------------------------------------------------------
|
||||
SCRIPTSDIR="tests/template-flavors"
|
||||
DIST="wheezy"
|
||||
@ -447,7 +488,7 @@ TEMPLATE_OPTIONS=""
|
||||
INSTALLDIR="${SCRIPTSDIR}/test_copy_location"
|
||||
|
||||
header <<EOF
|
||||
18. Copy files
|
||||
20. Copy files
|
||||
Just test copying from here to ${INSTALLDIR}
|
||||
INSTALLDIR="${SCRIPTSDIR}/test_copy_location"
|
||||
EOF
|
||||
@ -459,6 +500,5 @@ ls -l "${INSTALLDIR}"
|
||||
assertTest "ls ${INSTALLDIR}" "test1\ntest2\ntest3"
|
||||
assertEnd
|
||||
|
||||
|
||||
# Done
|
||||
popd
|
||||
|
Loading…
Reference in New Issue
Block a user