#!/bin/bash
# ==============================================================================
# title			:TheeMahn's O/S Builder
# description	:Builds Ultimate Edition Operating Systems.
# author		:theemahn <theemahn@ultimateedition.info>
# date			:06/04/2016
# version		:1.9.7
# usage			:tmosb --help
# manual		:man tmosb
# notes			:See change-log below for further information.
# ==============================================================================
# Change-log:
#		1.8.8:	Initial public release
#
#		1.8.9:	Internal test release.
#
# 		1.9.0:	Public release, added aditional DE (Desktop Environments)
#			Added support for foreign Architectures PPC and ARM
#			Multitude of bug fixes
#
#		1.9.1	Bug fixes, added ability to set the default desktop
#			environment (DE).
#
#		1.9.2	Bug squashing release, introduced internal --BUILDALL -YES
# 			Will build all x86 and x64 based Operating systems back to back
#			with 0 user intervention. Introduction of software automation.
#
#			Initated the anti-malware initive, there will be no spyware in
#			Ultimate Edition. Code written to not only remove malicous
#			software, but increase end user privacy.
#
#			Removed case sensitivity in command line interpreter:
#			tmosb --build ultimate-edition-4.4-x64.iso KdE MaTe LxQT awesome
#			will now work. Command line interpreter now rejects all non-
#			applicable information.
#
#			Fixed bugs in directory detection of current build, souped up eyecandy
#			Updated donors software to automously generate list of donors, date they donated and amt.
#
#			Initiated the no-one left behind aspect train of thought.
#			Ultimate Edition enters the server world.
#			General server configation begins - Apache, Mysql, Wordpress
#			all command line switchabilty in the build process.
#
#			A few extra hundred O/S's it will build.
#
#			Added --release <ISO> option will now directly from a server release
#			<ISO> operating system for immediate distribution.
#
#			Updated bash auto completion to accept all commands and provide
#			relevant information.  tmob [tab] [tab] or tmosb -- [tab] [tab]
#			expidites the entire process.  Updated DefaultDE, to not care about
#			case sensitivity.
#
#		1.9.3:	Fixed issues with network manager applet not autoloading / working
#			Added initial support for Vivid Vervet (Ubuntu 15.04).
#
#		1.9.4	Fully implemented the build of 4.6 / 4.7 Vivid Vervet (Ubuntu 15.04).
#			incorporated compiz into the mix - We will have eyecandy again.
#
#			Fixed a multitude of issues in presenting information to the end user.
#
#			Adjusted minimal server to provide tools for monitoring users & bandwidth.
#
#			Added --modify switch to allow enduser to chroot / customise.
#
#			souped up bash autocompetion & help system.
#
#			Added grid to present o/s options in a nice grid to allow users to
#			make informed decisions on best approach to receiving the O/S they
#			want --build with no secondary option will display posibilites.
#			Tmosb will now build 217 different Operating Systems - many currently unseen
#			1953 in total, when desktop environments are also calculated.
#
#			Added support for firefox prefs and build date / version based on LTS or not.
#
#			Fixed Even / Odd build defaults ie 4.7 will default to KDE as default de.
#			unless specified via defaultde=[DE]
#
#			Added initilal skelatal support for DE's (fully detected at build):
#			"MATE" "CINNAMON" "KDE" "GNOME" "LXQT"
#
#			Adjust internal (chroot) to use an array to build package availibilty.
#			Does not fail even if packages are missing in the repos.
#			Work smarter, not harder.
#
#			Repaired issues with "Ultimate Edition Software Center" not working
#			when building Operating systems on our servers.
#
#			Added XBMC integraded TV Support 70 Networks are pre-enabled with
#			or a million streams / channels.
#
#			Feature freeze - waiting on Beta testers input before Public Release.
#
#		1.9.5	Steped things up to visit the Wily Werewolf "15.10" can
#			Build Ultimate Edition 4.8 & 4.9
#
#			Allow solo environments.  defaultde=kde will intiate
#			a solo environment based on KDE.
#
#			Added stats switch, will break down various specs and
#			data based on tmosb.
#
#			Enhanced bash-autocompletion to support ultimate edition
#			4.8 and 4.9
#
#			Added initilal skelatal support for DE's (fully detected at build):
#			"MATE" "CINNAMON" "KDE" "GNOME" "LXQT"
#
#			Added bash auto-completion to uecorebuilder
#
#			Bumped internal data to version 999 in ubiquity splashes
#			added a few beta testers to the installing splash
#			Added support for detection of default DE's in corebuilder
#
#			Repostormed pre-built "dumby" packages for anti-malware
#			inititive
#
#			Fixed software-center issue for hopefully the last time
#			in uecorebuilder.
#
#			Fixed issues in permissions, should not let you do much
#			without full root access.
#
#		1.9.6	Introduction of Ultimate Edition 5.0 & 5.1 (Xenial Xerus;
#			Ubuntu 16.04) based systems.
#
#			Moved caching system to a centralized folder (full root).
#
#			Adjusted core builder to be universal in building based on the core
#
#			Added img support to allow for building Android & PPC based images
#
#			Put XBMC / Kodi off the chain. You can now watch movies
#			currently playing at the theater.
#
#			Added ability to build in the "True root" environment.
#			See code; It will remain un-documented.
#
#			Added debootstrap help system, initiated Diagnose switch
#			added Diagnose help system.
#
#			Enhanced Chroot based "Modify" software.
#
#		1.9.7	Closed LTS (Long Term Supported) Gap.
#			Added "KeepCache" switch currently undocumented, case "inSenSitive" &
#			does not matter where you integrate it in the switch.
#
#			uecorebuilder - entirely re-built & shellchecked, 90% of errors gone.
#
#			Added support for 16.10 Yakkety Yak / Ultimate Edition 5.2 & 5.3
#		1.9.8	Added support for 17.04 Zesty Zapus / Ultimate Edition 5.4 & 5.5
#			Added support for Budgie desktop Environment
#		1.9.9	Added support for "Artful Aardvark" 17.10 / UE 5.6, 5.7
#		2.0.0	Added support for Enlightenment Desktop Environment.
#			many bug fixes.
#		2.0.1	Added support for Ubuntu 18.04 "Bionic Beaver" LTS
#		2.0.3	Added full server support (integrated server security)
#				Added server support for automatic detection & release if apache
#				server is detected.  Work smarter, not harder.
#				Added support for Pantheon Desktop Envioronnment.
#				Adjusted supression to reflect the above changes I made.
#				Server building is now starting based on your request. Open
#				testing has not began yet.
#				Added "Speedtest" option.
#				Added support for Ultimate Edition 6.0 / 6.1 (Cosmic Cuttlefish)
#				Removed support for 3.4 / 3.5 Precise Pangolin is no more (5 YR)
#				Fixed Usplashmaker for Kubuntu based releases not displaying properly.
#				Fixed Firefox version support / identification
#				Added support for Ultimate Edition 6.2 / 6.3 (Disco Dingo)
#				Added multiple server based fixes
#				Added additional apps and configuration for Networking support for server.
#				Added initial support for Ultimate Edition DEVELOPMENT.
#				Feature build bringing in software development switch.
#		2.0.4	Fixed mounting / unmounting foriegn archs
#		2.0.5	Added Ubuntu 19.10 Eoan Ermine / Ultimate Edition 6.4 / 6.5 to the mix.
#				Added Ubuntu 20.04 Focal Fossa / Ultimate Edition 6.6 / 6.7 to the mix.
#				Adjusted internal base files.
#				Adjusted Game building routine - attempting to fully populate a DVD.
#				Re-wrote Distribution detection scheme.
#				Added Types of Operating Systems.  Things are about to come off the chain.
#				Added Ubuntu to the mix, Debian, Mint?  I could go on.
#				Added initial support to build Debian based Operating Systems (Incomplete).
#				Integrated Repostorm support (Currently Devoked via Programmer)
#				Integrated UNO (Ultimate Network Optimizer) support
#				Worked on Automation, build over 4,000 Operating Systems back to back.
#				Worked on Caching system (accelerates the building process)
#				Fixed broken auto-completion (not 100% yet)
#				Integrated Ventoy tool to create bootable USB drive for ISO files.
#				Encapsulated all varibles {} to ensure spaces etc. are supported.
#		2.0.6	Stable release
#		2.0.7	Added initial support for "Jammy Jellyfish" / Ultimate Edition 7.4 & 7.5
#		2.0.8	Added initial support for Arch Based Operating Systems.
# ==============================================================================
#
#ADVANCED DEBUGGING
#set -e
# Notes provided via TheeMahn, below I will provide assitance beyond the call
# of duty in hopes of protecting your vital information etc.  This tool is not to
# be taken lightly at this stage in development.

# Building on an external drive, no permissions for exec and access to /dev will
# be granted without the following use as an example:

# Find out which filesystem the path in this example I am providing mine as
# /media/theemahn/9TBRaid0/
# The /rootfs resides in (might be a dedicated partition or an LVM),
# and, as root (or using sudo) remount it with exec and dev options.

# mount -o remount,exec,dev /media/theemahn/9TBRaid0/
#
# Here, /media/theemahn/9TBRaid0/ is an example that assumes a
# separated partition or dedicated logical volume. 3 X 3TB volumes in a raid 0 array (LVM)
#
# CONSTRUCTION
# ============
# You may or may not notice in virtually all different O/S's this tool will build varies
# in output, as this tool advances it will pay closer attention to a LTS release and
# less so to a short term release.  This is being done in deliberation and with strong
# reasoning as other tools I am developing enter the mix a greater understanding as why
# will finally shine through, please be patient.  This program has expanded greatly and
# is no where near done.  The entire Linux Kernel was 10,000 lines long when it was
# initially released this app is already greater then that all comments aside, and have
# actually consolidated a bunch of code. Lean and mean, does not have to be big and bad ;)

# Breaking outside the box
# ========================
# I find myself consistently and constantly thinking outside the box, inovation begins
# here.  When I started writing this software I immidiately began utilizing arrays in
# software development.  I want you to concentrate on the initial statement of LTS used
# above.  I did not hem myself into being stuck or caughtup in Ultimate Edition, Ubuntu,
# or Debian users out there the same & it does not stop there.  The tip of the iceburg
# when things start to come together unbiased, uninhibited choice for the end users.

# Preliminary goal is just UE builds, a few lines of code Ubuntu enters the mix, same
# with Debian, does not stop?  All deb based builds and we do have a large following there.
# Mint, I could go on...
# ==============================================================================
# Version Control
APPNAME="TheeMahn's O/S Builder"
PROGNAME="tmosb"
VERSION="2.1.5"
BUILDDATE="06/09/2025"
WEBSITE="os-builder.com"
AUTHOR="TheeMahn"
EMAIL="<$AUTHOR@${WEBSITE}>"

# Logging output - Currently un-implemented
# exec 1> /var/log/tmosb-session.log
# exec 1>> /var/log/tmosb-session.log 2>&1
LOG_FILE="/var/log/tmosb.log"
# exec 1 | tee ${LOG_FILE}
# exec 2 | tee ${LOG_FILE}

declare -i USPLASH
declare -i TOTALOS

if [[ -f "ultimate-common" ]]; then
	source ultimate-common
elif [[ -f "/usr/share/ultimate_edition/ultimate-common" ]]; then
	source /usr/share/ultimate_edition/ultimate-common
else
	echo "No Ultimate Edition common source. Please install ultimate-edition-common."
fi
THECOMMAND="$*"
TOTALOS=0
DATECURRENT=$(date +"%Y%m%d")
DEBUG=$(echo "$*" | grep -i "debug")
CORE=$(echo "$*" | grep -i "core")
ARRAY=0
SECURITY="no"
HACKING="no"
HACK="no"
SECURITY=$(echo "$*" | grep -i "security")
if [[ "${SECURITY}" == "" ]]; then
	SECURITY="no"
else
	SECURITY="yes"
fi
HACKING=$(echo "$*" | grep -i "hacking")
if [[ "${HACKING}" == "" ]]; then
	HACKING="no"
else
	HACKING="yes"
fi
HACK=$(echo "$*" | grep -i "hack")
if [[ "${HACK}" == "" ]]; then
	HACK="no"
else
	HACK="yes"
fi

for EACH in "$@"
do
	for ITEM in "${DISTOPTIONS[@]}"
	do
		#echo "$@: looking for ${ITEM}"
		if [[ "${EACH}" == "${ITEM}" ]]; then
			#echo "found ${ITEM} ${ARRAY}"
			#INSTALLDE[${ARRAY}]="true"
			DISTOPTION="${EACH}"
			#ARRAY=$((ARRAY + 1))
		fi
	done
done
if [[ "${DISTOPTION}" == "" ]]; then
	DISTOPTION="stable"
fi
#DES
for EACH in "$@"
do
	for ITEM in "${DES[@]}"
	do
		#echo "$@: looking for ${ITEM}"
		if [[ "${EACH}" == "${ITEM}" ]]; then
			#echo "found ${ITEM} ${ARRAY}"
			#INSTALLDE[${ARRAY}]="true"
			WANTEDDES+="${EACH}, "
			#ARRAY=$((ARRAY + 1))
		fi
	done
done
WANTEDDES="${WANTEDDES::-2}"

# Declare Integer for root user detection - Set as initial normal user.
declare -i TRUEROOT
TRUEROOT=1000 #Set as 1000 initially, try and cause root access to fail.
#IHOME="/home/${IUSER}"
TRUEROOT="$(id -u)"
#echo "$@"
# human language intereptation.
Looking () {
	CheckRoot "$@"
	ISMOUNTED=$(mount | grep "${PWD}" | cut -d " " -f3)
	if [[ "${ISMOUNTED}" ]]; then
		sudo umount -a "${ISMOUNTED}" 2>/dev/null
	fi
	for EACH in "$@"
	do
		for ITEM in "${OSTYPES[@]}"
		do
			#echo "$@: looking for ${ITEM}"
			if [[ "${EACH}" == "${ITEM}" ]]; then
				#echo "found ${ITEM} ${ARRAY}"
				OSTYPE="${EACH}"
			fi
		done
	done

	Encapsulate "Sure, is this what you want?"
	if [[ "${ISARCH}" ]] ; then
		Encapsulate "Distro Base: Ultimate Edition Arch"
	else
		Encapsulate "Distro Base: Debootstapped Ultimate Debian / Ubuntu"
	fi
	ARRAY=0
	DRIVERS="No"
	COMPRESSION="Normal"
	SUBARRAY=0
	declare -a COMPRESSIONTYPES=( 'max' 'fast' 'normal' );
	declare -a COMPRESSOPTION=( "" "" "" "-9" "-1" "" "-9" "-1" "" "-9" "-0" "" "-9" "-1" "" "-9" "-1" "" "-9" "-1" "" "--ultra -22" "--fast=1" "" );
	declare -a COMPRESSDESCRIPTION=( "None" "Gunzip" "Bzip2" "Lempel-Ziv-Markov chain algorithm" "lossless data compression format" "data compression method that prioritizes extremely fast decompression speed over achieving the highest compression ratio" "Lossless data compression algorithm that prioritizes extremely fast compression and decompression speeds" "Zstandard FaceBook Compression fast lossless compression algorithm" );
	declare -a COMPRESSIONTYPE=( "cat" "gzip" "bzip2" "lzma" "xz" "lzop" "lz4" "zstd" );

	#COMPRESSIONTYPE="zstd"
	for EACH in "${COMPRESSIONTYPE[@]}"
	do
		GREPIT=$(echo "$*" | grep -i "${EACH}")
		if [[ "${GREPIT}" ]]; then
			COMPRESSDESC="${COMPRESSDESCRIPTION[${ARRAY}]}"
			CPRESS="${EACH}"
		fi
		ARRAY=$((ARRAY + 1))
	done
	ARRAY=0
	DEFAULTDE=$(echo "$*" | grep -i 'defaultde=' | sed 's/^.*defaultde=//g' | cut -d' ' -f1)
	for EACH in "${DES[@]}"
	do
		GREPIT=$(echo "${WANTEDDES}" | grep -i "${EACH}")
		if [[ "${GREPIT}" ]]; then
			#Encapsulate "Injectable found: ${EACH}."
			if [[ "${EACH^}" == "Drivers" ]]; then
				DRIVERS="Yes"
			fi
			INSTALLDE[${ARRAY}]="true"
			if ! [[ "${DEFAULTDE}" ]]; then
				DEFAULTDE="${EACH}"
				XSESSION="${SESSION[${ARRAY}]}"
			fi
		#else
			#Encapsulate "Injectable not found: ${EACH}."
		fi
		ARRAY=$((ARRAY + 1))
	done
	if [[ "${DEFAULTDE}" == "" ]]; then
		DEFAULTDE="None"
		WANTEDDES="None"
	fi
	if [[ "${CPRESS}" == "" ]]; then
		CPRESS="zstd"
		COMPRESSDESC="Zstandard FaceBook Compression fast lossless compression algorithm"
	fi
	ARRAY=0
	SUBARRAY=0
	for EACH in "${COMPRESSIONTYPE[@]}"
	do
		ARRAY=$((ARRAY + 1))
		GREPIT=$(echo "${EACH}" | grep -i "${CPRESS}")
		if [[ "${GREPIT}" ]]; then
			for EACHCASE in "${COMPRESSIONTYPES[@]}"
			do
				SUBARRAY=$((SUBARRAY + 1))
				SUBGREPIT=$(echo "$*" | grep -i "${EACHCASE}")
				if [[ "${SUBGREPIT}" ]]; then
					COMPRESSION="${EACHCASE^}"
					SELECTION=$((ARRAY * 3 - SUBARRAY - 2 ))
					#Encapsulate "SELECTION=${SELECTION} | ${ARRAY} | ${SUBARRAY}"
					COMPRESSIONOPT="${COMPRESSOPTION[${SELECTION}]}"
				fi
			done
		fi
	done

	Encapsulate "Operating System Type: ${OSTYPE^}"
	Encapsulate "Desktop Environment(s) ${WANTEDDES^}"
	Encapsulate "Default Desktop Environment: ${DEFAULTDE^}"
	Encapsulate "Stability: ${DISTOPTION^}"
	Encapsulate "Upgrade Security: ${SECURITY^}"
	Encapsulate "Hacking tools: ${HACK^} | ${HACKING^}"
	Encapsulate "Drivers: ${DRIVERS}"
	Encapsulate "Compression Type: ${CPRESS^} (${COMPRESSDESC^})"
	Encapsulate "Compression Options: ${COMPRESSION^} (${COMPRESSIONOPT})"
	if ! [[ "${PROMPTSUPPRESSION}" ]]; then
		PromptYN "Everything look correct? (Y/N) "
			case "${YN}" in
				[Nn]* ) echo -e "${TXTRST}"; exit 0;;
				[Yy]* ) echo -e "${TXTGRN}";
				FullBar;
				Center "Begining build of Ultimate Arch ${OSTYPE^} ...";;
				* ) echo "Please answer y or n.";;
			esac
	fi
	BUILDFOLDER="${OSTYPE}"
	if [[ -d "ultimate-arch-${BUILDFOLDER}" ]]; then
		Encapsulate "Scraping: ultimate-arch-${BUILDFOLDER}"
		sudo rm -R "ultimate-arch-${BUILDFOLDER}"
	fi
	if [[ -d "build" ]]; then
		Encapsulate "Scraping: build"
		sudo rm -R "build"
	fi
}

if [[ "${ISARCH}" ]]; then
	CONTAINS=$(echo "$@" | grep -w 'build')
	if [[ "${CONTAINS}" ]]; then
		VersionDump "@"
		Encapsulate "Build mode detected."
		Looking "$@"
#echo "ultimate-arch-${BUILDFOLDER}."
		if [[ -d "ultimate-arch-${BUILDFOLDER}" ]]; then
			FOLDER="ultimate-arch-${BUILDFOLDER}"
		else
			FOLDER="ultimate-arch-${BUILDFOLDER}"
			if [[ -d "/usr/share/ultimate_edition/arch/${BUILDFOLDER}" ]]; then
				Encapsulate "Pulling build folder: /usr/share/ultimate_edition/arch/${BUILDFOLDER}. OSTYPE: ${OSTYPE}"
				mkdir -p "${FOLDER}"
				cp -R /usr/share/ultimate_edition/arch/template/* "${FOLDER}"
				cp -R /usr/share/ultimate_edition/arch/${OSTYPE}/* "${FOLDER}/"
				sync
				if [[ "${DISTOPTION^}" == "Stable" ]]; then
					Encapsulate "Injecting Stable sources."
					cp -R /usr/share/ultimate_edition/arch/stable/* "${FOLDER}/airootfs/etc"
					cp -R /usr/share/ultimate_edition/arch/stable/* "${FOLDER}"
				else
					Encapsulate "Cutting Edge sources have been injected."
				fi
				BACKGROUND="Ultimate_Edition_Arch.png"
				declare -a TYPES=( '#BACKGROUND' '#SESSION' "#DISTTYPEUPPER" "#DISTTYPELOWER" "#BUILDDATE" "#COMMAND" "#COMPRESSIONOPTION" "#COMPESSIONTYPE" );
				declare -a REPLACEMENT=( "${BACKGROUND}" "${XSESSION}" "${OSTYPE^}" "${OSTYPE}" "${DATECURRENT}" "sudo tmosb ${THECOMMAND}" "${COMPRESSIONOPT}" "${CPRESS}");
				declare -a FILETOPROCESS=();
				Center "Pushing core to replicate settings for ${OSTYPE^}"
				ARRAY=0
				for ITEM in "${TYPES[@]}"
				do
					SAVEIFS=$IFS
					IFS=$'\n'
					#shopt -s nullglob
					#shopt -s dotglob
					FILETOPROCESS=$(grep -Rnw "ultimate-arch-${OSTYPE}" -e "${ITEM}" | cut -d ":" -f1)
					FOUND="${#FILETOPROCESS}"
					Encapsulate "FOUND: ${FOUND} REFERENCES. for ${ITEM}"
					IFS=$SAVEIFS
					FILETOPROCESS=(${FILETOPROCESS})
					for EACH in "${FILETOPROCESS[@]}"
					do
						REPLACE="${REPLACEMENT[${ARRAY}]}"
						Encapsulate "Processing ${EACH} setting it to: ${REPLACE}"
						if [[ "${DEBUG}" ]]; then
							Encapsulate "${EACH} contains a reference to ${ITEM}"
							Encapsulate "Item:${ITEM} Replacement:${REPLACE} File:${EACH} in ${PWD}"
						fi
						#sed -i "s/${ITEM}/${REPLACE}/g" "${EACH}"
						SUPRESS=$(sed -i "s/${ITEM}/${REPLACE}/g" "${EACH}" 2>/dev/null)
					done
					ARRAY=$((ARRAY + 1))
				done
			else
				Encapsulate "Build folder. not found: ${FOLDER}"
			fi
		fi
		# Environment?
		if [[ -d "/usr/share/ultimate_edition/arch/DES/env/${XSESSION}" ]]; then
			Encapsulate "Pulling environmental build folder: /usr/share/ultimate_edition/arch/DES/env/${XSESSION}."
			Encapsulate "Pushing environment to: ${FOLDER}/airootfs/"
			mkdir -p "${FOLDER}/airootfs/"
			cp -R /usr/share/ultimate_edition/arch/DES/env/${XSESSION}/* "${FOLDER}/airootfs" 2>/dev/null
			cp -R /usr/share/ultimate_edition/arch/DES/env/${XSESSION}/. "${FOLDER}/airootfs" 2>/dev/null
			sync
		else
			Encapsulate "Environment build folder not found: /usr/share/ultimate_edition/arch/DES/env/${XSESSION}."
		fi
		# Security?
		if [[ "${SECURITY}" != "no" ]]; then
			if [[ -d "/usr/share/ultimate_edition/arch/DES/env/security" ]]; then
				Encapsulate "Injecting extra security."
				Encapsulate "Pulling environmental build folder: /usr/share/ultimate_edition/arch/DES/env/security."
				Encapsulate "Pushing environment to: ${FOLDER}/airootfs/"
				mkdir -p "${FOLDER}/airootfs/etc/pacman.conf.d/hooks"
				cp -R /usr/share/ultimate_edition/arch/DES/env/security/* "${FOLDER}/airootfs/"
				if [[ -f "/usr/share/ultimate_edition/arch/DES/security" ]]; then
					Encapsulate "Adding Security apps."
					cat "/usr/share/ultimate_edition/arch/DES/security" >> "${FOLDER}/packages.x86_64"
				fi
				sync
			fi
		else
			Encapsulate "Default security will be used."
		fi
		# HACKING O/S?
		#if [[ "${HACKING}" != "no" ]]; then
		#	if [[ -d "/usr/share/ultimate_edition/arch/DES/env/hacking" ]]; then
		#		Encapsulate "Injecting Hacking tools."
		#		Encapsulate "Pulling environmental build folder: /usr/share/ultimate_edition/arch/DES/env/hacking."
		#		Encapsulate "Pushing environment to: ${FOLDER}/airootfs/"
		#		mkdir -p "${FOLDER}/airootfs/etc/pacman.conf.d/hooks"
		#		cp -R /usr/share/ultimate_edition/arch/DES/env/hacking/* "${FOLDER}/airootfs/"
		#		if [[ -f "/usr/share/ultimate_edition/arch/DES/hacking" ]]; then
		#			Encapsulate "Adding Hacking Tools."
		#			cat "/usr/share/ultimate_edition/arch/DES/hacking" >> "${FOLDER}/packages.x86_64"
		#		fi
		#		sync
		#	fi
		#else
		#	Encapsulate "No Hacking tools will be installed."
		#fi

		# HACK TOOLS?
		if [[ "${HACK}" != "no" ]]; then
			if [[ -d "/usr/share/ultimate_edition/arch/DES/env/hacking" ]]; then
				Encapsulate "Injecting Hacking tools."
				Encapsulate "Pulling environmental build folder: /usr/share/ultimate_edition/arch/DES/env/hacking."
				Encapsulate "Pushing environment to: ${FOLDER}/airootfs/"
				mkdir -p "${FOLDER}/airootfs/etc/pacman.conf.d/hooks"
				cp -R /usr/share/ultimate_edition/arch/DES/env/hacking/* "${FOLDER}/airootfs/"
				if [[ -f "/usr/share/ultimate_edition/arch/DES/hacking" ]]; then
					Encapsulate "Adding Hacking Tools."
					cat "/usr/share/ultimate_edition/arch/DES/hacking" >> "${FOLDER}/packages.x86_64"
				fi
				sync
			fi
		else
			Encapsulate "No Hacking tools will be installed."
		fi
		# Extra Apps?
		for EACH in "${EXTRAS[@]}"
		do
		GREPIT=$(echo "$*" | grep -i "${EACH}")
		if [[ "${GREPIT}" ]]; then
			if [[ -f "/usr/share/ultimate_edition/arch/DES/${EACH}" ]]; then
				Encapsulate "Injecting ${EACH}."
				cat "/usr/share/ultimate_edition/arch/DES/${EACH}" >> "${FOLDER}/packages.x86_64"
			fi
		fi
		done
		if [[ "${OSTYPE^}" == "Minimal" ]]; then
			if [[ -d "ultimate-arch-${OSTYPE}/airootfs/etc/skel/" ]]; then
				Encapsulate "Striping the Skelaton this is a Minimal O/S."
				rm -R "ultimate-arch-${OSTYPE}/airootfs/etc/skel/"
			else
				Encapsulate "Skelatal system not found."
			fi
		else
			if [[ -f "${FOLDER}/packages.x86_64" ]]; then
				ARRAY=0
				for EACH in "${DES[@]}"
				do
					if [[ ${INSTALLDE[${ARRAY}]} == "true" ]]; then
						GREPIT=$(grep -i "${GINFO[${ARRAY}]}" "${FOLDER}/packages.x86_64")
						if ! [[ "${GREPIT}" ]]; then
							Encapsulate "Injecting ${GINFO[${ARRAY}]} support."
							cat "/usr/share/ultimate_edition/arch/DES/${DES[${ARRAY}]}" >> "${FOLDER}/packages.x86_64"
						else
							Encapsulate "${GINFO[${ARRAY}]} support is already injected."
						fi
					fi
					#echo "${EACH}: ${INSTALLDE[$ARRAY]}"
					ARRAY=$((ARRAY + 1))
				done
			fi
		fi
		if ! [[ "${OSTYPE^}" == "Minimal" ]]; then
			GREPIT=$(grep -i "ultimate-calamares-config-${OSTYPE}" "${FOLDER}/packages.x86_64")
			if ! [[ "${GREPIT}" ]]; then
				Encapsulate "Injecting installer support."
				cat "/usr/share/ultimate_edition/arch/DES/installer" >> "${FOLDER}/packages.x86_64"
				Encapsulate "Injecting Calamares config installer support."
				echo "ultimate-calamares-config-${OSTYPE}" >> "${FOLDER}/packages.x86_64"
			else
				Encapsulate "Installer support already injected."
			fi
		else
			Encapsulate "Minimal O/S not injecting Calamares installer support."
		fi
		if [[ -d "${FOLDER}" ]]; then
			if [[ -d "/tmp/archiso-tmp" ]]; then
				rm -R "/tmp/archiso-tmp"
			fi
			CONTAINS=$(echo "$@" | grep -w 'memory')
			if ! [[ "${CONTAINS}" ]]; then
				tmosb-arch -v -w build ${FOLDER} ${WANTEDDES}
				exit 0;
			else
				Encapsulate "Building ${FOLDER} in memory."
				tmosb-arch -v -w /tmp/archiso-tmp ${FOLDER} ${WANTEDDES}
				exit 0;
			fi
		else
			Error "Please specify a build type."
			exit 0;
		fi
	fi
fi
if [[ "${ISARCH}" ]]; then
	Timer "Stop" "${APPNAME}"
fi
#if [[ "${ISARCH}" ]]; then
#	CONTAINS=$(echo "$@" | grep -w 'test')
#	if [[ "${CONTAINS}" ]]; then
#		VersionDump "@"
#		Encapsulate "Test mode detected. $*"
#		for EACH in "$@"
#		do
#			if [[ -f "${2}" ]]; then
#				ISO="${EACH}"
#			fi
#		done
#		if [[ "${ISO}" ]]; then
#			if [[ "${3}" ]]; then
#				run_archiso "${3}" -i "${ISO}"
#				exit 0;
#			else
#				run_archiso -u -i "${ISO}"
#				exit 0;
#			fi
#		else
#			Error "Please specify an ISO."
#			exit 0;
#		fi
#	fi
#fi
# Providing a switch to override, starting X from a sudo command for example.
# No documentation will be provided using this switch, let alone support ;)
if [[ ${XDISPLAY} != x ]] ; then
	echo "GUI Enabled"
	echo "USER: ${USER} | TRUEROOT:${TRUEROOT}"
	if [[ "${TRUEROOT}" != "0" ]]; then
		if [[ -f "/usr/share/tmosb/tmosb.py" ]]; then
			/usr/share/tmosb/tmosb.py
		fi
	fi
else
	echo "GUI Disabled"
fi

USETHEFORCE=$(echo "$*" | grep -i "usetheforce")
if [[ "${USETHEFORCE}" ]]; then
	USETHEFORCE="LUKE"
	echo "USE THE FORCE DETECTED: WElCOME ABOARD, ${USETHEFORCE}."
fi

# Declare integer for whether a drive is detachable.
#declare -i DETACHABLE

# Multiple OS builds?
declare -i NUMBERTOBUILD
STAGE="${PWD}"

# Quoting...
SINGLE="'"
#QUOTE='"'

# Not required, but optional. No prompting for testing etc. if false.
QEMUINSTALLED=$(type -p kvm)
PROMPT=$(echo "$*" | grep -i "yes")
BUILDALL=$(echo "$*" | grep -i "buildall")

# set colors so errors etc. stand out.
txtred=$(tput setaf 1)
txtgrn=$(tput setaf 2)
bldblu=$(tput setaf 4)
#txtwht=$(tput setaf 7)
BRIGHT=$(tput bold)
#BOLD=$(tput smso)
txtrst='\e[0m'	# Text Reset

# Get Directory executed in.
CURRENT="${PWD}"

# Set some internal variables and arrays
OS='ultimate-edition'
COS="Ultimate_Edition"
UOS="Ultimate Edition"

#CACHINGFOLDERTEMP="/root/${PROGNAME}/.cache/tmp"
CACHETEST=$(echo "$@" | grep -i "cache=")
COMPRESSION=$(echo "$@" | grep -i "compression=")
RECOMMENDED=$(echo "$@" | grep -i "recommended=")
REQUESTKERNEL=$(echo "$@" | grep -i "kernel=")
REPOSTORMDEFAULT=$(echo "$*" | grep -i "repostorm")
ROOTFOLDER="http://os-builder.com/UETOYS"
UEREPOSITORIES="ultimate-edition-repositories-0.2.5-apt-source_all.deb"
UEKEYSNATCHER="ultimate-edition-keysnatcher-1.1.4_all.deb"

if [[ "${RECOMMENDED}" ]]; then
	RECOMMENDED=$(echo "$@" | grep -i "recommended=" | sed "s/^.*recommended=//g" | cut -d" " -f1)
else
	# Set default recommended option as yes null if not specified. << - we can expand here ;)
	RECOMMENDED="YES"
fi
if [[ "${REQUESTKERNEL}" ]]; then
	REQUESTKERNEL=$(echo "$@" | grep -i "kernel=" | sed "s/^.*kernel=//g" | cut -d" " -f1)
fi
DEBUG=$(echo "$*" | grep -i "debug")

if [[ "${COMPRESSION}" ]]; then
	COMPRESSION=$(echo "$@" | grep -i "compression=" | sed "s/^.*compression=//g" | cut -d" " -f1)
else
	# Set default compression option as Fast null if not specified. << - we can expand here ;)
	COMPRESSION=""
fi

if [[ "$CACHETEST" ]]; then
	CACHEOPTION=$(echo "$@" | grep -i "cache=" | sed "s/^.*cache=//g" | cut -d" " -f1)
else
	# Set default caching option as Fast if not specified.
	CACHEOPTION="FAST"
fi
if [[ "${DEBUG}" ]]; then
	echo "DEBUG: Cacheoption set as ${CACHEOPTION} | Compression: ${COMPRESSION} | Recommended: ${RECOMMENDED} | REQUESTKERNEL: ${REQUESTKERNEL}"
fi

# A future implementation
# For now set Ubuntu as base of distribution, we will eventually allow the end user to choose.
#DISTBASE="Ubuntu"



LIQUORIX=$(echo "$*" | grep -i 'LIQUORIX')
# Android support - PowerPC the same?  Will have to buy one and see.
#ISOTYPE=$(echo "$*" | grep -i "img")
#if [[ "${ISO}TYPE" ]]; then
#	ANDROID=true
#else
#	ANDROID=false
#fi

# Check if is an ISO
#ISOTYPE=$(echo "$*" | grep -i "iso")
#if [[ "${ISO}TYPE" ]]; then
#	ISANISO=true
#else
#	ISANISO=false
#fi


# Pulls stored cache if any, from the chroot environment to the .cache/ folder.
PullCache () {
	if [[ "${DEBUG}" ]]; then
		echo "DEBUGGING: we are in ${PWD} in function PullCache."
	fi
	if [[ "${CACHEOPTION}" == "none" ]]; then
		Encapsulate "Cacheoption specified as none, not doing any cacheing."
		return 0;
	fi
	BASEPULL="${1}"
	ARCH="${2}"
	if ! [[ "${BASEPULL}" && "${ARCH}" ]]; then
		Error "CRITICAL ERROR Pull Cache: Invalid caching switches provided. BASE: ${1} ARCH:${2}"
		exit 1;
	fi
	CACHESIZE=$(du -hs "edit/var/cache/apt/archives/" | awk '{print $1}')
	if [[ "${CACHESIZE}" == "4.0K" ]]; then
		CACHESIZE=""
	fi
	if [[ -d "${CACHINGFOLDER}/${BASEPULL}/${ARCH}/apt/" ]]; then
		if [[ "${CACHESIZE}" ]]; then
			Encapsulate "Pulling ${CACHESIZE} of cache for ${BASEPULL} ${ARCH} build. Please wait..."
			SUCCESS=$(cp "edit/var/cache/apt/archives/*.deb" "${CACHINGFOLDER}/${BASEPULL}/${ARCH}/apt/" 2>/dev/null)
		fi
		if ! [[ "${SUCCESS}" ]]; then
			Encapsulate "Success"
			Encapsulate "Clearing Cache from build."
			SUCCESS=$(rm "edit/var/cache/apt/archives/*.deb" 2>/dev/null)
		else
			Encapsulate "Failure."
		fi
	else
		Encapsulate "No cache folder, first ${BASEPULL} ${ARCH} based O/S build?"
		mkdir -p "${CACHINGFOLDER}/${BASEPULL}/${ARCH}/apt/"
	fi
		#TMP CACHE

	CACHESIZE=""
	if [[ -d "edit/tmp/" ]]; then
		CACHESIZE=$(du -hs "edit/tmp/" | awk '{print $1}' 2>/dev/null)
	fi
	if [[ "${CACHESIZE}" == "4.0K" ]]; then
		CACHESIZE=""
	fi
	CURRENTFOLDER="${PWD}"
	if [[ "${CACHESIZE}" ]]; then
		if [[ -d "${CACHINGFOLDERTEMP}" ]]; then
			Encapsulate "Initiating Temp cache sync operation of ${CACHESIZE} in ${PWD}. Please wait"
			if [[ -d "edit/tmp/" ]]; then
				cd "edit/tmp/" || exit 1;
				shopt -s dotglob
				shopt -s nullglob
				array=(*/)
				for dir in "${array[@]}"; do Encapsulate "Removing temp dir: $dir"; rm -R "$dir" 2>/dev/null; done
				shopt -s extglob
				#SUCCESS=$(cp !(*-core-files.deb) "${CACHINGFOLDERTEMP}/" 2>/dev/null)
				if ! [[ "${SUCCESS}" ]]; then
					SUPPRESS=$(rm -R "*" 2>/dev/null)
					Encapsulate "Success"
				else
					Encapsulate "Failure"
				fi
				shopt -u extglob
				shopt -u dotglob
				shopt -u nullglob
				cd "${CURRENTFOLDER}" || exit 1;
			fi

			if ! [[ "${SUCCESS}" ]]; then
				SUPPRESS=$(rm -R "edit/tmp/*" 2>/dev/null)
				Encapsulate "Success"
			else
				Encapsulate "Failure"
			fi
		else
			Encapsulate "No Temp cache folder, first build?"
			mkdir -p "${CACHINGFOLDERTEMP}"
		fi
	else
		Encapsulate "No Temp cache folder, first build?"
		mkdir -p "${CACHINGFOLDERTEMP}"
	fi
	sync
}

