Added ability to name tempaltes within configuration file and check/fix to make sure names under 32 characters

pull/1/head
Jason Mehring 10 years ago
parent 0b341f4fb2
commit deb4cbd867

@ -6,10 +6,19 @@ export DIST
dist_ver := $(shell DIST=$(DIST) ./builder_setup) dist_ver := $(shell DIST=$(DIST) ./builder_setup)
DISTRIBUTION := $(word 1,$(dist_ver)) DISTRIBUTION := $(word 1,$(dist_ver))
DIST_VERSION := $(word 2,$(dist_ver)) DIST_VERSION := $(word 2,$(dist_ver))
TEMPLATE_NAME := $(word 3,$(dist_ver))
ifeq (,$(TEMPLATE_NAME))
TEMPLATE_NAME := $(DISTRIBUTION)-$(DIST_VERSION)-x64 TEMPLATE_NAME := $(DISTRIBUTION)-$(DIST_VERSION)-x64
ifdef TEMPLATE_FLAVOR ifdef TEMPLATE_FLAVOR
TEMPLATE_NAME := $(TEMPLATE_NAME)-$(TEMPLATE_FLAVOR) TEMPLATE_NAME := $(TEMPLATE_NAME)-$(TEMPLATE_FLAVOR)
endif endif
endif
# Make sure names are < 32 characters
fix_up := $(shell TEMPLATE_NAME=$(TEMPLATE_NAME) ./builder_fix_filenames)
TEMPLATE_NAME := $(word 1,$(fix_up))
VERSION := $(shell cat version) VERSION := $(shell cat version)
TIMESTAMP := $(shell date -u +%Y%m%d%H%M) TIMESTAMP := $(shell date -u +%Y%m%d%H%M)

@ -0,0 +1,9 @@
#!/bin/bash
# Check template name length and fix if not under 32 characters
# Return the result
. ./functions.sh > /dev/null
# Check for custom template name
templateNameDist "${TEMPLATE_NAME}"

@ -2,6 +2,8 @@
# Setup env variables # Setup env variables
. ./functions.sh > /dev/null
case "$DIST" in case "$DIST" in
fc*) fc*)
DISTRIBUTION=fedora DISTRIBUTION=fedora
@ -31,3 +33,6 @@ CACHEDIR=cache_$DIST
export SCRIPTSDIR CACHEDIR export SCRIPTSDIR CACHEDIR
echo $DISTRIBUTION $VERSION echo $DISTRIBUTION $VERSION
# Check for custom template name
#templateName > /dev/null && templateName