finish () {
	if [[ "${DEBUG}" ]]; then
		echo "EUID: ${EUID} | USER: ${USER} | IUSER: ${IUSER} | ROOT: ${TRUEROOT} EXIT CODE: $?"
	fi
	if ! [[ "${ISARCH}" ]]; then
		if [[ "${CODEBASE}" ]]; then
			if [[ -d "${CHROOTFOLDER}" ]]; then
				cd "${CHROOTFOLDER}" || exit 1;
			fi
			Encapsulate "Rsyncing cache for ${CODEBASE} in ${PWD}. This could take a long time the first time it is ran, please wait..."
			PullCache "${CODEBASE}" "${ARCH}"
		fi
		if ! [[ "${EUID}" -ne 0 ]]; then
			Encapsulate "Cleaning packages."
			FullBar
			apt-get clean
			apt-get autoclean
			FullBar
		else
			FullBar
		fi
	fi
}

# trap ctrl-c and call ctrl_c()
ctrl_c () {
		Encapsulate "** Trapped CTRL-C, exiting."
		FullBar
		exit 1;
}

trap ctrl_c INT
trap finish EXIT

NamingConvention () {
	NEWISONAME=$(basename "${PWD}")
	if [[ "${DEBUG}" ]]; then
		echo "DEBUG: ISO CURRENT entering function NamingConvention:${ISO} in ${PWD}"
	fi
	if ! [[ "${STAGE}" == "${PWD}" ]]; then
		if [[ "${DEBUG}" ]]; then
			echo "DEBUG: Processing ISO in ${PWD} to ${NEWISONAME}"
		fi
	fi
	NEWISONAME+=".iso"
	if ! [[ "${ISO}" == "${NEWISONAME}" ]]; then
		Encapsulate "Changing ISONAME from: ${ISO} to ${NEWISONAME}"
		ISO="${NEWISONAME}"
	fi
}

GridOS () {
	VersionDump
	TDUMP=0
	GREPIT=$(echo "$*" | grep -i 'env')
	if [[ "${GREPIT}" ]]; then
		GColumnize -t "VERSION" "OPERATING_SYSTEM" "DISTROBASE" "ARCH" "ENVIRONMENTS"
		TDUMP=1
	fi
	GREPIT=$(echo "$*" | grep -i 'type')
	if [[ $GREPIT ]]; then
		GColumnize -t "VERSION" "OPERATING_SYSTEM" "DISTROBASE" "ARCH" "TYPES"
		TDUMP=1
	fi
	GREPIT=$(echo "$*" | grep -i 'default')
	if [[ "${GREPIT}" ]]; then
		#TODO: Make it work - Simple as that.
		GColumnize -t "VERSION" "OPERATING_SYSTEM" "DISTROBASE" "ARCH" "DEFAULTDE"
		TDUMP=1
	fi
	if [[ "$TDUMP" == 0 ]]; then
		Help grid 1
	fi
	Center "Operating System Grid View"
	COUNTER=0
	OSTYPE='Ultimate_Edition'
	for EACH in "${UEARRAY[@]}"
	do
		DATATOPROCESS=""
		if [[ "${EACH}" == "12.10" ]]; then
			OSTYPE="Ubuntu_Desktop"
		fi
		if [[ "${EACH}" == "1" ]]; then
			OSTYPE="Debian"
		fi
		DTYPE="${DISTARRAY[$COUNTER]// /_}"
		#DTYPE=$(echo "${DISTARRAY[$COUNTER]}" | sed 's/ /_/g')
		GREPIT=$(echo "$*" | grep -i 'env')
		TCOUNTER=0
		if [[ "${GREPIT}" ]]; then
			for ENVS in "${EXTRADE[@]}"
			do
				ITEMS="${#EXTRADE[@]}"
				TCOUNTER=$((TCOUNTER + 1))
				if [[ "$TCOUNTER" -lt "${ITEMS}" ]]; then
					DATATOPROCESS+="${ENVS^}, "
				else
					DATATOPROCESS+="${ENVS^}"
				fi
			done
		fi
		TCOUNTER=0
		GREPIT=$(echo "$*" | grep -i "type")
		if [[ "${GREPIT}" ]]; then
			DATATOPROCESS='Standard, '
			for TYPES in "${UETYPES[@]}"
			do
				ITEMS="${#UETYPES[@]}"
				TCOUNTER=$((TCOUNTER + 1))
				if [[ "$TCOUNTER" -lt "${ITEMS}" ]]; then
					DATATOPROCESS=${DATATOPROCESS}"${TYPES^}, "
				else
					DATATOPROCESS=${DATATOPROCESS}"${TYPES^}"
				fi
			done
		fi
		case "$TDUMP" in
			0)	GColumnize "${EACH}" "${OSTYPE}" "${DTYPE}" "ALL";;
			1)	GColumnize "${EACH}" "${OSTYPE}" "${DTYPE}" "ALL" "${DATATOPROCESS}";;
		esac
		COUNTER=$((COUNTER + 1))
	done
	FullBar
}

FinalCheck () {
	shopt -s nullglob
	declare -a LASTCHECK=();
	#LASTCHECK=$(mount | grep "none" | sort -r | grep "${PWD}" | cut -d " " -f3)
	OIFS=$IFS
	IFS=$'\n'
	LASTCHECK=($(mount | grep "none" | sort -r | grep "${PWD}" | cut -d " " -f3))
	IFS=$OIFS
	if [[ "${LASTCHECK[@]}" ]]; then
		Encapsulate "We have hooks in ${PWD}:"
		Encapsulate "We are going to forefully unhook them & re-sync."
		for EACH in "${LASTCHECK[@]}"
		do
			Encapsulate "UNMOUNING: ${EACH}"
			umount "${EACH}"
			sync
		done
		#echo "Bailing..."
		#exit 1;
	else
		Encapsulate "No hooks in the O/S."
	fi
}

# Begin enhanced caching system
CACHINGFOLDER="/root/${PROGNAME}/.cache"
CACHINGFOLDERTEMP="/root/${PROGNAME}/.cache/tmp"

# Last second check... of caching structure.
# Create basic caching Structure
if [[ "${IUSER}" != "root" && "${TRUEROOT}" != "0" ]]; then
	if [[ -w "${CACHINGFOLDERTEMP}" ]]; then
			mkdir -p "${CACHINGFOLDERTEMP}"
		else
			if ! [[ "${SUPPRESS}" ]]; then
				Error "Permission denied writing ${CACHINGFOLDERTEMP}."
			fi
		fi
	if [[ "${DIST}" ]]; then
		if [[ -w "${CACHINGFOLDERTEMP}/${DIST}/" ]]; then
			mkdir -p "${CACHINGFOLDERTEMP}/${DIST}/"
		else
			if ! [[ "${SUPPRESS}" ]]; then
				Error "Permission denied writing ${CACHINGFOLDERTEMP}/${DIST}/"
			fi
		fi
	fi
	if [[ -d "${CACHINGFOLDERTEMP}" ]]; then
		Encapsulate "Caching folder exists."
	else
		if ! [[ "${SUPPRESS}" ]]; then
			Error "No caching folder exists. We will not process cache."
		fi
	fi
else
	if [[ "${USETHEFORCE}" ]]; then
		ENCAPSULATE "Doing as you requested ${IUSER}, err Luke.  Using the force."
		CACHINGFOLDER="/root/${PROGNAME}/.cache/"
		CACHINGFOLDERTEMP="/root/${PROGNAME}/.cache/tmp/"
		if [[ -w "${CACHINGFOLDERTEMP}" ]]; then
			mkdir -p "${CACHINGFOLDERTEMP}"
		else
			if ! [[ "${SUPPRESS}" ]]; then
				Error "Permission denied writing ${CACHINGFOLDERTEMP}."
			fi
		fi
		if [[ "${DIST}" ]]; then
			if [[ -w "${CACHINGFOLDERTEMP}/${DIST}/" ]]; then
				mkdir -p "${CACHINGFOLDERTEMP}/${DIST}/"
			else
				if ! [[ "${SUPPRESS}" ]]; then
					Error "Permission denied writing ${CACHINGFOLDERTEMP}/${DIST}/"
				fi
			fi
		fi
		if [[ -d "${CACHINGFOLDERTEMP}" ]]; then
			Encapsulate "Caching folder exists."
		else
			if ! [[ "${SUPPRESS}" ]]; then
				Error "No caching folder exists. We will not process cache."
			fi
		fi
	fi
fi

# Virtual machine testing function.
Virtual () {
	# Amazes me the extra code you have to write for sheeple.
	ARRAYCOUNTER=0
	for EACH in "$@";
	do
		GREPIT=$(echo "${EACH}" | grep -i '.iso')
		if [[ "${GREPIT}" ]]; then
			FOLDER="${2%.*}"
			if [[ -d "${FOLDER}" ]]; then
				ISO="${EACH}"
			else
				if [[ -f "${EACH}" ]]; then
					ISO="${EACH}"
				fi
			fi
		fi
		if [[ -d "${EACH}" ]]; then
			FOLDER="${EACH}"
		fi
		ARRAYCOUNTER=$((ARRAYCOUNTER + 1))
	done
	if [[ "${ISO}" || "${FOLDER}" ]]; then
		TOPROCESS="${ISO}"
		if [[ "${DEBUG}" ]] ; then
			if [[ "${ISO}" ]]; then
				Encapsulate "DEBUG: ISO set and found as ${ISO}"
			fi
			if [[ -d "${FOLDER}" ]]; then
				Encapsulate "DEBUG: ISO set and found as ${ISO}"
			fi
		fi
	else
		Error "MASSIVE FAILURE: ISO NOR FOLDER found."
	fi

	if ! [[ "${ISO}" || "${FOLDER}" ]]; then
		Encapsulate "Critical error: ISO or image requested does not exist, exiting."
		exit 1;
	fi

	if ! [[ "${TOPROCESS}" ]]; then
		Error "Critical Error: invalid switch passed.  Exiting."
		exit 1;
	fi

	#echo -e "${bldylw}DEBUGGING PASSED VARS: 1:${1} 2:${2} 3:${3}${TXTRST} PROCESS: $TOPROCESS"
	if ! [[ "${DISPLAY}" ]]; then
		Center "No X11 session detected.  Exiting."
		exit 1;
	fi

	# Declare a few integer variables
	declare -i MEMORY
	declare -i DEDICATED
	TEMPO=$(grep -i "MEMTOTAL" "/proc/meminfo" | cut -d ':' -f2 | sed 's/ kB//g')
	MEMORY="${TEMPO}"
	# See if end user has 3GB or greater memory
	if [[ "${MEMORY}" -ge 32000 ]]; then
		# If so set maximum the virtual machine can have.
		DEDICATED="32000"
	else
		# Limited resources. Use a quarter the end users memory.
		MAINS=$(echo "scale=2; ${MEMORY}/1000*.25" | bc)
		# dump the decimal, we want a raw integer.
		DEDICATED="${MAINS%.*}"
	fi
	if [[ "${DEDICATED}" -gt 32000 ]]; then
		DEDICATED="32000"
	fi
	# Snatch the number of CPU Core(s) the end user has.
	CORES=$(grep -i "processor" "/proc/cpuinfo" | sed '/model/d' | wc -l)

	# Dump data to the end user.
	Encapsulate "${MEMORY} memory and ${CORES} CPU core(s) detected."
	#DEDICATED="${MEMORY}"
	Encapsulate "Utilizing ${DEDICATED} bytes of memory and ${CORES} CPU Core(s) to full potential."

	# Check for existence of ISO, if so launch VM, enable kvm acceleration.
	DEVICE=$(echo "${TOPROCESS}" | grep "/dev")
	ISISO=$(echo "${TOPROCESS}" | grep ".iso")
	#echo -e "${bldylw}DEBUGGING (this will be removed prior to final release):\n"

	if [[ "${DEVICE}" ]]; then
		Encapsulate "DEVICE: ${DEVICE}"
	fi
	if [[ "${ISISO}" ]]; then
		Encapsulate "ISO: ${ISISO}"
	fi
	#echo "INFOLDER: ${PWD}"

	if [ -f "${ISISO}" ]; then
		FullBar
		Center "${APPNAME}: Testing ISO ${TOPROCESS} in a virtual machine."
		FullBar
		qemu-system-x86_64 -enable-kvm -m "${DEDICATED}" -smp "${CORES}" -usb -boot d -cdrom "${TOPROCESS}" -name TMOSB 2>/dev/null
		#qemu-system-x86_64 -enable-kvm -b "${DEDICATED}" --boot d menu=on cdrom="${TOPROCESS}" 2>/dev/null
		#if ! [[ $A ]]; then
		kvm -m "${DEDICATED}" -smp "${CORES}" -usb -boot d -cdrom "${TOPROCESS}" -name TMOSB 2>/dev/null
		#fi
	else
		# Block device?

		if [[ "${DEVICE}" ]]; then
			if [[ -b "${1}" ]]; then
				FullBar
				Center "${APPNAME}: Testing Thumb-drive ${1} in a virtual machine."
				qemu-system-x86_64 -enable-kvm -m "${DEDICATED}" --boot d menu=on cdrom="${TOPROCESS}" 2>/dev/null
				if ! [[ -r "${1}" ]]; then
					kvm -m "${DEDICATED}" -smp "${CORES}" -usb -boot d -cdrom "${TOPROCESS}" -name TMOSB 2>/dev/null
				else
					Error "ERROR: Permission is denied, please use escalated permissions."
					Encapsulate "sudo ${PROGNAME} --test $*"
					exit 1;
				fi
			else
				# Lost in space !!! ;)
				Error "Error: Invalid option ${TOPROCESS}"
				Help "test" "${1}"
				exit 1;
			fi
		else
			TD="/dev/${TOPROCESS}"
			if [[ -b "${TD}" ]]; then
				FullBar
				Center "${APPNAME}: Testing Thumb-drive ${TD} in a virtual machine."
				qemu-system-x86_64 -enable-kvm -m "${DEDICATED}" --boot d cdrom="${TD}" 2>/dev/null
				if ! [[ "${A}" ]]; then
					if [[ -r "${TD}" ]]; then
						kvm -m "${DEDICATED}" -smp "${CORES}" -usb -boot d -cdrom "${TD}" -name TMOSB
					else
						Error "ERROR: Permission is denied, please use escalated permissions."
						Encapsulate "sudo ${PROGNAME} --test $*"
						exit 0;
					fi
				fi
			else
				# Lost in space !!! ;)
				Error "Invalid option ${TOPROCESS}"
				Help "test" "${1}"
				exit 0;
			fi
		fi
	fi
	Notification "All operations completed successfully."
}

# END Code borrowed from ThumbOS 1.0.8
# Pushes stored cache if any, into the chroot environment.
PushCache () {
	if [[ "${DEBUG}" ]]; then
		echo "DEBUGGING: we are in ${PWD} in function PushCache."
	fi
	if [[ "${CACHEOPTION}" == "none" ]]; then
		Encapsulate "Cacheoption specified as none, not doing any caching."
		return 0;
	fi
	BASEPULL="${1}"
	ARCH="${2}"
	if ! [[ "${BASEPULL}" ]]; then
		if [[ -f "${FOLDER}/extract-cd/.disk/info" ]]; then
			BASEPULL=$(grep -i "RELEASE" "extract-cd/.disk/info" | cut -d'"' -f2 | cut -d ' ' -f1 | tr '[:upper:]' '[:lower:]')
		else
			Error "PushCache FATAL: ${FOLDER}/extract-cd/.disk/info does not exist."
			exit 1;
		fi
	fi
	if ! [[ "${BASEPULL}" && "${ARCH}" ]]; then
		echo -e "CRITICAL ERROR Push Cache: Invalid caching switches provided. BASE: ${1} ARCH:${2}"
		exit 1;
	fi
	if [[ "${BASEPULL}" ]]; then
		# APT CACHE - WE ARE ALWAYS LOOKING TO ACCELERATE THE ENTIRE PROCESS
		# Why rsync as we did way down below when we can move files.
		# Much faster to just straight up move the files back and forth.
		# We provide the option for "keep" cache copying is slower.
		#FAST OPTION is default
		if [[ -d "${CACHINGFOLDER}/${BASEPULL}/${ARCH}/apt/" ]]; then
			CACHESIZE=$(du -hs "${CACHINGFOLDER}/${BASEPULL}/${ARCH}/apt/" | awk '{print $1}')
			if [[ "${CACHESIZE}" == "4.0K" ]]; then
				CACHESIZE=""
			fi
			if [[ "${CACHEOPTION}" == "FAST" ]]; then
				DESTCACHE="edit/var/cache/apt/archives/"
				if [[ "${CACHESIZE}" ]];then
					Encapsulate "Pushing Cache of ${CACHESIZE}, please wait."
					if [[ "${DEBUG}" ]]; then
						echo "DEBUG: Command to EXEC: cp ${CACHINGFOLDER}/${BASEPULL}/${ARCH}/apt/*.deb edit/var/cache/apt/archives/ in ${PWD}"
					fi
					SUCCESS=$(cp "${CACHINGFOLDER}/${BASEPULL}/${ARCH}/apt/"*.deb "${DESTCACHE}") 2>/dev/null
				else
					Encapsulate "No cache folder, first ${BASEPULL} ${ARCH} based O/S build or cacheoption not specified."
					if [[ "${TRUEROOT}" ]]; then
						mkdir -p "${CACHINGFOLDER}/${BASEPULL}/${ARCH}/apt/"
					fi
				fi
			fi
			if [[ "${CACHEOPTION}" == "KEEP" ]]; then
				SUCCESS=$(cp "${CACHINGFOLDER}/${BASEPULL}/${ARCH}/apt/*.deb edit/var/cache/apt/archives/") 2>/dev/null
			fi
		else
			if ! [[ "${CACHEOPTION}" == "NONE" ]]; then
				if [[ "${TRUEROOT}" ]]; then
					mkdir -p "${CACHINGFOLDER}/${BASEPULL}/${ARCH}/apt/"
				fi
			fi
			Encapsulate "No cache folder, first ${BASEPULL} ${ARCH} based O/S build or cacheoption not specified."
			if [[ "${TRUEROOT}" ]]; then
				mkdir -p "${CACHINGFOLDER}/${BASEPULL}/${ARCH}/apt/"
			fi
		fi

		#TMP CACHE
		mkdir -p "${CACHINGFOLDERTEMP}/"
		EXTERNALCACHE=$(du -hs "${CACHINGFOLDERTEMP}/" | awk '{print $1}')
		if [[ "${EXTERNALCACHE}" == "4.0K" ]]; then
				EXTERNALCACHE=""
		fi
		if [[ -d "${CACHINGFOLDERTEMP}" ]]; then
			if [[ "${EXTERNALCACHE}" ]]; then
				if [[ -d "${CACHINGFOLDERTEMP}" ]]; then
					CACHESIZE=$(du -hs "${CACHINGFOLDERTEMP}" | awk '{print $1}')
				fi
				if [[ "${CACHEOPTION}" == "FAST" ]]; then
					SUCCESS=$(cp "${CACHINGFOLDERTEMP}/"*.deb edit/tmp/) 2>/dev/null
				fi
				if [[ "${CACHEOPTION}" == "KEEP" ]]; then
					SUCCESS=$(cp "${CACHINGFOLDERTEMP}/"*.deb edit/tmp/) 2>/dev/null
				fi
			fi
			if ! [[ "${SUCCESS}" ]]; then
				Encapsulate "Pushing ${CACHESIZE} of cache for ${BASEPULL} ${ARCH} build in ${PWD}. Please wait: Success."
			else
				Encapsulate "No Cache option specified."
			fi
		else
			Encapsulate "No Temp cache folder, first ${BASEPULL} ${ARCH} based O/S build or cacheoption none specified."
			if [[ "${TRUEROOT}" ]]; then
				mkdir -p "${CACHINGFOLDERTEMP}/"
			fi
		fi
	sync
	else
		Error "CRITICAL ERROR: FUNCTION Push Cache called without or missing switch."
		echo "debug: 1:${1} 2:${2}"
		exit 1;
	fi
}

KoreFilez () {
	if [[ "${BUILDALL}" ]]; then
		CURRENTBUILD="${AUTOMOUSBUILD}"
	fi
	if [[ "${CORE}" ]]; then
		if [[ -f "${CACHINGFOLDER}/${DIST}/ultimate-edition-${CVERSION}-${DEBTYPE}-core-files.deb" ]]; then
			Encapsulate "Core Option specified, not building core files."
			return 0;
		else
			Encapsulate "Core option specified, however core files do not exist.  First build?"
		fi
	fi
	CURRENTFOLDER="${PWD}"
	if [[ "${CURRENTBUILD}" && -d "${CURRENTBUILD}" ]]; then
		cd "${CURRENTBUILD}" || exit 1
	fi
	if [[ "${DEBUG}" ]]; then
		Encapsulate "DEBUG: We are in ${PWD} | CURRENTBUILD is ${CURRENTBUILD}"
	fi
	if [[ -f "${CACHINGFOLDER}/${DIST}/ultimate-edition-${LONGVERSION}-${DEBTYPE}-core-files.deb" ]]; then
		Encapsulate "Copying Core files to chroot environment."
		if [[ -d "edit/tmp/" ]]; then
			cd "edit/tmp" || exit 1
			SUCCESS=$(cp "${CACHINGFOLDER}/${DIST}/ubiquity-slideshow-kubuntu_999_all.deb" . 2>/dev/null)
			SUCCESS=$(cp "${CACHINGFOLDER}/${DIST}/ubiquity-slideshow-ubuntu_999_all.deb" . 2>/dev/null)
			SUCCESS=$(cp "${CACHINGFOLDER}/${DIST}/ultimate-edition-${LONGVERSION}-${DEBTYPE}-core-files.deb" .)
			if [[ -d "${CURRENTFOLDER}" ]]; then
				cd "${CURRENTFOLDER}" || exit 1;
			else
				Error "${CURRENTFOLDER}, not found from ${PWD}."
			fi
			if [[ -d "${CURRENTBUILD}" ]]; then
				cd "${CURRENTBUILD}" || exit 1
			else
				Error "Directory not found: ${CURRENTBUILD} from ${PWD}."
			fi
			if [[ -f "edit/tmp/ultimate-edition-${LONGVERSION}-${DEBTYPE}-core-files.deb" ]]; then
				Encapsulate "Installing base files in the chroot environment, ignore errors. We will overwrite most of them."
				FullBar
				/usr/sbin/chroot edit /bin/sh -c "cd /tmp/ ; apt-get install -y -f --no-install-recommends base-files lsb-release wget"
				FullBar
				Encapsulate "Installing Core files in the chroot environment, ignore errors. We will fix them later (Stage 3)."
				FullBar
				/usr/sbin/chroot edit /bin/sh -c "cd /tmp/ ; DEBIAN_PRIORITY=critical ; DEBCONF_FRONTEND=noninteractive ; dpkg -i --force-overwrite ultimate-edition-${LONGVERSION}-${DEBTYPE}-core-files.deb"
			else
				Error "File not found: edit/tmp/ultimate-edition-${LONGVERSION}-${DEBTYPE}-core-files.deb from ${PWD}."
			fi
		else
			Error "Critical Error: No temp folder in chroot."
			Encapsulate "DEBUG: We are in ${PWD}"
			exit 1;
		fi
	else
		Error "MASSIVE FAILURE: No core Files."
		exit 1;
	fi
	cd "${CURRENTFOLDER}" || exit 1
}
# Displays various caching information.
CacheInfo () {
	shopt -s nullglob
	declare -a FOLDERS=();
	declare -a SUBFOLDERS=();
	FOLDERS=(/*)
	INFOLDER="${PWD}"
	if [[ "${DEBUG}" ]]; then
		Encapsulate "1:${1} 2:${2} 3:${3} 4:${4} *:$*"
	fi
	if [[ -d "${CACHINGFOLDER}/" ]]; then
		TOTALUSAGE=$(du -hs "${CACHINGFOLDER}/"  | awk '{print $1}' 2>/dev/null)
		VersionDump
		FullBar
		Encapsulate "Total cache usage: ${TOTALUSAGE}"
		FullBar
		Center "Caching System Information"
		if [[ -d "${CACHINGFOLDER}" ]]; then
			cd "${CACHINGFOLDER}/" || exit 1
		fi
		FOLDERS=(./*)
		for EACH in "${FOLDERS[@]}"
		do
			du -hs "${EACH}"
		done
		FullBar
		if [[ -d "${2}" ]]; then
			Center "${2} Caching Information"
			cd "${2}/" || exit 1
			SUBFOLDERS=(./*)
			for EACH in "${SUBFOLDERS[@]}"
			do
				du -hs "${EACH}"
			done
			FullBar
		else
			if [[ "${2}" ]]; then
				if ! [[ -d "${2}" ]]; then
					Error "Folder: ${2} does not exist."
					Encapsulate "Example: ${PROGNAME} --cacheinfo eoan"
					Encapsulate "Using reference above: "
					FullBar
				fi
			fi
		fi
	else
		VersionDump
		Center "No cache has been created yet or you are not root."
		FullBar
	fi

	if [[ -d "${INFOLDER}" ]]; then
		cd "${INFOLDER}" || exit 1
	fi
}

PrebuildInfo () {
	ARRAYCOUNTER=0
	for EACH in "$@";
	do
		GREPIT=$(echo "${EACH}" | grep -i '.iso')
		if [[ "${GREPIT}" ]]; then
			FOLDER="${2%.*}"
			if [[ -d "${FOLDER}" ]]; then
				ISO="${EACH}"
			fi
		fi
		if [[ -d "${EACH}" ]]; then
			FOLDER="${EACH}"
		fi
		ARRAYCOUNTER=$((ARRAYCOUNTER++))
	done

	if ! [[ "${FOLDER}" || "${ISO}" ]]; then
		Error "Critical Error no FOLDER: ${FOLDER} or ISO:${ISO} specified."
		exit 1;
	fi

	if ! [[ "${ISO}" ]]; then
		ISO="${FOLDER}.iso"
	fi

	if [[ "${DEBUG}" ]]; then
		echo "DEBUG: ISO:${ISO} | FOLDER: ${FOLDER}"
	fi

	GREPIT=$(echo "$*" | grep -i 'suppress')

	if [[ "${ISO}" ]]; then
		EXTENSION="${ISO##*.}"
		FOLDER="${ISO%.*}"
		if [[ -d "${FOLDER}" ]]; then
			cd "${FOLDER}" || exit 1;
		else
			CONTAINS=$(echo "${PWD}" | grep "${FOLDER}")
			if ! [[ -d "${CONTAINS}" ]]; then
				mkdir -p "${FOLDER}"
			fi
		fi
	else
		EXTENSION="${ISO##*.}"
		FOLDER="${ISO%.*}"
		if [[ "${ISO}" && -d "${FOLDER}" ]]; then
			ISO="${FOLDER}.iso"
			if [[ -d "${FOLDER}" ]]; then
				cd "${FOLDER}" || exit 1;
			else
				Error "Critical Error \"No FOLDER\" specified, exiting."
				exit 1;
			fi
		else
			mkdir -p "${FOLDER}"
		fi
	fi
	z="${ISO}"
	CVERSION=$(echo "${z}" | cut -d "-" -f3)
	LONGVERSION="${CVERSION}"
	if [[ "${DEBUG}" ]]; then
		Encapsulate "DEBUG: VERSION: ${CVERSION}"
	fi

	#cd ${z}
	# Default naming scheme for Ultimate Edition
	ARCH=$(echo "${z}" | grep -i 'x86')
	# Nothing? Is the user wanting a ubuntu build?
	if ! [[ "${ARCH}" ]]; then
		ARCH=$(echo "${z}" | grep -i 'i386')
	fi
	# Wanting Lite / Gamers? This data will be pushed to the internal app
	# and adjusted accordingly.

	ARCH=""
	for ARCHITECTURE in "${UEARCH[@]}"
	do
		TESTCONDITION=$(echo "${z}" | grep -i "${ARCHITECTURE}")
		if [[ "${DEBUG}" ]]; then
			echo "DEBUGGING ARCH:${z} against ${ARCHITECTURE}"
		fi
		if [[ "${TESTCONDITION}" ]]; then
			if [[ "${DEBUG}" ]]; then
				Encapsulate "Architecture detected as ${ARCHITECTURE}"
			fi
			ARCH="${ARCHITECTURE}"
			GREPIT=$(echo "${ARCH}" | grep '64')
			if [[ "${GREPIT}" ]]; then
				LONGARCH="amd64"
			fi
			GREPIT=$(echo "${ARCH}" | grep '86')
			if [[ "${GREPIT}" ]]; then
				LONGARCH="i386"
			fi
		fi
	done
	if ! [[ "${ARCH}" ]]; then
		Error "FATAL: ARCHITECTURE NOT FOUND."
		exit 1;
	fi
	COUNTDOTS=$(echo "${CVERSION}" |grep -o "\." | wc -l)
		if [[ "${COUNTDOTS}" -le 2 ]]; then
			CVERSION=$(echo "${CVERSION}" | cut -d "." -f1,2)
		fi
	#DIST debugging.
	declare -i ARRAYCOUNTER;
	ARRAYCOUNTER=0
	for DISTROZ in "${UEARRAY[@]}"
	do
		TESTCONDITION=$(echo "${DISTROZ}" | grep -i "${CVERSION}")
		if [[ "${DEBUG}" ]]; then
			echo "DEBUGGING DISTRO:${DISTROZ} against ${CVERSION} as ${DISTARRAY[$ARRAYCOUNTER]}"
		fi
		if [[ "${TESTCONDITION}" ]]; then
			if [[ "${DEBUG}" ]]; then
				Encapsulate "Distro base detected as ${DISTARRAY[$ARRAYCOUNTER]} | ${CVERSION}"
			fi
			#ARCH="${ARCHITECTURE}"
			#GREPIT=$(echo "${ARCH}" | grep '64')
			#if [[ "${GREPIT}" ]]; then
			#	LONGARCH="amd64"
			#fi
			#GREPIT=$(echo "${ARCH}" | grep '86')
			#if [[ "${GREPIT}" ]]; then
			#	LONGARCH="i386"
			#fi
		fi
		ARRAYCOUNTER=$((ARRAYCOUNTER +1))
	done
	#Foreign architectures
	#debootstrap --arch=armhf --verbose --foreign trusty edit/
	#chroot edit /bin/bash /debootstrap/debootstrap --second-stage
	#cp /usr/bin/qemu-arm-static edit/usr/bin

	# Process via default name if Ubuntu:
	# ubuntu-13.10-desktop-amd64.iso
	EXTENSION="${z##*.}"
	FILENAME="${z%.*}"

	UBUNTU=$(echo "${z}" | grep -i 'ubuntu')

	if [[ "${UBUNTU}" ]]; then
		CVERSION=$(echo "${z}" | cut -d "-" -f2)
	fi

	# Check to see if release is Long Term Supported.
	LTS="NO"
	#LONGVERSION="${CVERSION}"

	COUNTDOTS=$(echo "${CVERSION}" | grep -c -o "\.")
	if [[ "${COUNTDOTS}" -ge 2 ]]; then
		#echo "DETECTED A LTS THAT IS GREATER THEN 2 DIGITS"
		LONGVERSION="${CVERSION}"
		CVERSION="${CVERSION%.*}"
	fi
	for zx in "${ISLTS[@]}"
	do
		if [[ "${CVERSION}" == "${zx}" && "${LTS}" == "NO" ]]; then
			LTS="YES"
		fi
	done

	EVENODD="${DISTREL##*.}"
	#echo "DEBUGGING: ${EVENODD}"
	#if [ $((EVENODD%2)) -eq 0 ]; then
	#	DTYPE="STANDARD"
	#	DE="MATE"
	#else
	#	DTYPE="FULL"
	#	DE="KDE"
	#fi

	#if ! [[ "${ODD}" -eq 0 ]]; then
	#	DE="KDE"
	#	DTYPE="FULL"
	#fi

	if [[ "${LITE}" ]] ; then
		if ! [[ "${DE}" ]]; then
			DE="mate"
		fi
		DTYPE="LITE"
	fi

	if [[ "${GAMERS}" ]] ; then
		DE="mate"
		DTYPE='GAMERS'
	fi
	if [[ "${SERVER}" ]] ; then
		if ! [[ "${DE} " ]]; then
			DE="mate"
		fi
		DTYPE='SERVER'
	fi

	if [[ "${MSERVER}" ]] ; then
		DE="NONE"
		DTYPE='MSERVER'
	fi

	if [[ "${DEVELOPER}" ]] ; then
		DTYPE='DEVELOPER'
		if ! [[ "${DE}" ]]; then
			DE="kde"
		fi
	fi

	if ! [[ "${DE}" ]]; then
		DTYPE="FULL"
	fi


	array_counter=0;
	for OST in "${UEARRAY[@]}"
	do
		# DEBUGGING
		# echo "Checking: ${OST}"
		if [[ "${OST}" == "${CVERSION}" ]]; then
			# DEBUGGING
			# echo "YES: ${OST} DIST: ${OSARRAY[$array_counter]} NAME: ${DISTARRAY[$array_counter]}"
			DIST="${OSARRAY[$array_counter]}"
			FULLNAME="${DISTARRAY[$array_counter]}"
		fi
		array_counter=$((array_counter + 1))
	done
	if [[ "${UBUNTU}" ]]; then
		OUTDISTRO="Ubuntu"
	else
		OUTDISTRO="Ultimate Edition"
	fi

	################ EXTRA DE'S?
	# PULL ${2}, ${3} etc for extra DE's
	PROCESS=0;
	for var in "$@"
	do
		array_counter=$((array_counter + 1))
		# echo "Switch $array_counter: ${var}"
		CSWITCH=$(echo "${var}" | grep -i "iso")
		if [[ "${PROCESS}" == 1 ]]; then
			nested_array=0;
			for TE in "${EXTRADE[@]}"
			do
				DETC="${EXTRADE[$nested_array]}"
				#echo "Comparing ${DETC} to ${var}"
				shopt -s nocasematch
				if [[ "${var}" == "${DETC}" ]]; then
					var=$(echo "${var}" | tr '[:lower:]' '[:upper:]')
					DE="${DE}, ${var}"
				fi
				nested_array=$((nested_array + 1))
			done
		fi
		if [[ "${CSWITCH}" && "${PROCESS}" == 0 ]]; then
			PROCESS=1
		fi
	done
	if [[ "${DEFAULTDE}" ]]; then
		DE="${DEFAULTDE}"
	fi
	#echo "${DE}"
	if ! [[ "${DE}" ]]; then
		DE="mate"
	fi
	NamingConvention
	#if [[ "${COUNTDOTS}" -gt 1 ]]; then
	#	LONGVERSION="${CVERSION}"
	#	#Relinquish the proper version as originally requested.
	#	CVERSION=$(echo "${z}" | cut -d "-" -f3)
	#fi
}

# Dump vaild build switches to the end user.
InvalidBuildSwitch () {
	GREPIT=$(echo "$*" | grep -i 'build')
	if [[ "${GREPIT}" ]]; then
		CBE="--build"
		SWITCH="build"
	fi
	GREPIT=$(echo "$*" | grep -i 'debootstrap')
	if [[ "${GREPIT}" ]]; then
		CBE="--debootstrap"
		SWITCH="debootstrap"
	fi
	GREPIT=$(echo "$*" | grep -i 'suppress')
	SUPPRESS=$(echo "$*" | grep -i 'suppress')
	if ! [[ "${CBE}" ]]; then
		Error "FATAL ERROR: No switch provided to internal InvalidBuildSwitch function."
		exit 1;
	fi
	if ! [[ "${SUPPRESS}" ]]; then
		if [[ "${SWITCH}" == "build" ]]; then
			VersionDump
		fi
	fi
	if ! [[ "${SUPPRESS}" ]]; then
		Error "ERROR: Invalid ${SWITCH} switch. Generating valid switches:"
	fi
	UE="ultimate-edition"
	UBUNTUBASE="ubuntu-desktop"
	ARCH32='x86'
	ARCH64='x64'
	ARCHARM='armel'
	ARCHHF='armhf'
	ARCHPOWERPC='powerpc'
	LITE='lite'
	SERVER='server'
	MSERVER='minimal-server'
	GAMERS='gamers'
	OUTDISTRO="Ultimate Edition"
	counter=0
	if [[ "${DEBUG}" ]]; then
		echo "DEBUGGING OST: ${OST}"
	fi
	for OST in "${UEARRAY[@]}"
	do
		# echo "Checking: ${OST}"
		COUNTDOTS=$(echo "${OST}" |grep -o "\." | wc -l)
		if [[ "${COUNTDOTS}" -le 2 ]]; then
			VER=$(echo "${OST}" | cut -d "." -f2)
		else
			VER=$(echo "${OST}" | cut -d "." -f1,2)
		fi
		EVENODD=$(( VER % 2 ))
		DIST="${OSARRAY[$counter]}"
		FULLNAME="${DISTARRAY[$counter]}"
		counter=$((counter + 1))

		# Check to see if release is Long Term Supported.
		LTS="NO"
		for zx in "${ISLTS[@]}"
		do
			if [[ "${OST}" == "${zx}" && ${LTS} == 'NO' ]]; then
				LTS="YES"
			fi
		done

		#echo "VERSION: $VER"
		#if [[ $VER == '04' ]]; then
		#	OUTDISTRO="Ubuntu"
		#fi

		if ! [[ ${EVENODD} -eq 0 ]]; then
			DTYPE='STANDARD'
			DE="kde"
		else
			DTYPE='LITE/STANDARD'
			DE="mate"
		fi

		# Last second adjustment is the end user has requested a default de.
		if [[ ${DEFAULTDE} ]]; then
			DE="${DEFAULTDE}"
		fi

		if ! [[ "${GREPIT}" && "${SUPPRESS}" ]]; then
			FullBar
			Columnize -t 'OPERATING SYSTEM' 'VERSION' 'RELEASE BASE' 'ARCH' 'LTS' 'DIST TYPE' 'COMPRESSION' 'DE(s)'
			#echo -e -n "${undwht}"
			FullBar
			if [[ ${#LONGVERSION} -ge 4 ]]; then
				if [[ "${DEBUG}" ]]; then
					echo "DEBUGGING LONGVERSION: ${LONGVERSION}"
				fi
				VERSUB="${OST}"
				VERSUB+=" (${LONGVERSION})"
				Columnize "${OUTDISTRO}" "$VERSUB" "${FULLNAME}" "x86/x64" "${LTS}" "${DTYPE}" "${DE}"
			else
				Columnize "${OUTDISTRO}" "${OST}" "${FULLNAME}" "x86/x64" "${LTS}" "${DTYPE}" "${DE}"
			fi
			#echo "${OUTDISTRO}" "${OST}" "${FULLNAME}" "x86/x64" "${LTS}" "${DTYPE}" "${DE}"
			FullBar
			Encapsulate "Default Build command(s):"
		fi

		if [[ "$counter" -lt "${DISTSSUPPORTED}" ]]; then
			if [[ ${EVENODD} ]]; then
				for EACH in "${UETYPES[@]}"
				do

					if ! [[ "${GREPIT}" ]]; then
						Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH32}-${EACH}.iso"
						Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH64}-${EACH}.iso"
						TOTALOS=$((TOTALOS +2))
					else
						echo "${UE}-${OST}-${ARCH32}-${EACH}.iso"
						echo "${UE}-${OST}-${ARCH64}-${EACH}.iso"
					fi
				done
				if ! [[ $GREPIT ]]; then
					Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH64}.iso"
					Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH32}.iso"
					Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH}ARM.iso"
					Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH}HF.iso"
					Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH}ARM.img"
					Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH}HF.img"
					Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH}POWERPC.iso"
					TOTALOS=$((TOTALOS +7))
				else
					echo "${UE}-${OST}-${ARCH64}.iso"
					echo "${UE}-${OST}-${ARCH32}.iso"
					echo "${UE}-${OST}-${ARCH}ARM.iso"
					echo "${UE}-${OST}-${ARCH}HF.iso"
					echo "${UE}-${OST}-${ARCH}ARM.img"
					echo "${UE}-${OST}-${ARCH}HF.img"
					echo "${UE}-${OST}-${ARCH}POWERPC.iso"
				fi
			else
				if ! [[ $GREPIT ]]; then
					Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH32}.iso"
					Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH64}.iso"
					Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH}ARM.iso"
					Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH}HF.iso"
					Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH}ARM.img"
					Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH}HF.img"
					Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH}POWERPC.iso"
					TOTALOS=$((TOTALOS +5))
				else
					echo "${UE}-${OST}-${ARCH32}.iso"
					echo "${UE}-${OST}-${ARCH64}.iso"
					echo "${UE}-${OST}-${ARCH}ARM.iso"
					echo "${UE}-${OST}-${ARCH}HF.iso"
					echo "${UE}-${OST}-${ARCH}ARM.img"
					echo "${UE}-${OST}-${ARCH}HF.img"
					echo "${UE}-${OST}-${ARCH}POWERPC.iso"
				fi
			fi
		else
			if ! [[ $GREPIT ]]; then
				Encapsulate "${PROGNAME} ${CBE} ${UBUNTUBASE}-${OST}-${ARCH32}.iso"
				Encapsulate "${PROGNAME} ${CBE} ${UBUNTUBASE}-${OST}-${ARCH64}.iso"
				Encapsulate "${PROGNAME} ${CBE} ${UBUNTUBASE}-${OST}-${ARCH}ARM.iso"
				Encapsulate "${PROGNAME} ${CBE} ${UBUNTUBASE}-${OST}-${ARCH}HF.iso"
				Encapsulate "${PROGNAME} ${CBE} ${UBUNTUBASE}-${OST}-${ARCH}ARM.img"
				Encapsulate "${PROGNAME} ${CBE} ${UBUNTUBASE}-${OST}-${ARCH}HF.img"
				Encapsulate "${PROGNAME} ${CBE} ${UBUNTUBASE}-${OST}-${ARCH}POWERPC.iso"
				TOTALOS=$((TOTALOS +5))
			else
				echo "${UBUNTUBASE}-${OST}-${ARCH32}.iso"
				echo "${UBUNTUBASE}-${OST}-${ARCH64}.iso"
				echo "${UBUNTUBASE}-${OST}-${ARCH}ARM.iso"
				echo "${UBUNTUBASE}-${OST}-${ARCH}HF.iso"
				echo "${UBUNTUBASE}-${OST}-${ARCH}ARM.img"
				echo "${UBUNTUBASE}-${OST}-${ARCH}HF.img"
				echo "${UBUNTUBASE}-${OST}-${ARCH}POWERPC.iso"
			fi
			#array_counter=$(($array_counter + 1))
		fi
		#array_counter=$(($array_counter + 1))
	done
	if ! [[ "${GREPIT}" ]]; then
		Center "${APPNAME} (${VERSION}) STATS"
		Center "${PROGNAME} can build ${TOTALOS} different above Operating Systems."
		CALC=$((TOTALOS * ${#EXTRADE[@]}))
		Center "${CALC} in total, when desktop environments are also calculated."
		Encapsulate "Extra Desktop Environments (DE's) are also available:"
		EXAMPLE="${PROGNAME} ${CBE} ultimate-edition-6.7-x64.iso defaultde=kde "
	fi
	if ! [[ "${GREPIT}" ]]; then
		for EACH in "${EXTRADE[@]}"
		do
			EXAMPLE+="${EACH} "
		done
		Encapsulate "Example: ${EXAMPLE}"
		Help "--help" "build" "3"
	fi
	if ! [[ "${BUILDALL}" ]]; then
		exit 0;
	fi
}

# Build Ultimate Edition core files.
BuildCoreFiles () {
	if [[ "${IUSER}" != 'root' && "${TRUEROOT}" != 0 ]]; then
		if [[ "${USETHEFORCE}" ]]; then
			Encapsulate "${IUSER}, using the force as requested Luke."
		else
			Error "Proper root privilages are required to use this app ${USER}."
			Encapsulate "IUSER should be root: ${IUSER}, or TRUEROOT should be 0:${TRUEROOT}"
			Encapsulate "Please consult the manpages or os-builder website: http://www.os-builder.com/#REQUIREMENTS"
			Encapsulate "With heightened permissions comes great responsibility."
			Encapsulate "Exiting graciously, I did at least let you try..."
			FullBar
			exit 0;
		fi
	fi
	#echo "DEBUGGING: 1:${1} 2:${2} 3:${3} 4:${4} 5:${5} 6:${6} 7:${7} *:$*"
	# Requested additional DE(s)?
	for EACH in "$@"
	do
		CHECKIT=$(echo "${EACH}" | tr '[:lower:]' '[:upper:]')
		for OPTIONAL in "${EXTRADE[@]}"
		do
			if [[ "${CHECKIT}" == "$OPTIONAL" ]]; then
				CHECKIT=$(echo "${EACH}" | tr '[:upper:]' '[:lower:]')
				Encapsulate "Adding support for environment: ${CHECKIT}"
				ENVIRONMENTS+=" ${CHECKIT}"
			fi
		done
	done
	#Encapsulate "ENVIRONMENTS: ${ENVIRONMENTS}"
	DEBTYPE=""
	COMMANDISSUED=$(echo "$*" | tr '[:upper:]' '[:lower:]')
	SETDEFAULT=$(echo "${COMMANDISSUED}" | grep -i "defaultde=")
	if [[ "${SETDEFAULT}" ]]; then
		DEFAULTDE=$(echo "${COMMANDISSUED}" | grep -i 'defaultde=' | sed 's/^.*defaultde=//g' | cut -d' ' -f1)
		if [[ "${DEFAULTDE}" ]]; then
			Encapsulate "Default Desktop Environment (DE) specified as: ${DEFAULTDE}"
		fi
	fi
	GAMERS=$(echo "$*" | grep -i "gamers")
	SERVER=$(echo "$*" | grep -i "server")
	MSERVER=$(echo "$*" | grep -i "minimal-server")
	LITE=$(echo "$*" | grep -i "lite")
	if [[ ${LITE} ]]; then
		DEBTYPE='lite'
	fi
	if [[ "${MSERVER}" ]]; then
		DEBTYPE="minimal-server"
		DEFAULTDE="NONE"
		DE="NONE"
	fi
	if [[ "${SERVER}" ]]; then
		DEBTYPE="server"
	fi
	if [[ "${GAMERS}" ]]; then
		DEBTYPE="gamers"
	fi
	if [[ "${DEVELOPER}" ]]; then
		DEBTYPE="developers"
	fi
	#if ! [[ ${DEBTYPE} ]]; then
	#	DEBTYPE='full'
	#fi
	if [[ "${BUILDALL}" && -d "${AUTOMOUSBUILD}" ]]; then
		cd "${AUTOMOUSBUILD}" || exit 1;
	fi
	#cd ${CURRENT}
	Center "Passing control to uecorebuilder subprogram"
	if [[ -f "uecorebuilder" ]]; then
		if [[ "${PROMPT}" ]]; then
			if [[ "${DEBUG}" ]]; then
				echo "DEBUGGING: ./uesplash-builder --build "${LONGVERSION}" "${DTYPE}" defaultde="${DEFAULTDE}" -YES" "${DEBUG}"
			fi
			if [[ "${DEFAULTDE}" ]]; then
				if [[ -f "${CACHINGFOLDER}/${DIST}/${UOS}-${LONGVERSION}-${DEBTYPE}-core-files.deb" ]]; then
					Encapsulate "Core files, previously built, pulling from cache."
				else
					./uecorebuilder --build "${LONGVERSION}" "${DEBTYPE}" "${ENVIRONMENTS}" --defaultde="${DEFAULTDE}" -YES "${DEBUG}"
				fi
			else
				if [[ -f "${CACHINGFOLDER}/${DIST}/${UOS}-${LONGVERSION}-${DEBTYPE}-core-files.deb" ]]; then
					Encapsulate "Core files, previously built, pulling from cache."
				else
		if ! [[ "${DEBTYPE}" ]]; then
			DEBTYPE="standard"
		fi
					./uecorebuilder --build "${LONGVERSION}" "${DEBTYPE}" "${ENVIRONMENTS}" -YES "${DEBUG}"
				fi
			fi
		else
			if [[ "${DEFAULTDE}" ]]; then
				if [[ -f "${CACHINGFOLDER}/${DIST}/${UOS}-${LONGVERSION}-${DEBTYPE}-core-files.deb" ]]; then
					Encapsulate "Core files, previously built, pulling from cache."
				else
					./uecorebuilder --build "${LONGVERSION}" "${DEBTYPE}" "${ENVIRONMENTS}" --defaultde="${DEFAULTDE}" "${DEBUG}"
				fi
			else
				if [[ -f "${CACHINGFOLDER}/${DIST}/${UOS}-${LONGVERSION}-${DEBTYPE}-core-files.deb" ]]; then
					Encapsulate "Core files, previously built, pulling from cache."
				else
					./uecorebuilder --build "${LONGVERSION}" "${DEBTYPE}" "${ENVIRONMENTS}" "${DEBUG}"
				fi
			fi
		fi
	else
		if [[ "${PROMPT}" ]]; then
			if [[ "${DEBUG}" ]]; then
				echo "DEBUGGING: ./uesplash-builder --build "${LONGVERSION}" "${DTYPE}" defaultde="${DEFAULTDE}" -YES" "${DEBUG}"
			fi
			if [[ "${DEFAULTDE}" ]]; then
				if [[ -f "${CACHINGFOLDER}/${DIST}/${UOS}-${LONGVERSION}-${DEBTYPE}-core-files.deb" ]]; then
					Encapsulate "Core files, previously built, pulling from cache."
				else
					uecorebuilder --build "${LONGVERSION}" "${DEBTYPE}" "${ENVIRONMENTS}" --defaultde="${DEFAULTDE}" -YES "${DEBUG}"
				fi
			else
				if [[ -f "${CACHINGFOLDER}/${DIST}/${UOS}-${LONGVERSION}-${DEBTYPE}-core-files.deb" ]]; then
					Encapsulate "Core files, previously built, pulling from cache."
				else
					uecorebuilder --build "${LONGVERSION}" "${DEBTYPE}" "${ENVIRONMENTS}" -YES "${DEBUG}"
				fi
			fi
		else
			if [[ "${DEFAULTDE}" ]]; then
				if [[ -f "${CACHINGFOLDER}/${DIST}/${UOS}-${CVERSION}-${DEBTYPE}-core-files.deb" ]]; then
					Encapsulate "Core files, previously built, pulling from cache."
				else
					uecorebuilder --build "${LONGVERSION}" "${DEBTYPE}" "${ENVIRONMENTS}" --defaultde="${DEFAULTDE}" "${DEBUG}"
				fi
			else
				if [[ -f "${CACHINGFOLDER}/${DIST}/${UOS}-${CVERSION}-${DEBTYPE}-core-files.deb" ]]; then
					Encapsulate "Core files, previously built, pulling from cache."
				else
					uecorebuilder --build "${LONGVERSION}" "${DEBTYPE}" "${ENVIRONMENTS}" "${DEBUG}"
				fi
			fi
		fi
	fi

	if ! [[ "${EVENODD}" ]]; then
		if ! [[ "${DEBTYPE}" ]]; then
			DEBTYPE="standard"
		fi
	else
		if ! [[ "${DEBTYPE}" ]]; then
			DEBTYPE="full"
		fi
	fi
	for TYPES in "${DEBS[@]}"
	do
		if [[ -f "ultimate-edition-${LONGVERSION}-${TYPES}-core-files.deb" ]]; then
			Encapsulate "ultimate-edition-${LONGVERSION}-${TYPES}-core-files.deb found."
			DEBTYPE="${TYPES}"
		else
			Encapsulate "ultimate-edition-${LONGVERSION}-${TYPES}-core-files.deb not found."
		fi
	done

	if [[ -s "ultimate-edition-${LONGVERSION}-${DEBTYPE}-core-files.deb" ]]; then
		Center "Core files for Ultimate Edition ${LONGVERSION} successfully built."
		Encapsulate "Copying core files for ${LONGVERSION} to cache:"
		SUCCESS=$(cp "ultimate-edition-${LONGVERSION}-${DEBTYPE}-core-files.deb" "${CACHINGFOLDER}/${DIST}/" 2>/dev/null)
		if [[ "${SUCCESS}" && -f "ultimate-edition-${LONGVERSION}-${DEBTYPE}-core-files.deb" ]]; then
			Encapsulate "Success."
		else
			Error "Failed."
		fi
	else
		if [[ -s "${CACHINGFOLDER}/${DIST}/ultimate-edition-${LONGVERSION}-${DEBTYPE}-core-files.deb" ]]; then
			Encapsulate "Core files have been previously backed up to cache."
		else
			Error "ERROR: Failure building core files for Ultimate Edition ${LONGVERSION}."
			echo "DEBUG info: looking for ultimate-edition-${LONGVERSION}-${DEBTYPE}-core-files.deb in ${PWD}."
			exit 1;
		fi
	fi
	### SPLASH ###
	if [[ -s "${CACHINGFOLDER}/${DIST}/ubiquity-slideshow-ubuntu_999_all.deb" ]]; then
		FILEISCACHED=1
		cp "${CACHINGFOLDER}/${DIST}/ubiquity-slideshow-ubuntu_999_all.deb" .
	fi
	if [[ -s "${CACHINGFOLDER}/${DIST}/ubiquity-slideshow-kubuntu_999_all.deb" ]]; then
		FILEISCACHED=1
		cp "${CACHINGFOLDER}/${DIST}/ubiquity-slideshow-kubuntu_999_all.deb" .
	fi
	USPLASH=0
	if ! [[ "$FILEISCACHED" ]]; then
		Encapsulate "Building prerequisites, passing control to external uesplash-builder."
		if ! [[ "${CVERSION}" || "${CVERSION}" == 1 ]];then
			CVERSION="${LONGVERSION}"
		fi
		if [[ "${DEBUG}" ]]; then
			echo "DEBUGGING: ./uesplash-builder --build "${LONGVERSION}" "${DTYPE}" defaultde="${DEFAULTDE}" -YES" "${DEBUG}"
		fi
		if [[ "${DEFAULTDE}" ]]; then
			USPLASH=1
			if [[ -f "uesplash-builder" ]]; then
				if [[ "${DEBUG}" ]]; then
					echo "DEBUGGING: ./uesplash-builder --build "${LONGVERSION}" "${DTYPE}" defaultde="${DEFAULTDE}" -YES" "${DEBUG}"
				fi
				if [[ "${PROMPT}" ]]; then
					./uesplash-builder --build "${LONGVERSION}" "${DTYPE}" defaultde="${DEFAULTDE}" -YES "${DEBUG}"
				else
					./uesplash-builder --build "${LONGVERSION}" "${DTYPE}" defaultde="${DEFAULTDE}" "${DEBUG}"
				fi
			else
				if [[ "${DEBUG}" ]]; then
					echo "DEBUGGING: ./uesplash-builder --build "${LONGVERSION}" "${DTYPE}" defaultde="${DEFAULTDE}" -YES" "${DEBUG}"
				fi
				if [[ "${PROMPT}" ]]; then
					uesplash-builder --build "${LONGVERSION}" "${DTYPE}" defaultde="${DEFAULTDE}" -YES "${DEBUG}"
				else
					uesplash-builder --build "${LONGVERSION}" "${DTYPE}" defaultde="${DEFAULTDE}" "${DEBUG}"
				fi
			fi
		fi
		if [[ "$USPLASH" == 0 ]]; then
			USPLASH=1
			if [[ "${DEBUG}" ]]; then
				echo "DEBUGGING: ./uesplash-builder --build "${LONGVERSION}" "${DTYPE}" defaultde="${DEFAULTDE}" -YES" "${DEBUG}"
			fi
			if [[ -f "uesplash-builder" ]]; then
				if [[ ${PROMPT} ]]; then
					./uesplash-builder --build "${LONGVERSION}" "${DTYPE}" -YES "${DEBUG}"
				else
					./uesplash-builder --build "${LONGVERSION}" "${DTYPE}" "${DEBUG}"
				fi
			else
				if [[ ${PROMPT} ]]; then
					uesplash-builder --build "${LONGVERSION}" "${DTYPE}" -YES "${DEBUG}"
				else
					uesplash-builder --build "${LONGVERSION}" "${DTYPE}" "${DEBUG}"
				fi
			fi
		fi

		if [[ "$USPLASH" != 1 ]]; then
			if [[ "${DEBUG}" ]]; then
				echo "DEBUGGING: ./uesplash-builder --build "${LONGVERSION}" "${DTYPE}" defaultde="${DEFAULTDE}" -YES" "${DEBUG}"
			fi
			if [[ -f "uesplash-builder" ]]; then
				if [[ "${PROMPT}" ]]; then
					./uesplash-builder --build "${LONGVERSION}" -YES "${DEBUG}"
				else
					./uesplash-builder --build "${LONGVERSION}" "${DEBUG}"
				fi
			else
				if [[ "${PROMPT}" ]]; then
					uesplash-builder --build "${LONGVERSION}" -YES "${DEBUG}"
				else
					uesplash-builder --build "${LONGVERSION}" "${DEBUG}"
				fi
			fi
		fi
		Encapsulate "Copying Usplash files for ${LONGVERSION} to cache:"

		if [[ -s "ubiquity-slideshow-ubuntu_999_all.deb" ]]; then
			cp ubiquity-slideshow-ubuntu_999_all.deb "${CACHINGFOLDER}/${DIST}/"
		fi
		if [[ -s "ubiquity-slideshow-kubuntu_999_all.deb" ]]; then
			cp ubiquity-slideshow-kubuntu_999_all.deb "${CACHINGFOLDER}/${DIST}/"
		fi
		if [[ -f "${CACHINGFOLDER}/${DIST}/ubiquity-slideshow-ubuntu_999_all.deb" || -f "${CACHINGFOLDER}/${DIST}/ubiquity-slideshow-kubuntu_999_all.deb" ]]; then
			Encapsulate "Success."
		else
			Error "Failed. DEBUG: CACHING FOLDER:${CACHINGFOLDER} DIST:${DIST}/"
		fi
	fi

	if [[ -f "ubiquity-slideshow-kubuntu_999_all.deb" || -f "ubiquity-slideshow-ubuntu_999_all.deb" ]]; then
		Encapsulate "Usplash files for Ultimate Edition ${LONGVERSION} successfully built."
	else
		Error "ERROR: Failure building Usplash files for Ultimate Edition ${LONGVERSION}."
		exit 1;
	fi
}

# Extracts existing ISO(s)
ExtractISO () {
	# Call the Version Dump Function
	VersionDump
	Timer "Start" "ExtractISO"
	array_counter=0
	if [[ "${IUSER}" != "root" && "${TRUEROOT}" != "0" ]]; then
		Error "True root access is required to preform this operation."
		exit 1;
	fi
	# Scan for ISO's. Suppress errors if they do not exist.
	# Allow / Set nullification of arrays
	shopt -s nullglob
	declare -a ISOS=();
	declare -i NISOS
	ISOS=(./*.iso)
	NISOS="${#ISOS[@]}"
	# Process ISO's only if they exist.
	if [[ "$NISOS" -gt 0 ]]; then
		# TODO: add error suppression for non-existence.
		# Grab all ISO's in current folder.

		# Setup a counter to initiate at the value of 1
		array_counter=$((array_counter + 1))
		Encapsulate "Processing $array_counter of $NISOS detected Operating system(s), please wait."
		# Cycle all found ISO's
		# TODO: Add ability to process a single ISO if the user requests it.
		for i in "${ISOS[@]}"
		do
			EXTENSION="${i##*.}"
			FILENAME="${i%.*}"
			CVERSION=$(echo "${FILENAME}" | cut -d "-" -f3)
			Encapsulate "Operating System Version detected: ${CVERSION}"
			if [[ -d "${FILENAME}" ]]; then
				Encapsulate "Folder already exists."
			else
				Encapsulate "Creating folder ${FILENAME}/"
				mkdir -p "${FILENAME}/"
			fi
			# Does the user have write permissions?
			if [[ -w "${i}" ]]; then
				Encapsulate "Moving ${i} to ${FILENAME}/"
				mv "${i}" "${FILENAME}"
			else
				Error "ERROR: Insufficient privileges to move ${i}."
				exit 1;
			fi
		done
	else
		Error "No ISO's to process in current folder.  Are we building ISO(s)? Continuing..."
	fi
	# Begin extracting ISO's
	Encapsulate "Scanning folders..."
	shopt -s nullglob
	declare -a FOLDERS=();
	FOLDERS=(./*/)
	if ! [[ "${#FOLDERS[@]}" ]]; then
		Error "No folder(s) to process, exiting."
		exit 1;
	fi
	for Z in "${FOLDERS[@]}"
	do
		Encapsulate "Processing Folder: ${Z}"
		if [[ -d "${Z}" ]]; then
			cd "${Z}" || exit 1
		else
			Error "${Z} does not exist."
			exit 1;
		fi
		#prepare
		ISOS=(*.iso)
		#ISOS=$(ls *.iso 2>/dev/null)
		if [[ "${ISOS[*]}" ]]; then
			for I in "${ISOS[@]}"
			do
				Encapsulate "Processing ${I}/"
				if [[ -d "${I}" ]]; then
					cd "${I}" || exit 1;
				fi
				sudo mkdir -p {edit,extract-cd,mnt,squashfs}
				if ! [[ -d "edit" ]]; then
					mkdir -p "edit"
				fi
				if ! [[ -d "extract-cd" ]]; then
					mkdir -p "extract-cd"
				fi
				if ! [[ -d "mnt" ]]; then
					mkdir -p "mnt"
				fi
				if ! [[ -d "squashfs" ]]; then
					mkdir -p "squashfs"
				fi
				#mount & extract
				if [[ -f "${I}" ]]; then
					# TODO: Add additional checks we can never be too
					# Safe when it comes to mounting / permissions
					Encapsulate "Mounting ${I}"
					mount -o loop "${I}" mnt/  2>/dev/null
					Encapsulate "Synchronizing ${I}"
					rsync --exclude=/casper/filesystem.squashfs -a mnt/ extract-cd
					if [[ -f "mnt/casper/filesystem.squashfs" ]]; then
						Encapsulate "Mounting SquashFs Stage 1"
						if ! [[ -d "squashfs/" ]]; then
							mkdir -p "squashfs/"
						fi
						mount -t squashfs -o loop mnt/casper/filesystem.squashfs squashfs
					else
						Encapsulate "Mounting failed at Stage 1, are we playing with a server?"
					fi

					if [[ -f "mnt/install/filesystem.squashfs" ]]; then
						Encapsulate "Entering Stage 2, Stage 1 failed."
						Encapsulate "Mounting SquashFs Stage 2 (server)"
						mount -t squashfs -o loop mnt/install/filesystem.squashfs squashfs
					else
						if ! [[ -d "squashfs/" ]]; then
							Error "Massive Error, we are quitting."
							exit 1;
						fi
					fi
					Encapsulate "Copying SquashFs in ${PWD}"
					if [[ -d "edit/" ]]; then
						rsync -a "squashfs/" "edit/" & Spinner "Rsyncing SquashFs in ${PWD}"
						sync
					else
						mkdir -p "edit/"
						rsync -a "squashfs/" "edit/"
						sync
					fi
					Encapsulate "Unmounting SquashFS"
					umount "squashfs/"
					sync
					Encapsulate "Unmounting ${I}"
					umount "mnt/"
					sync
					#				echo -e "${bldred}Failure mounting ${i}, exiting...${TXTRST}"
					#				exit 0
					#fi
				fi
				Encapsulate "Cleaning up..."
				if [[ -d "mnt" ]]; then
					rm -R "mnt"
				fi
				if [[ -d "squashfs" ]]; then
					rm -R "squashfs"
				fi
				SUCCESS=$(ls edit/)
				if [[ "${SUCCESS}" ]]; then
					if [[ -f "${I}" ]]; then
						rm "${I:?}"
					fi
				else
					Error "ERROR: Synchronization error, not deleting ${I}. Are you a superuser?"
					exit 1;
				fi
			done
		fi
		if [[ -d "${CURRENT}" ]]; then
			cd "${CURRENT}" || exit 1
		else
			Error "CRITICAL ERROR: ${CURRENT} does not exist."
		fi
	done
	Notification "All extraction operations completed successfully."
	#LogResults
	FullBar
	Timer "Stop" "ExtractISO"
	shopt -u nullglob
}