@ -157,13 +157,61 @@ templateFlavorPrefix() {
echo "${DIST}${template_flavor:++}" echo "${DIST}${template_flavor:++}"
} }
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
echo ${dist_name}
}
templateName() {
local template_flavor=${1-$(templateFlavor)}
retval=1 # Default is 1; mean no replace happened
# Only apply options if $1 was not passed
if [ -n "${1}" ]; then
local template_options=
else
local template_options="${TEMPLATE_OPTIONS// /+}"
fi
local template_name="$(templateFlavorPrefix ${template_flavor})${template_flavor}${template_options:++}${template_options}"
for element in "${TEMPLATE_LABEL[@]}"; do
if [ "${element%:*}" == "${template_name}" ]; then
template_name="${element#*:}"
retval=0
break
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}
return $retval
}
templateDir() { templateDir() {
local template_flavor=${1-$(templateFlavor)} local template_flavor=${1-$(templateFlavor)}
for element in "${TEMPLATE_FLAVOR_DIR[@]}" for element in "${TEMPLATE_FLAVOR_DIR[@]}"
do do
# (wheezy+whonix-gateway / wheezy+whonix-gateway+gnome[+++] / wheezy+gnome ) # (wheezy+whonix-gateway / wheezy+whonix-gateway+gnome[+++] / wheezy+gnome )
if [ "${element%:*}" == "$(templateFlavorPrefix ${template_flavor})${template_flavor}" ]; then #if [ "${element%:*}" == "$(templateFlavorPrefix ${template_flavor})${template_flavor}" ]; then
if [ "${element%:*}" == "$(templateName ${template_flavor})" ]; then
eval echo -e ${element#*:} eval echo -e ${element#*:}
return return
# Very short name compare (+proxy) # Very short name compare (+proxy)

@ -55,6 +55,7 @@ values() {
else else
printf " ${bold}${black}%-22s = ${value}${reset}\n" "${label}" || : printf " ${bold}${black}%-22s = ${value}${reset}\n" "${label}" || :
fi fi
#printf "${bold}${black}%s=\"${value}\"${reset}\n" "${label}" || :
VALUES[$label]="${value}" VALUES[$label]="${value}"
} }
} }
@ -86,8 +87,11 @@ assertEnd() {
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
SCRIPTSDIR="tests/template-flavors" SCRIPTSDIR="tests/template-flavors"
DIST="wheezy" DIST="wheezy"
DISTS_VM=""
TEMPLATE_FLAVOR="whonix-gateway" TEMPLATE_FLAVOR="whonix-gateway"
TEMPLATE_FLAVOR_PREFIX="" TEMPLATE_FLAVOR_PREFIX=""
TEMPLATE_FLAVOR_DIR=""
TEMPLATE_OPTIONS=""
header <<EOF header <<EOF
1. With TEMPLATE_FLAVOR 1. With TEMPLATE_FLAVOR
@ -100,7 +104,13 @@ assertEnd
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# 2. Without TEMPLATE_FLAVOR # 2. Without TEMPLATE_FLAVOR
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
SCRIPTSDIR="tests/template-flavors"
DIST="wheezy"
DISTS_VM=""
TEMPLATE_FLAVOR="" TEMPLATE_FLAVOR=""
TEMPLATE_FLAVOR_PREFIX=""
TEMPLATE_FLAVOR_DIR=""
TEMPLATE_OPTIONS=""
header <<EOF header <<EOF
2. Without TEMPLATE_FLAVOR 2. Without TEMPLATE_FLAVOR
@ -113,7 +123,12 @@ assertEnd
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# 3. Template Options # 3. Template Options
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
SCRIPTSDIR="tests/template-flavors"
DIST="wheezy"
DISTS_VM=""
TEMPLATE_FLAVOR="whonix-gateway" TEMPLATE_FLAVOR="whonix-gateway"
TEMPLATE_FLAVOR_PREFIX=""
TEMPLATE_FLAVOR_DIR=""
TEMPLATE_OPTIONS=('gnome' 'kde') TEMPLATE_OPTIONS=('gnome' 'kde')
header <<EOF header <<EOF
@ -129,11 +144,16 @@ assertEnd
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# 4. Template Options with custom prefix # 4. Template Options with custom prefix
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
SCRIPTSDIR="tests/template-flavors"
DIST="wheezy"
DISTS_VM=""
TEMPLATE_FLAVOR="whonix-gateway"
TEMPLATE_FLAVOR_DIR=""
TEMPLATE_OPTIONS=('gnome' 'kde')
TEMPLATE_FLAVOR_PREFIX=( TEMPLATE_FLAVOR_PREFIX=(
'wheezy+whonix-gateway:debian+' 'wheezy+whonix-gateway:debian+'
'wheezy+whonix-workstation:debian+' 'wheezy+whonix-workstation:debian+'
) )
header <<EOF header <<EOF
4. Template Options with custom prefix 4. Template Options with custom prefix
EOF EOF
@ -146,11 +166,16 @@ assertEnd
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# 5. Template Options with NO prefix # 5. Template Options with NO prefix
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
SCRIPTSDIR="tests/template-flavors"
DIST="wheezy"
DISTS_VM=""
TEMPLATE_FLAVOR="whonix-gateway"
TEMPLATE_FLAVOR_DIR=""
TEMPLATE_OPTIONS=('gnome' 'kde')
TEMPLATE_FLAVOR_PREFIX=( TEMPLATE_FLAVOR_PREFIX=(
'wheezy+whonix-gateway:' 'wheezy+whonix-gateway:'
'wheezy+whonix-workstation:' 'wheezy+whonix-workstation:'
) )
header <<EOF header <<EOF
5. Template Options with NO prefix 5. Template Options with NO prefix
EOF EOF
@ -163,9 +188,13 @@ assertEnd
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# 6. Custom template directory for options within \${SCRIPTSDIR} # 6. Custom template directory for options within \${SCRIPTSDIR}
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
unset TEMPLATE_FLAVOR_PREFIX SCRIPTSDIR="tests/template-flavors"
DIST="wheezy"
DISTS_VM=""
TEMPLATE_FLAVOR="whonix-gateway"
TEMPLATE_FLAVOR_PREFIX=""
TEMPLATE_FLAVOR_DIR="wheezy+whonix-gateway+gnome:${SCRIPTSDIR}/another_location/whonix_gnome"
TEMPLATE_OPTIONS=('gnome') TEMPLATE_OPTIONS=('gnome')
TEMPLATE_FLAVOR_DIR='wheezy+whonix-gateway+gnome:${SCRIPTSDIR}/another_location/whonix_gnome'
header <<EOF header <<EOF
6. Custom template directory for options within \${SCRIPTSDIR} 6. Custom template directory for options within \${SCRIPTSDIR}
@ -180,9 +209,13 @@ assertEnd
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# 7. Custom template directory # 7. Custom template directory
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
unset TEMPLATE_FLAVOR_PREFIX SCRIPTSDIR="tests/template-flavors"
unset TEMPLATE_OPTIONS DIST="wheezy"
DISTS_VM=""
TEMPLATE_FLAVOR="whonix-gateway"
TEMPLATE_FLAVOR_PREFIX=""
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=""
header <<EOF header <<EOF
7. Custom template directory 7. Custom template directory
@ -195,7 +228,13 @@ assertEnd
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# 8. Custom template directory with space in name # 8. Custom template directory with space in name
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
SCRIPTSDIR="tests/template-flavors"
DIST="wheezy"
DISTS_VM=""
TEMPLATE_FLAVOR="whonix-gateway"
TEMPLATE_FLAVOR_PREFIX=""
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=""
header <<EOF header <<EOF
8. Custom template directory with space in name 8. Custom template directory with space in name
@ -208,9 +247,13 @@ assertEnd
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# 9. Custom template directory for options # 9. Custom template directory for options
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
unset TEMPLATE_FLAVOR_PREFIX SCRIPTSDIR="tests/template-flavors"
TEMPLATE_OPTIONS=('gnome') DIST="wheezy"
DISTS_VM=""
TEMPLATE_FLAVOR="whonix-gateway"
TEMPLATE_FLAVOR_PREFIX=""
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"
TEMPLATE_OPTIONS=('gnome')
header <<EOF header <<EOF
9. Custom template directory for options 9. Custom template directory for options
@ -223,10 +266,13 @@ assertEnd
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# 10. Template directory for options within $SCRIPTSDIR using short name filter # 10. Template directory for options within $SCRIPTSDIR using short name filter
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
unset TEMPLATE_FLAVOR_PREFIX SCRIPTSDIR="tests/template-flavors"
unset TEMPLATE_FLAVOR_DIR DIST="wheezy"
DISTS_VM=""
TEMPLATE_FLAVOR="whonix-gateway"
TEMPLATE_FLAVOR_PREFIX=""
TEMPLATE_FLAVOR_DIR="wheezy+proxy:${SCRIPTSDIR}/proxy"
TEMPLATE_OPTIONS=('proxy') TEMPLATE_OPTIONS=('proxy')
TEMPLATE_FLAVOR_DIR='wheezy+proxy:${SCRIPTSDIR}/proxy'
header <<EOF header <<EOF
10. Template directory for options within $SCRIPTSDIR using short name filter 10. Template directory for options within $SCRIPTSDIR using short name filter
@ -239,10 +285,13 @@ assertEnd
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# 11. Template directory for options within using VERY short name filter (+proxy) # 11. Template directory for options within using VERY short name filter (+proxy)
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
unset TEMPLATE_FLAVOR_PREFIX SCRIPTSDIR="tests/template-flavors"
unset TEMPLATE_FLAVOR_DIR DIST="wheezy"
DISTS_VM=""
TEMPLATE_FLAVOR="whonix-gateway"
TEMPLATE_FLAVOR_PREFIX=""
TEMPLATE_FLAVOR_DIR="+proxy:${SCRIPTSDIR}/proxy"
TEMPLATE_OPTIONS=('proxy') TEMPLATE_OPTIONS=('proxy')
TEMPLATE_FLAVOR_DIR='+proxy:${SCRIPTSDIR}/proxy'
header <<EOF header <<EOF
11. Template directory for options within using VERY short name filter (+proxy) 11. Template directory for options within using VERY short name filter (+proxy)
@ -253,13 +302,81 @@ assertEnd
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# 12. Configuration Files # 12. Template Name - Custom
# ------------------------------------------------------------------------------
SCRIPTSDIR="tests/template-flavors"
DIST="wheezy"
DISTS_VM=""
TEMPLATE_FLAVOR="whonix-gateway"
TEMPLATE_FLAVOR_PREFIX=""
TEMPLATE_FLAVOR_DIR=""
TEMPLATE_OPTIONS=""
TEMPLATE_LABEL="wheezy+whonix-gateway:whonix-gateway"
header <<EOF
12. Template Name - Custom
TEMPLATE_LABEL = wheezy+whonix-gateway:whonix-gateway
EOF
info "Template name: $(templateName)"
assertTest "templateName" "whonix-gateway"
assertEnd
# ------------------------------------------------------------------------------
# 13. Template Name - Custom with sub-options
# ------------------------------------------------------------------------------
SCRIPTSDIR="tests/template-flavors"
DIST="wheezy"
DISTS_VM=""
TEMPLATE_FLAVOR="whonix-gateway"
TEMPLATE_FLAVOR_PREFIX=""
TEMPLATE_FLAVOR_DIR=""
TEMPLATE_OPTIONS=('proxy')
TEMPLATE_LABEL="wheezy+whonix-gateway+proxy:whonix-gateway"
header <<EOF
13. Template Name - Custom with sub-options
TEMPLATE_LABEL = wheezy+whonix-gateway+proxy:whonix-gateway
EOF
info "Template name: $(templateName)"
assertTest "templateName" "whonix-gateway"
assertEnd
# ------------------------------------------------------------------------------
# 14. Template Name - NO template
# ------------------------------------------------------------------------------
SCRIPTSDIR="tests/template-flavors"
DIST="wheezy"
DISTS_VM=""
TEMPLATE_FLAVOR=""
TEMPLATE_FLAVOR_PREFIX=""
TEMPLATE_FLAVOR_DIR=""
TEMPLATE_OPTIONS=""
TEMPLATE_LABEL="wheezy:debian-7"
header <<EOF
14. Template Name - NO template
TEMPLATE_LABEL = wheezy:debian-7
EOF
info "Template name: $(templateName)"
assertTest "templateName" "debian-7"
assertEnd
# ------------------------------------------------------------------------------
# 15. Configuration Files
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
SCRIPTSDIR="tests/template-flavors"
DIST="wheezy"
DISTS_VM=""
TEMPLATE_FLAVOR="whonix-gateway"
TEMPLATE_FLAVOR_PREFIX=""
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') TEMPLATE_OPTIONS=('gnome')
header <<EOF header <<EOF
12. Configuration Files 15. Configuration Files
Find packages.list for every template available Find packages.list for every template available
EOF EOF
getFileLocations filelist 'packages.list' getFileLocations filelist 'packages.list'
@ -272,13 +389,18 @@ assertEnd
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# 13. Configuration Files - No Template # 16. Configuration Files - No Template
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
TEMPLATE_FLAVOR= SCRIPTSDIR="tests/template-flavors"
TEMPLATE_FLAVOR_DIR= DIST="wheezy"
DISTS_VM=""
TEMPLATE_FLAVOR=""
TEMPLATE_FLAVOR_PREFIX=""
TEMPLATE_FLAVOR_DIR=""
TEMPLATE_OPTIONS=('gnome')
header <<EOF header <<EOF
13. Configuration Files - No Template 16. Configuration Files - No Template
Find packages.list for every template available Find packages.list for every template available
EOF EOF
getFileLocations filelist 'packages.list' getFileLocations filelist 'packages.list'
@ -291,13 +413,18 @@ assertEnd
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# 14. Configuration Files - No Template - with suffix # 17. Configuration Files - No Template - with suffix
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
TEMPLATE_FLAVOR= SCRIPTSDIR="tests/template-flavors"
TEMPLATE_FLAVOR_DIR= DIST="wheezy"
DISTS_VM=""
TEMPLATE_FLAVOR=""
TEMPLATE_FLAVOR_PREFIX=""
TEMPLATE_FLAVOR_DIR=""
TEMPLATE_OPTIONS=('gnome')
header <<EOF header <<EOF
14. Configuration Files - No Template - with suffix 17. Configuration Files - No Template - with suffix
Find packages.list for every template available Find packages.list for every template available
EOF EOF
getFileLocations filelist 'packages.list' 'wheezy' getFileLocations filelist 'packages.list' 'wheezy'
@ -309,19 +436,25 @@ assertTest "echo ${result}" "tests/template-flavors/packages_wheezy.list"
assertEnd assertEnd
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# 14. Copy files # 18. Copy files
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
SCRIPTSDIR="tests/template-flavors"
DIST="wheezy"
DISTS_VM=""
TEMPLATE_FLAVOR="whonix-gateway" TEMPLATE_FLAVOR="whonix-gateway"
TEMPLATE_FLAVOR_PREFIX=""
TEMPLATE_FLAVOR_DIR="" TEMPLATE_FLAVOR_DIR=""
TEMPLATE_OPTIONS="" TEMPLATE_OPTIONS=""
INSTALLDIR="${SCRIPTSDIR}/test_copy_location" INSTALLDIR="${SCRIPTSDIR}/test_copy_location"
header <<EOF header <<EOF
14. Copy files 18. Copy files
Just test copying from here to ${INSTALLDIR} Just test copying from here to ${INSTALLDIR}
INSTALLDIR="${SCRIPTSDIR}/test_copy_location" INSTALLDIR="${SCRIPTSDIR}/test_copy_location"
EOF EOF
rm -rf "$INSTALLDIR"/* rm -f "$INSTALLDIR"/test1
rm -f "$INSTALLDIR"/test2
rm -f "$INSTALLDIR"/test3
copyTree "files" copyTree "files"
ls -l "$INSTALLDIR" ls -l "$INSTALLDIR"
assertTest "ls $INSTALLDIR" "test1\ntest2\ntest3" assertTest "ls $INSTALLDIR" "test1\ntest2\ntest3"

Loading…
Cancel
Save