# Builds only the ISO, zero customization
BuildISO () {
	Timer "Start" "BuildISO"
	shopt -u nullglob
	ARRAYCOUNTER=0
	for EACH in "$@";
	do
		GREPIT=$(echo "${EACH}" | grep -i '.iso')
		if [[ "${GREPIT}" ]]; then
			FOLDER="${EACH%.*}"
			EXTENSION="${EACH##*.}"
			if [[ -d "${FOLDER}" ]]; then
				ISO="${EACH}"
			fi
		fi
		if [[ -d "${EACH}" ]]; then
			FOLDER="${EACH}"
		fi
		ARRAYCOUNTER=$((ARRAYCOUNTER + 1))
	done

	if ! [[ "${FOLDER}" || "${ISO}" ]]; then
		Error "Critical Error no FOLDER: ${FOLDER} or ISO:${ISO} specified."
		exit 1;
	fi

	GREPIT=$(echo "$*" | grep -i 'suppress')

	if ! [[ "${GREPIT}" ]]; then
		VersionDump
	fi
	INFOLDER="${PWD}"
	PrebuildInfo "${ISO}"
	if [[ -d "${INFOLDER}" ]]; then
		cd "${INFOLDER}" || exit 1
	else
		Error "Critical Error: ${INFOLDER} does not exist."
	fi

	if [[ "${ISO}" ]]; then
		if [[ -d "${FOLDER}" ]]; then
			cd "${FOLDER}" || exit 1
		else
			EXISTS=$(echo "${PWD}" | grep "${FOLDER}")
			if ! [[ "$EXISTS" ]]; then
				Error "CRITICAL ERROR: ${FOLDER}, does not exist exiting in ${PWD}."
				exit 1;
			fi
		fi
	fi

	# KERNEL & INITRD processing - set array in case there are multiple.
	declare -a KERNEL=();
	declare -a INITRD=();
	shopt -s nullglob
	if [[ -d "edit/boot" ]]; then
		KERNEL=$(find edit/boot/ -name "vmlinuz-*") 2>/dev/null
		INITRD=$(find edit/boot/ -name "initrd.img-*") 2>/dev/null
	else
		if ! [[ -d ${INFOLDER}/edit/boot/ ]]; then
			Error "Critical / Fatal Error: ${INFOLDER}/edit/boot/ does not exist, we are in ${PWD}"
			exit 1;
		else
			cd "${INFOLDER}" || exit 1;
			KERNEL=$(find edit/boot/ -name "vmlinuz-*") 2>/dev/null
			INITRD=$(find edit/boot/ -name "initrd.img-*") 2>/dev/null
		fi
	fi
	# echo -e "${bldred}DEBUG: in ${PWD} KERNEL DETECTED: ${KERNEL}${TXTRST}"
	# echo -e "${bldred}PASSED:" "${OUTDISTRO}" "${CVERSION}" "${FULLNAME}" "${ARCH}" "${LTS}" "${DTYPE}" "${DE}" "${DTB}"
	if [[ "${KERNEL}" && "${INITRD}" ]]; then
		# ISOLINUX
		if [[ -f "/usr/lib/syslinux/isolinux.bin" ]]; then
			Encapsulate "Injecting isolinux: Done."
			cp /usr/lib/syslinux/isolinux.bin extract-cd/isolinux/
		else
			if [[ -f "/usr/share/ultimate_edition/isolinux.bin" ]]; then
				Encapsulate "Injecting isolinux: Done."
				cp /usr/share/ultimate_edition/isolinux.bin extract-cd/isolinux/
			else
				Error "FATAL ERROR: Isolinux not found."
				Center "sudo apt-get install isolinux"
				exit 1;
			fi
		fi
		# MEMTEST
		if [[ -f "/boot/memtest86+.bin" ]]; then
			if ! [[ -f "extract-cd/install/memtest" ]]; then
				if [[ -d "extract-cd/install/" ]]; then
					cp "/boot/memtest86+.bin" "extract-cd/install/memtest"
					Encapsulate "Injecting Memtest: Done."
				else
					mkdir -p "extract-cd/install/"
					cp "/boot/memtest86+.bin" "extract-cd/install/memtest"
					Encapsulate "Injecting Memtest: Done."
				fi
			fi
		else
			Center "Memtest not installed on host, not populating: sudo apt-get install memtest86+"
		fi
		# Kernel processing ...
		for EACH in "${KERNEL[@]}"
		do
			Encapsulate "Copying Kernel: ${EACH}: Done."
			cp "${EACH}" extract-cd/casper/vmlinuz
		done
		# Initrd processing ...
		for EACH in "${INITRD[@]}"
		do
			Encapsulate "Copying Initrd: ${EACH}: Done."
			cp "${EACH}" extract-cd/casper/initrd.lz
		done
	fi
	Center "DISRO STAMPING EXTERNAL:"
	LTS="NO"
	for zx in "${ISLTS[@]}"
	do
		if [[ "${CVERSION}" == "${zx}" && "${LTS}" == "" ]]; then
			LTS="YES"
		fi
	done
	if ! [[ -f ".disk/info" ]]; then
		if [[ "${LTS}" == "YES" ]]; then
			echo "${OUTDISTRO} ${CVERSION} LTS \"${FULLNAME}\" - Release ${ARCH} (${DATECURRENT})" >  extract-cd/.disk/info
		else
			echo "${OUTDISTRO} ${CVERSION} \"${FULLNAME}\" - Release ${ARCH} (${DATECURRENT})" >  extract-cd/.disk/info
		fi
		cat "extract-cd/.disk/info"
	else
		cat "extract-cd/.disk/info"
	fi
	if [[ -f "extract-cd/.disk/release_notes_url" ]]; then
		sed -i "s/#VERSION/${CVERSION}/g" "extract-cd/.disk/release_notes_url"
	fi
	FullBar
	if [[ -f "extract-cd/casper/filesystem.squashfs" ]]; then
		Encapsulate "Scraping old squash filesystem, we will build a new one."
		rm "extract-cd/casper/filesystem.squashfs"
	fi
	FinalCheck
	Encapsulate "Building new squash file system:"
	FullBar

	if [[ -d "extract-cd/casper/" ]]; then
		if [[ "${COMPRESSION}" == "maximum" ]]; then
			Encapsulate "Using Maximum compression."
			FullBar
			mksquashfs edit extract-cd/casper/filesystem.squashfs -b 1048576 -comp xz -Xdict-size 100% -no-sparse
			SQUASHCOMPLETE=1
			FullBar
		fi
		if ! [[ "${SQUASHCOMPLETE}" ]]; then
			if ! [[ "${COMPRESSION}" ]]; then
				Encapsulate "Using default compression."
				FullBar
				mksquashfs edit extract-cd/casper/filesystem.squashfs -no-sparse
				SQUASHCOMPLETE=1
			fi
		fi
		if ! [[ "${SQUASHCOMPLETE}" ]]; then
			if [[ "${COMPRESSION}" == "fast" ]]; then
				Encapsulate "Using fast compression."
				FullBar
				mksquashfs edit extract-cd/casper/filesystem.squashfs -no-sparse -comp lz4
				SQUASHCOMPLETE=1
			fi
		fi
		if [[ "${SQUASHCOMPLETE}" == 0 ]]; then
			Error "No SquashFS built error exiting."
			exit 1;
		fi
		FullBar
		Encapsulate "Manifesting new operating system, please wait:"
	#manifest
		touch "extract-cd/casper/filesystem.manifest"
		chmod +w "extract-cd/casper/filesystem.manifest"
		chroot edit dpkg-query -W --showformat='${Package} ${Version}\n' > "extract-cd/casper/filesystem.manifest"
		cp extract-cd/casper/filesystem.manifest extract-cd/casper/filesystem.manifest-desktop
		sed -i '/ubiquity/d' extract-cd/casper/filesystem.manifest-desktop
		Encapsulate "Done."
	else
		if [[ -f "extract-cd/install/filesystem.squashfs" ]]; then
			Encapsulate "Entering Stage 2, Stage 1 failed. (Server)"
			if [[ "${COMPRESSION}" == "maximum" ]]; then
				Encapsulate "Using Maximum compression."
				mksquashfs edit extract-cd/install/filesystem.squashfs -b 1048576 -comp xz -Xdict-size 100% -no-sparse
			else
				mksquashfs edit extract-cd/casper/filesystem.squashfs -no-sparse
			fi
			FullBar
			Encapsulate "Manifesting new operating system, please wait:"
			#manifest
			touch "extract-cd/casper/filesystem.manifest"
			chmod +w "extract-cd/casper/filesystem.manifest"
			chroot edit dpkg-query -W --showformat='${Package} ${Version}\n' > "extract-cd/casper/filesystem.manifest"
			cp extract-cd/casper/filesystem.manifest extract-cd/casper/filesystem.manifest-desktop
			sed -i '/ubiquity/d' extract-cd/casper/filesystem.manifest-desktop
			Encapsulate "Done."
		else
			Error "Massive Failure Quiting..."
			exit 0;
		fi
	fi

	#calculate disksize or ubiquity will be inaccurate
	FILESYSTEMSIZE=$(sudo du -sx --block-size=1 edit | cut -f1)
	printf "%s" "${FILESYSTEMSIZE}" > extract-cd/casper/filesystem.size

	#report disk size information in formated numerals: 6,584,020,992 bytes
	if [[ -f "extract-cd/casper/filesystem.size" ]]; then
		DISKSIZE=$(cat "extract-cd/casper/filesystem.size")
		FDISKSIZE=$(printf "%'.3f\n" "${DISKSIZE}")
		DISKSIZE=$(echo "${FDISKSIZE}" | cut -d. -f1)
		Encapsulate "DiskSize: ${DISKSIZE} bytes"
	else
		Error "Build failure: Exiting..."
		exit 1;
	fi

	Center "Creating final ISO, please wait..."
	GREPIT=$(echo "${OUTDISTRO}" | grep -i "LTS")
	NUSER=$(grep 1000 /etc/passwd | cut -f1 -d:)
	if ! [[ "${NUSER}" ]]; then
		NUSER="root"
	fi

	# PRE-DETERMINE user selection
	if [[ "${DEFAULTDE}" ]]; then
		# STRIP ISO
		ISO=${ISO//.iso/}
		#ISO=$(echo "${ISO}" | sed "s/\.iso//g")
		ISO=$(echo "${ISO}-${DEFAULTDE}.iso")
	fi

	GAMERS=$(echo "$*" | grep -i "gamers")
	SERVER=$(echo "$*" | grep -i "server")
	MSERVER=$(echo "$*" | grep -i "minimal-server")
	LITE=$(echo "$*" | grep -i "lite")
	DEVELOPER=$(echo "$*" | grep -i "developer")

	if [[ "${GAMERS}" ]]; then
		DEBTYPE="gamers"
	fi
	if [[ "${SERVER}" ]]; then
		DEBTYPE="server"
	fi
	if [[ "${MSERVER}" ]]; then
		DEBTYPE="minimal-server"
	fi
	if [[ "${LITE}" ]]; then
		DEBTYPE="lite"
	fi
	if [[ "${DEVELOPER}" ]]; then
		DEBTYPE="developer"
		if ! [[ "${DE}" ]]; then
			DE="kde"
		fi
	fi
	if ! [[ "${DEBTYPE}" ]]; then
		#EVENODD=$(( "$VER" % 2 ))
		if ! [[ "${EVENODD}" -eq 0 ]]; then
			DEBTYPE="Full"
		else
			DTEBTYPE="Standard"
		fi
	fi
	FullBar
	Encapsulate "DISTRO: ${OUTDISTRO}"
	echo "Distro: ${OUTDISTRO}" >> extract-cd/README.TXT
	Encapsulate "VERSION: ${CVERSION}"
	echo "Version: ${CVERSION}" >> extract-cd/README.TXT
	CKERNEL=$(echo "${KERNEL}" | sed 's/edit//g' | sed 's/boot//g' | sed 's/vmlinuz//g' | sed 's/\///g')
	if [[ "${CKERNEL}" ]]; then
		Encapsulate "KERNEL: ${CKERNEL}"
		echo "KERNEL: ${CKERNEL}" >> extract-cd/README.TXT
	fi
	if [[ "${LTS}" != "NO" || "${GREPIT}" ]]; then
		Encapsulate "LTS (Long term supported): Yes"
		echo "LTS (Long term supported): Yes" >> extract-cd/README.TXT
	else
		Encapsulate "LTS (Long term supported): No"
		echo "LTS (Long term supported): No" >> extract-cd/README.TXT
	fi
	if [[ ${HOSTNAME} ]]; then
		Encapsulate "DATA PREPARER: <${NUSER}@${HOSTNAME}>"
		echo "Data Preparer: <${NUSER}@${HOSTNAME}>" >> extract-cd/README.TXT
	else
		Encapsulate "DATA PREPARER: ${NUSER}"
		echo "Data Preparer: ${NUSER}" >> extract-cd/README.TXT
	fi
	Encapsulate "DATA PUBLISHER: TMOSB <http://os-builder.com/>"
	echo "Data Publisher: TMOSB <http://os-builder.com/>" >> extract-cd/README.TXT
	echo "Type: ${DEBTYPE^}" >> extract-cd/README.TXT
	Encapsulate "Type: ${DEBTYPE^}"
	if [[ -f "edit/etc/skel/.dmrc" ]]; then
		DEFAULTSESSION=$(grep -i "session" "edit/etc/skel/.dmrc" | tr '[:upper:]' '[:lower:]' | sed 's/session=//g')
		DEFAULTSESSION="${DEFAULTSESSION^}"
		if [[ "${DEFAULTSESSION}" ]]; then
			Encapsulate "Default Desktop Environment(DE): ${DEFAULTSESSION}"
			echo "Default Desktop Environment(DE): ${DEFAULTSESSION}" >> extract-cd/README.TXT
		else
			Encapsulate "Default Desktop Environment(DE): UNKNOWN / NONE (MINIMAL SERVER)"
			echo "Default Desktop Environment(DE): UNKNOWN / NONE (MINIMAL SERVER)" >> extract-cd/README.TXT
		fi
	else
		Error "No dmrc in the skelaton."
	fi
	if [[ "${BUILDALL}" ]]; then
		DTYPE=""
		for DSTTYPE in "${UETYPES[@]}"
		do
			GREPIT=$(echo "${PWD}" | grep -i "$DSTYPE")
			if [[ "${GREPIT}" ]]; then
				DTYPE="${DSTTYPE}"
			fi
		done
		if ! [[ "${DTYPE}" ]]; then
			DTYPE="mate"
		fi
		ARCHTECH=""
		for ARCHTECH in "${CYCLE[@]}"
		do
			GREPIT=$(echo "${PWD}" | grep -i "${ARCHTECH}")
			if [[ "${GREPIT}" ]]; then
				ARCH="${ARCHTECH}"
			fi
		done
		SOURCE="${ISO}"
		#DESTINATION=$(basename ${ISO})
		GREPIT=$(echo "${DESTINATION}" | grep -i "ultimate")
		if ! [[ "${GREPIT}" ]]; then
			DESTINATION="ultimate-edition"
		fi
		DESTINATION+="-${CVERSION}"
		DESTINATION+="-${ARCH}"
		if [[ "${DTYPE}" ]]; then
			DESTINATION+="-${DTYPE}"
		else
			DESTINATION+=$(basename ${ISO})
		fi
		if [[ "${DEFAULTSESSION}" ]]; then
			DECAPITOLIZE=$(echo "${DEFAULTSESSION}" | tr '[:upper:]' '[:lower:]')
			DESTINATION+="-${DECAPITOLIZE}"
		fi
		DESTINATION+=".iso"
		ISO="${DESTINATION}"
		if [[ "${DEBUG}" ]]; then
			echo "SOURCE:$SOURCE | DESTINATION:${STAGE}/${DESTINATION} | DEST FILENAME:${DESTINATION} ISO: ${ISO}"
		fi
	fi

	#SUPPRESS=$(mv "$SOURCE" "${STAGE}/${DESTINATION}")

	Encapsulate "ISONAME: ${ISO}"
	echo "Isoname: ${ISO}" >> "extract-cd/README.TXT"
	Encapsulate "Installed Size: ${DISKSIZE} bytes."
	echo "Installed Size: ${DISKSIZE} bytes." >> extract-cd/README.TXT
	cat "extract-cd/.disk/info" >> "extract-cd/README.TXT"
	# CacheInfo ${DIST} suppress
	# echo "Build cache:" >> extract-cd/README.TXT
	# CacheInfo ${DIST} suppress
	if [[ -f "extract-cd/.disk/tmosb-${VERSION}-build-logs.tar.gz" ]]; then
		BUILDLOGS="extract-cd/.disk/tmosb-${VERSION}-build-logs.tar.gz"
		echo "Build logs: $BUILDLOGS"  >> extract-cd/README.TXT
	fi
	COUNTDOTS=$(echo "${CVERSION}" | grep -c -o "\.")
	if [[ "${COUNTDOTS}" -gt 1 ]]; then
		# echo "DETECTED A LTS THAT IS GREATER THEN 2 DIGITS"
		LONGVERSION="${CVERSION}"
		CVERSION="${CVERSION%.*}"
	else
		CVERSION="${CVERSION}"
	fi
	echo "URL: http://ultimateedition.info/Ultimate_Edition_${CVERSION}/"  >> extract-cd/README.TXT
	echo ""  >> extract-cd/README.TXT
	echo "Please note: The above url, may not work if the release has not been made public." >> extract-cd/README.TXT
	echo ""  >> extract-cd/README.TXT
	echo "Destination Distribution Software" >> extract-cd/README.TXT
	echo "=================================" >> extract-cd/README.TXT
	dpkg -l >> "extract-cd/README.TXT"

	#calculate crc
	Encapsulate "Calculating CRC (Cyclic Redundancy Check):"
	if [[ -f "extract-cd/md5sum.txt" ]]; then
		rm "extract-cd/md5sum.txt"
	fi
	cd extract-cd && find . ! -name 'md5sum.txt' -type f -print0 | xargs -0 md5sum > md5sum.txt
	Encapsulate "Done."
	FullBar
	# FINALLY BUILD
	LIMITED=$(echo "$*" | grep -i "limited")
	if [[ "${LIMITED}" ]]; then
		LIMITED="-allow-limited-size"
		ISOTYPE="-iso-level 3"
	fi
	if ! [[ "${LIMITED}" ]]; then
		mkisofs -r -V "${OUTDISTRO} ${CVERSION}" -preparer "${NUSER}" -publisher "TMOSB" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o ../"${ISO}" .
	else
		Encapsulate "Unlimited switch detected."
		Encapsulate "Please note: this ISO most likely will not fit on a DVD."
		Encapsulate "Proceeding as requested."
	mkisofs -iso-level 3 -r -V "${OUTDISTRO} ${CVERSION}" -preparer "${NUSER}" -publisher "TMOSB" -cache-inodes -allow-limited-size -udf -J -l -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -c isolinux/boot.cat -o ../"${ISO}" .
	fi
	cd ..
	if [[ -f "${ISO}" ]]; then
		FullBar
		Center "DISTRO INFO:"
		cat edit/etc/lsb-release
		Center "External Dist Info:"
		cat extract-cd/.disk/info
		FullBar
		if [[ "${BUILDALL}" ]]; then
			SOURCE="${ISO}"
			DESTINATION=$(basename ${ISO})
			GREPIT=$(echo "${DESTINATION}" | grep -i "ultimate")
			if ! [[ "${GREPIT}" ]]; then
				DESTINATION="ultimate-edition"
				DESTINATION+=$(basename ${ISO})
			fi
			echo "SOURCE:$SOURCE | DESTINATION:${STAGE}/${DESTINATION} | DEST FILENAME:${DESTINATION}"
			SUPPRESS=$(mv "$SOURCE" "${STAGE}/${DESTINATION}")
		fi
		Encapsulate "SUCCESSFULLY BUILT: ${ISO} in ${PWD}"
		if ! [[ "${BUILDALL}" ]]; then
			Encapsulate "Moving ${ISO} back to ../"
			SUPPRESS=$(mv "${ISO}" "../")
			Encapsulate "tmosb --test ${ISO}"
			Encapsulate "To test, if you are satisfied."
			PromptYN "Would you like to test ${ISO} now in a virtual machine? (Y/N) "
			case "${YN}" in
				[Nn]* ) echo -e "${TXTRST}"; exit 0;;
				[Yy]* ) echo -e "${TXTGRN}";
				FullBar;
				Center "Testing build of ${2} ...";;
				* ) echo "Please answer y or n.";;
			esac
			tmosb --test "${ISO}"
			exit 0;
		fi
		if [[ "${BUILDALL}" ]]; then
			if [[ -d "${STAGE}" ]]; then
				cd "${STAGE}" || exit 1;
			fi
			if [[ -f "${ISO}" ]]; then
				FTS=$(basename "${ISO}" | sed "s/\.iso//g")
				if [[ -d "${FTS}/" ]]; then
					echo "Scrapping folder: ${FTS}/ in ${PWD} to save space for future builds."
					rm -R "${FTS}/"
				else
					echo "Folder NOT found: ${FTS}/ in ${PWD}"
				fi
			else
				echo "ISO Build failure: ${ISO}"
			fi
		fi
		FullBar
	else
		Error "ERROR: BUILD FAILURE FOR ${ISO}"
		Encapsulate "Did you try compression=maximum"
		exit 1;
	fi
	#LogResults
	Timer "Stop" "BuildISO"
	if [[ -d "${CURRENT}" ]]; then
		cd "${CURRENT}" || exit 1
	fi
	if ! [[ "${BUILDALL}" ]]; then
		if [[ "${DISPLAY}" ]]; then
			if [[ "${QEMUINSTALLED}" ]]; then
				if ! [[ "${PROMPT}" ]]; then
						FullBar
						PromptYN "Would you like to test the drive now in a virtual machine?. (Y/N)? "
						case "${YN}" in
							[Nn]* ) echo -e -n "${TXTRST}"; Encapsulate "If you would like to customise your distro:"; echo -e "${TXTGRN}${PROGNAME} --modify ${FOLDER}${TXTRST}"; Notification "All operations completed successfully."; 								exit 0;;
							[Yy]* ) echo -e "${TXTGRN}"
							echo "Booting ${2}...";;
							* ) echo "Please answer y or n.";;
						esac
					tmosb --test "${ISO}"
				fi
			fi
		else
			Encapsulate "No X11 session installed, skiping prompting for testing."
		fi
	fi
	NUSER=$(grep 1000 /etc/passwd | cut -f1 -d:)
	X=$( pidof X )
	if [[ -f "/home/${NUSER}/.config/caja/scripts/ThumbOS" && "$X" ]]; then
		# Does enduser have Thumbos >= 1.1.0 installed?
		Encapsulate "ThumbOS greater then or equal to version 1.1.0 & X11 is running, initiating GUI version."
		THUMBOS="/home/${NUSER}/.config/caja/scripts/ThumbOS"
	else
		# Does enduser have Thumbos installed at all?
		if ! [[ "${BUILDALL}" ]]; then
			Encapsulate "ThumbOS less then version 1.1.0, initiating CLI version."
			THUMBOS=$(type -p thumbos)
		fi
	fi
	if [[ "${THUMBOS}" ]]; then
		if ! [[ "${PROMPT}" ]]; then
			FullBar
			PromptYN "Would you like to load the resulting O/S out to a thumbdrive? (Y/N)? "
			case "${YN}" in
				[Nn]* ) echo -e -n "${TXTRST}"; Encapsulate "If you would like to customise your distro:"; echo -e "${TXTGRN}${PROGNAME} --modify ${FOLDER}${TXTRST}"; Notification "All operations completed successfully."; exit 0;;
				[Yy]* ) echo -e "${TXTGRN}"
				echo "Initiatiating Thumbos ${2}...";;
					* ) echo "Please answer y or n.";;
			esac

			echo "THUMBOS: ${THUMBOS}"
			${THUMBOS} --load "${ISO}"
		fi
	fi
	echo -e -n "${TXTRST}";
	if ! [[ "${BUILDALL}" ]]; then
		Encapsulate "If you would like to customise your distro:"
		echo -e "${TXTGRN}${PROGNAME} --modify ${FOLDER}${TXTRST}"
		Encapsulate "After customization to build your final product:"
		echo "tmosb --buildiso ${FOLDER}"
		APACHE=$(type -p apache2)
		if [[ "${APACHE}" ]]; then
			Encapsulate "Apache server detected: tmosb --release ${FOLDER}.iso to release to the world."
		fi
	fi
	Notification "All operations completed successfully.";
}

# begin building all operating systems automously.
# Dump vaild build switches & build w/o prompting.
BuildAll () {
	UE="ultimate-edition"
	UBUNTUBASE="ubuntu-desktop"
	ARCH32='x86'
	ARCH64='x64'
	ARCHARM='armel'
	ARCHHF='armhf'
	ARCHPOWERPC='powerpc'
	LITE='lite'
	OUTDISTRO="Ultimate Edition"
	ENVIRONMENTS=$(echo "$@" | grep -i "ENVIRONMENTS")
	echo -e -n "${TXTGRN}"
	for EACH in "${UEONLY[@]}"
	do
		TESTCONDITION=$(echo "$@" | grep -i "${EACH}")
		if [[ "${TESTCONDITION}" ]]; then
			SERIES="${EACH}"
			Center "BUILDALL SERIES REQUESTED AT: ${EACH}"
		fi
	done
	counter=0
	for OST in "${UEONLY[@]}"
	do
		if [[ "$SERIES" ]]; then
			OST="$SERIES"
		fi
		#echo "Checking: ${OST}"
		VER=$(echo "${OST}" | cut -d "." -f2)
		EVENODD=$(( VER % 2 ))
		DIST="${UEONLY[$counter]}"
		FULLNAME="${UEDISTARRAY[$counter]}"
		counter=$((counter + 1))

		# Check to see if release is Long Term Supported.
		LTS="NO"
		for zx in "${ISLTS[@]}"
		do
			if [[ "${OST}" == "${zx}" && ${LTS} == 'NO' ]]; then
				LTS="YES"
			fi
		done

		#echo "VERSION: $VER"
		if [[ $VER == '04' ]]; then
			OUTDISTRO="Ubuntu"
		fi

		if ! [[ ${EVENODD} -eq 0 ]]; then
			DTYPE='STANDARD'
			DE="kde"
		else
			DTYPE='LITE/STANDARD'
			DE="mate"
		fi
		echo -e -n "${TXTRST}"
		if [[ -d "${CURRENT}" ]]; then
			cd "${CURRENT}" || exit 1;
		fi
		if [[ "$counter" -lt "${DISTSSUPPORTED}" ]]; then
			if [[ "${EVENODD}" ]]; then
				for EACH in "${UETYPES[@]}"
				do
					if ! [[ $GREPIT ]]; then
						if ! [[ "${ENVIRONMENTS}" ]]; then
							# Encapsulate "Building: ${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH32}-${EACH}.iso"
							if ! [[ -f "${UE}-${OST}-${ARCH32}-${EACH}-${DE}.iso" ]]; then
								mkdir -p "${UE}-${OST}-${ARCH32}-${EACH}-${DE}"
							fi
							# Encapsulate "Building: ${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH64}-${EACH}.iso"
							if ! [[ -f "${UE}-${OST}-${ARCH64}-${EACH}-${DE}.iso" ]]; then
								mkdir -p "${UE}-${OST}-${ARCH64}-${EACH}-${DE}"
							fi
							TOTALOS=$((TOTALOS +2))
						else
							for ENVS in "${EXTRADE[@]}"
							do
								if ! [[ -f "${UE}-${OST}-${ARCH32}-${EACH}-${ENVS}.iso" ]]; then
									mkdir -p "${UE}-${OST}-${ARCH32}-${EACH}-${ENVS}"
								fi
								# Encapsulate "Building: ${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH64}-${EACH}.iso"
								if ! [[ -f "${UE}-${OST}-${ARCH64}-${EACH}-${ENVS}.iso" ]]; then
									mkdir -p "${UE}-${OST}-${ARCH64}-${EACH}-${ENVS}"
								fi
								TOTALOS=$((TOTALOS +2))
							done
						fi
					else
						#echo "${UE}-${OST}-${ARCH32}-${EACH}.iso"
						echo "${UE}-${OST}-${ARCH64}-${EACH}.iso"
					fi
				done
				if ! [[ "${GREPIT}" ]]; then
					# Encapsulate "Building: ${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH64}.iso"
					if ! [[ -d "${UE}-${OST}-${ARCH64}-${DE}" ]]; then
						mkdir -p "${UE}-${OST}-${ARCH64}-${DE}"
					fi
					# Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH32}.iso"
					if ! [[ -d "${UE}-${OST}-${ARCH32}-${DE}" ]]; then
						mkdir -p "${UE}-${OST}-${ARCH32}-${DE}"
					fi
					# Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH}ARM.iso"
					# Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH}HF.iso"
					# Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH}POWERPC.iso"
					TOTALOS=$((TOTALOS +5))
					#else
					#echo "${UE}-${OST}-${ARCH64}.iso"
					#echo "${UE}-${OST}-${ARCH32}.iso"
					#echo "${UE}-${OST}-${ARCH}ARM.iso"
					#echo "${UE}-${OST}-${ARCH}HF.iso"
					#echo "${UE}-${OST}-${ARCH}POWERPC.iso"
				fi
			else
				if ! [[ "${GREPIT}" ]]; then
					#Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH32}.iso"
					if ! [[ -d "${UE}-${OST}-${ARCH64}-${DE}" ]]; then
						mkdir -p "${UE}-${OST}-${ARCH64}-${DE}"
					fi
					# Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH32}.iso"
					if ! [[ -d "${UE}-${OST}-${ARCH32}-${DE}" ]]; then
						mkdir -p "${UE}-${OST}-${ARCH32}-${DE}"
					fi
					#Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH}ARM.iso"
					#Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH}HF.iso"
					#Encapsulate "${PROGNAME} ${CBE} ${UE}-${OST}-${ARCH}POWERPC.iso"
					TOTALOS=$((TOTALOS +5))
					#else
					#echo "${UE}-${OST}-${ARCH32}.iso"
					#echo "${UE}-${OST}-${ARCH64}.iso"
					#echo "${UE}-${OST}-${ARCH}ARM.iso"
					#echo "${UE}-${OST}-${ARCH}HF.iso"
					#echo "${UE}-${OST}-${ARCH}POWERPC.iso"
				fi
			fi
		else
			if ! [[ "${GREPIT}" ]]; then
				#Encapsulate "${PROGNAME} ${CBE} ${UBUNTUBASE}-${OST}-${ARCH32}.iso"
				#Encapsulate "${PROGNAME} ${CBE} ${UBUNTUBASE}-${OST}-${ARCH64}.iso"
				#Encapsulate "${PROGNAME} ${CBE} ${UBUNTUBASE}-${OST}-${ARCH}ARM.iso"
				#Encapsulate "${PROGNAME} ${CBE} ${UBUNTUBASE}-${OST}-${ARCH}HF.iso"
				#Encapsulate "${PROGNAME} ${CBE} ${UBUNTUBASE}-${OST}-${ARCH}POWERPC.iso"
				TOTALOS=$((TOTALOS +5))
				#else
				#echo "${UBUNTUBASE}-${OST}-${ARCH32}.iso"
				#echo "${UBUNTUBASE}-${OST}-${ARCH64}.iso"
				#echo "${UBUNTUBASE}-${OST}-${ARCH}ARM.iso"
				#echo "${UBUNTUBASE}-${OST}-${ARCH}HF.iso"
				#echo "${UBUNTUBASE}-${OST}-${ARCH}POWERPC.iso"
			fi
			#array_counter=$(($array_counter + 1))
		fi
		#array_counter=$(($array_counter + 1))
	done
	FOLDERS=(*/)
	for OS in "${FOLDERS[@]}"
	do
		if [[ "${DEBUG}" ]]; then
			#NOWOS=(( NOWOS +1 ))
			echo "Building ${OS} 1 of ${TOTALOS}"
			#exit 1;
		fi
		if [[ -d "${OS}" ]]; then
			BuildNEWISO "${OS}.iso"
		fi
		echo "SCANNING FOR ${OS}.ISO IN ${PWD}"
		if [[ -d "$TAGE" ]]; then
			cd "${STAGE}" || exit 1;
			echo "FOLDER CHANGED to ${PWD} SCANNING FOR ${OS}.ISO"
		fi
	done
}

BuildItNow () {
	GAMERS=$(echo "$*" | grep -i "gamers")
	RAW=$(echo "$*" | grep -i "raw")
	SERVER=$(echo "$*" | grep -i "server")
	MSERVER=$(echo "$*" | grep -i "minimal-server")
	DEVELOPER=$(echo "$*" | grep -i "developer")
	LITE=$(echo "$*" | grep -i "lite")
	SETDEFAULT=$(echo "$*" | grep -i "defaultde=")
	COUNTDOTS=$(echo "${CVERSION}" | grep -c -o "\.")
	if [[ "${COUNTDOTS}" -gt 1 ]]; then
		#echo "DETECTED A LTS THAT IS GREATER THEN 2 DIGITS"
		LONGVERSION="${CVERSION}"
		CVERSION="${CVERSION%.*}"
	fi
	EVENODD="${CVERSION##*.}"
	#echo "DEBUGGING: ${EVENODD}"

	if [[ "${GAMERS}" ]]; then
		DTYPE="GAMERS"
		if ! [[ "${DE}" ]]; then
			DE="mate"
		fi
	fi

	if [[ "${SERVER}" ]]; then
		DTYPE="SERVER"
		if ! [[ "${DE}" ]]; then
			DE="mate"
		fi
	fi

	if [[ "${MSERVER}" ]]; then
		DTYPE="MINIMAL SERVER"
		DE="NONE"
	fi

	if [[ ${LITE} ]]; then
		DTYPE="LITE"
		if ! [[ "${DE}" ]]; then
			DE="mate"
		fi
	fi

	if [[ "${DEVELOPER}" ]]; then
		DTYPE="DEVELOPER"
		DE="mate"
	fi

	if ! [[ "${DEBTYPE}" ]]; then
		DEBTYPE="standard"
	fi
	if [ $((EVENODD%2)) -eq 0 ]; then
		if ! [[ "${DTYPE}" ]]; then
			DTYPE='STANDARD'
		fi
		if ! [[ "${DE}" ]]; then
			DE="gnome"
		fi
	fi
	# Last second adjustment if the user has opted for a defaultde
	COMMANDISSUED=$(echo "$*" | tr '[:upper:]' '[:lower:]')
	SETDEFAULT=$(echo "${COMMANDISSUED}" | grep -i "defaultde=")
	if [[ "${SETDEFAULT}" ]]; then
		DEFAULTDE=$(echo "${COMMANDISSUED}" | grep -i "defaultde=" | sed 's/^.*defaultde=//g' | cut -d' ' -f1)
		if [[ "${DEFAULTDE}" ]]; then
			Encapsulate "Default Desktop Environment (DE) specified as: ${DEFAULTDE}"
		fi
	fi
	if [[ "${DEFAULTDE}" ]]; then
		DE="${DEFAULTDE}"
	fi
	Center "Operating System pre-build information for: ${2}"
	DE=${DE// /}
	#DE=$(echo "${DE}" | sed "s/^, //g")
	echo -e -n "${TXTGRN}"
	FullBar
	TColumnize -t "OPERATING SYSTEM" "VERSION" "RELEASE BASE" "ARCH" "LTS" "TYPE" "DE(s)" "COMPRESSION"
	if ! [[ "${COMPRESSION}" ]]; then
		COMPRESSION="DEFAULT"
	fi
	if [[ "${LONGVERSION}" != "${CVERSION}" ]]; then
		if [[ "${DEBUG}" ]]; then
			echo "DEBUGGING LONGVERSION: ${LONGVERSION}"
		fi
		VEROUT="${CVERSION}"
		VEROUT+=" ("
		VEROUT+="${LONGVERSION}"
		VEROUT+=")"
		TColumnize "${OUTDISTRO}" "${VEROUT}" "${FULLNAME}" "${ARCH}" "${LTS}" "${DTYPE}" "${DE}" "${COMPRESSION^^}"
	else
		TColumnize "${OUTDISTRO}" "${CVERSION}" "${FULLNAME}" "${ARCH}" "${LTS}" "${DTYPE}" "${DE}" "${COMPRESSION^^}"
	fi
	PROMPT=$(echo "$*" | grep -i "YES")
	if ! [[ "${PROMPT}" ]]; then
	Encapsulate "Is the above correct?"
	FullBar
			PromptYN "${WARNING}WARNING: ${TXTRED}this will take a long time and download vast quantanties of data. (Y/N)? "
			case "${YN}" in
				[Nn]* ) echo -e "${TXTRST}"; exit 0;;
				[Yy]* ) echo -e "${TXTGRN}";
				FullBar;
				Center "Initiating build of ${2} ...";
				FullBar;;
				* ) echo "Please answer y or n.";;
			esac
	else
		FullBar
	fi
	if [[ "${COMPRESSION}" == "DEFAULT" ]]; then
		COMPRESSION=""
	fi
	if ! [[ -d "${CACHINGFOLDER}/${BASEPULL}/apt/" ]]; then
		mkdir -p "${CACHINGFOLDER}/${DIST}/${ARCH}/apt/"
	fi

	### CORE FILES ? ###
	GAMERS=$(echo "$*" | grep -i "gamers")
	SERVER=$(echo "$*" | grep -i "server")
	MSERVER=$(echo "$*" | grep -i "minimal-server")
	LITE=$(echo "$*" | grep -i "lite")
	if [[ "${GAMERS}" ]]; then
		DEBTYPE="gamers"
	fi
	if [[ "${SERVER}" ]]; then
		DEBTYPE="server"
	fi
	if [[ "${MSERVER}" ]]; then
		DEBTYPE="minimal-server"
	fi
	if [[ "${LITE}" ]]; then
		DEBTYPE="lite"
	fi
	if ! [[ "${DEBTYPE}" ]]; then
		DEBTYPE=$(echo "${DTYPE}" | tr '[:upper:]' '[:lower:]')
	fi
	SETDEFAULT=$(echo "$*" | grep -i "defaultde=")
	if [[ -s "${CACHINGFOLDER}/${DIST}/ultimate-edition-${CVERSION}-${DEBTYPE}-core-files.deb" && "${SETDEFAULT}" == "" ]]; then
		Encapsulate "Pulling core files from cache."
		cp "${CACHINGFOLDER}/${DIST}/ultimate-edition-${CVERSION}-${DEBTYPE}-core-files.deb" .
	else

		BuildCoreFiles "$*"
		CURRENTBUILD="${PWD}"
	fi
	#if ! [[ -d ${FILENAME} ]]; then mkdir ${FILENAME}; fi
	#cd ${FILENAME}
	mkdir -p {edit,extract-cd}
	CURRENTBUILD="${PWD}"
	if ! [[ -f ""extract-cd/README.diskdefines"" ]]; then
		if ! [[ -f "${CACHINGFOLDER}/extract-cd.tar.gz" ]]; then
			Encapsulate "Downloading a generic extract-cd contents..."
			cd "extract-cd/" || exit 1
			Download "http://os-builder.com/Toolz/extract-cd.tar.gz"
			if [[ -f "extract-cd.tar.gz" ]]; then
				mkdir -p "${CACHINGFOLDER}/"
				cp extract-cd.tar.gz "${CACHINGFOLDER}/"
			else
				Error "http://os-builder.com/Toolz/extract-cd.tar.gz file not found."
				exit 1
			fi
		else
			Center "Pulling archive from cache, this saves you from having to re-download it."
		cd "${CURRENTBUILD}"
		if [[ -d "extract-cd" ]]; then
				cd "extract-cd/" || exit 1
		else
				echo "DEBUG: failure in ${PWD}"
			fi
			mkdir -p "${CACHINGFOLDER}/"
			cp "${CACHINGFOLDER}/extract-cd.tar.gz" .
		fi
		Encapsulate "Extracting archive:"
		SUCCESS=$(tar xfv "extract-cd.tar.gz" 2>/dev/null)
		sync
		if [[ -f "extract-cd.tar.gz" ]]; then
			chown root:root -R ./*
		else
			Error "No extract-cd.tar.gz, exiting. DEBUG: Infolder ${PWD}"
		fi
		if [[ "${SUCCESS}" ]]; then
			Encapsulate "Success."
		else
			Error "ERROR in extraction."
			exit 1;
		fi
		if [[ -f "extract-cd.tar.gz" ]]; then
			Encapsulate "Backing up extract-cd.tar.gz to Cache."
			cp extract-cd.tar.gz "${CACHINGFOLDER}/"
		else
			Error "No extract-cd.tar.gz.  DEBUG: Infolder: ${PWD}"
			exit 1
		fi
		if [[ -f "extract-cd.tar.gz" ]]; then
			Encapsulate "Cleaning up extract cd archive."
			rm "extract-cd.tar.gz"
		fi
		cd "${CURRENTBUILD}" || exit 1
		#mv isolinux/txt.cfg isolinux/isolinux.cfg
		if [[ -d "extract-cd/" ]]; then
			find "extract-cd/" -type d -exec chmod 755 {} \;
			chmod 644 extract-cd/isolinux/* extract-cd/autorun.inf extract-cd/logo.ico
		else
			Error "No extract-cd/ folder, exiting. DEBUG: Infolder: ${PWD}"
			exit 1;
		fi
	else
		Encapsulate "Previous build detected, not downloading the extract-cd contents."
	fi
	FullBar
	Encapsulate "Operating System Output: ${OUTDISTRO}"
	Encapsulate "Operating System version requested: ${CVERSION}"
	Encapsulate "Operating System distribution base: ${DIST}"
	BASE="${DIST}"
	Encapsulate "Architecture requested: ${ARCH}"
	Encapsulate "Distribution Long Name: ${FULLNAME}"
	FullBar
	if [[ "${IUSER}" != "root" && "${TRUEROOT}" != "0" ]]; then
		if [[ "${USETHEFORCE}" ]];then
			Encapsulate "${IUSER}, using the force Luke."
		else
			Error "ERROR: This operation requires true root (su) access."
			Encapsulate "sudo passwd, to create a superuser account."
			Encapsulate "su, to login.  Then re-execute command."
			FullBar
			exit 0;
		fi
	fi

	#PREVIOUS MINIMAL ISO & NO EDIT/
	if ! [[ "${ARCH}" && "${DIST}" ]]; then
		Error "DEBUG ARCH: ${ARCH} DIST:${DIST}"
		exit 1;
	fi
	if [[ -f "${CACHINGFOLDER}/${DIST}/${ARCH}/debootstrap.tar.gz" ]]; then
		Center "Debootstrap has been previously backed up to cache."
		if ! [[ -f "edit/etc/lsb-release" ]]; then
			Encapsulate "Pulling bootstrap from cache:"
			cp "${CACHINGFOLDER}/${DIST}/${ARCH}/debootstrap.tar.gz" .
			if [[ -f "debootstrap.tar.gz" ]]; then
				Encapsulate "Success."
			else
				Error "FAILURE. Corrupt tar? ${PROGNAME} --cleancache"
			fi
			Encapsulate "Extracting archive:"
			SUCCESS=$(tar -xf debootstrap.tar.gz 2>/dev/null)
			if [[ -f "edit/etc/lsb-release" ]]; then
				Encapsulate "Success."
			else
				Error "FAILURE. Corrupt tar? ${PROGNAME} --cleancache"
				exit 1;
			fi
		else
			Encapsulate "Prior debootstrap / build exists for ${DIST} ${ARCH} build."
		fi
	else
		Encapsulate "Prior debootstrap / build does not exist for ${DIST} ${ARCH} build. First build?"
	fi
	Timer "Start" "Debootstrap"
	if ! [[ -f "edit/etc/lsb-release" ]]; then
		if [[ "${ARCH}" && "${DIST}" ]]; then
			#debootstrap --arch=armhf --verbose --foreign trusty edit/
			#chroot edit /bin/bash /debootstrap/debootstrap --second-stage
			#cp /usr/bin/qemu-arm-static edit/usr/bin
			BARCH="${ARCH}"
			for EACHARCH in "${UEARCH[@]}";
			do
				TESTIT=$(echo "$@" | grep -i "${EACHARCH}")
				if [[ "${TESTIT}" ]]; then
					if [[ "${DEBUG}" ]]; then
						echo "DEBUG: Stage 1 (debootstrap), not done."
						echo "DEBUG: Architecture Detected as: ${EACHARCH}"
					fi
					ARCH="${EACHARCH}"
				else
					if [[ "${DEBUG}" ]]; then
						echo "DEBUG: Stage 1 (debootstrap), not done."
						echo "DEBUG: Architecture is NOT: ${EACHARCH}"
					fi
				fi
			done
			if [[ "${ARCH}" == "x64" ]]; then
				BARCH="amd64"
			else
				BARCH="i386"
			fi
			FOREIGN=""
			case "${ARCH}" in
				armel)FOREIGN=$(echo "${ARCH}" | grep "arm");;
				armhf)FOREIGN=$(echo "${ARCH}" | grep "arm");;
				powerpc)FOREIGN=$(echo "${ARCH}" | grep "powerpc");;
				powerpc-smp)FOREIGN=$(echo "${ARCH}" | grep "powerpc-smp");;
				*)if [[ "${CURRENTARCH}" == "i386" && ${ARCH} == "amd64" || "${ARCH}" == "AMD64" ]]; then FOREIGN="amd64"; else FOREIGN=""; fi;;
			esac
			if [[ "${FOREIGN}" ]]; then
				Encapsulate "Foreign architecture: ${FOREIGN} detected."
				case "${FOREIGN}" in
					powerpc)debootstrap --components=main,contrib,nonfree --arch="${ARCH}" --foreign "${DIST}" "edit";;
					armel)debootstrap --components=main,contrib,nonfree --arch="${ARCH}" --foreign "${DIST}" "edit";;
					armhf)debootstrap --components=main,contrib,nonfree --arch="${ARCH}" --foreign "${DIST}" "edit";;
					*)Encapsulate "ARCH: ${ARCH} | FOREIGN: ${FOREIGN}, exiting."; exit 1;;
				esac
				FullBar
			else
				Encapsulate "Native architecture detected."
				#Encapsulate "DEBUG ARCH:${BARCH} DIST:${DIST}"
				#Encapsulate "IN FOLDER: ${PWD}"
				FullBar
				debootstrap --components=main,contrib,nonfree --variant=minbase --arch="${BARCH}" "${DIST}" "edit"
				#debootstrap --components=main,contrib,nonfree --variant=minbase --include=linux-generic,grub-pc --arch="${BARCH}" "${DIST}" "edit"
			fi
			FullBar
			if ! [[ -f "edit/bin/bash" ]]; then
				Error "Epic Failure: Debootstrap has failed, exiting."
				exit 1;
			fi
			## Initiate debootstrap process...

			case "${FOREIGN}" in
				armel) Center "Inserting ARM support into chroot environment.";
					if [[ -f "/usr/bin/qemu-system-arm" ]]; then
						Encapsulate "Inserting support for arm from ${PWD}";
						cp /usr/bin/qemu-system-arm edit/bin/ ;
					else
						Error "Qemu is not installed on host machine, exiting.";
						exit 0;
					fi;;
				armhf) Center "Inserting ARM support into chroot environment.";
					if [[ -f "/usr/bin/qemu-system-arm" ]]; then
						Encapsulate "Inserting support for arm from ${PWD}";
						cp /usr/bin/qemu-system-arm edit/bin/ ;
					else
						if [[ -f "/usr/bin/qemu-system-arm" ]]; then
							Encapsulate "Inserting support for arm from ${PWD}";
							cp "/usr/bin/qemu-system-arm edit/bin/"
						else
							Error "Qemu is not installed on host machine, exiting.";
							exit 1;
						fi
					fi;;
				powerpc) Center "Inserting PowerPC support into chroot environment.";
					if [[ -f "/usr/bin/qemu-arm-static" ]]; then
						Encapsulate "Inserting support for PPC from ${PWD}";
						cp /usr/bin/qemu-ppc-static edit/bin/ ;
					else
						Error "Qemu is not installed on host machine, exiting.";
						exit 1;
					fi;;
				powerpc-smp) Center "Inserting PowerPC support into chroot environment.";
					if [[ -f "/usr/bin/qemu-arm-static" ]]; then
						Encapsulate "Inserting support for PPC from ${PWD}";
						cp /usr/bin/qemu-ppc-static edit/bin/ ;
					else
						Error "Qemu is not installed on host machine, exiting.";
						exit 1;
					fi;;
				*) Encapsulate "${ARCH} support is native."; NATIVE=1;;
			esac
			if ! [[ "${NATIVE}" ]]; then
				if [[ -f "edit/debootstrap/debootstrap" ]]; then
					Encapsulate "Please note: Continuing debootstrap process, for non-native architecture."
					if [[ -f "edit/bin/bash" ]]; then
						chroot edit /bin/bash /debootstrap/debootstrap --second-stage
					else
						Error "Failure: we did not find: edit/bin/bash from ${PWD}"
						exit 1
					fi
				else
					if [[ -f "edit/etc/lsb-release" ]]; then
						Error "FATAL ERROR: no debootstrap to continue for foreign architecture, exiting."
						exit 1;
					else
						Error "Can't continue second stage of debootstrap."
					fi
				fi
			fi
			# Final check of debootstrap completion.
			if ! [[ -f "edit/etc/lsb-release" ]]; then
				Error "CRITICAL ERROR: Debootstrap failed."
				Encapsulate "DEBUG: DIST | ${DIST} ARCH | ${ARCH}"
				exit 1;
			fi

			Encapsulate "Compressing debootstrap:"
			SUCCESS=$(tar -zcvf debootstrap.tar.gz edit)
			if [[ "${SUCCESS}" ]]; then
				Encapsulate "Successfully compressed."
				sync
				Encapsulate "Moving debootstrap.tar to cache."
				mkdir -p "${CACHINGFOLDER}/${DIST}/${ARCH}/"
				mv debootstrap.tar.gz "${CACHINGFOLDER}/${DIST}/${ARCH}/"
				Timer "Stop" "Debootstrap"
				Encapsulate "This caching process will save you aprox ${TTIMEM} in future builds."
			else
				Error "FAILURE. Corrupt tar? tmosb --cleancache"
				exit 1;
			fi
		else
			Error "ERROR: Invalid switch please see ${PROGNAME} --help build / debootstrap"
			exit 1;
		fi
	else
		for EACHARCH in "${UEARCH[@]}";
		do
			TESTIT=$(echo "$@" | grep -i "${EACHARCH}")
			if [[ "${TESTIT}" ]]; then
				if [[ "${DEBUG}" ]]; then
					echo "DEBUG: Stage 1 (debootstrap), not done."
					echo "DEBUG: Architecture Detected as: ${EACHARCH}"
				fi
				ARCH="${EACHARCH}"
			else
				if [[ "${DEBUG}" ]]; then
					echo "DEBUG: Stage 1 (debootstrap), not done."
					echo "DEBUG: Architecture is NOT: ${EACHARCH}"
				fi
			fi
		done
		Encapsulate "Previous build detected, skipping Stage 1 (debootstrap)."
	fi

	if [[ "${RAW}" ]]; then
		Encapsulate "Raw switch engaged, exiting."
		Encapsulate "tmosb --modify ${FOLDER} to modify."
		FullBar
		WriteDiskInfo
		exit 0;
	fi

	# exit 0;
	# PULL ${2}, ${3} etc for extra DE's
	array_counter=0
	if ! [[ -f "edit/tmp/DE" ]]; then
		PROCESS=0;
		for var in "$@"
		do
			array_counter=$((array_counter + 1))
			# echo "Switch $array_counter: ${var}"
			CSWITCH=$(echo "${var}" | grep -i "iso")
			if [[ "${PROCESS}" == 1 ]]; then
				nested_array=0;
				for TE in "${EXTRADE[@]}"
				do
					DETC="${EXTRADE[$nested_array]}"
					# echo "Comparing ${DETC} to ${var}"
					GREPIT=$(echo "${var}" | grep " ")
					if ! [[ "${GREPIT}" ]]; then
						if [[ "${var}" == "${TE}" ]]; then
							echo "${var}" | tr '[:upper:]' '[:lower:]' >> "edit/tmp/DE"
						fi
					fi
					nested_array=$((nested_array + 1))
				done
			fi
			if [[ "${CSWITCH}" && "${PROCESS}" == 0 ]]; then
				PROCESS=1
			fi
		done
	fi
	if [[ "${DE}" ]]; then
		if ! [[ -f "edit/tmp/DE" ]]; then
			echo "${DE}" | tr '[:upper:]' '[:lower:]' > "edit/tmp/DE"
		fi
	else
		CENTER "${DEFAULTDE} IS BEING SET......................................"
		if [ "${LITE}" ]; then
			if ! [[ -f "edit/tmp/DE" ]]; then
				echo "MATE" > "edit/tmp/DE"
			fi
		fi

		if [ "${GAMERS}" ]; then
			if ! [[ -f "edit/tmp/DE" && "${DEFAULTDE}" ]]; then
				echo "MATE" > "edit/tmp/DE"
			else
				echo "${DEFAULTDE}" > "edit/tmp/DE"
			fi
		fi
		if [ "${SERVER}" ]; then
			if ! [[ -f "edit/tmp/DE" ]]; then
				echo "MATE" > "edit/tmp/DE"
			fi
		fi

		if [ "${MSERVER}" ]; then
			if ! [[ -f "edit/tmp/DE" ]]; then
				echo "NONE" > "edit/tmp/DE"
			fi
		fi

		if ! [[ "${LITE}" && "${GAMERS}" && "${ODD}" ]]; then
			if ! [[ -f "edit/tmp/DE" ]]; then
				echo "GNOME" > "edit/tmp/DE"
			fi
		fi

		if ! [[ "${EVENODD}" ]]; then
			if ! [[ -f "edit/tmp/DE" ]]; then
				echo "KDE" > "edit/tmp/DE"
			fi
		fi
	fi
	#exit 0;
	#PUSH CORE FILEZ into chroot
	#Core files previously built? TODO: ADD Check and retrieve.
	if [[ -f "edit/etc/issue" ]]; then
		COREINSTALLED=$(grep -i "ultimate" "edit/etc/issue")
	fi
	if [[ -d "${CURRENTBUILD}" ]]; then
		cd "${CURRENTBUILD}" || exit 1
	fi
	if ! [[ "${COREINSTALLED}" ]]; then
		KoreFilez
	fi
	FullBar
	PushCache "${DIST}" "${ARCH}"
	FullBar
	if [[ "${DTYPE}" ]]; then
		DTYPE=$(echo "${DTYPE}" | tr '[:upper:]' '[:lower:]')
	fi
	if [[ "${LITE}" ]]; then
		LITE="lite"
		if [[ -d "extract-cd/.disk/" ]]; then
			if [[ "${LTS}" ]]; then
				echo "${UOS} ${CVERSION} Lite LTS ${QUOTE}${FULLNAME}${QUOTE} - Release ${DOUT} (${DATECURRENT})" > "extract-cd/.disk/info"
			else
				echo "${UOS} ${CVERSION} Lite ${QUOTE}${FULLNAME}${QUOTE} - Release ${DOUT} (${DATECURRENT})" > "extract-cd/.disk/info"
			fi
			ISO="${OS}-${CVERSION}-${ARCH}-${LITE}.iso"
		else
			Error "Extract CD contents are non-existant, please contact TheeMahn <theemahn@gmail.com>"
			exit 1
		fi
	else
		LITE=''
		if [[ "${LTS}" ]]; then
			echo "Ultimate Edition ${CVERSION} LTS ${QUOTE}${FULLNAME}${QUOTE} - Release ${DOUT} (${DATECURRENT})" > "extract-cd/.disk/info"
		else
			echo "Ultimate Edition ${CVERSION} ${QUOTE}${FULLNAME}${QUOTE} - Release ${DOUT} (${DATECURRENT})" > "extract-cd/.disk/info"
		fi
		ISO="${OS}-${CVERSION}-${ARCH}.iso"
	fi
	#INFORMATION=$(cat "extract-cd/.disk/info")
	Encapsulate "Distribution: ${INFORMATION}"
	if [[ -d "${CURRENT}" ]]; then
		cd "${CURRENT}" || exit 1
	fi
	UpgradeISO "$@"
	Timer "Stop" "${APPNAME}"
	echo "If you would like to customise your distro:"; echo -e "${TXTGRN}${PROGNAME} --modify ${FOLDER}${TXTRST}"; echo "After customization to build your final product:"; echo "tmosb --buildiso ${FOLDER}"; echo "All operations completed successfully.";
	echo -e "${TXTGRN}Execution Time: ${TTIMEM}${TXTRST}"
	if ! [[ "${BUILDALL}" ]]; then
		exit 0;
	fi
}

BuildNEWISO () {
	GREPIT=$(echo "$*" | grep -i "suppress")

	if [[ "${GREPIT}" ]]; then
		InvalidBuildSwitch "$@"
		exit 1;
	fi
	if ! [[ "${BUILDALL}" ]]; then
		ID="${2}"
		if [[ "${3}" != "--no-cache" ]]; then
			CACHE="--cache"
		fi
		EXTENSION="${ID##*.}"
		FILENAME="${ID%.*}"
		if [[ -d "${2}" && -f "${2}.iso" ]]; then
			echo "Smash the ISO."
			exit 1;
		fi

		# DEBUGGING
		# echo "1:${1} 2:${2} 3:${3}"

		# UPGRADE ROUTINE - Did the user request an ISO? Does the ISO exist?
		# If so extract the ISO...

		if [[ -d "${ID}" ]]; then
			FILENAME="${2}"
			EXTENSION="FOLDER"
		fi
		#prepare


		# TODO: ADD CODE TO PREVENT FALURE FROM RETURNING FUNCTION VALUES [.ISO]

		if [[ "${FILENAME}" == "" ]]; then
			InvalidBuildSwitch "$@"
		else
			VersionDump
		fi

		#ISO Check
		if ! [[ "$EXTENSION" == 'iso' ]]; then
			FILENAME="${2}"
			CURRENTBUILD="${2}"
			mkdir -p "${2}"
		else
			CURRENTBUILD="${FILENAME}"
			mkdir -p "${FILENAME}"
		fi
	fi

	#Folder?
	if [[ -d "${CURRENT}" ]]; then
		cd "${CURRENT}" || exit 1
	fi

	#Multibuild? Number of O/S's to build.
	shopt -s nullglob
	declare -a NUMBERBUILD=();
	declare -i NUMBERTOBUILD
	NUMBERBUILD=(*/)
	NUMBERTOBUILD="${#NUMBERBUILD[@]}"
	if [[ "${BUILDALL}" ]]; then
		VersionDump
		Center "Autonomous mode detected building multiple Operating Systems"
		for EACH in "${UEONLY[@]}"
		do
			TESTCONDITION=$(echo "$@" | grep -i "${EACH}")
			if [[ "${TESTCONDITION}" ]]; then
				Center "BUILDALL SERIES REQUESTED AT: ${EACH}"
			fi
		done
	else
		# echo "DEBUGGING: 1:${1} 2:${2} 3:${3}"
		if [[ "${NUMBERTOBUILD}" -gt 1 ]]; then
			Error "${NUMBERTOBUILD} build / erroronous folders detected, exiting."
			Encapsulate "Remove offending / invalid old build folders before retrying:"
			shopt -s nullglob
			declare -a FOLDERS=();
			FOLDERS=(*/)
			for EACH in "${FOLDERS[@]}"
			do
				GREPIT=$(echo "${EACH}" | grep -i "${FILENAME}")
				if ! [[ "${GREPIT}" ]]; then
					echo "rm -R ${EACH}"
				fi
			done
			FullBar
			exit 1;
		fi
	fi

	if ! [[ "${BUILDALL}" ]]; then
		PrebuildInfo "$@"
		BuildItNow "$@"
	else
		NOOS=0;
		shopt -s nullglob
		declare -a FOLDERS=();
		FOLDERS=(*/)
		for EACH in "${FOLDERS[@]}"
		do
			NOOS=$((NOOS + 1))
			OSTOBUILD=$(echo "${EACH}" | sed "s/\///g")
			echo "Currently building ${NOOS} of ${NUMBERTOBUILD} autonomous builds: ${OSTOBUILD}"
			AUTOMOUSBUILD="${OSTOBUILD}"
			PrebuildInfo --build "${OSTOBUILD}"
			if [[ -d "${CURRENT}" ]]; then
				cd "${CURRENT}" || exit 1
			else
				Error "Critical Error: Can not find \"CURRENT\" Folder.  Exiting."
				exit 1;
			fi
			for ENVIRONMENTS in "${EXTRADE[@]}"
			do
				TESTIT=$(echo "${EACH}" | grep -i "${ENVIRONMENTS}")
				if [[ "${TESTIT}" ]]; then
					Encapsulate "DESKTOP ENVIRONMENT detected as ."
					SELECTEDENV="${ENVIRONMENTS}"
				fi
				if [[ "${DEBUG}" ]]; then
					echo "DEBUGGING EACH:${EACH} against ENVIRONMENTS:${ENVIRONMENTS}"
				fi
			done
			if [[ "${DEBUG}" ]]; then
				echo "Trying to CD to ${AUTOMOUSBUILD}"
			fi
			if [[ -d "${AUTOMOUSBUILD}" ]]; then
				cd "${AUTOMOUSBUILD}" || exit 1;
			else
				Error "${AUTOMOUSBUILD} folder does not exist."
			fi
			if [[ "${DEBUG}" ]]; then
				echo "DEBUGGING: BuildItNow --build ${EACH} ${SELECTEDENV} defaultde=${SELECTEDENV} -YES in ${PWD}"
			fi
			BuildItNow --build ${EACH} ${SELECTEDENV} defaultde=${SELECTEDENV} -YES
		done
		Center "${PROGNAME} has built ${NOOS} Operating Systems."
		FullBar
		exit 0;
	fi
}

# Clear system cache or part of it.
ClearCache () {
	VersionDump
	if [[ "${2}" == "debootstrap" ]]; then
		CACHETOCLEAR="debootstrap"
	fi
	if [[ "${2}" == "apt" ]]; then
		CACHETOCLEAR='apt'
	fi
	if [[ "${2}" == 'all' ]]; then
		CACHETOCLEAR='all'
	fi
	if [[ "${2}" == 'all' ]]; then
		if [[ -d ${CACHINGFOLDER} ]]; then
			SUPPRESS=$(rm -R "${CACHINGFOLDER}")
			Encapsulate "${CACHINGFOLDER} entire folder and subfolders removed."
			FullBar
			exit 0;
		else
			Error "${CACHINGFOLDER}, not found."
			exit 1;
		fi
	if [[ "${2}" == 'build' ]]; then
		echo "Immediate future implementation, please be patient with TheeMahn ;)"
	fi
	fi
	for EACH in "${OSARRAY[@]}"
	do
		if [[ "${2}" == "${EACH}" ]]; then
			DISTBASE="${EACH}"
			#echo "Distbase: ${DISTBASE}"
			for ARCHS in "${CYCLE[@]}"
			do
				if [[ "${3}" == "${ARCHS}" ]]; then
					ARCHITECTURETOCLEAR="${ARCHS}"
					#echo "Architecture: ${ARCHITECTURETOCLEAR}"
				fi
			done
		fi
	done
	if [[ "${DISTBASE}" && "${ARCHITECTURETOCLEAR}" ]]; then
		if [[ -d "${CACHINGFOLDER}/${DISTBASE}/${ARCHITECTURETOCLEAR}" ]]; then
			CTC=$(du -hs "${CACHINGFOLDER}/${DISTBASE}/${ARCHITECTURETOCLEAR}" | awk '{print $1}')
			CAPS=$(echo "${DISTBASE}" | tr '[:lower:]' '[:upper:]')
			Encapsulate "CLEARING ${CTC} OF ${CAPS} ${ARCHITECTURETOCLEAR} CACHE:"
			SUPPRESS=$(rm -R "${CACHINGFOLDER:?}/${DISTBASE}/${ARCHITECTURETOCLEAR}" 2>/dev/null)
			Encapsulate "Done."
			exit 0;
		else
			Error "ERROR: There is no ${DISTBASE} ${ARCHITECTURETOCLEAR} CACHE, exiting..."
			exit 1;
		fi
	fi
	if ! [[ "${ARCHITECTURETOCLEAR}" && "${DISTBASE}" ]]; then
		if [[ -d "${CACHINGFOLDER}/${DISTBASE}" ]]; then
			CTC=$(du -hs "${CACHINGFOLDER}/${DISTBASE}/" | awk '{print $1}')
			CAPS=$(echo "${DISTBASE}" | tr '[:lower:]' '[:upper:]')
			Encapsulate "CLEARING ${CTC} OF ${CAPS} CACHE:"
			SUPPRESS=$(rm -R "${CACHINGFOLDER:?}/${DISTBASE}/${ARCHITECTURETOCLEAR}" 2>/dev/null)
			Encapsulate "Done."
			exit 0;
		else
			Error "ERROR: There is no ${DISTBASE} CACHE, exiting..."
			exit 1;
		fi
	fi

	if [[ "$CACHETOCLEAR" ]]; then
		#Default option is to scrap it all.
		#all cache
		Encapsulate "Clearing $CACHETOCLEAR Cache:"
		if [[ "$CACHETOCLEAR" == "all" ]]; then
			if [[ -d "${CACHINGFOLDER}/" ]]; then
				if [[ -w "${CACHINGFOLDER}/" ]]; then
					SUCCESS=$(rm -rf "${CACHINGFOLDER:?}/*" > /dev/null 2>&1)
					if [[ "${SUCCESS}" ]]; then
						Encapsulate "Success."
					else
						Error "Failure"
					fi
				else
					Error "You do not have permission to access the cache folder, are you su?"
				fi
			else
				Error "There is no cache, did you already clear it?"
			fi
		fi

		#CLEAR DEBOOTSTRAP
		if [[ "$CACHETOCLEAR" == "debootstrap" ]]; then

			DEBOOTSTRAP=$(find "${CACHINGFOLDER}/" -name debootstrap.tar.gz)
			if [[ "${DEBOOTSTRAP}" ]]; then
				SUCCESS=$(rm -f "${DEBOOTSTRAP}")
				if [[ "${SUCCESS}" ]]; then
					Encapsulate "Success"
				else
					Error "Failure, no debootstrap?"
				fi
			else
				Error "Failure, no debootstrap?"
			fi
		fi

		#APT
		if [[ "$CACHETOCLEAR" == "apt" ]]; then
			MINIMAL=$(find "${CACHINGFOLDER}/" -type d -name "apt")
			if [[ "${MINIMAL}" ]]; then
				SUCCESS=$(rm -R "${MINIMAL}")
				if ! [[ "${SUCCESS}" ]]; then
					Encapsulate "Success."
				else
					Error "Failure, no apt cache?"
				fi
			else
				Error "Failure, no prior apt cache?"
			fi
		fi
		FullBar
	else
		Help "clearcache" "a"
	fi
}

# InjectSources function ( "${DIST}" "${CODEBASE}" "${ARCH}" )
InjectSources () {
	CUTTINGEDGE=$(echo "$@" | grep -i "edge")
	LOCALSOURCES=$(echo "$@" | grep -i "local")
	if [[ "${CUTTINGEDGE}" ]]; then
		Encapsulate "Injecting cutting edge sources."
	fi
	#CODEBASE="${DISTREL}" # try to pre-deterime it. - We have launched code on this off the rip.
	if ! [[ "${CODEBASE}" ]]; then
		if [[ -f "extract-cd/.disk/info" ]]; then
			CODEBASE=$(grep -i "RELEASE" "extract-cd/.disk/info" | cut -d'"' -f2 | cut -d ' ' -f1 | tr '[:upper:]' '[:lower:]')
			if  [[ "${CODEBASE}" == "ultimate" ]]; then
				if [[ -f "edit/etc/lsb-release" ]]; then
					CODEBASE=$(grep -i "DISTRIB_CODENAME=" "edit/etc/lsb-release" | cut -d "=" -f2)
				fi
			fi
			if [[ "${CODEBASE}" ]]; then
				Encapsulate "Codebase set as: ${CODEBASE}"
				DIST="${CODEBASE}"
			elif [[ -f "edit/etc/os-release" ]]; then
				CODEBASE=$(grep -i "version_codename" "/etc/os-release" | cut -d "=" -f2)
			else
				Error "Fatal Error: could not detect codebase. Exiting."
				exit 170;
			fi
		else
			Error "FATAL: Missing extract-cd/.disk/info, or /etc/os-release exiting."
			exit 170;
		fi
	fi
	#echo "DEBUG: * | $* 1:${1} 2:${2} 3:${3} 4:${4}"
	#echo "DEBUG: CODEBASE: ${CODEBASE} ARCH:${ARCH}"
	if ! [[ "${DEFAULTREPO}" ]]; then
		DEFAULTREPO="http://us.archive.ubuntu.com/ubuntu/"
	fi
	# echo "OST:${OST}"
	for OST in "${OLDRELEASES[@]}"
	do
		if [[ "${OST}" == "${CVERSION}" ]]; then
			Error "OLD RELEASE DETECTED: ${OST}"
			DIST="${OSARRAY[$array_counter]}"
			FULLNAME="${DISTARRAY[$array_counter]}"
			DEFAULTREPO="http://old-releases.ubuntu.com"
		fi
		array_counter=$((array_counter + 1))
	done
	#Encapsulate "Setting 2 second server timeout a fix for IPV6 issues:"
	#SUCCESS=$(echo '//Server down takes too long, add timeout' | tee -a  edit/etc/apt/apt.conf.d/70debconf)
	#SUCCESS=$(echo 'Acquire::http::Timeout "2";' | tee -a  edit/etc/apt/apt.conf.d/70debconf)
	#SUCCESS=$(echo 'Acquire::ftp::Timeout "2";' | tee -a  edit/etc/apt/apt.conf.d/70debconf)
	#if [[ "${SUCCESS}" ]]; then
	#	Encapsulate "Success."
	#else
	#	Encapsulate "Failure."
	#fi

	if [[ "${ARCH}" == "armhf" || "${ARCH}" == "armel" || "${ARCH}" == "powerpc" ]]; then
		DEFAULTREPO="http://ports.ubuntu.com/"
	fi
	if ! [[ "${LOCALSOURCES}" ]]; then
		Encapsulate "Injecting ${DEFAULTREPO} of ${CODEBASE} ${ARCH} into sources list..."
		echo "###### ${UOS} Repos" > "edit/etc/apt/sources.list"
		echo "deb ${DEFAULTREPO} ${CODEBASE} main restricted universe multiverse" >> "edit/etc/apt/sources.list"
		echo "# deb-src ${DEFAULTREPO} ${CODEBASE} main restricted universe multiverse" >> "edit/etc/apt/sources.list"
		echo "" >> "edit/etc/apt/sources.list"
		echo "###### ${UOS} Update Repos" >> "edit/etc/apt/sources.list"
		echo "deb ${DEFAULTREPO} ${CODEBASE}-security main restricted universe multiverse" >> "edit/etc/apt/sources.list"
		echo "deb ${DEFAULTREPO} ${CODEBASE}-updates main restricted universe multiverse" >> "edit/etc/apt/sources.list"
		echo "deb ${DEFAULTREPO} ${CODEBASE}-proposed main restricted universe multiverse" >> "edit/etc/apt/sources.list"
		echo "deb ${DEFAULTREPO} ${CODEBASE}-backports main restricted universe multiverse" >> "edit/etc/apt/sources.list"
		echo "# deb-src ${DEFAULTREPO} ${CODEBASE}-security main restricted universe multiverse" >> "edit/etc/apt/sources.list"
		echo "# deb-src ${DEFAULTREPO} ${CODEBASE}-updates main restricted universe multiverse" >> "edit/etc/apt/sources.list"
		echo "# deb-src ${DEFAULTREPO} ${CODEBASE}-proposed main restricted universe multiverse" >> "edit/etc/apt/sources.list"
		echo "# deb-src ${DEFAULTREPO} ${CODEBASE}-backports main restricted universe multiverse" >> "edit/etc/apt/sources.list"
		echo "" >> "edit/etc/apt/sources.list"
		echo "###### ${UOS} Partner Repo" >> "edit/etc/apt/sources.list"
		echo "deb http://archive.canonical.com/ubuntu ${CODEBASE} partner" >> "edit/etc/apt/sources.list"
		echo "# deb-src http://archive.canonical.com/ubuntu ${CODEBASE} partner" >> "edit/etc/apt/sources.list"
		Encapsulate "Checking for existance of \"EXTRA\" Repositories for ${CODEBASE}, please wait..."
		EXISTANCE=$(wget --timeout=6 "http://extras.ubuntu.com/ubuntu/dists/${CODEBASE}/main/${ARCH}/Packages.gz" 2>/dev/null)
		if [[ -s "Packages.gz" ]]; then
			rm "Packages.gz"
			echo "" >> "edit/etc/apt/sources.list"
			echo "###### ${UOS} Extras Repo" >> "edit/etc/apt/sources.list"
			echo "deb http://extras.ubuntu.com/ubuntu ${CODEBASE} main" >> "edit/etc/apt/sources.list"
		fi
	else
		if [[ -f "edit/etc/apt/sources.list" ]]; then
			rm "edit/etc/apt/sources.list"
		fi
		if [[ -f "edit/etc/apt/sources.list.d/local.list" ]]; then
			GREPIT=$(grep -i "#Local Repository" "edit/etc/apt/sources.list.d/local.list")
			if ! [[ "${GREPIT}" ]]; then
				Encapsulate "Injecting local sources."
				echo "deb http://192.168.1.189/ultimate-edition/ ultimate-edition all #Local Repository" >> "edit/etc/apt/sources.list.d/local.list"
			fi
		else
			Encapsulate "Injecting local sources."
			echo "deb http://192.168.1.189/ultimate-edition/ ultimate-edition all #Local Repository" > "edit/etc/apt/sources.list.d/local.list"
		fi
	fi
}

InjectLTSSources () {
	# InjectSources ${DIST} ${CODEBASE} ${ARCH}
	if ! [[ "${CODEBASE}" ]]; then
		if [[ -f "extract-cd/.disk/info" ]]; then
			CODEBASE=$(grep -i "RELEASE" "extract-cd/.disk/info" | cut -d'"' -f2 | cut -d ' ' -f1 | tr '[:upper:]' '[:lower:]')
			DIST="${CODEBASE}"
		else
			Error "FATAL: Missing extract-cd/.disk/info,  exiting."
			exit 1;
		fi
	fi

	#echo "DEBUG: * | $* 1:${1} 2:${2} 3:${3} 4:${4}"
	#echo "DEBUG: CODEBASE: ${CODEBASE} ARCH: ${ARCH}"
	DEFAULTREPO="http://us.archive.ubuntu.com/ubuntu/"
	# echo "OST:${OST}"
	for OST in "${OLDRELEASES[@]}"
	do
		if [[ "${OST}" == "${CVERSION}" ]]; then
			Error "OLD RELEASE DETECTED: ${OST}"
			DIST="${OSARRAY[$array_counter]}"
			FULLNAME="${DISTARRAY[$array_counter]}"
			DEFAULTREPO="http://old-releases.ubuntu.com"
		fi
		array_counter=$((array_counter + 1))
	done
	Encapsulate "LTS (Long term supported) release Setting stable sources: ${CODEBASE}"
	if [[ "${ARCH}" == "armhf" || "${ARCH}" == "armel" || "${ARCH}" == "powerpc" ]]; then
		DEFAULTREPO="http://ports.ubuntu.com/"
	fi
	LOCALSOURCES=$(echo "$@" | grep -i "local")
	if ! [[ "${LOCALSOURCES}" ]]; then
		Encapsulate "Injecting ${DEFAULTREPO} of ${CODEBASE} ${ARCH} into sources list..."
		echo "###### ${UOS} Repos ######" > "edit/etc/apt/sources.list"
		echo "deb ${DEFAULTREPO} ${CODEBASE} main restricted universe multiverse" >> "edit/etc/apt/sources.list"
		echo "deb ${DEFAULTREPO} ${CODEBASE}-security main restricted universe multiverse" >> "edit/etc/apt/sources.list"
		echo "# deb-src ${DEFAULTREPO} ${CODEBASE} main restricted universe multiverse" >> "edit/etc/apt/sources.list"
		echo "" >> "edit/etc/apt/sources.list"
		echo "###### ${UOS} Partner Repo" >> "edit/etc/apt/sources.list"
		echo "deb http://archive.canonical.com/ubuntu ${CODEBASE} partner" >> "edit/etc/apt/sources.list"
		echo "# deb-src http://archive.canonical.com/ubuntu ${CODEBASE} partner" >> "edit/etc/apt/sources.list"
	else
		if [[ -f "edit/etc/apt/sources.list" ]]; then
			rm "edit/etc/apt/sources.list"
		fi
		if [[ -f "edit/etc/apt/sources.list.d/local.list" ]]; then
			GREPIT=$(grep -i "#Local Repository" "edit/etc/apt/sources.list.d/local.list")
			if ! [[ "${GREPIT}" ]]; then
				Encapsulate "Injecting local sources."
				echo "deb http://192.168.1.189/ultimate-edition/ ultimate-edition all #Local Repository" >> "edit/etc/apt/sources.list.d/local.list"
			fi
		else
			Encapsulate "Injecting local sources."
			echo "deb http://192.168.1.189/ultimate-edition/ ultimate-edition all #Local Repository" > "edit/etc/apt/sources.list.d/local.list"
		fi
	fi
	Encapsulate "Checking for existance of \"EXTRA\" Repositories for ${CODEBASE}, please wait..."
	EXISTANCE=$(wget "http://extras.ubuntu.com/ubuntu/dists/${CODEBASE}/main/${ARCH}/Packages.gz" 2>/dev/null)
	if [[ -s "Packages.gz" || "${EXISTANCE}" ]]; then
		rm "Packages.gz"
		if [[ -f "edit/etc/apt/sources.list" ]]; then
			Encapsulate "Extra repositories detected: Enabling."
			echo "" >> "edit/etc/apt/sources.list"
			echo "###### ${UOS} Extras Repo" >> "edit/etc/apt/sources.list"
			echo "deb http://extras.ubuntu.com/ubuntu ${CODEBASE} main" >> "edit/etc/apt/sources.list"
		else
			Encapsulate "Extra repositories detected: Enabling."
			echo "###### ${UOS} Extras Repo" > "edit/etc/apt/sources.list"
			echo "deb http://extras.ubuntu.com/ubuntu ${CODEBASE} main" >> "edit/etc/apt/sources.list"
		fi
	fi
}

UpgradeISO () {
	#echo -e "${bldred}DEBUGGING UPGRADEISO function: 1:${1} 2:${2} 3:${3} 4:${4}${TXTRST}"
	if [[ "${BUILDALL}" ]]; then
		for BASWITCH in "$@"
		do
			GREPIT=$(echo "${BASWITCH}" | grep -i ".iso")
			if [[ "${GREPIT}" ]]; then
				ISO="${GREPIT}"
			else
				ISO="${AUTOMOUSBUILD}"
			fi
			array_counter=$((array_counter + 1))
			if [[ "${DEBUG}" ]]; then
				echo "Switch $array_counter: ${BASWITCH}"
			fi
		done
		if [[ "${ISO}" ]]; then
			ID="${ISO}"
			EXTENSION="${ID##*.}"
			FILENAME="${ID%.*}"
			if [[ -d "${FILENAME}" ]]; then
				cd "${FILENAME}" || exit 1
			fi
		else
			Error "Automous Failure in ${PWD}"
		fi
	fi
	# Currently unused switch - I can't imagine why someone would prefer to not use cache.'
	if [[ "${3}" != "--no-cache" ]]; then
		CACHE="--cache"
	fi
	EXTENSION="${ID##*.}"
	FILENAME="${ID%.*}"

	# DEBUGGING
	# echo "1:${1} 2:${2} 3:${3}"
	# exit 0;
	# UPGRADE ROUTINE - Did the user request an ISO? Does the ISO exist?
	# If so extract the ISO...

	if [[ -f "${ID}" ]]; then
		if ! [[ -d "${FILENAME}" ]]; then
			ExtractISO "${ID}"
		else
			Error "${ID} exists. Scrapping, we will build a new one."
			rm "${ID}"
		fi
	fi

	if [[ "${ID}" == "" ]]; then
		ExtractISO
	fi

	if [[ -d "${ID}" ]]; then
		FILENAME="${ID}"
		EXTENSION="FOLDER"
	fi
	#prepare

	#ISO Check
	if [[ "$EXTENSION" == "iso" ]]; then
		ID="${FILENAME}"
	fi
	#Folder?
	Encapsulate "Upgrade routine is processing ${ID}"
	Encapsulate "TYPE=$EXTENSION"
	Encapsulate "NAME=${FILENAME}"

	# Did the user request a directory? Does the directory exist?
	if [[ -d "${ID}" ]]; then
		shopt -s nullglob
		declare -a FOLDERS=();
		FOLDERS=(*/)
		for z in "${FOLDERS[@]}"
		do
			CVERSION=$(echo "${z}" | cut -d "-" -f3)

			if [[ -d "${z}" ]]; then
				cd "${z}" || exit 1
			fi

			Encapsulate "Processing Folder: ${z}"
			ARCH=""
			for ARCHITECTURE in "${UEARCH[@]}"
			do
				TESTCONDITION=$(echo "${z}" | grep -i "${ARCHITECTURE}")
				# echo "DEBUGGING ARCH:${z} against ${ARCHITECTURE}"
				if [[ "${TESTCONDITION}" ]]; then
					TARCH="${ARCHITECTURE}"
					GREPIT=$(echo "${TARCH}" | grep "64")
					if [[ "${GREPIT}" ]]; then
						LONGARCH="amd64"
						ARCH="x64"
					fi
					GREPIT=$(echo "${TARCH}" | grep "86")
					if [[ "${GREPIT}" ]]; then
						LONGARCH="i386"
						ARCH="x86"
					fi
				fi
			done
			if ! [[ "${ARCH}" ]]; then
				if [[ "${TARCH}" ]]; then
					ARCH="${TARCH}"
				fi
			fi
			if ! [[ "${ARCH}" ]]; then
				Error "FATAL: ARCHITECTURE NOT FOUND."
				exit 1;
			fi
			#DISRO STAMPING EXTERNAL:
			if [[ -f "extract-cd/.disk/info" ]]; then
				DISTNAME=$(grep -i "RELEASE" "extract-cd/.disk/info" | sed 's/.*"\(.*\)"[^"]*$/\1/')
				if [[ "${DISTNAME}" ]]; then
					Encapsulate "External distro name detected: ${DISTNAME}"
				else
					Error "ERROR: No Distro name detected exiting..."
					Error "DEBUG DATA:"
					cat "extract-cd/.disk/info"
					exit 1;
				fi
			else
				Error "FATAL ERROR: No Distro name detected exiting..."
				exit 170;
			fi

			RELEASETYPE="standard"
			if ! [[ -f "extract-cd/.disk/info" ]]; then
				if [[ "${LITE}" ]]; then
					LITE="lite"
					RELEASETYPE="lite"
					FULLDATAOUT=""
					FULLDATAOUT+="${UOS} ${CVERSION} Lite "
					FULLDATAOUT+="${SINGLE}${DISTNAME}${SINGLE}"
					FULLDATAOUT+=" - Release ${DOUT} ("
					FULLDATAOUT+=$(date +"%Y%m%d")
					FULLDATAOUT+=")"
					echo "${FULLDATAOUT}" > "extract-cd/.disk/info"
					Encapsulate "Upgrading ${UOS} ${CVERSION} ${LITE}"
					ISO="${OS}-${CVERSION}-${ARCH}-${LITE}.iso"
				else
					LITE=""
					if [[ "${GAMERS}" ]]; then
						Encapsulate "Upgrading ${UOS} ${CVERSION} ${GAMERS}"
						ISO="${OS}-${CVERSION}-${ARCH}-gamers.iso"
						RELEASETYPE="gamers"
					fi
					if [[ "${SERVER}" ]]; then
						Encapsulate "Upgrading ${UOS} ${CVERSION} ${SERVER}"
						ISO="${OS}-${CVERSION}-${ARCH}-server.iso"
						RELEASETYPE="server"
					fi
					if [[ "${MSERVER}" ]]; then
						Encapsulate "Upgrading ${UOS} ${CVERSION} ${MSERVER}"
						ISO="${OS}-${CVERSION}-${ARCH}-minimal-server.iso"
						RELEASETYPE="minimal-server"
					fi
					Encapsulate "Upgrading ${UOS} ${CVERSION}"
					FULLDATAOUT=""
					FULLDATAOUT+="Ultimate Edition ${CVERSION} "
					FULLDATAOUT+="${SINGLE}${FULLNAME}${SINGLE}"
					FULLDATAOUT+=" - Release ${DOUT} ("
					FULLDATAOUT+=$(date +"%Y%m%d")
					FULLDATAOUT+=")"
					echo "${FULLDATAOUT}" > "extract-cd/.disk/info"
				fi
			fi
			if [[ -f "extract-cd/.disk/release_notes_url" ]]; then
				Encapsulate "Setting Release Notes URL."
				sed -i "s/#VERSION/${CVERSION}/g" "extract-cd/.disk/release_notes_url"
				RELEASEURL=$(cat "extract-cd/.disk/release_notes_url")
				Encapsulate "Release URL: ${RELEASEURL}"
			fi
			if ! [[ "${DTB}" ]]; then
				ISO="${OS}-${CVERSION}-${ARCH}.iso"
			fi

			echo "${CVERSION}" > edit/tmp/release.info
			echo "$RELEASETYPE" > edit/tmp/type.info

			#Detect current code-base / distribution
			if [[ -f "edit/etc/lsb-release" ]]; then
				DISTREL=$(grep -i "DISTRIB_RELEASE=" "edit/etc/lsb-release" | cut -d "=" -f2)
				CODEBASE=$(grep -i "DISTRIB_CODENAME=" "edit/etc/lsb-release" | cut -d "=" -f2)
				for OST in "${UEARRAY[@]}"
				do
					if [[ "${OST}" == "${CVERSION}" ]]; then
						DIST="${OSARRAY[$array_counter]}"
						FULLNAME="${DISTARRAY[$array_counter]}"
					fi
					array_counter=$((array_counter + 1))
				done
				if [[ "${LITE}" ]]; then
					UNDERSCORED="${COS}"
					UNDERSCORED+="_Lite"
				else
					UNDERSCORED="${COS}"
				fi
				#sed -i "s/${DIST}REL/${CVERSION}/g" edit/etc/lsb-release
				#sed -i "s/${OS}R/${COS}/g" edit/etc/lsb-release
				#sed -i "s/^DISTRIB_DESCRIPTION=.*/DISTRIB_DESCRIPTION=\"Ultimate Edition ${CVERSION} ${FULLNAME}\"/g" edit/etc/lsb-release
			fi
			TESTLTS=""
			TESTLTS=$(grep -i "LTS" "extract-cd/.disk/info")
			if [[ "${TESTLTS}" ]]; then
				InjectLTSSources
			else
				InjectSources
			fi

			#UPGRADE PROCESS
			if [[ "${CACHEOPTION}" != "NONE" ]]; then
				touch "edit/tmp/cache"
			fi
			if ! [[ -f "edit/run/resolvconf/resolv.conf"  ]]; then
				if [[ -f "/run/resolvconf/resolv.conf" ]]; then
					Encapsulate "Restoring network information."
					mkdir -p "edit/run/resolvconf/"
					cp "/run/resolvconf/resolv.conf" "edit/run/resolvconf/"
				fi
			else
				Encapsulate "Network information detected."
			fi
			if [[ "${CACHEOPTION}" != "NONE" ]]; then
				#Encapsulate "Caching previously downloaded packages."
				#PushCache "${CODEBASE}" "${ARCH}"
				if ! [[ -f "${CURRENT}/internal" ]]; then
					Encapsulate "Copying internal script to chroot environment."
					if [[ -f "/usr/share/ultimate_edition/internal" && -d "edit/tmp/" ]]; then
						cp "/usr/share/ultimate_edition/internal" "edit/tmp/"
					else
						Error "Critical Error, Exited immediately please verify copying of internal in ${PWD}"
						exit 1;
					fi
				fi
				if ! [[ -f "${CURRENT}/ultimate-common" ]]; then
					Encapsulate "Copying common software base to chroot environment."
					if [[ -f "/usr/share/ultimate_edition/ultimate-common" && -d "edit/usr/bin/" ]]; then
						cp "/usr/share/ultimate_edition/ultimate-common" "edit/usr/bin/"
					else
						Error "Critical Error, Exited immediately please verify copying of ultimate-common in ${PWD}"
						exit 1;
					fi
				fi
				if [[ -f "${CURRENT}/internal" ]]; then
					Encapsulate "Copying custom internal script to chroot environment."
					cp "${CURRENT}/internal" "edit/tmp/"
				fi
				if [[ -f "${CURRENT}/ultimate-common" ]]; then
					Encapsulate "Copying common software base to chroot environment."
					cp "${CURRENT}/ultimate-common" "edit/tmp/"
				fi
				Encapsulate "Stage 2 of 3: Internal Software (Chrooting)"
				if [[ "${SETDEFAULT}" ]]; then
					/usr/sbin/chroot edit /bin/sh -c "cd /tmp/ ; DEBIAN_PRIORITY=critical ; DEBCONF_FRONTEND=noninteractive ; mount none -t proc /proc ; mount none -t sysfs /sys ; mount none -t devpts /dev/pts ; export HOME=/root ; export LC_ALL=C ; ./internal --defaultde=${SETDEFAULT} $*"
				else
					/usr/sbin/chroot edit /bin/sh -c "cd /tmp/ ; DEBIAN_PRIORITY=critical ; DEBCONF_FRONTEND=noninteractive ; mount none -t proc /proc ; mount none -t sysfs /sys ; mount none -t devpts /dev/pts ; export HOME=/root ; export LC_ALL=C ; ./internal $*"
				fi

				mkdir -p extract-cd/{casper,isolinux,install,.disk}

				# CACHING out at each stage ...
				if [[ "${CACHE}" ]]; then
					#						SUCCESS=$(rsync -avz edit/var/cache/apt/ ../.cache/${CODEBASE}/apt/ 2>/dev/null)
					if [[ -f "edit/tmp/internal" ]]; then
						rm "edit/tmp/internal"
					fi
					if [[ -f "edit/tmp/ultimate-common" ]]; then
						rm "edit/tmp/ultimate-common"
					fi
					if [[ -f "edit/tmp/tmgrub" ]]; then
						rm "edit/tmp/tmgrub"
					fi
				fi
				sync
				Center "Final external deployment information:..."
				FullBar
				cat "edit/etc/lsb-release"
				cat "edit/etc/os-release"
				cat "edit/etc/issue"
				cat "edit/etc/issue.net"
				FullBar
			fi
			Timer "Stop" "${APPNAME}"
			Center "This cache processing will save you aprox ${TTIMEM} in future builds."

			#exit 0;
			#TODO:ADD CHECK EDIT IF NOT [EXIST] THEN MOUNT AND EXTRACT MINIMAL ISO.
			if [[ "${LITE}" ]]; then
				if ! [[ -f "edit/tmp/DE" ]]; then
					echo "MATE" > "edit/tmp/DE"
				fi
			fi

			if [[ "${GAMERS}" ]]; then
				if ! [[ -f "edit/tmp/DE" ]]; then
					echo "MATE" > "edit/tmp/DE"
				fi
			fi
			if [[ "${SERVER}" ]]; then
				if ! [[ -f "edit/tmp/DE" ]]; then
					echo "MATE" > "edit/tmp/DE"
				fi
			fi
			if [[ "${MSERVER}" ]]; then
				if ! [[ -f "edit/tmp/DE" ]]; then
					echo "NONE" > "edit/tmp/DE"
				fi
			fi
			if ! [[ "${LITE}" || "${GAMERS}" ]]; then
				if [[ "${ODD}" ]]; then
					if ! [[ -f "edit/tmp/DE" ]]; then
						echo "KDE" > "edit/tmp/DE"
					fi
				else
					if ! [[ -f "edit/tmp/DE" ]]; then
						echo "GNOME" > "edit/tmp/DE"
					fi
				fi
			fi
			if ! [[ "${LITE}" || "${SERVER}" ]]; then
				if [[ "${ODD}" ]]; then
					if ! [[ -f "edit/tmp/DE" ]]; then
						echo "KDE" > "edit/tmp/DE"
					fi
				else
					if ! [[ -f "edit/tmp/DE" ]]; then
						echo "GNOME" > "edit/tmp/DE"
					fi
				fi
			fi

			if [[ "${MSERVER}" ]]; then
					echo "NONE" > "edit/tmp/DE"
			fi

			# PULL ${2}, ${3} etc for extra DE's
			if ! [[ -f "edit/tmp/DE" ]]; then
				PROCESS=0;
				for var in "$@"
				do
					array_counter=$((array_counter + 1))
					# echo "Switch $array_counter: ${var}"
					CSWITCH=$(echo "${var}" | grep -i "iso")
					if [[ "${PROCESS}" == 1 ]]; then
						nested_array=0
						for TE in "${EXTRADE[@]}"
						do
							DETC="${EXTRADE[$nested_array]}"
							# echo "Comparing ${DETC} to ${var}"
							GREPIT=$(echo "${var}" | grep " ")
							if ! [[ "${GREPIT}" ]]; then
								if [[ "${var}" == "${TE}" ]]; then
									echo "${var}" | tr '[:upper:]' '[:lower:]' >> "edit/tmp/DE"
								fi
							fi
							nested_array=$((nested_array + 1))
						done
					fi
					if [[ "${CSWITCH}" && "${PROCESS}" == 0 ]]; then
						PROCESS=1
					fi
				done
			fi
			if ! [[ -f "edit/run/resolvconf/resolv.conf"  ]]; then
				if [[ -f "/run/resolvconf/resolv.conf" ]]; then
					Encapsulate "Restoring network information. From ${PWD}"
					mkdir -p "edit/run/resolvconf/"
					cp "/run/resolvconf/resolv.conf edit/run/resolvconf/"
				fi
			else
				Encapsulate "Network information detected."
			fi

			#Cache out stage 2...
			if [[ "$CACHE" ]]; then
				Encapsulate "Rsyncing cache. This could take a long time the first time it is ran, please wait..."
				PullCache "${CODEBASE}" "${ARCH}"
				#SUCCESS=$(rsync -avz edit/var/cache/apt/ ../.cache/${CODEBASE}/apt/ 2>/dev/null)
				if [[ -f "edit/tmp/minimal" ]]; then
					rm "edit/tmp/minimal"
				fi
				if [[ -f "edit/tmp/internal" ]]; then
					rm "edit/tmp/internal"
				fi
				if [[ -f "edit/tmp/tmgrub" ]]; then
					rm "edit/tmp/tmgrub"
				fi
			fi
			sync
			LASTCHECK=$(mount | grep "none" | sort -r | grep "${PWD}" | cut -d " " -f3)
			if [[ "${LASTCHECK}" ]]; then
				Encapsulate "We have hooks in ${PWD} as: ${LASTCHECK}"
				Encapsulate "We are going to forefully unhook them & re-sync."
				mount | grep "none" | sort -r | grep "${PWD}" | cut -d " " -f3 | umount -f
			else
				Encapsulate "No hooks in the O/S."
			fi
			if [[ -f "${CURRENT}/tmgrub" ]]; then
				Center "Stage 3 of 3: Grub section (custom):"
				Encapsulate "Passing control to custom tmgrub software."
				cp "${CURRENT}/tmgrub" edit/tmp/
				/usr/sbin/chroot edit /bin/sh -c "cd /tmp/ ; ./tmgrub $@"
			else
				if [[ -f "/usr/share/ultimate_edition/tmgrub" ]]; then
					sync
					Center "Re-entering chroot Stage 3 of 3 Grub section:"
					Encapsulate "passing control to internal software (tmgrub)."
					cp "/usr/share/ultimate_edition/tmgrub" "edit/tmp/"
					/usr/sbin/chroot edit /bin/sh -c "cd /tmp/ ; ./tmgrub $@"
				else
					Error "ERROR: Missing internal grub script."
					exit 1;
				fi
			fi
			sync


			#umount ${CURRENT}/edit/dev
			Encapsulate "Generating README.diskdefines"
			DISTROINFORMATION=$(cat "extract-cd/.disk/info")
			echo "#define DISKNAME  ${INFORMATION}" > "extract-cd/README.diskdefines"
			echo "#define TYPE  binary" >> "extract-cd/README.diskdefines"
			echo "#define TYPEbinary  1" >> "extract-cd/README.diskdefines"
			echo "#define ARCH  ${LONGARCH}" >> "extract-cd/README.diskdefines"
			echo "#define ARCH${LONGARCH}  1" >> "extract-cd/README.diskdefines"
			echo "#define DISKNUM  1" >> "extract-cd/README.diskdefines"
			echo "#define DISKNUM1  1" >> "extract-cd/README.diskdefines"
			echo "#define TOTALNUM  0" >> "extract-cd/README.diskdefines"
			echo "#define TOTALNUM0  1" >> "extract-cd/README.diskdefines"
			Encapsulate "Creating Readme file"
			if ! [[ -f "extract-cd/README" ]]; then
				NUSER=$(grep 1000 /etc/passwd | cut -f1 -d:)
				if ! [[ ${NUSER} ]]; then
					NUSER="root"
				fi
				echo "This Operating System was auto generated using:" > "extract-cd/README.TXT"
				VersionDump --suppress >> "extract-cd/README.TXT"
				echo "" >> "extract-cd/README.TXT"
				echo -e -n "Using the command: tmosb " >> "extract-cd/README.TXT"
				echo "$@"  >> extract-cd/README.TXT
				echo "on $(date) by ${NUSER} on ${HOSTNAME}" >> "extract-cd/README.TXT"
				#Get CPU model
				echo "" >> "extract-cd/README.TXT"
				echo "Source Build platform:" >> "extract-cd/README.TXT"
				echo "======================" >> "extract-cd/README.TXT"
				RESONATION=$(lscpu | grep -i 'cpu max Mhz' | cut -d ":" -f2)
				if ! [[ "${RESONATION}" ]]; then
					RESONATION=$(sudo dmidecode -t 4 | grep -i "Max Speed:" | cut -d":" -f2)
				fi
				PROC=$(grep -m1 'model name' /proc/cpuinfo | sed -e 's/.*: //' | uniq)
				echo "${HOSTNAME} is an ${PROC} resonating at${RESONATION}" >> "extract-cd/README.TXT"
				CORES=1 #Set default
				CORES=$(grep -i "processor" /proc/cpuinfo | sed '/model/d' | wc -l)
				echo "CPU Core(s) / Thread(s): ${CORES}" >> "extract-cd/README.TXT"
				MEMORY=$(grep -i 'memtotal' /proc/meminfo | awk '{print $2}')
				if [[ "${MEMORY}" ]]; then
					MEMORYBYTES=$(printf "%'.3f\n" "${MEMORY}")
					MEMORY=$(echo "${MEMORYBYTES}" | cut -d. -f1)
					echo "MEMORY: ${MEMORY} bytes" >> "extract-cd/README.TXT"
				fi
				HOSTARCH=$(getconf LONG_BIT)
				echo "HOST ARCH: ${HOSTARCH} bit" >> "extract-cd/README.TXT"
				if [[ -f "/etc/lsb-release" ]]; then
					echo "HOST BUILD O/S:" >> "extract-cd/README.TXT"
					cat "/etc/lsb-release" >> "extract-cd/README.TXT"
				fi
				echo "" >> "extract-cd/README.TXT"
				echo "Destination Distribution Information" >> "extract-cd/README.TXT"
				echo "====================================" >> "extract-cd/README.TXT"
				echo "Distribution Base: ${DISTBASE} ${CODEBASE}" >> "extract-cd/README.TXT"
				echo "Architecture: ${LONGARCH}" >> "extract-cd/README.TXT"
				shopt -s nullglob
				declare -a DETECTEDPLATFORMS=();
				if [[ -d "edit/usr/share/xsessions" ]]; then
					CURRENT="${PWD}"
					cd "edit/usr/share/xsessions" || exit 1;
					DETECTEDPLATFORMS=(./*.desktop)
					cd "${CURRENT}" || exit 1;
					if [[ "${#DETECTEDPLATFORMS[@]}" -gt 0 ]]; then
						echo "Detected Desktop Environments:" >> "extract-cd/README.TXT"
						Center "Detected Desktop Environments:"
						for EACH in "${DETECTEDPLATFORMS[@]}"
						do
							PLATFORM="${EACH//.desktop/}"
							PLATFORM="${PLATFORM/.\//}"
							#PLATFORM=$(echo "${EACH}" | sed "s/.desktop//g" 2>/dev/null)
							Encapsulate "${PLATFORM}"
							echo "${PLATFORM}" >> "extract-cd/README.TXT"
						done
						cd "${CURRENT}" || exit 1;
					else
						Error "No detected platform(s) (DE). Minimal or server?"
					fi
				fi


				LOGGS=$(ls edit/var/log 2>/dev/null)
				if [[ "$LOGGS" ]]; then
					Encapsulate "Detected build logs..."
					if [[ -f "tmosb-${VERSION}-build-logs.tar.gz" || -f "extract-cd/.disk/tmosb-${VERSION}-build-logs.tar.gz" ]]; then
						Encapsulate "Build logs have already been backed up."
					else
						Encapsulate "Archiving build logs, please wait..."
						FullBar
						tar -zcvf "tmosb-${VERSION}-build-logs.tar.gz" "edit/var/log" 2>/dev/null

						sync
					fi
				else
					Encapsulate "No logs detected."
				fi
				if [[ -f "tmosb-${VERSION}-build-logs.tar.gz" || -f "extract-cd/.disk/tmosb-${VERSION}-build-logs.tar.gz" ]]; then
					FullBar
					Encapsulate "Success."

					if [[ -f "tmosb-${VERSION}-build-logs.tar.gz" ]]; then
						Encapsulate "Moving build logs to DVD."
						SUPPRESS=$(mv "tmosb-${VERSION}-build-logs.tar.gz" "extract-cd/.disk/")
						echo "Build Logs: .disk/tmosb-${VERSION}-build-logs.tar.gz" >> "extract-cd/README.TXT"
					fi
					if [[ -d "edit/var/log/" ]]; then
						# Some applications stroke out over not have a log folder - leave struture intact. Scrap logs we have already backed them up for the user
						Encapsulate "Cleaning old logs, we have already archived them for the user(s). Leaving Directory structure and permissions intact."
						# Leave all logs intact for now.
						SUPPRESS=$(find "edit/var/log/*" -type f -exec rm -iv {} \;)
					fi
					#SUPPRESS=$(rm -R edit/var/log/* 2>/dev/null)
				else
					Error "Error: Could not archive build logs."
				fi
				CRASHLOGS=$(ls "edit/var/crash/" 2>/dev/null)
				if [[ "${CRASHLOGS}" ]]; then
					Error "Error: Crashlogs have been detected. Archiving for debugging purposes."
					tar -zcvf "tmosb-${VERSION}-crash-logs.tar.gz" "edit/var/crash/" 2>/dev/null
					Encapsulate "Moving crash logs to DVD."
					SUPPRESS=$(mv "tmosb-${VERSION}-crash-logs.tar.gz" "extract-cd/.disk/")
					SUPPRESS=$(rm edit/var/crash/*)
					echo "Crash Logs: .disk/tmosb-${VERSION}-crash-logs.tar.gz"  >> "extract-cd/README.TXT"
				else
					Encapsulate "Congradulations, no crash logs detected."
					echo "Crash Logs: NONE" >> extract-cd/README.TXT
				fi
			fi
			PullCache "${CODEBASE}" "${ARCH}"
			if [[ -f "edit/run/resolvconf/resolv.conf" ]]; then
				Encapsulate "Removing network information from chroot."
				rm "edit/run/resolvconf/resolv.conf"
			fi
			if [[ "${LTS}" != "NO" ]]; then
				InjectLTSSources "${DIST}" "${CODEBASE}" "${ARCH}"
			fi

			if [[ -f "${ISO}" ]]; then
				Center "INITIATING FINAL BUILD PROCESS: ${ISO}"
			fi
			#RE-BUILD IT
			SUPPRESS=$(rm -R edit/tmp/.* 2>/dev/null)
			SUPPRESS=$(rm -f edit/tmp/* 2>/dev/null)
			Encapsulate "Clearing tmp from chroot: Success."
			#mkdir -p "extract-cd/{casper,isolinux,install,.disk}"


			Timer "Stop" "${APPNAME}"
			#cd ${CURRENT}
			BuildISO "--buildiso" "${ISO}" "--suppress"
			if ! [[ "${BUILDALL}" ]]; then
				exit 0;
			fi
		done
	else
		Error "ERROR: ${1} Not found."
	fi
}

Help () {
	CONTAINS=$(echo "$@" | grep -w '\-h\|\-\-help')
	LATESTUBUNTU=${UEARRAY[-1]}
	if [[ "${DEBUG}" ]]; then
		echo "DEBUGGING HELP FUNCTION: 1:${1} 2:${2} 3:${3} CONTAINS:${CONTAINS}"
	fi
	if ! [[ "${3}" == "" && "${CONTAINS}" ]]; then
		if [[ "${2}" != "" ]]; then
			PRAM="${2}"
		else
			PRAM="ALL"
		fi
	fi
	if [[ "${CONTAINS}" ]]; then
		if [[ "${3}" == "" ]]; then
			VersionDump
		fi
		if [[ "${2}" != "" ]]; then
			PRAM="${2}"
		else
			PRAM="ALL"
			VersionDump
		fi
	fi
	if ! [[ "${1}" ]]; then
		VersionDump
	else
		if ! [[ "$PRAM" ]]; then
			PRAM="${1}"
		fi
	fi
	case $PRAM in

		# Main Menu
		ALL)
		Encapsulate "Usage: ${PROGNAME} -<-COMMAND> [OPTION]"
		FullBar
		Encapsulate "Mandatory arguments to long options are identical for short options."
		Encapsulate "  possible commands..."
		Encapsulate " "
		Encapsulate "  -b       --build       builds Operating System(s)."
		Encapsulate "  -B       --buildiso    builds ISO(s)."
		Encapsulate "  -C       --clearcache  clears / adjusts system cache."
		Encapsulate "  -c       --cacheinfo   displays various cache information."
		Encapsulate "  -d       --debootstrap debootstraps system."
		Encapsulate "  -D       --diagnose    diagnoses operating system(s)."
		Encapsulate "  -e       --extract     extract ISO(s)"
		Encapsulate "  -g       --grid        grid build options."
		Encapsulate "  -h       --help        this help message."
		Encapsulate "  -i       --info        displays information about iso / folder."
		Encapsulate "  -m       --modify      modify an exiting O/S (chroot)."
		Encapsulate "  -p       --pull        pulls all source code to current folder."
		Encapsulate "  -r       --release     releases file for download."
		Encapsulate "  -t       --test        test ISO in virtual machine and exit."
		Encapsulate "  -u       --upgrade     distro upgrades existing Operating System(s)."
		Encapsulate "  -v       --version     dump version info and exit."
		Encapsulate " "
		FullBar
		Center "${PROGNAME} --help [COMMAND] for further information."
		FullBar;;

		# Build Help
		ALL|b|build)
		Encapsulate ""
		Encapsulate "Usage build;"
		FullBar
		Center "${PROGNAME} -b <VERSION>"
		FullBar
		declare -i INDEX;
		INDEX=1
		declare -i NENV;
		NENV="${#UETYPES[@]}"
		BUILDSTRING=""
		for EACH in "${UETYPES[@]}"
		do
			if [[ "${INDEX}" == "${NENV}" ]]; then
				BUILDSTRING+="${EACH}"
			else
				BUILDSTRING+="${EACH} / "
			fi
			if [[ "${INDEX}" == "0" ]]; then
				BUILDSTRING="${EACH} / "
			fi
			INDEX=$(( INDEX + 1 ))
		done
		#Encapsulate "${BUILDSTRING}"
		Encapsulate "Invokes ${PROGNAME} to build Operating System <VERSION> from scratch."
		Encapsulate "The format must comply as follows:"
		Encapsulate "<DISTBASE>-<VERSION>-[${BUILDSTRING}]-<ARCH> [DE(s)]"
		Encapsulate "Valid arguments are as follows and <REQUIRED>:"
		Encapsulate " "
		Encapsulate "DIST BASE:"
		declare -i INDEX;
		NENV="${#DISTBASE[@]}"
		INDEX=1
		for EACH in "${DISTBASE[@]}"
		do
			if [[ "${INDEX}" == "${NENV}" ]]; then
				BUILDSTRING+="or ${EACH}."
			else
				BUILDSTRING+="${EACH}, "
			fi
			if [[ "${INDEX}" == "1" ]]; then
				BUILDSTRING="Ultimate Edition, "
			fi
			#if [[ "${DEBUG}" ]]; then
				#echo "DEBUGGING: BUILDSTRING: ${BUILDSTRING} | EACH: ${EACH} | INDEX: ${INDEX}"
			#fi
			INDEX=$(( INDEX + 1 ))
		done
		Encapsulate "${BUILDSTRING}"
		Encapsulate " "
		Encapsulate "Building Operating system:"
		Encapsulate "Version:  ${UEARRAY[0]} - ${NEWESTUE} (Ultimate Edition), ${UEARRAY[${DISTSSUPPORTED}/3*2]} - ${UEARRAY[-1]} (Ubuntu), ${DEBIAN[0]} - ${#DEBIAN[@]} (Debian)"
		Encapsulate " "
		Encapsulate "[OPTIONAL TYPES]"
		declare -i INDEX;
		INDEX=1
		declare -i NENV;
		NENV="${#UETYPES[@]}"
		BUILDSTRING=""
		for EACH in "${UETYPES[@]}"
		do
			if [[ "${INDEX}" == "${NENV}" ]]; then
				BUILDSTRING+="or ${EACH}."
			else
				BUILDSTRING+="${EACH}, "
			fi
			if [[ "${INDEX}" == "0" ]]; then
				BUILDSTRING="${EACH}, "
			fi
			INDEX=$(( INDEX + 1 ))
		done
		Encapsulate "${BUILDSTRING}"
		Encapsulate " "
		Encapsulate "[OPTIONAL DE]"
		Encapsulate " "
		Encapsulate "Desktop Environment(s) (DE):"
		declare -i INDEX;
		INDEX=1
		declare -i NENV;
		NENV="${#EXTRADE[@]}"
		BUILDSTRING=""
		for EACH in "${EXTRADE[@]}"
		do
			if [[ "${INDEX}" == "${NENV}" ]]; then
				BUILDSTRING+="and or ${EACH}."
			else
				BUILDSTRING+="${EACH}, "
			fi
			if [[ "${INDEX}" == "0" ]]; then
				BUILDSTRING="${EACH}, "
			fi
			INDEX=$(( INDEX + 1 ))
		done
		Encapsulate "${BUILDSTRING}"
		Encapsulate "iso, lite, gamers, server, developer and DE's as per synopsis is [OPTIONAL]"
		FullBar
		Encapsulate "Example: ${PROGNAME} --build ultimate-edition-6.2-x64-lite.iso xfce kde --defaultde=xfce"
		Encapsulate "Will build Ultimate Edition 6.2 adding kde & setting xfce as the default (DE), even though not designed that way."
		Encapsulate "Please see ${PROGNAME} --grid env for more information."
		FullBar;;

		# Build ISO Help
		ALL|B|buildiso)
		Encapsulate "Usage buildiso;"
		FullBar
		Center "${PROGNAME} -B [TARGETISO]"
		FullBar
		Encapsulate "Invokes ${PROGNAME} to build [TARGETISO] from a previous build. The format of the ISO"
		Encapsulate "must comply as follows:"
		Encapsulate "[TARGETISO]"
		Encapsulate "Valid arguments are as follows:"
		Encapsulate "Existant folder, is optional.  It will otherwise look for information in .disk/info"
		Encapsulate "Example: ${PROGNAME} --buildiso ultimate-edition-5.1-x64-full/"
		Encapsulate "Will build Ultimate Edition 5.1 64 bit KDE Operating System in ISO format."
		FullBar;;

		# Clear Cache Help
		ALL|C|clearcache)
		Encapsulate "Usage clearcache;"
		FullBar
		Center "${PROGNAME} -C <REQUIREMENT>"
		FullBar
		Encapsulate "Clears cache by disgression."
		Encapsulate "<REQUIREMENT> is as follows:"
		Encapsulate "<debootstrap> clears debootstrap image(s)."
		Encapsulate "<minimal> clears minimal ISO image(s)"
		Encapsulate "<all> clears the entire cache system."
		Encapsulate "Example: ${PROGNAME} --clearcache debootstrap"
		FullBar;;

		# Cache Info Help
		ALL|c|cacheinfo)
		Encapsulate "Usage cacheinfo;"
		FullBar
		Center "${PROGNAME} -c"
		FullBar
		Encapsulate "Displays various cache information."
		Encapsulate "Example: ${PROGNAME} --cacheinfo"
		FullBar;;

		# Debootstrap Help
		ALL|d|debootstrap)
		Encapsulate "Usage debootstrap;"
		FullBar
		Center "${PROGNAME} -d <VALID O/S>[.iso]"
		FullBar
		Encapsulate "Debootstraps <VALID O/S> to allow for further processing."
		Encapsulate "Debootstrap is a tool which will install a Debian base system"
		Encapsulate "into a subdirectory of another, already installed system."
		Encapsulate "It doesn't require an installation CD, just access to a repository."
		Encapsulate " "
		Encapsulate "<VALID O/S> can be obtained using ${PROGNAME} --build suppress"
		Encapsulate "Please note: the [.iso] extension is optional."
		Encapsulate "Example: ${PROGNAME} --debootstrap ultimate-edition-4.8-x64-lite"
		FullBar;;
		ALL|D|diagnose)
		Encapsulate "Usage diagnose;"
		FullBar
		Center "${PROGNAME} -D <VALID ISO(S)>[.iso]"
		FullBar
		Encapsulate "Diagnoses <VALID ISO(S)> prodvides attional details."
		Encapsulate "It doesn't require an installation CD, just access to a repository."
		Encapsulate " "
		Encapsulate "<VALID O/S> can be obtained using ${PROGNAME} --build suppress"
		Encapsulate "Please note: the [.iso] extension is optional."
		Encapsulate "Example: ${PROGNAME} --diagnose ultimate-edition-4.6-x64-lite"
		FullBar;;

		# Extract Help
		ALL|e|extract)
		Encapsulate "Usage extract;"
		FullBar
		Center "${PROGNAME} -e <ISO>"
		FullBar
		Encapsulate "Extracts <ISO> for further processing."
		Encapsulate "Example: ${PROGNAME} --extract ultimate-edition-4.0-x64.iso"
		FullBar;;

		# Grid Help
		ALL|g|grid)
		Encapsulate "Usage grid;"
		FullBar
		Center "${PROGNAME} -g [env / type / defaults]"
		FullBar
		Encapsulate "Puts build options into a grid to allow the end user to make an informed"
		Encapsulate "decision of what he / she wants to build.  Optional [env] will display"
		Encapsulate "environments that are availible for build.  Optional [type] will display"
		Encapsulate "types of distros available. Optional [defaults] will display default DE"
		Encapsulate "per distro."
		Encapsulate "Example: ${PROGNAME} --grid env"
		FullBar;;

		#Information
		ALL|i|information)
		Encapsulate "Usage information;"
		FullBar
		Center "${PROGNAME} -i <FOLDER/ISO>"
		FullBar
		Encapsulate "Provides information about current ISO / folder."
		Encapsulate "Example: ${PROGNAME} --informatiom ultimate-edition-5.7-x64-lite/"
		FullBar;;

		# Modify Help
		ALL|m|modify)
		Encapsulate "Usage modify;"
		FullBar
		Center "${PROGNAME} -m <FOLDER>"
		FullBar
		Encapsulate "Allows end user to modify (chroot) an existing build."
		Encapsulate "Example: ${PROGNAME} --modify ultimate-edition-4.6-x64-lite/"
		FullBar;;

		# Pull Help
		ALL|p|pull)
		Encapsulate "Usage pull;"
		FullBar
		Center "${PROGNAME} -p [option]"
		FullBar
		Encapsulate "Pulls all source code to current folder to allow you to modify it."
		Encapsulate "The [option] switch allows you to overwrite if existant source code."
		Encapsulate "Example: ${PROGNAME} --pull --overwrite"
		FullBar;;

		# Release Help
		ALL|r|release)
		Encapsulate "Usage release;"
		FullBar
		Center "${PROGNAME} -r <FILENAME> [FOLDER]"
		FullBar
		Encapsulate "Pushes FILENAME to Apache webserver /var/www/... optionally to"
		Encapsulate "[FOLDER] to avoid prompting.  Specifying no [FOLDER] will"
		Encapsulate "cause ${PROGNAME} to scan for Apache webserver(s)."
		Encapsulate "Example: ${PROGNAME} --release ultimate-edition-4.2.2-x64-gamers.iso"
		FullBar;;

		# Info Help
		ALL|i|info)
		Encapsulate "Usage info;"
		FullBar
		Center "${PROGNAME} -i <FOLDER/ISOIMAGE>"
		FullBar
		Encapsulate "Displays general information for an ISO or Linux build folder."
		Encapsulate "Example: ${PROGNAME} --info ultimate-edition-5.7-x64.iso"
		FullBar;;

		# Stats Help
		ALL|s|stats)
		Encapsulate "Usage stats;"
		FullBar
		Center "${PROGNAME} -s"
		FullBar
		Encapsulate "Displays general stats of tmosb."
		Encapsulate "Example: ${PROGNAME} --stats"
		FullBar;;

		# Upgrade Help
		ALL|u|upgrade)
		Encapsulate "Usage upgrade;"
		FullBar
		Center "${PROGNAME} -u [ISO]"
		FullBar
		Encapsulate "Will mount and extract [ISO] image and invoke distribution upgrade."
		Encapsulate "The [ISO] is only [OPTIONAL] because it will process folders as well."
		Encapsulate "Example: ${PROGNAME} --upgrade ultimate-edition-3.4-x64.iso"
		FullBar;;

		# Test Help
		ALL|t|test)
		Encapsulate "Usage test;"
		FullBar
		Center "${PROGNAME} -t [ISO]"
		FullBar
		Encapsulate "Invokes a virtual machine to boot [ISO]."
		Encapsulate "Example: ${PROGNAME} --test ultimate-edition-4.2-x64.iso"
		FullBar;;

		# Version Help
		ALL|v|version)
		Encapsulate "Usage version;"
		FullBar
		Center "${PROGNAME} -v"
		FullBar
		Encapsulate "Displays ${PROGNAME}'s version number and exits."
		FullBar;;

		# Help Help
		ALL|h|help|\?)
		Encapsulate "Usage Help [COMMAND]"
		FullBar
		Center "${PROGNAME} -h [COMMAND]"
		FullBar
		Encapsulate "Displays this message. For futher information ${PROGNAME} help [COMMAND]"
		Encapsulate "or refer to the manpages."
		Encapsulate " "
		Encapsulate "man ${PROGNAME}"
		Encapsulate " "
		Encapsulate "Example: ${PROGNAME} -h version"
		Encapsulate "Will display help about the command switch version"
		FullBar
	esac
	exit 0
}

# Pull the souce code to the current running folder.
PullSource() {
	VersionDump
	OVERWRITE=$(echo "$@" | grep -i 'overwrite')
	# echo -e "${bldgrn}DEBUGGING PULLSOURCE function: 1:${1} 2:${2} 3:${3}"
	array_counter=0;
	for i in "${APPLICATIONS[@]}"
	do
		APPLICATIONSOURCE="${APPSRC[$array_counter]}"
		if [[ -f "${i}" && "${OVERWRITE}" ]]; then
			Error "ERROR: ${i} exists, not overwriting. \nUse: tmosb --pull --overwrite if you are sure."
		else
			if [[ -f "${APPLICATIONSOURCE}/${i}" ]]; then
				Encapsulate "Copying source ${i} to ${PWD}:"
				cp "${APPLICATIONSOURCE}/${i} ." 2>/dev/null
				if [[ -f "${i}" ]]; then
					Encapsulate "Success."
				else
					Encapsulate "Failure. Source missing?"
				fi
			else
				Error "ERROR FILE NOT FOUND: ${APPLICATIONSOURCE}/${i}"
			fi
		fi
		array_counter=$((array_counter + 1))
	done
	Encapsulate "Feel free to modify the source in your favorite editor"
	Encapsulate "Example: gedit internal"
}

WriteDiskInfo () {
	#Ultimate Edition 3.6 "Quantal Quetzal" - Release i386 (20131016)
	INFOLDER="${PWD}"
	cd extract-cd/.disk/ || exit 0;
	DTE=$(date +"%Y%m%d")
	if [[ "${ISLTS}" ]]; then
		OUTPUTDISKINFO="${OUTDISTRO} ${CVERSION} LTS \"${FULLNAME}\" - Release ${LONGARCH} ($DTE)"
	else
		OUTPUTDISKINFO="${OUTDISTRO} ${CVERSION} \"${FULLNAME}\" - Release ${LONGARCH} ($DTE)"
	fi
	Encapsulate "Injecting the following information to disk info"
	Encapsulate "Operating System Output: ${OUTDISTRO}"
	Encapsulate "Operating System version requested: ${CVERSION}"
	Encapsulate "Operating System distribution base: ${DIST}"
	Encapsulate "Architecture requested: ${LONGARCH}"
	Encapsulate "Distribution Long Name: ${FULLNAME}"
	FullBar
	echo "${OUTPUTDISKINFO}" > info
	cd "${INFOLDER}" || exit 0;
}

Debootstrap () {
	Timer "START" "Debootstrap"
	RAW=$(echo "$*" | grep -i "raw")
	ID="${2}"
	EXTENSION="${ID##*.}"
	FILENAME="${ID%.*}"

	# DEBUGGING
	# echo "1:${1} 2:${2} 3:${3}"

	# UPGRADE ROUTINE - Did the user request an ISO? Does the ISO exist?
	# If so extract the ISO...
	if [[ "${IUSER}" != "root" && "${TRUEROOT}" != "0" ]]; then
		if [[ ${USETHEFORCE} ]]; then
			Encapsulate "${IUSER}, using the force Luke."
		else
			Error "ERROR: This operation requires true root or (su) access."
			exit 0;
		fi
	fi

	if ! [[ -d "${FILENAME}" ]]; then
		if [[ -f "${ID}" ]]; then
			ExtractISO "${ID}"
		fi
	fi

	if [[ -d "${ID}" ]]; then
		FILENAME="${2}"
		EXTENSION="FOLDER"
	fi
	#prepare


	# TODO: ADD CODE TO PREVENT FALURE FROM RETURNING FUNCTION VALUES [.ISO]

	if [[ "${FILENAME}" == "" ]]; then
		VersionDump
		InvalidBuildSwitch "$@"
		Help "debootstrap" "3"
		exit 0;
	else
		VersionDump
	fi

	#ISO Check
	if ! [[ "$EXTENSION" == "iso" ]]; then
		FILENAME="${2}"
		mkdir -p "${2}"
	else
		mkdir -p "${FILENAME}"
	fi
	#Folder?
	if [[ -d "${CURRENT}" ]]; then
		cd "${CURRENT}" || exit 1
	else
		Error "Critical Error: No ${CURRENT}"
		exit 1;
	fi

	shopt -s nullglob
	declare -a FOLDERS=();
	FOLDERS=(*/)
	for z in "${FOLDERS[@]}"
	do
		CVERSION=$(echo "${z}" | cut -d "-" -f3)
		if [[ -d "${z}" ]]; then
			cd "${z}" || exit 1
		fi
		# Default naming scheme for Ultimate Edition
		ARCH=$(echo "${z}" | grep -i "x86")
		# Nothing? Is the user wanting a ubuntu build?
		if ! [[ "${ARCH}" ]]; then
			ARCH=$(echo "${z}" | grep -i "i386")
		fi
		# Wanting Lite? This data will be pushed to the internal app
		# and adjusted accordingly.
		# TODO: ADD GAMERS ETC?
		LITE=$(echo "${z}" | grep -i "lite")
		GAMERS=$(echo "${z}" | grep -i "gamers")
		SERVER=$(echo "${z}" | grep -i "server")
		MSERVER=$(echo "${z}" | grep -i "minimal")
		if [[ "${MSERVER}" ]]; then
			SERVER=""
		fi
		ARCH=""
		for ARCHITECTURE in "${UEARCH[@]}"
		do
			# echo "DEBUGGING TESTING ${ARCHITECTURE} from ${z}:"
			TESTCONDITION=$(echo "${z}" | grep -i "${ARCHITECTURE}")
			if [[ "${TESTCONDITION}" ]]; then
				ARCH="${ARCHITECTURE}"
				GREPIT=$(echo "${ARCH}" | grep '64')
				if [[ "${GREPIT}" ]]; then
					LONGARCH="amd64"
				fi
				GREPIT=$(echo "${ARCH}" | grep '86')
				if [[ "${GREPIT}" ]]; then
					LONGARCH="i386"
				fi
			fi
		done
		if ! [[ "${ARCH}" ]]; then
			Error "FATAL: ARCHITECTURE NOT FOUND."
			exit 0;
		fi
		# Process via default name if Ubuntu:
		# ubuntu-13.10-desktop-amd64.iso
		EXTENSION="${z##*.}"
		FILENAME="${z%.*}"

		UBUNTU=$(echo "${z}" | grep -i "ubuntu")

		if [[ "${UBUNTU}" ]]; then
			CVERSION=$(echo "${z}" | cut -d "-" -f2)
		fi

		# Check to see if release is Long Term Supported.
		LTS="NO"
		for zx in "${ISLTS[@]}"
		do
			if [[ "${CVERSION}" == "${zx}" ]]; then
				LTS="YES"
			fi
		done

		array_counter=0;
		for OST in "${UEARRAY[@]}"
		do
			# DEBUGGING
			# echo "Checking: ${OST}"
			if [[ "${OST}" == "${CVERSION}" ]]; then
				# DEBUGGING
				# echo "YES: ${OST} DIST: ${OSARRAY[$array_counter]} NAME: ${DISTARRAY[$array_counter]}"
				DIST="${OSARRAY[$array_counter]}"
				FULLNAME="${DISTARRAY[$array_counter]}"
			fi
			array_counter=$((array_counter + 1))
		done
		if [[ "${UBUNTU}" ]]; then
			OUTDISTRO="Ubuntu"
		else
			OUTDISTRO="Ultimate Edition"
		fi
		EVENODD="${2##*.}"
		#echo "DEBUGGING: ${EVENODD}"
		#if [[ $((EVENODD%2)) -eq 0 ]]; then
		#	DTYPE="FULL"
		#else
		#	DTYPE="STANDARD"
		#	DE="GNOME"
		#fi

		if [[ "${LITE}" ]]; then
			DTYPE="LITE"
			DE="mate"
		else
			DTYPE="STANDARD"
		fi
		if [[ "${GAMERS}" ]]; then
			DTYPE="GAMERS"
			DE="mate"
		fi
		if [[ "${SERVER}" ]]; then
			DTYPE="SERVER"
			DE="mate"
		fi
		if [[ "${DEVELOPER}" ]]; then
			DTYPE="DEVELOPER"
			if ! [[ "${DE}" ]]; then
				DE="KDE"
			fi
		fi
		if [[ "${MSERVER}" ]]; then
			DTYPE="SERVER"
			DE="NONE"
		fi
		if ! [[ "${DE}" ]]; then
			DE="KDE"
		fi
		################ EXTRA DE'S?
		# PULL ${2}, ${3} etc for extra DE's
		################

		if ! [[ "${OUTDISTRO}" || "${CVERSION}" || "${FULLNAME}" || "${ARCH}" || "${LTS}" || "${DTYPE}" || "${DE}" ]]; then
			InvalidBuildSwitch "$@"
		fi
		# Last second adjustment if the user has opted for a defaultde
		COMMANDISSUED=$(echo "$*" | tr '[:upper:]' '[:lower:]')
		SETDEFAULT=$(echo "${COMMANDISSUED}" | grep -i "defaultde=")
		if [[ "${SETDEFAULT}" ]]; then
			DEFAULTDE=$(echo "${COMMANDISSUED}" | grep -i "defaultde=" | sed "s/^.*defaultde=//g" | cut -d" " -f1)
			if [[ "${DEFAULTDE}" ]]; then
				Encapsulate "Default Desktop Environment (DE) specified as: ${DEFAULTDE}"
			fi
		fi
		if [[ "${DEFAULTDE}" ]]; then
			DE="${DEFAULTDE}"
		fi
		Encapsulate "Operating System pre-build information for: ${2}"
		PrebuildInfo "$@"
		################
		echo -e -n "${TXTGRN}"
		FullBar
		Columnize -t "OPERATING SYSTEM" "VERSION" "RELEASE BASE" "ARCH" "LTS" "TYPE" "DE(s)"
	if [[ "${LONGVERSION}" != "${CVERSION}" ]]; then
		VEROUT="${CVERSION}"
		VEROUT+="("
		VEROUT+="${LONGVERSION}"
		VEROUT+=")"
		Columnize "${OUTDISTRO}" "${CVERSION}" "${FULLNAME}" "${ARCH}" "${LTS}" "${DTYPE}" "${DE}"
	else
		Columnize "${OUTDISTRO}" "${CVERSION}" "${FULLNAME}" "${ARCH}" "${LTS}" "${DTYPE}" "${DE}"
	fi
		FullBar
		PROMPT=$(echo "$*" | grep -i "YES")
		if ! [[ "${PROMPT}" ]]; then
			Encapsulate "Is the above correct?"
			PromptYN "${WARNING}WARNING: this will take a long time and download vast quantanties of data. (Y/N)? "
			case "${YN}" in
				[Nn]* ) echo -e "${TXTRST}"; exit 0;;
				[Yy]* ) echo -e "${TXTGRN}"
				Center "Initiating build of ${2} ...";;
				* ) echo "Please answer y or n.";;
			esac

		fi
		if ! [[ -d "${CACHINGFOLDER}/${BASEPULL}/apt/" ]]; then
			mkdir -p "${CACHINGFOLDER}/${DIST}/${ARCH}/apt/"
		fi

		### CORE FILES ? ###
		if [[ -s "${CACHINGFOLDER}/${DIST}/ultimate-edition-${CVERSION}-${DEBTYPE}-core-files.deb" ]]; then
			Encapsulate "Pulling core files from cache."
			cp "${CACHINGFOLDER}/${DIST}/ultimate-edition-${CVERSION}-${DEBTYPE}-core-files.deb" .
		else
			BuildCoreFiles "$@"
		fi
		#if ! [[ -d "${FILENAME}" ]]; then mkdir ${FILENAME}; fi
		#cd ${FILENAME}
		mkdir -p {edit,extract-cd}
		if ! [[ -f ""extract-cd/README.diskdefines"" ]]; then
			if ! [[ -f "${CACHINGFOLDER}/extract-cd.tar.gz" ]]; then
				Encapsulate "Downloading a generic extract-cd contents..."
				cd "extract-cd/" || exit 1
				Download "http://ultimateedition.info/Toolz/extract-cd.tar.gz"
				mkdir -p "${CACHINGFOLDER}/"
				cp extract-cd.tar.gz "${CACHINGFOLDER}/"
			else
				Center "Pulling archive from cache, this saves you from having to re-download it."
				cd "${CURRENTBUILD}"
				if [[ -d "extract-cd" ]]; then
					cd "extract-cd/" || exit 1
				else
					echo "DEBUG: failure in ${PWD}"
				fi
			mkdir -p "${CACHINGFOLDER}/"
			cp "${CACHINGFOLDER}/extract-cd.tar.gz" .
			fi
			Encapsulate "Extracting archive:"
			SUCCESS=$(tar xfv extract-cd.tar.gz 2>/dev/null)
			sync
			if [[ "${SUCCESS}" ]]; then
				Encapsulate "Success."
			else
				Error "ERROR in extraction."
				exit 0;
			fi
			cp "extract-cd.tar.gz" "${CACHINGFOLDER}/extract-cd.tar.gz"
			if [[ -f "extract-cd.tar.gz" ]]; then
				Encapsulate "Cleaning up extract cd archive."
				rm "extract-cd.tar.gz"
			fi
			chown root:root -R ./*
			#mv isolinux/txt.cfg isolinux/isolinux.cfg
			cd ..
			find 'extract-cd/' -type d -exec chmod 755 {} \;
			chmod 644 "extract-cd/isolinux/*" "extract-cd/autorun.inf extract-cd/logo.ico"
			WriteDiskInfo "$*"
		else
			Encapsulate "Previous build detected, not downloading the extract-cd contents."
		fi
		FullBar
		Encapsulate "Operating System Output: ${OUTDISTRO}"
		Encapsulate "Operating System version requested: ${CVERSION}"
		Encapsulate "Operating System distribution base: ${BASE}"
		Encapsulate "Architecture requested: ${LONGARCH}"
		Encapsulate "Distribution Long Name: ${FULLNAME}"
		FullBar


		if [[ -f "${CACHINGFOLDER}/${DIST}/${ARCH}/debootstrap.tar.gz" ]]; then
			Encapsulate "Debootstrap has been previously backed up to cache."
			if ! [[ -f "edit/etc/lsb-release" ]]; then
				Encapsulate "Pulling bootstrap from cache:"
				cp "${CACHINGFOLDER}/${DIST}/${ARCH}/debootstrap.tar.gz" .
				if [[ -f debootstrap.tar.gz ]]; then
					Encapsulate "Success."
				else
					Error "FAILURE. Corrupt tar? tmosb --cleancache"
				fi
				Encapsulate "Extracting archive:"
				SUCCESS=$(tar -xf debootstrap.tar.gz 2>/dev/null)
				if [[ -f "edit/etc/lsb-release" ]]; then
					Encapsulate "Success."
				else
					Error "FAILURE. Corrupt tar? tmosb --cleancache"
					exit 1;
				fi
			else
				Encapsulate "Prior debootstrap / build exists for ${DIST} ${ARCH} build."
			fi
		else
			Encapsulate "Prior debootstrap / build does not exist for ${DIST} ${ARCH} build."
			Encapsulate "First build?  Entering Stage 1 (debootstrap)."
		fi

		if ! [[ -f "edit/etc/lsb-release" ]]; then
			for EACHARCH in "${UEARCH[@]}";
			do
				TESTIT=$(echo "$@" | grep -i "${EACHARCH}")
				if [[ "${TESTIT}" ]]; then
					if [[ "${DEBUG}" ]]; then
						echo "DEBUG: Architecture Detected as: ${EACHARCH}"
					fi
					ARCH="${EACHARCH}"
					Encapsulate "Architecture Detected as: ${EACHARCH}"
				else
					if [[ "${DEBUG}" ]]; then
						echo "DEBUG: Architecture is NOT: ${EACHARCH}"
					fi
				fi
			done
			if [[ "${ARCH}" && "${DIST}" ]]; then
				debootstrap --arch="${LONGARCH}" --foreign "${DIST}" edit	## Initiate debootstrap process...
				case "${ARCH}" in
					armel) Center "Inserting ARM support into chroot environment."; cp "/usr/bin/qemu-arm-static" "edit/usr/bin" ;;
					armhf) Center "Inserting ARM support into chroot environment."; cp "/usr/bin/qemu-arm-static" "edit/usr/bin" ;;
					powerpc) Center "Inserting PowerPC support into chroot environment."; cp "/usr/bin/qemu-ppc-static" "edit/usr/bin" ;;
					powerpc-smp) Center "Inserting PowerPC support into chroot environment."; cp "/usr/bin/qemu-ppc-static" "edit/usr/bin" ;;
					*) Center "${ARCH} support is native." ;;
				esac
				chroot edit /bin/bash /debootstrap/debootstrap --second-stage
				Encapsulate "Compressing debootstrap:"
				SUCCESS=$(tar -zcvf debootstrap.tar.gz edit)
				if [[ "${SUCCESS}" ]]; then
					Encapsulate "Successfully compressed."
					sync
					Encapsulate "Moving debootstrap.tar to cache."
					mkdir -p "${CACHINGFOLDER}/${DIST}/${ARCH}/"
					mv debootstrap.tar.gz "${CACHINGFOLDER}/${DIST}/${ARCH}/"
					Timer "Stop" "Debootstrap"
					Center "Caching process will save you above in future builds."
				else
					Encapsulate "FAILURE. Corrupt tar? tmosb --cleancache"
					exit 0;
				fi
			else
				Encapsulate "ERROR: Invalid switch please see ${PROGNAME} --help build"
				exit 1;
			fi
		else
			Encapsulate "Previous build detected, skipping Stage 1 (debootstrap)."
		fi
		if [[ "${RAW}" ]]; then
			Encapsulate "Raw debootstrap switch engaged, exiting as requested.  Please note Ultimate Edition core files were not installed."
			Encapsulate "tmosb --modify ${FOLDER} to modify."
			FullBar
			WriteDiskInfo
			exit 0;
		fi
		#PUSH CORE FILEZ into chroot
		#Core files previously built? TODO: ADD Check and retrieve.
		cd "${CURRENTBUILD}" || exit 1
		KoreFilez
		TESTLTS=$(grep -i "LTS" "extract-cd/.disk/info")
		if [[ "${TESTLTS}" ]]; then
			InjectSourcesLTS
		else
			InjectSources
		fi
		# Only update sources list if they have not already been updated.
		if ! [[ -f "edit/var/cache/apt/pkgcache.bin" ]]; then
			Encapsulate "Updating Sources list in chroot environment."
			FullBar
			# Snatch missing keys while we are at it.
			#/usr/sbin/chroot edit /bin/sh -c "apt-get update 2> /tmp/keymissing; for key in $(grep \"NO_PUBKEY\" /tmp/keymissing |sed \"s/.*NO_PUBKEY //\"); do echo -e \"\nProcessing key: \"$key\"; gpg --keyserver \"$KEYSERVER\" --recv \"$key\" && gpg --export --armor \"$key\" | apt-key add -; done"
			/usr/sbin/chroot edit /bin/sh -c "apt-get update"
		fi

		Encapsulate "Fixing any prior errors."
		/usr/sbin/chroot edit /bin/sh -c "cd /tmp/ ; apt-get install -f -y --no-install-recommends wget"
		INSTALLED=$((/usr/sbin/chroot edit /bin/sh -c dpkg-query -l "ultimate-edition-repositories-apt-source" | grep "ii")2>/dev/null)
		if ! [[ "${INSTALLED}" ]]; then
			Center "Retriving Ultimate Edition Repositories in chroot..."
			FullBar
			/usr/sbin/chroot edit /bin/sh -c "cd /tmp/ ; wget ${ROOTFOLDER}/${UEREPOSITORIES}; dpkg -i ${UEREPOSITORIES}"
			/usr/sbin/chroot edit /bin/sh -c "cd /tmp/ ; DEBIAN_PRIORITY=critical ; DEBCONF_FRONTEND=noninteractive ; mount -t proc /proc ; mount -t sysfs /sys ; mount -t devpts /dev/pts ; export HOME=/root ; export LC_ALL=C ; apt-get update; apt-get install -f -y "
			FullBar
		else
			Center "Ultimate Edition Repositories already installed."
		fi
		/usr/sbin/chroot edit /bin/sh -c "cd /tmp/ ; DEBIAN_PRIORITY=critical ; DEBCONF_FRONTEND=noninteractive ; mount -t proc /proc ; mount -t sysfs /sys ; mount -t devpts /dev/pts ; export HOME=/root ; export LC_ALL=C ; apt-get dist-upgrade -f -y "
		#KeySnatcher
		INSTALLED=$((/usr/sbin/chroot edit /bin/sh -c dpkg-query -l "${UEKEYSNATCHER}" | grep "ii")2>/dev/null)
		if ! [[ "${INSTALLED}" ]]; then
			/usr/sbin/chroot edit /bin/sh -c "cd /tmp/ ; wget ${ROOTFOLDER}/${UEKEYSNATCHER}; dpkg -i ${UEKEYSNATCHER}"
			/usr/sbin/chroot edit /bin/sh -c "cd /tmp/ ; DEBIAN_PRIORITY=critical ; DEBCONF_FRONTEND=noninteractive ; mount -t proc /proc ; mount -t sysfs /sys ; mount -t devpts /dev/pts ; export HOME=/root ; export LC_ALL=C ; apt-get install -f -y "
			/usr/sbin/chroot edit /bin/sh -c "cd /tmp/ ; keysnatcher -s; keysnatcher -f"
		fi
		Encapsulate "Grabing new sources."
		/usr/sbin/chroot edit /bin/sh -c "cd /tmp/ ; apt-get update"
		Encapsulate "Distribution updgrading chroot environment."
		/usr/sbin/chroot edit /bin/sh -c "cd /tmp/ ; apt-get dist-upgrade -y"
		Encapsulate "Installing the bare minimum to allow distro to boot"
		Encapsulate "Once again ignore errors, we will fix them later (Stage 3)."
		/usr/sbin/chroot edit /bin/sh -c "cd /tmp/ ; DEBIAN_PRIORITY=critical ; DEBCONF_FRONTEND=noninteractive ; apt-get install --yes --no-install-recommends casper ubuntu-minimal lupin-casper laptop-detect os-prober xdg-user-dirs xdg-utils command-not-found bash fonts-liberation bash-completion"
		Encapsulate "Fixing any prior errors."
		/usr/sbin/chroot edit /bin/sh -c "cd /tmp/ ; DEBIAN_PRIORITY=critical ; DEBCONF_FRONTEND=noninteractive ; mount none -t proc /proc ; mount none -t sysfs /sys ; mount none -t devpts /dev/pts ; export HOME=/root ; export LC_ALL=C ; apt-get dist-upgrade -f -y ; umount /proc ; umount /sys ; umount /dev/pts"
		CODEBASE="${DIST}"
		#MINIMAL TO BOOT
		if [[ -f "${CURRENT}/tmgrub" ]]; then
			Center "Stage 3 of 3 (tmgrub) section:"
			Encapsulate "Passing control to tmgrub software."
			cp "${CURRENT}/tmgrub" edit/tmp/
			/usr/sbin/chroot edit /bin/sh -c "cd /tmp/ ; ./tmgrub $@"
		else
			if [[ -f "/usr/share/ultimate_edition/tmgrub" ]]; then
				Encapsulate "RE-ENTERING CHROOT Stage 3 of 3 Grub section:"
				Encapsulate "passing control to internal software (tmgrub)."
				cp "/usr/share/ultimate_edition/tmgrub" edit/tmp/
				/usr/sbin/chroot edit /bin/sh -c "cd /tmp/ ; ./tmgrub $@"
			else
				Error "ERROR: Missing internal grub script."
				exit 1;
			fi
		fi
		PushCache "${DIST}" "${ARCH}"
		#exit 0;

		if [[ ${LITE} ]]; then
			LITE="lite"
			FULLDATAOUT=""
			FULLDATAOUT+="${UOS} ${CVERSION} "
			FULLDATAOUT+="${SINGLE}${DISTNAME}${SINGLE}"
			FULLDATAOUT+=" - Release ${DOUT} ("
			FULLDATAOUT+=$(date +"%Y%m%d")
			FULLDATAOUT+=")"
			echo "${FULLDATAOUT}" > "extract-cd/.disk/info"
			DTB="${OS}-${CVERSION}-${ARCH}-${LITE}.iso"
		else
			LITE=""
			FULLDATAOUT=""
			FULLDATAOUT+="Ultimate Edition ${CVERSION} "
			FULLDATAOUT+="${SINGLE}${FULLNAME}${SINGLE}"
			FULLDATAOUT+=" - Release ${DOUT} ("
			FULLDATAOUT+=$(date +"%Y%m%d")
			FULLDATAOUT+=")"
			echo "${FULLDATAOUT}" > "extract-cd/.disk/info"
			DTB="${OS}-${CVERSION}-${ARCH}.iso"
		fi
		if [[ -f "extract-cd/.disk/info" ]]; then
			cat "extract-cd/.disk/info"
		fi
	done
	cd "${CURRENT}" || exit 1
	Timer "Stop" "${APPNAME}"
	Encapsulate "If you would like to customise your distro:"
	echo -e "${TXTGRN}cp /run/resolvconf/resolv.conf ${FOLDER}/edit/run/resolvconf/resolv.conf"
	echo -e "chroot ${FOLDER}/edit/${TXTRST}";
	Encapsulate "After customization to build your final product:"
	echo "tmosb --buildiso ${FOLDER}"
	APACHE=$(type -p apache2)
	if [[ "${APACHE}" ]]; then
		Encapsulate "Apache server detected: tmosb --release ${DTB} to release to the world."
	fi
	Notification "All operations completed successfully.";
	Encapsulate "Execution Time: ${TTIMEM}"
	shopt -u nullglob
}

# Command line pre-processor
# SAMPLE INPUTS
# tmos --build ultimate-edition-3.8-x64
# tmos --upgrade ultimate-edition-4.0-x64.iso
# Switch debugging will be removed in the final product
#CommandLineInterpreter "$@"
#echo "DEBUG CLI: ${1}"
Release () {
	declare -a RELEASEFOLDER=();
	declare -a SERVERS=();
	declare -a DOCUMENTROOTS=();
	declare -a UNIQUE=();
	shopt -s nullglob
	declare -i FOUND
	VersionDump
	if ! [[ -f "${2}" ]]; then
		Error "File not found: ${2}"
		Help "release" "1"
		exit 1;
	fi
	if [[ "${3}" ]]; then
		Encapsulate "Optional subfolder selected as ${3}."
	fi
	APACHE=$(type -p apache2)
	CURRENT="${PWD}"
	if [[ "${APACHE}" ]]; then
		Encapsulate "Apache installation detected at ${APACHE}, Detecting apache server(s)..."

		if [[ -d "/etc/apache2/sites-enabled/" ]]; then
			cd "/etc/apache2/sites-enabled/" || exit 1;
		else
			Error "No sites enabled in apache (/etc/apache2/sites-enabled/), exiting release routine."
			exit 0;
		fi
		shopt -s globstar
		SERVERS=( * * )
		if [[ "${DEBUG}" ]]; then
				echo "DEBUGGING SERVERS: ${SERVERS} in ${PWD}"
		fi
		for EACH in "${SERVERS[@]}"
		do
			if [[ "${DEBUG}" ]]; then
				echo "DEBUGGING FOUND FOLDERS: ${EACH} in ${PWD}"
			fi
			Encapsulate "Server detected at: ${EACH}, scanning for document root of server."
			DOCUMENTROOT=$(grep -m 1 'DocumentRoot' "${EACH}" | cut -d ' ' -f2)
			if [[ -d "${DOCUMENTROOT}" ]]; then
				shopt -s nullglob dotglob
				DOCUMENTROOTS=("${DOCUMENTROOTS[@]}" "${DOCUMENTROOT}")
				((FOUND++))
			fi
				#if ! [[ "$OLD" ]]; then
				#	DOCUMENTROOTS=("${DOCUMENTROOTS[@]}" "${DOCUMENTROOT}")
					#((FOUND++))
					#unset OLD
				#fi

			if [[ "${DEBUG}" ]]; then
				echo "DEBUGGING CURRENT DOCUMENTROOTS: ${DOCUMENTROOTS[@]}, found: ${FOUND}"
			fi
			if [[ "${DEBUG}" ]]; then
				echo "DEBUGGING DOCUMENTROOT: ${DOCUMENTROOT} in ${PWD}"
			fi
		done

		#shopt -s nullglob
		#UNIQUE=$(echo "${DOCUMENTROOTS[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')
		IFS=$' '
		UNIQUE=($(printf "%s\n" "${DOCUMENTROOTS[@]}" | sort -u | tr '\n' ' '))
		PHYSICAL=${#UNIQUE[@]}
		Encapsulate "Virtual Server(s) detected: ${FOUND}.  Physical servers online: ${PHYSICAL}"
		#unset IFS
		for EACH in "${UNIQUE[@]}"
		do
			if [[ "${DEBUG}" ]]; then
				echo "DEBUGGING FOUND SERVER FOLDERS: ${EACH} in ${PWD}"
			fi
			Encapsulate "Found Server ROOT(s) at: ${EACH}"
		done
		shopt -s nullglob
		cd "${CURRENT}" || exit 1;
		INFOLDER="${PWD}"
		Encapsulate "Scanning Domain: ${HOSTNAME} to see if it local or internet supported."
		#DNS=$(nslookup "${HOSTNAME}" | grep -v "127.0" | grep -i "Name" | cut -d ":" -f2 | sed "s/$(echo '\t')//" | sed "s/ //g")
		DNS=$(hostname --fqdn | grep -i "\.")
		declare -a EXTERNALLOCALIP=();
		SAVEIFS=$IFS
		# Change IFS to new line.
		IFS=$'\n'
		EXTERNALLOCALIP=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1')
		EXTERNALLOCALIP=(${EXTERNALLOCALIP})
		if [[ "${DEBUG}" ]]; then
			echo "Debugging DNS: ${DNS} LOCALHOST: ${HOSTNAME} EXTERNAL: ${EXTERNALLOCALIP[@]}"
		fi
		IFS="$SAVEIFS"
		if ! [[ "${DNS}" ]]; then
			Encapsulate "Local host support only."
		else
			Encapsulate "Domain ${DNS} is online."
		fi
		Encapsulate "You want to move ${2} to?"
		FullBar
		select FOLDER in "${UNIQUE[@]}";
		do
				FullBar
			if [[ "${3}" ]]; then
				Encapsulate "Moving ${2} to ${FOLDER}/${3}/ OPTION ($REPLY) as selected above in ${PWD}"
				if [[ -d "${FOLDER}/${3}/" ]]; then
					sudo mv "${2}" ${FOLDER}/${3}/
				else
					Encapsulate "Creating directory structure as requested: ${FOLDER}/${3}/."
					mkdir -p "${FOLDER}/${3}/"
					sudo mv "${2}" ${FOLDER}/${3}/
				fi
				Encapsulate "Chowning ${FOLDER}/${3}/${2} to www-data"
				sudo chown www-data:www-data "${FOLDER}/${3}/${2}"
				Encapsulate "Success."
			else
				Encapsulate "Moving ${2} to ${FOLDER} OPTION ($REPLY) as selected above in ${PWD}"
				sudo mv "${2}" ${FOLDER}/
				Encapsulate "Chowning ${FOLDER}/${2} to www-data"
				sudo chown www-data:www-data "${FOLDER}/${2}"
				Encapsulate "Success."
			fi
				if [[ "${DNS}" ]]; then
					if [[ "${3}" ]]; then
							Encapsulate "You can now download your release at http://${DNS}/${3}/${2}"
						for IFACES in "${EXTERNALLOCALIP[@]}"
						do
							Encapsulate "Internal IP: http://${i}FACES/${3}/${2}"
						done
						Encapsulate "wget http://${DNS}/${3}/${2} for the terminal jockeys."
						FullBar
					else
						Encapsulate "You can now download your release at http://${DNS}/${2}"
						for IFACES in "${EXTERNALLOCALIP[@]}"
						do
							Encapsulate "Internal IP: http://${i}FACES/${2}"
						done
						Encapsulate "wget http://${DNS}/${2} for the terminal jockeys."
						FullBar
					fi
				else
					if ! [[ "${3}" ]]; then
						Encapsulate "You can now download your release at http://127.0.0.1/${2}"
						Encapsulate "External Local IP: http://${EXTERNALLOCALIP}/${2}"
							Encapsulate "wget http://${EXTERNALLOCALIP}/${2} for the terminal jockeys."
						FullBar
					else
						Encapsulate "You can now download your release at http://127.0.0.1/${3}/${2}"
						Encapsulate "External Local IP: http://${EXTERNALLOCALIP}/${3}/${2}"
							Encapsulate "wget http://${EXTERNALLOCALIP}/${3}/${2} for the terminal jockeys."
						FullBar
					fi
				fi
				exit 0;
			done
			cd "${INFOLDER}" || exit 1;
	else
		Error "Apache is not installed on host system: sudo apt-get install apache2"
		exit 1;
	fi
	unset IFS
}

Chroot () {
	VersionDump
	declare -i FOUND;
	if [[ $(id -u) -ne 0 ]]; then
		Error "You need to re-run as root"
		exit 1;
	fi
	# Wow, try and determine the base of the O/S. Handle foriegn architectures off the rip.
	# crack open a new array, thanks Shwn for the extra work ;)  All good, will do he same
	# Ripping on the droid.
	CUTTINGEDGE=$(echo "$@" | grep -i "edge")
	INFOLDER="${PWD}"
	for EACH in "$@"
	do
		if [[ -d "${EACH}" ]]; then
			Encapsulate "Directory: ${EACH} exists:"
			CHROOTFOLDER="${EACH%/}"
			FOUND=1
		fi
	done

	if [[ "${FOUND}" == 1 ]]; then
		Encapsulate "Chroot Logging in."
	else
		Error "Directory not found. Please check your spelling."
		exit 1;
	fi

	if [[ "${CUTTINGEDGE}" ]]; then
		Encapsulate "Injecting cutting edge sources."
		if [[ -d "${CHROOTFOLDER}" ]]; then
			cd "${CHROOTFOLDER}" || exit 1;
		else
			Error "ERROR: folder ${INFOLDER} does not exist."
			exit 1;
		fi
		InjectSources
		cd "${INFOLDER}" || exit 1;
	fi

	if [[ -f "${CHROOTFOLDER}/edit/etc/lsb-release" ]]; then
		FOREIGN=$(file "${CHROOTFOLDER}/edit/bin/bash")
		for EACH in "${UEARCH[@]}"
		do
			ARCH=$(echo "${FOREIGN}" | grep -i "${EACH}")
			if [[ "${ARCH}" ]]; then
				Center "Architecture detected as: ${EACH}"
				ARCH="${EACH}"
				Encapsulate "Not looking for any other architecture, exiting loop."
				break;
			fi
			case "${ARCH}" in
				armel) Center "Inserting ARM support into chroot environment.";
					if [[ -f "/usr/bin/qemu-arm-static" ]]; then
						Encapsulate "Inserting support for arm from ${PWD}";
						cp "/usr/bin/qemu-arm-static ${2}/edit/bin/";
					else
						Error "Qemu is not installed on host machine, exiting.";
						exit 1;
					fi;;
				armhf) Center "Inserting ARM support into chroot environment.";
					if [[ -f "/usr/bin/qemu-arm-static" ]]; then
						Encapsulate "Inserting support for arm from ${PWD}";
						cp "/usr/bin/qemu-arm-static ${2}/edit/bin/";
					else
						Error "Qemu is not installed on host machine, exiting.";
						exit 1;
					fi;;
				powerpc) Center "Inserting PowerPC support into chroot environment.";
					if [[ -f "/usr/bin/qemu-arm-static" || -f "/usr/bin/qemu-ppc" ]]; then
						Encapsulate "Inserting support for PPC from ${PWD}";
						SUPPRESS=$(cp "/usr/bin/qemu-ppc-static ${2}/edit/bin/" 2>/dev/null);
						#SUPPRESS=$((cp /usr/bin/qemu-ppc ${2}/edit/bin/) 2>/dev/null);
					else
						Error "Qemu is not installed on host machine, exiting.";
						exit 1;
					fi;;
				*) Encapsulate "Scanning for ${EACH} support."; NATIVE=1;;
			esac
		done
	else
		Error "No O/S detected at ${CHROOTFOLDER}"
		exit 1;
	fi

	if [[ -d "${CHROOTFOLDER}/edit" ]]; then
		if [[ "${DEBUG}" ]]; then
			Encapsulate "DEBUGGING: ${CHROOTFOLDER}/edit does exist, no matter what this software may tell you."
		fi
		if [[ -f "/run/resolvconf/resolv.conf" ]]; then
			Encapsulate "Setting up Internet for the chroot environment."
			cp "/run/resolvconf/resolv.conf" "${CHROOTFOLDER}/edit/run/resolvconf/resolv.conf"
		else
			Error "Error: /run/resolvconf/resolv.conf does not exist, this could be a critical error, proceeding."
			Encapsulate "Attempting to set nameserver(s)"
			if [[ -f "/etc/resolv.conf" ]]; then
				cp "/etc/resolv.conf" "${CHROOTFOLDER}/edit/etc/resolv.conf"
			else
				Error "Error: /etc/resolv.conf does not exist, this could be a critical error, proceeding."
				Encapsulate "Setting nameserver to 8.8.8.8 & 127.0.0.1, trying to save us from a undesireable situation of no internet."
				if [[ "${DEBUG}" ]]; then
					echo "DEBUGGING FROM ${PWD}"
				fi
				PUNCHIT=$(echo "nameserver 8.8.8.8" | tee /etc/resolv.conf > /dev/null)

			fi
		fi

		if [[ -f "/usr/share/ultimate_edition/tmmount" ]]; then
			Encapsulate "Installing tmmount into the chroot environment."
			cp "/usr/share/ultimate_edition/tmmount" "${CHROOTFOLDER}/edit/bin/"
			if [[ -f "/usr/share/ultimate_edition/ultimate-common" ]]; then
				Encapsulate "Installing Common software to chroot environment."
				cp "/usr/share/ultimate_edition/ultimate-common" "${CHROOTFOLDER}/edit/bin/"
				cp "/usr/share/ultimate_edition/ultimate-common" "${CHROOTFOLDER}/edit/tmp/"
			fi
		else
			Error "Error tmmount, not found. Continuing."
		fi

		if [[ -f "${CHROOTFOLDER}/edit/bin/bash" ]]; then
			Center "You are about to enter chroot. Please type exit when done."
			/usr/sbin/chroot "${CHROOTFOLDER}/edit" /bin/bash -c "cd /tmp/ ; tmmount $*"
			chroot "${CHROOTFOLDER}/edit"
			Center "Exiting: Chroot Environment"

			if [[ -d "${CHROOTFOLDER}" ]]; then
				cd "${CHROOTFOLDER}" || exit 1;
			else
				Error "ERROR: folder ${CHROOTFOLDER} does not exist."
				exit 1;
			fi
			TESTLTS=""
			TESTLTS=$(grep -i "LTS" "extract-cd/.disk/info")

			if [[ "${TESTLTS}" ]]; then
				Center "Setting LTS sources"
				InjectLTSSources
			else
				Center "Setting NON-LTS sources"
				InjectSources
			fi

			cd "${INFOLDER}" || exit 1;
			Encapsulate "Unmounting points..."
			DISMOUNT=$(mount | grep "${PWD}" | cut -d' ' -f3 2>/dev/null)

			for EACH in ${DISMOUNT}
			do
				Encapsulate "Unmounting ${EACH}."
				SUPPRESS=$(umount "${EACH}" 2>/dev/null)
			done
			DISMOUNT=$(mount | grep "${PWD}" | cut -d' ' -f3 2>/dev/null)

			if ! [[ "${DISMOUNT}" ]]; then
				Encapsulate "Unmounting successful."
			else
				Error "Unmount unsuccessful: ${DISMOUNT}"
			fi

			Encapsulate "Attempting hidden dismount at ${PWD}"

			for EACH in "${MOUNTPOINTS[@]}"
			do
				Encapsulate "Unmounting: ${CHROOTFOLDER}/edit/${EACH}"
				SUPPRESS=$(umount "${CHROOTFOLDER}/edit/${EACH}" 2>/dev/null)
			done

		Encapsulate "Cleaning up."

				if [[ -f "${CHROOTFOLDER}/edit/run/resolvconf/resolv.conf" ]]; then
			rm "${CHROOTFOLDER}/edit/run/resolvconf/resolv.conf"
				fi
			ITB=$(echo "${CHROOTFOLDER}" | sed 's/\///g')
			GREPIT=$(echo "${ITB}" | grep -i 'iso')
			if ! [[ "${GREPIT}" ]]; then
				ITB+=".iso"
			fi
			Encapsulate "${PROGNAME} --buildiso ${ITB}"
			Encapsulate "to build the iso."
			FullBar
			exit 0;
		fi
	else
		Error "${CHROOTFOLDER}/edit does not exist, exiting."
		exit 1;
	fi
}

Diagnose () {
	if [[ -f "${1}" ]]; then
		Encapsulate "Diagnosing ${1}"
		Encapsulate "NOT CURRENTLY IMPLEMENTED, EXITING."
		exit 0;
	fi
}

SpeedTest () {
	VersionDump
	Center "Testing Internet speed"
	FullBar
	curl -s  https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python -
	FullBar
	RESONATION=$( lscpu | grep -i 'cpu max Mhz' | cut -d ":" -f2 | sed "s/ //g" )
	PROC=$( cat /proc/cpuinfo | grep -m1 'model name' | sed -e 's/.*: //' | uniq )
	CORES=$( cat /proc/cpuinfo | grep "processor" | sed '/model/d' | wc -l )
	Center "Testing Processor: ${PROC} resonating at ${RESONATION} Mhz"
	FullBar
	Encapsulate "Testing single core speed at 1 thread.  Please wait one minute."
	FullBar
	time $(seq 1 | xargs -P0 -n1 timeout 60 md5sum /dev/zero)
	FullBar
	Encapsulate "Testing multi-core speed at ${CORES} threads. Please wait one minute, CPU cores will now goto 100% during test."
	FullBar
	time $(seq "${CORES}" | xargs -P0 -n1 timeout 60 md5sum /dev/zero)
	FullBar
	if ! [[ "${IUSER}" != "root" && "${TRUEROOT}" != "0" ]]; then
		Center "Testing Disk speed"
		FullBar
		hdparm -Tt /dev/sda
		FullBar
	fi
	Encapsulate "Based on findings:"
}

Information () {
	VersionDump
	ISISO=$(echo "$*" | grep -i ".iso")
	OUTPUT=$(echo "$*" | grep -i "output=")
	INFOLDER="${PWD}"
	declare -i FOUND;

	for EACH in "$@"
	do
		if [[ -d "${EACH}" ]]; then
			Encapsulate "Directory: ${EACH} exists:"
			PROCESS"${EACH%/}"
			FOUND=1
		fi
		if [[ "${ISISO}" && -f "${EACH}" ]]; then
			FOUND=1
			PROCESS="${EACH}"
			Encapsulate "Processing ${EACH}"
			FINFO=$(file "${EACH}")
			FILESIZE=$(stat -c%s "${EACH}")
			FDISKSIZE=$(printf "%'.3f\n" "${FILESIZE}")
			FILESIZE=$(echo "${FDISKSIZE}" | cut -d. -f1)
			Encapsulate "Build: ${FINFO}"
			Encapsulate "ISO Filesize: ${FILESIZE} bytes"

			if ! [[ -d mnt/ ]]; then
				Encapsulate "Mounting image: ${PROCESS}"
				mkdir -p "mnt/"
				if [[ -d "mnt/" ]]; then
					SUPPRESS=$((mount -o loop "${PROCESS}" mnt/) 2>/dev/null)
					sync;
				fi
			fi
			#exit 1;
			if [[ -f "mnt/.disk/info" ]]; then
				DINFO=$(cat mnt/.disk/info)
				Encapsulate "Diskinfo: ${DINFO}"
			else
				Encapsulate "Internal Disk info not found."
			fi

			if [[ -f "mnt/casper/filesystem.size" ]]; then
				DISKSIZE=$(cat "mnt/casper/filesystem.size")
				FDISKSIZE=$(printf "%'.3f\n" "${DISKSIZE}")
				DISKSIZE=$(echo "${FDISKSIZE}" | cut -d. -f1)
				Encapsulate "Installed Size: ${DISKSIZE} bytes"
			fi

			if [[ -f "mnt/casper/filesystem.squashfs" ]]; then
				if ! [[ -d "squash/" ]]; then
					Encapsulate "Mounting Squash filesystem."
					mkdir squash
					SUPPRESS=$(mount -o loop "mnt/casper/filesystem.squashfs" "squash/")
				fi
			else
				Encapsulate "Squash Filesystem not found on ${PROCESS}"
			fi

			declare -a KERNEL=();
			shopt -s nullglob
			if [[ -d "squash/boot/" ]]; then
				KERNEL=$(find squash/boot/ -name "vmlinuz-*") 2>/dev/null
			fi

			if [[ "${KERNEL}" ]]; then
				CKERNEL=$(echo "${KERNEL}" | cut -d "z" -f2 | cut -d "-" -f2,3,4,5)
				Encapsulate "Kernel: ${CKERNEL}"
			fi

			if [[ -f "squash/etc/skel/.dmrc" ]]; then
				DESKTOPENV=$(grep -i "session" squash/etc/skel/.dmrc | cut -d"=" -f2)
				Encapsulate "Default Desktop: ${DESKTOPENV}"
			fi

			if [[ -f "squash/etc/lsb-release" ]]; then
				DISTRO=$(grep -i "DISTRIB_ID=" squash/etc/lsb-release | cut -d "=" -f2)
				RELEASEVER=$(grep -i "DISTRIB_RELEASE=" squash/etc/lsb-release | cut -d "=" -f2)
				CODENAME=$(grep -i "DISTRIB_CODENAME=" squash/etc/lsb-release | cut -d "=" -f2)
				DISTRIB_DESCRIPTION=$(grep -i "DISTRIB_DESCRIPTION=" squash/etc/lsb-release | cut -d "=" -f2)
				Encapsulate "Distro: ${DISTRO}"
				Encapsulate "Release Version: ${RELEASEVER}"
				Encapsulate "Dist Codename: ${CODENAME}"
				Encapsulate "Dist Description: ${DISTRIB_DESCRIPTION}"
			else
				Encapsulate "no /etc/lsb-release found."
			fi

			Encapsulate "Calculating md5sum please wait..."
			MDSUM=$(md5sum "${PROCESS}")
			Encapsulate "MD5SUM: ${MDSUM}"
			Encapsulate "Unmounting images."
			ISMOUNTED=""
			ISMOUNTED=$(mount | grep -i "squash/")

			if [[ "${ISMOUNTED}" ]]; then
				umount squash
				sync;
			fi

			ISMOUNTED=""
			ISMOUNTED=$(mount | grep -i "mnt/")
			if [[ "${ISMOUNTED}" ]]; then
				umount mnt
				sync;
			fi
			Encapsulate "Cleaning up."

			if [[ -d "squash/" ]]; then
				EMPTY=""
				EMPTY=$(find "squash/" -type d -empty -print)

				if [[ "${EMPTY}" ]]; then
					rm -R "squash/"
					sync;
				fi
			fi

			if [[ -d "mnt/" ]]; then
				EMPTY=""
				EMPTY=$(find "mnt/" -type d -empty -print)

				if [[ "${EMPTY}" ]]; then
					rm -R "mnt/"
					sync;
				fi
			fi
			Timer "Stop" "${APPNAME}"
			FullBar
		fi
	done

}
# Command Line Interpreter. - We do have a function above to handle invalidity (unused btw)
# We also have bash autocompletion to herd users into the corral ;)
# Each function has is's own invalidity options.  This will expand, and why I pass $@ (everything*)
# In every function.

shopt -u nullglob
if ! [[ "${SUPPRESS}" ]]; then
	VersionDump "$@"
	Timer "Start" "${APPNAME}"
fi

case "${1}" in
	-b|--build) BuildNEWISO "$@"; exit 0;;
	-B|--buildiso) BuildISO "$@"; exit 0;;
	-Z|--BUILDALL) BuildAll "$@";; # exit 0;; #Hidden feature, used when I goto work at my other job.
	-m|--modify) Chroot "$@"; exit 0;;
	-c|--cacheinfo) CacheInfo "$@"; exit 0;;
	-C|--clearcache) ClearCache "$@"; exit 0;;
	-d|--debootstrap) Debootstrap "$@"; exit 0;;
	-D|--diagnose) Diagnose "$@"; exit 0;;
	-e|--extract) ExtractISO "$@"; exit 0;;
	-g|--grid) GridOS "$@"; exit 0;; # TODO: Enhance this section.
	-i|--info|--information)Information "$@"; exit 0;;
	-h|--help|-\?) Help "$@"; exit 0;; # TODO: Enhance this section.
	-p|--pull) PullSource "$@"; exit 0;;
	-r|--release) Release "$@"; exit 0;;
	-s|--speedtest) SpeedTest "$@"; exit 0;;
	-t|--test|test) Virtual "$@"; exit 0;;
	-u|--upgrade) UpgradeISO "$@"; exit 0;;
	-v|--version) exit 0;;
	*) Help; exit 0;;
esac

# ==============================================================================
# This code was automatically cleaned up using code-cleanup
# title			:code-cleanup
# description	:Bash code cleanup script
# Author		:root
# date			:10/23/2013
# version		:1.7.2-1
# http://ultimateedition.info/
# ==============================================================================
