#!/bin/bash
#This is the single-file version of multicd.sh, compiled on: Sat Nov 17 18:58:27 CST 2012

set -e

#MCDDIR: directory where functions.sh, plugins.md5 and plugins folder are expected to be. Not used in a combined .sh file.
export MCDDIR="."
. "${MCDDIR}"/functions.sh

MCDVERSION="7.1"
#multicd.sh 7.1
#Copyright (c) 2012 Isaac Schemm
#
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in
#all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#THE SOFTWARE.

#Needs to be changed when a new version of syslinux comes out.
RECENT_SYSLINUX="4.05"

mcdclean() {
	for i in *;do
		if [ -n "$(readlink "$i"|grep -v '/')" ];then
			rm -v "$i"
		fi
	done
	rm -fv *.defaultname 2> /dev/null
	rm -fv *.version 2> /dev/null
}

#Clean operation runs here
if [ "$1" = "clean" ];then
	mcdclean
	exit 0 #quit program
else
	mcdclean
fi

#GUI helper - calls a terminal emulator which calls another multicd
if [ "$1" = "gui" ];then
	if which zenity &> /dev/null;then
		DIR=$(zenity --file-selection --directory --filename=$HOME/ --title="MultiCD - Choose directory")
		cd "$DIR"
		RUN="$0 -w"
	else
		RUN="$0 give-error"
	fi
	if which x-terminal-emulator &> /dev/null;then
		exec x-terminal-emulator -e $RUN
	else
		exec xterm -e $RUN
	fi
fi

if [ "$1" = "give-error" ];then
	echo "Zenity is not installed. Please navigate to your ISO directory in the terminal, and run multicd from there."
	echo "Press ENTER to continue..."
	read
	exit 1
fi

#if getopt -T > /dev/null;then
#	echo "You have a non-GNU getopt. Don't use an output path with spaces in it."
	ARGS=$(getopt cdmviVo:tw $*)
#else
#	ARGS=$(getopt cdmviVo:tw "$@")
#fi
export MD5=false
export MEMTEST=true
export VERBOSE=true
export INTERACTIVE=false
export DEBUG=false
export OUTPUT='multicd.iso'
export TESTISO=false
export WAIT=false
eval set -- $ARGS
for i do
	case "$i" in
		-c) shift;export MD5=true;;
		-d) shift;export DEBUG=true;;
		-i) shift;export INTERACTIVE=true;;
		-m) shift;export MEMTEST=false;;
		-o) shift;export OUTPUT="$1";shift;;
		-t) shift;export TESTISO=true;shift;;
		-v) shift;export VERBOSE=true;;
		-V) shift;echo $MCDVERSION;exit 0;; #quit program
		-w) shift;export WAIT=true;shift;;
	esac
done

if ! touch "${OUTPUT}" 2> /dev/null;then
	echo "Error: cannot write to "${OUTPUT}""
	exit 1
else
	rm "${OUTPUT}"
fi

#--------Directory Variables--------#
#WORK: the directory that the eventual CD/DVD contents will be stored temporarily.
export WORK="$(pwd)/multicd-working"
#MNT: the directory inside which new folders will be made to mount the ISO images.
export MNT="$(pwd)/temporary-mountpoints"
mkdir -p "${MNT}"
#TAGS: used to store small text files (temporary)
export TAGS="${MNT}/tags"

if [ $(whoami) = root ] && uname|grep -q Linux;then
	export EXTRACTOR=mount #When possible, loop-mount is preferred because it is faster (files are copied once, not twice, before the ISO is generated) and because it runs without an X server. However, it is only available to root, which opens up security risks.
elif which fuseiso &> /dev/null; then
	export EXTRACTOR=fuseiso
elif which file-roller &> /dev/null;then
	export EXTRACTOR=file-roller #file-roller is a GNOME application
elif which ark &> /dev/null;then
	export EXTRACTOR=ark #Ark is a KDE application
else
	if !(uname|grep -q Linux);then
		echo "Unless file-roller or ark is installed to extract ISOs, only Linux kernels are supported (due to the use of \"-o loop\")."
		exit 1
	elif [ $(whoami) != "root" ];then
		echo "Unless file-roller or ark is installed to extract ISOs, this script must be run as root, so it can mount ISO images on the filesystem during the building process."
		exit 1
	fi
fi
if ( [ $EXTRACTOR = file-roller ] || [ $EXTRACTOR = ark ] ) && [ ! -n "$DISPLAY" ];then
	echo "This script cannot use file-roller or ark to extract ISOs, because no X server  is available. Please launch an X server or run this script as root."
	exit 1
fi

if [ -d "${TAGS}" ];then rm -r "${TAGS}";fi
mkdir -p "${TAGS}"
mkdir "${TAGS}"/puppies
mkdir "${TAGS}"/debians
chmod -R 777 "${TAGS}"

#START PREPARE#
#!/bin/sh
mcdmount () {
	# "${MNT}" is defined in multicd.sh and is normally in /tmp
	# $1 is the argument passed to mcdmount - used for both ISO name and mount folder name
	if [ $EXTRACTOR = mount ] && grep -q "${MNT}"/$1 /etc/mtab ; then
		umount "${MNT}"/$1
	fi
	if [ -d "${MNT}"/$1 ];then
		rm -r "${MNT}"/$1
	fi
	mkdir "${MNT}"/$1
	if [ $EXTRACTOR = file-roller ];then
		file-roller -e "${MNT}"/$1 $1.iso
		chmod -R +w "${MNT}"/$1 #To avoid confirmation prompts on BSD cp
	elif [ $EXTRACTOR = ark ];then
		ark -b -o "${MNT}"/$1 $1.iso
		chmod -R +w "${MNT}"/$1 #To avoid confirmation prompts on BSD cp
	elif [ $EXTRACTOR = mount ];then
		mount -o loop,ro $1.iso "${MNT}"/$1/
	elif [ $EXTRACTOR = fuseiso ];then
		fuseiso $1.iso $MNT/$1 -orw,umask=0000
	else
		echo "mcdmount function: \$EXTRACTOR not defined! (this is a bug in multicd.sh)"
		exit 1
	fi
}
umcdmount () {
	if [ $EXTRACTOR = mount ];then
		umount "${MNT}"/$1;rmdir "${MNT}"/$1
	elif [ $EXTRACTOR = fuseiso ];then
		fusermount -u $MNT/$1; rmdir $MNT/$1
	else
		rm -r "${MNT}"/$1
	fi
}

isoaliases () {
	true > "${TAGS}"/linklist #Clears the file that keeps track of the links.

	#The data from START LINKS to END LINKS is not copied when combine.sh makes a single file.
	#In that case, this is instead handled by adding " >> "${TAGS}"/linklist" to each line in the "links" section of a plugin.
	#START LINKS#
#START FUNCTIONS#
debianExists () {
	if [ "*.debian.iso" != "$(echo *.debian.iso)" ];then
		echo true
	else
		echo false
	fi
}

getDebianName () {
	BASENAME=$(echo $i|sed -e 's/\.iso//g')
	#get version
	if [ -f $BASENAME.version ] && [ "$(cat $BASENAME.version)" != "" ];then
		VERSION=" $(cat $BASENAME.version)" #Version based on isoaliases()
	else
		VERSION=""
	fi
	#get name
	if [ -f "${TAGS}"/$BASENAME.name ] && [ "$(cat "${TAGS}"/$BASENAME.name)" != "" ];then
		DEBNAME=$(cat "${TAGS}"/$BASENAME.name)
	elif [ -f $BASENAME.defaultname ] && [ "$(cat $BASENAME.defaultname)" != "" ];then
		DEBNAME="$(cat $BASENAME.defaultname) ${VERSION}"
	else
		DEBNAME="$(echo $BASENAME|sed -e 's/\.debian//g') ${VERSION}"
	fi
	#return
	echo ${DEBNAME}
}
#END FUNCTIONS#
#START FUNCTIONS#
linuxmintExists () {
	if [ "*.linuxmint.iso" != "$(echo *.linuxmint.iso)" ];then
		echo true
	else
		echo false
	fi
}

getLinuxmintName () {
	BASENAME=$(echo $i|sed -e 's/\.iso//g')
	#get version
	if [ -f $BASENAME.version ] && [ "$(cat $BASENAME.version)" != "" ];then
		VERSION=" $(cat $BASENAME.version)" #Version based on isoaliases()
	else
		VERSION=""
	fi
	#get name
	if [ -f "${TAGS}"/$BASENAME.name ] && [ "$(cat "${TAGS}"/$BASENAME.name)" != "" ];then
		UBUNAME=$(cat "${TAGS}"/$BASENAME.name)
	elif [ -f $BASENAME.defaultname ] && [ "$(cat $BASENAME.defaultname)" != "" ];then
		UBUNAME="$(cat $BASENAME.defaultname) ${VERSION}"
	else
		UBUNAME="$(echo $BASENAME|sed -e 's/\.ubuntu//g') ${VERSION}"
	fi
	#return
	echo ${UBUNAME}
}
#END FUNCTIONS#
#START FUNCTIONS#
ubuntuExists () {
	if [ "*.ubuntu.iso" != "$(echo *.ubuntu.iso)" ];then
		echo true
	else
		echo false
	fi
}

getUbuntuName () {
	BASENAME=$(echo $i|sed -e 's/\.iso//g')
	#get version
	if [ -f $BASENAME.version ] && [ "$(cat $BASENAME.version)" != "" ];then
		VERSION=" $(cat $BASENAME.version)" #Version based on isoaliases()
	else
		VERSION=""
	fi
	#get name
	if [ -f "${TAGS}"/$BASENAME.name ] && [ "$(cat "${TAGS}"/$BASENAME.name)" != "" ];then
		UBUNAME=$(cat "${TAGS}"/$BASENAME.name)
	elif [ -f $BASENAME.defaultname ] && [ "$(cat $BASENAME.defaultname)" != "" ];then
		UBUNAME="$(cat $BASENAME.defaultname)"
	else
		UBUNAME="$(echo $BASENAME|sed -e 's/\.ubuntu//g') ${VERSION}"
	fi
	#return
	echo ${UBUNAME}
}
#END FUNCTIONS#
	#Only one will be included >> $TAGS/linklist
	echo "archlinux-*-netinstall-dual.iso arch.iso none" >> $TAGS/linklist
	echo "archlinux-*-core-dual.iso arch.iso none" >> $TAGS/linklist
	echo "archlinux-*-netinstall-i686.iso arch.iso none" >> $TAGS/linklist
	echo "archlinux-*-netinstall-x86_64.iso arch.iso none" >> $TAGS/linklist
	echo "archlinux-*-core-i686.iso arch.iso none" >> $TAGS/linklist
	echo "archlinux-*-core-x86_64.iso arch.iso none" >> $TAGS/linklist
	echo "archlinux-*-archboot.iso archboot.iso none" >> $TAGS/linklist
	echo "archiso-live-*.iso archiso-live.iso none" >> $TAGS/linklist
	echo "avg_*.iso avg.iso none" >> $TAGS/linklist
	echo "BT5-*.iso backtrack.iso none" >> $TAGS/linklist
	echo "CentOS-*-netinstall.iso centos-boot.iso none" >> $TAGS/linklist
	echo "clonezilla-live-*-i686-pae.iso clonezilla686.iso none" >> $TAGS/linklist
	echo "connos-*.iso connos.iso none" >> $TAGS/linklist
	echo "debian-*-i386-netinst.iso debian-install.iso none" >> $TAGS/linklist
	echo "debian-*-amd64-netinst.iso debian-install64.iso none" >> $TAGS/linklist
	echo "binary.iso binary.debian.iso none" >> $TAGS/linklist
	echo "debian-live-*.iso debian-live.debian.iso Debian_Live:" >> $TAGS/linklist
	echo "doudoulinux-*.iso doudoulinux.iso none" >> $TAGS/linklist
	echo "drweb-livecd-*.iso drweb.iso none" >> $TAGS/linklist
	echo "feather-*.iso feather.iso none" >> $TAGS/linklist
	echo "Fedora-*-i386-netinst.iso fedora-boot.iso none" >> $TAGS/linklist
	echo "Fedora-*-x86_64-netinst.iso fedora-boot64.iso none" >> $TAGS/linklist
	#Only one will be included >> $TAGS/linklist
	echo "fd11src.iso freedos.iso FreeDOS_1.1" >> $TAGS/linklist
	echo "fdfullcd.iso freedos.iso FreeDOS_Full_CD" >> $TAGS/linklist
	echo "fdbasecd.iso freedos.iso FreeDOS_Base_CD" >> $TAGS/linklist
	echo "Fusion-Linux-*.iso fusion.iso none" >> $TAGS/linklist
	if [ -f generic.lst ];then >> $TAGS/linklist
		cat generic.lst | sed -e '/^#/d' -e '/^$/d' >> $TAGS/linklist
	fi >> $TAGS/linklist
	echo "gparted-live-*.iso gparted.iso none" >> $TAGS/linklist
	echo "grml32-full*.iso grml.iso none" >> $TAGS/linklist
	echo "grml64-full*.iso grml64.iso none" >> $TAGS/linklist
	echo "Hiren's.BootCD.*.iso hirens.iso none" >> $TAGS/linklist
	echo "ipcop-*-install-cd.i486.iso ipcop.iso none" >> $TAGS/linklist
	echo "kav_rescue_*.iso kav.iso none" >> $TAGS/linklist
	echo "KDu-Small-*.iso kdusmall.iso none" >> $TAGS/linklist
	echo "KDuXPv*.iso kduxp.iso none" >> $TAGS/linklist
	echo "KNOPPIX_V*.iso knoppix.iso none" >> $TAGS/linklist
	echo "linuxmint-*.iso mint.linuxmint.iso Linux_Mint" >> $TAGS/linklist
	echo "Mandriva.*.iso mandriva.iso none" >> $TAGS/linklist
	echo "linuxmint-debian-*.iso mintdebian.iso none" >> $TAGS/linklist
	echo "NetbootCD-*.iso netbootcd.iso none" >> $TAGS/linklist
	echo "cd??????.iso ntpasswd.iso none" >> $TAGS/linklist
	echo "openSUSE-*-GNOME-LiveCD-i686.iso opensuse-gnome.iso none" >> $TAGS/linklist
	echo "openSUSE-*-NET-i586.iso opensuse-net.iso none" >> $TAGS/linklist
	echo "openSUSE-*-NET-x86_64.iso opensuse-net64.iso none" >> $TAGS/linklist
	echo "pclinuxos-kde-*.iso pclos.iso none" >> $TAGS/linklist
	echo "pclinuxos-lxde-*.iso pclx.iso none" >> $TAGS/linklist
	echo "Pinguy_OS_*.iso pinguy.iso none" >> $TAGS/linklist
	echo "pmagic-*.iso pmagic.iso none" >> $TAGS/linklist
	echo "Porteus-*.iso porteus.iso none" >> $TAGS/linklist
	echo "lupu-*.iso lupu.puppy.iso none" >> $TAGS/linklist
	echo "racy-*.iso racy.puppy.iso none" >> $TAGS/linklist
	echo "redobackup-livecd-*.iso redobackup.iso none" >> $TAGS/linklist
	echo "rescatux_*.iso rescatux.iso none" >> $TAGS/linklist
	echo "RIPLinuX-*.iso riplinux.iso none" >> $TAGS/linklist
	echo "Sabayon_Linux_*.iso sabayon.iso none" >> $TAGS/linklist
	echo "SL-*-boot.iso scientific-boot.iso none" >> $TAGS/linklist
	echo "slax-*.iso slax.iso none" >> $TAGS/linklist
	echo "systemrescuecd-x86-*.iso sysrcd.iso none" >> $TAGS/linklist
	#Only one will be included >> $TAGS/linklist
	echo "CorePlus-*.iso tinycore.iso none" >> $TAGS/linklist
	echo "TinyCore-*.iso tinycore.iso none" >> $TAGS/linklist
	echo "Core-*.iso tinycore.iso none" >> $TAGS/linklist
	echo "trinity-rescue-kit.*.iso trk.iso none" >> $TAGS/linklist
	echo "ubcd*.iso ubcd.iso none" >> $TAGS/linklist
	#Only one will be included, because only one can be used. >> $TAGS/linklist
	echo "ubuntu-*-alternate-i386.iso ubuntu-alternate.iso Ubuntu_alternate_installer_(32-bit)" >> $TAGS/linklist
	echo "ubuntu-*-alternate-amd64.iso ubuntu-alternate.iso Ubuntu_alternate_installer_(64-bit)" >> $TAGS/linklist
	echo "kubuntu-*-alternate-i386.iso ubuntu-alternate.iso Kubuntu_alternate_installer_(32-bit)" >> $TAGS/linklist
	echo "kubuntu-*-alternate-amd64.iso ubuntu-alternate.iso Kubuntu_alternate_installer_(64-bit)" >> $TAGS/linklist
	echo "xubuntu-*-alternate-i386.iso ubuntu-alternate.iso Xubuntu_alternate_installer_(32-bit)" >> $TAGS/linklist
	echo "xubuntu-*-alternate-amd64.iso ubuntu-alternate.iso Xubuntu_alternate_installer_(64-bit)" >> $TAGS/linklist
	echo "lubuntu-*-alternate-i386.iso ubuntu-alternate.iso Lubuntu_alternate_installer_(32-bit)" >> $TAGS/linklist
	echo "lubuntu-*-alternate-amd64.iso ubuntu-alternate.iso Lubuntu_alternate_installer_(64-bit)" >> $TAGS/linklist
	echo "ubuntu-*-server-i386.iso ubuntu-alternate.iso Ubuntu_server_(32-bit)" >> $TAGS/linklist
	echo "ubuntu-*-server-amd64.iso ubuntu-alternate.iso Ubuntu_server_(64-bit)" >> $TAGS/linklist
	echo "ubuntu-*-desktop-i386.iso i386.ubuntu.iso Ubuntu_(32-bit)_*" >> $TAGS/linklist
	echo "ubuntu-*-desktop-amd64.iso amd64.ubuntu.iso Ubuntu_(64-bit)_*" >> $TAGS/linklist
	echo "kubuntu-*-desktop-i386.iso i386.k.ubuntu.iso Kubuntu_(32-bit)_*" >> $TAGS/linklist
	echo "kubuntu-*-desktop-amd64.iso amd64.k.ubuntu.iso Kubuntu_(64-bit)_*" >> $TAGS/linklist
	echo "xubuntu-*-desktop-i386.iso i386.x.ubuntu.iso Xubuntu_(32-bit)_*" >> $TAGS/linklist
	echo "xubuntu-*-desktop-amd64.iso amd64.x.ubuntu.iso Xubuntu_(64-bit)_*" >> $TAGS/linklist
	echo "edubuntu-*-dvd-i386.iso i386.x.ubuntu.iso Edubuntu_(32-bit)_*" >> $TAGS/linklist
	echo "edubuntu-*-dvd-amd64.iso amd64.x.ubuntu.iso Edubuntu_(64-bit)_*" >> $TAGS/linklist
	echo "lubuntu-*-desktop-i386.iso i386.l.ubuntu.iso Lubuntu_(32-bit)_*" >> $TAGS/linklist
	echo "lubuntu-*-desktop-amd64.iso amd64.l.ubuntu.iso Lubuntu_(64-bit)_*" >> $TAGS/linklist
	echo "WEAKERTHAN*.iso weaknet.iso WeakNet_WEAKERTHAN*" >> $TAGS/linklist
	echo "xbmc-*-live.iso xbmc.iso none" >> $TAGS/linklist
	echo "zorin-os-*.iso zorin.iso none" >> $TAGS/linklist
	#END LINKS#

	cat "${TAGS}"/linklist|while read i;do

		DEFAULTNAME=$(echo "$i"|awk '{print $NF}')
		LINKNAME=$(echo "$i"|awk '{LESS=NF-1; print $LESS}') #What should be linked to
		MATCHING_ISOS=$(echo $i|awk '{LESS=NF-1; for (i=1; i<LESS; i++) print $i }') #Prints all except the last 2 fields. $i is NOT surrounded by quotes, so wildcards are expanded.

		if !( echo $MATCHING_ISOS | grep -q '\*' ) && [ ! -e $LINKNAME ];then
			#MATCHING_ISOS exists (i.e. the asterisk got expanded) and LINKNAME doesn't exist yet
			COUNTER=0
			for j in $MATCHING_ISOS;do
				#This is done for each matching ISO.

				if [ $COUNTER = 0 ];then
					LINKTO=$LINKNAME #The intended link name.
				else
					#Adds the counter number and an underscore to the beginning of the link name.
					#I'm not sure if any plugins use this. I know that if this happens, any later aliasing rules for the same LINKNAME will be skipped. :(
					#This might cause a little (harmless) clutter in the working directory.
					LINKTO=${COUNTER}_${LINKNAME}
				fi

				if [ -e "$j" ] && ln -s $j $LINKTO;then
					#The ISO that the link should point to exists, and the link was created sucessfully.

					ISOBASENAME=$(echo $LINKTO|sed -e 's/\.iso//g')

					touch "${TAGS}"/madelinks #This function will pause for 1 second if this file exists, so the notifications are readable

					CUTOUT1=$(echo "$i"|awk 'BEGIN {FS = "*"} ; {print $1}') #The parts of the ISO name before the asterisk
					CUTOUT2=$(echo "$i"|awk '{print $1}'|awk 'BEGIN {FS = "*"} ; {print $2}') #The parts after the asterisk
					VERSION=$(echo "$j"|awk '{sub(/'"$CUTOUT1"'/,"");sub(/'"$CUTOUT2"'/,"");print}') #Cuts out whatever the asterisk represents (which will be the version number)

					if [ "$VERSION" != "*" ] && [ "$VERSION" != "$j" ];then
						echo $VERSION > $ISOBASENAME.version #Some plugins (like SystemRescueCD) don't use this, because the version number is on a file in the ISO.
						echo "Made a link named $LINKTO pointing to $j (version $VERSION)"
					else	
						echo "Made a link named $LINKTO pointing to $j"
						VERSION="*"
					fi
					if [ "$DEFAULTNAME" != "none" ];then
						#The last field of the row will be the default name when multicd.sh asks the user to enter a name (activated with "i" option.)
						#This could also be used by the menu-writing portion of the plugin script if "${TAGS}"/whatever.name (created by the "i" option) is not present.
						#Underscores are replaced with spaces. Asterisks are replaced with the $VERSION found above.
						echo $DEFAULTNAME|sed -e 's/_/ /g' -e "s/\*/$VERSION/g">$ISOBASENAME.defaultname
					fi

				COUNTER=$(($COUNTER+1))
				fi
			done
		fi
	done
	if [ -f "${TAGS}"/madelinks ];then
		#If the file exists, remove it, then pause for 1 second so the notifications can be seen.
		rm "${TAGS}"/madelinks
		sleep 1
	fi
}

tinycorecommon () {
	if [ ! -z "$1" ] && [ -f $1.iso ];then
		mcdmount $1
		mkdir "${WORK}"/boot/tinycore
		cp "${MNT}"/$1/boot/vmlinuz "${WORK}"/boot/tinycore/vmlinuz #Linux kernel - 4.0 or newer
		cp "${MNT}"/$1/boot/*.gz "${WORK}"/boot/tinycore/ #Copy any initrd there may be - this works for (old) microcore too
		if [ -d "${MNT}"/$1/tce ];then
			cp -r "${MNT}"/$1/tce "${WORK}"/
		fi
		if [ -d "${MNT}"/$1/cde ];then
			cp -r "${MNT}"/$1/cde "${WORK}"/
		fi
		sleep 1
		umcdmount $1
	else
		echo "$0: \"$1\" is empty or not an ISO"
		exit 1
	fi
}
puppycommon () {
	if [ ! -z "$1.puppy" ] && [ -f $1.puppy.iso ];then
		mcdmount $1.puppy
		#The installer will only work if Puppy is in the root dir of the disc
		if [ -f "${TAGS}"/puppies/$1.inroot ];then
			cp "${MNT}"/$1.puppy/*.sfs "${WORK}"/
			cp "${MNT}"/$1.puppy/vmlinuz "${WORK}"/vmlinuz
			cp "${MNT}"/$1.puppy/initrd.gz "${WORK}"/initrd.gz
		else
			mkdir "${WORK}"/$1
			cp "${MNT}"/$1.puppy/*.sfs "${WORK}"/$1/
			cp "${MNT}"/$1.puppy/vmlinuz "${WORK}"/$1/vmlinuz
			cp "${MNT}"/$1.puppy/initrd.gz "${WORK}"/$1/initrd.gz
		fi
		umcdmount $1.puppy
	else
		echo "$0: \"$1.puppy\" is empty or not an ISO, so it will not be copied. This is a bug."
		exit 1
	fi
}
ubuntucommon () {
	if [ ! -z "$1" ] && [ -f $1.iso ];then
		mcdmount $1
		cp -R "${MNT}"/$1/casper "${WORK}"/boot/$1 #Live system
		if [ -d "${MNT}"/$1/preseed ];then
			cp -R "${MNT}"/$1/preseed "${WORK}"/boot/$1
		fi
		# Fix the isolinux.cfg
		if [ -f "${MNT}"/$1/isolinux/text.cfg ];then
			UBUCFG=text.cfg
		elif [ -f "${MNT}"/$1/isolinux/txt.cfg ];then
			UBUCFG=txt.cfg
		else
			UBUCFG=isolinux.cfg #For custom-made live CDs like Weaknet and Zorin
		fi
		cp "${MNT}"/$1/isolinux/splash.* \
		"${MNT}"/$1/isolinux/bg_redo.png \
		"${WORK}"/boot/$1/ 2> /dev/null || true #Splash screen - only if the filename is splash.something or bg_redo.png
		cp "${MNT}"/$1/isolinux/$UBUCFG "${WORK}"/boot/$1/$1.cfg
		echo "label back
		menu label Back to main menu
		com32 menu.c32
		append /boot/isolinux/isolinux.cfg
		" >> "${WORK}"/boot/$1/$1.cfg
		sed -i "s@menu background @menu background /boot/$1/@g" "${WORK}"/boot/$1/$1.cfg #If it uses a splash screen, update the .cfg to show the new location
		sed -i "s@MENU BACKGROUND @MENU BACKGROUND /boot/$1/@g" "${WORK}"/boot/$1/$1.cfg #uppercase
		sed -i "s@default live@default menu.c32@g" "${WORK}"/boot/$1/$1.cfg #Show menu instead of boot: prompt
		sed -i "s@file=/cdrom/preseed/@file=/cdrom/boot/$1/preseed/@g" "${WORK}"/boot/$1/$1.cfg #Preseed folder moved - not sure if ubiquity uses this
		sed -i "s^initrd=/casper/^live-media-path=/boot/$1 ignore_uuid initrd=/boot/$1/^g" "${WORK}"/boot/$1/$1.cfg #Initrd moved, ignore_uuid added
		sed -i "s^kernel /casper/^kernel /boot/$1/^g" "${WORK}"/boot/$1/$1.cfg #Kernel moved
		sed -i "s^KERNEL /casper/^KERNEL /boot/$1/^g" "${WORK}"/boot/$1/$1.cfg #For uppercase KERNEL
		if [ -f "${TAGS}"/lang ];then
			echo added lang
			sed -i "s^initrd=/boot/$1/^debian-installer/language=$(cat "${TAGS}"/lang) initrd=/boot/$1/^g" "${WORK}"/boot/$1/$1.cfg #Add language codes to cmdline
		fi
		if [ -f "${TAGS}"/country ];then
			echo added country
			sed -i "s^initrd=/boot/$1/^console-setup/layoutcode?=$(cat "${TAGS}"/country) initrd=/boot/$1/^g" "${WORK}"/boot/$1/$1.cfg #Add language codes to cmdline
		fi
		umcdmount $1
	else
		echo "$0: \"$1\" is empty or not an ISO"
		exit 1
	fi
}

#Returns the version saved by the isoaliases function. For use in writing the menu.
getVersion() {
	BASENAME=$(echo $1|sed -e 's/\.iso//g')
	if [ -f $BASENAME.version ] && [ "$(cat $BASENAME.version)" != "" ];then
		VERSION=" $(cat $BASENAME.version)" #Version based on isoaliases()
	else
		VERSION=""
	fi

	echo ${VERSION}
}
#END FUNCTIONS
#END PREPARE#

isoaliases #This function is in functions.sh

echo "multicd.sh $MCDVERSION"
echo "Extracting ISO images with $EXTRACTOR; will build "${OUTPUT}"; UID $(id -u)."
echo

#START SCAN
	if [ -f antix.iso ];then
		echo "AntiX"
	fi
	if [ -f arch.iso ];then
		echo "Arch Linux"
	fi
	if [ -f archboot.iso ];then
		echo "Arch Linux Installer"
	fi
	if [ -f archiso-live.iso ];then
		echo "Archiso-live"
	fi
	if [ -f austrumi.iso ];then
		echo "Austrumi"
	fi
	if [ -f avg.iso ];then
		echo "AVG Rescue CD"
	fi
	if [ -f avira.iso ];then
		echo "Avira Rescue CD"
	fi
	if [ -f backtrack.iso ];then
		echo "BackTrack"
	fi
    if [ -f caine.iso ];then
        echo "Caine"
    fi
	if [ -f cdl.iso ];then
		echo "CDlinux"
	fi
	if [ -f centos-boot.iso ];then
		echo "CentOS netboot installer"
	fi
	if [ -f clonezilla$2.iso ];then
		echo "Clonezilla $2"
	fi
	if [ -f connos.iso ];then
		echo "ConnochaetOS"
	fi
	if [ -f dban.iso ];then
		echo "DBAN"
	fi
	if [ -f debian-install.iso ];then
		echo "Debian netinst"
	fi
	if [ -f debian-install64.iso ];then
		echo "Debian netinst (amd64)"
	fi
	if $(debianExists);then
		for i in *.debian.iso; do
			getDebianName
			echo > "${TAGS}"/$(echo $i|sed -e 's/\.iso/\.needsname/g') #Comment out this line and multicd.sh won't ask for a custom name for this ISO
			touch "${TAGS}"/debians/$(echo $i|sed -e 's/\.iso//g')
		done
	fi
	if [ -f debian-mini.iso ];then
		echo "Debian netboot installer"
	fi
	if [ -f deli.iso ];then
		echo "DeLi Linux"
	fi
	if [ -f diskcopy.iso ];then
		echo "EASEUS Disk Copy"
	fi
	if [ -f doudoulinux.iso ];then
		echo "DoudouLinux"
	fi
	if [ -f drweb.iso ];then
		echo "Dr.Web LiveCD"
	fi
	if [ -f dsl.iso ];then
		echo "Damn Small Linux"
	fi
	if [ -f dvl.iso ];then
		echo "Damn Vulnerable Linux"
	fi
	if [ -f efw.iso ];then
		echo "Endian Firewall"
	fi
	if [ -f elastix.iso ];then
		echo "Elastix"
		#touch "${TAGS}"/redhats/elastix
	fi
	if [ -f feather.iso ];then
		echo "Feather"
	fi
	if [ -f fedora-boot.iso ];then
		echo "Fedora netboot installer"
		#touch "${TAGS}"/redhats/fedora-boot
	fi
	if [ -f fedora-boot64.iso ];then
		echo "Fedora 64-bit netboot installer"
		#touch "${TAGS}"/redhats/fedora-boot64
	fi
	if [ -f finnix.iso ];then
		echo "Finnix"
	fi
	if [ -f freedos.iso ];then
		echo "FreeDOS"
	fi
	if [ -f fusion.iso ];then
		echo "Fusion Linux"
	fi
	if [ -f geexbox.iso ];then
		echo "GeeXboX"
	fi
	if $(genericExists);then for i in *.generic.iso;do
		getGenericName
		echo > "${TAGS}"/$(echo $i|sed -e 's/\.iso/\.needsname/g') #Comment out this line and multicd.sh won't ask for a custom name for this ISO
	done;fi
	if [ -f gparted.iso ];then
		echo "GParted Live"
	fi
	if [ -f grml.iso ];then
		echo "GRML"
	fi
	if [ -f grml64.iso ];then
		echo "GRML64"
	fi
	if [ -f hirens.iso ];then
		echo "Hiren's BootCD (Not open source - do not distribute)"
		DUPLICATES=false #Initialize variable
		for i in riplinux dban konboot ntpasswd;do
			if [ -f $i.iso ];then
				echo "  Note: Hiren's BootCD already includes $i. Continuing anyway."
				DUPLICATES=true
			fi
		done
	fi
	if [ -f insert.iso ];then
		echo "INSERT"
	fi
	if [ -f ipcop.iso ];then
		echo "IPCop"
	fi
	if [ -f kav.iso ];then
		echo "Kapersky Rescue Disk"
	fi
	if [ -f kdusmall.iso ];then
		echo "KDu-Small"
	fi
	if [ -f kduxp.iso ];then
		echo "KDuXP"
	fi
	if [ -f knoppix.iso ];then
		echo "Knoppix"
	fi
	if $(linuxmintExists);then
		for i in *.linuxmint.iso; do
			getLinuxmintName
			echo > "${TAGS}"/$(echo $i|sed -e 's/\.iso/\.needsname/g') #Comment out this line and multicd.sh won't ask for a custom name for this ISO
		done
	fi
	if [ -f macpup.iso ];then
		echo "Macpup"
		mkdir -p "${TAGS}"/puppies
		touch "${TAGS}"/puppies/macpup
	fi
	if [ -f mandriva-boot.iso ];then
		echo "Mandriva netboot installer"
	fi
	if [ -f mandriva.iso ];then
		echo "Mandriva Linux"
	fi
	if [ -f mepis.iso ];then
		echo "Mepis"
	fi
	if [ -f mintdebian.iso ];then
		echo "Linux Mint Debian Edition"
	fi
	if [ -f netbootcd.iso ];then
		echo "NetbootCD"
	fi
	if [ -f ntpasswd.iso ];then
		echo "NT Password Editor"
	fi
	if [ -f opensuse-gnome.iso ];then
		echo "openSUSE GNOME Live CD"
	fi
	if [ -f opensuse-net.iso ];then
		echo "openSUSE netboot installer"
	fi
	if [ -f opensuse-net64.iso ];then
		echo "openSUSE 64-bit netboot installer"
	fi
	if [ -f ophxp.iso ] && [ ! -f ophvista.iso ];then
		echo "OPH Crack XP"
	fi
	if [ ! -f ophxp.iso ] && [ -f ophvista.iso ];then
		echo "OPH Crack Vista"
	fi
	if [ -f ophxp.iso ] && [ -f ophvista.iso ];then
		echo "OPH Crack XP/Vista"
	fi
	if [ -f pclos.iso ];then
		echo "PCLinuxOS"
	fi
	if [ -f pclx.iso ];then
		echo "PCLinuxOS LXDE"
	fi
    if [ -f pentoo.iso ];then
        echo "Pentoo Linux"
    fi
	if [ -f ping.iso ];then
		echo "PING"
	fi
	if [ -f pinguy.iso ];then
		echo "Pinguy OS"
	fi
	if [ -f pmagic.iso ];then
		echo "Parted Magic"
	fi
	if [ -f porteus.iso ];then
		echo "Porteus"
	fi
	if $(puppyExists);then for i in *.puppy.iso;do
		echo "Puppy Linux"
		#touch "${TAGS}"/puppy.needsname #Comment out this line and multicd.sh won't ask for a custom name for this ISO
		touch "${TAGS}"/puppies/$(echo $i|sed -e 's/\.puppy\.iso//g')
		mkdir -p "${TAGS}"/puppies
	done;fi
	if [ -f puppy2.iso ];then
		echo "Puppy Linux #2"
		touch "${TAGS}"/puppy2.needsname #Comment out this line and multicd.sh won't ask for a custom name for this ISO
		mkdir -p "${TAGS}"/puppies
		touch "${TAGS}"/puppies/puppy2
	fi
	if [ -f redobackup.iso ];then
		echo "Redo Backup"
	fi
	if [ -f rescatux.iso ];then
		echo "Rescatux"
	fi
	if [ -f riplinux.iso ];then
		echo "RIPLinuX"
	fi
	if [ -f sabayon.iso ];then
		echo "Sabayon Linux"
	fi
	if [ -f scientific-boot.iso ];then
		echo "Scientific Linux netboot installer"
	fi
	if [ -f slax.iso ];then
		echo "Slax"
	fi
	if [ -f slitaz.iso ];then
		echo "SliTaz"
	fi
	if [ -f sysrcd.iso ];then
		echo "SystemRescueCd"
	fi
	if [ -f tc+nb.iso ];then
		echo "NetbootCD / Tiny Core / GRUB4DOS"
	fi
	if [ -f tinycore.iso ];then
		echo "Tiny Core Linux"
	fi
	if [ -f tinyme.iso ];then
		echo "TinyMe"
	fi
	if [ -f trk.iso ];then
		echo "Trinity Rescue Kit"
	fi
	if [ -f ubcd.iso ];then
		echo "Ultimate Boot CD"
	fi
	if [ -f dban.iso ] && [ -f ubcd.iso ];then
		echo "  Note: Ultimate Boot CD includes DBAN, so it is not necessary alone as well. Continuing anyway."
	fi
	if [ -f ntpasswd.iso ] && [ -f ubcd.iso ];then
		echo "  Note: UBCD includes ntpasswd, so it is not necessary alone as well. Continuing anyway."
	fi
	if [ -f pmagic.iso ] && [ -f ubcd.iso ];then
		echo "  Note: UBCD includes Parted Magic, so it is not necessary alone as well. Continuing anyway."
	fi
	if [ -f ubuntu-alternate.iso ];then
		echo "Ubuntu alternate installer"
	fi
	if [ -f ubuntu-mini.iso ];then
		echo "Ubuntu netboot installer"
	fi
	if $(ubuntuExists);then
		for i in *.ubuntu.iso; do
			getUbuntuName
			echo > "${TAGS}"/$(echo $i|sed -e 's/\.iso/\.needsname/g') #Comment out this line and multicd.sh won't ask for a custom name for this ISO
		done
	fi
	if [ -f vyatta.iso ];then
		echo "Vyatta"
	fi
	if [ -f weaknet.iso ];then
		echo "WeakNet Linux"
	fi
	if [ -f win7recovery.iso ];then
		echo "Windows 7 Recovery Disc (Not open source)"
	fi
	if [ -f win98se.iso ];then
		echo "Windows 98 SE (Not open source - do not distribute the final ISO)"
		touch tags/win9x #This tells the interactive option of the script to ask about the add-ons & tools folders
	fi
	if [ -f winme.iso ];then
		echo "Windows Me (Not open source - do not distribute the final ISO)"
		touch tags/win9x #This tells the interactive option of the script to ask about the add-ons & tools folders
	fi
	if [ -f wolvix.iso ];then
		echo "Wolvix"
	fi
	if [ -f xbmc.iso ];then
		echo "XBMC"
	fi
	if [ -f zorin.iso ];then
		echo "Zorin OS"
	fi
#END SCAN

for i in *.im[agz]; do
	test -r "$i" || continue
	echo $i|sed 's/\.im.//'
done
GAMES=0 #Will be changed if there are games
for i in games/*.im[agz]; do
	test -r "$i" || continue
	echo Game: $(echo $i|sed 's/\.im.//'|sed 's/games\///')
	GAMES=1
done
if [ -f grub.exe ];then
	echo "GRUB4DOS"
fi
if $MEMTEST;then
	echo "Memtest86+"
fi

echo
echo "Continuing in 2 seconds - press Ctrl+C to cancel"
sleep 2

if $INTERACTIVE;then
	if ! which dialog &> /dev/null;then
		echo "You must install dialog to use the interactive options."
		exit 1
	fi

	dialog --inputbox "What would you like the title of the CD's main menu to be?" 8 70 "MultiCD - Created $(LANG=C date +"%b %d, %Y")" 2> /tmp/cdtitle
	CDTITLE=$(cat /tmp/cdtitle)
	rm /tmp/cdtitle

	dialog --inputbox "What would you like the CD label to be?" 9 40 "MultiCD" 2> /tmp/cdlabel
	export CDLABEL=$(cat /tmp/cdlabel)
	rm /tmp/cdlabel

	dialog --menu "What menu BACKGROUND color would you like?" 0 0 0 40 black 41 red 42 green 43 brown 44 blue 45 magenta 46 cyan 47 white 2> /tmp/color
	MENUCOLOR=$(cat /tmp/color)
	echo $(echo -e "\r\033[0;$(cat /tmp/color)m")Color chosen.$(echo -e '\033[0;39m')
	rm /tmp/color

	dialog --menu "What menu TEXT color would you like?" 0 0 0 37 white 30 black 31 red 32 green 33 brown 34 blue 35 magenta 36 cyan 2> /tmp/color
	TEXTCOLOR=$(cat /tmp/color)
	echo $(echo -e "\r\033[0;$(cat /tmp/color)m")Color chosen.$(echo -e '\033[0;39m')
	rm /tmp/color

	dialog --inputbox "Enter the language code for the language you would like to use.\n\
Leaving this empty will leave the choice up to the plugin (usually English.)\n\
Examples: fr_FR = Francais (France); es_ES = Espanol (Espana)" 12 50 "${LANGFULL}" 2> "${TAGS}"/lang-full

	dialog --inputbox "Enter the code for your keyboard layout.\n
Leaving this blank will typically default to QWERTY (US).\n\
Examples: fr (AZERTY France), fr_CH (QWERTZ Switzerland)" 12 50 "${COUNTRY}" 2> "${TAGS}"/country

	if [ -f slax.iso ];then
		dialog --checklist "Slax modules to include:" 13 45 6 \
		002 Xorg on \
		003 KDE on \
		004 "KDE applications" on \
		005 "KDE Office" on \
		006 Development on \
		007 Firefox on \
		2> "${TAGS}"/slaxlist0
		echo >> "${TAGS}"/slaxlist0
		cat "${TAGS}"/slaxlist0|sed -e 's/"//g' -e 's/ /\n/g'>"${TAGS}"/slaxlist
		rm "${TAGS}"/slaxlist0
		if wc -c "${TAGS}"/slaxlist|grep -q 24;then #24 bytes means they are all checked
			rm "${TAGS}"/slaxlist #If they are all checked, delete the file
		fi
	fi
	if [ -f porteus.iso ];then
		dialog --checklist "Porteus modules to include:" 13 45 6 \
		002 Xorg on \
		003 LXDE on \
		004 KDE on \
		005 "KDE apps" on \
		006 KOffice on \
		007 Development on \
		008 Firefox on \
		2> "${TAGS}"/porteuslist0
		echo >> "${TAGS}"/porteuslist0
		cat "${TAGS}"/porteuslist0|sed -e 's/"//g' -e 's/ /\n/g'>"${TAGS}"/porteuslist
		rm "${TAGS}"/porteuslist0
		if wc -c "${TAGS}"/porteuslist|grep -q 28;then #28 bytes means they are all checked
			rm "${TAGS}"/porteuslist #If they are all checked, delete the file
		fi
	fi
	if [ -f win98se.iso ] || [ -f winme.iso ];then
		if dialog --yesno "Would you like to copy the \"tools\" and \"add-ons\" folders from the Windows 9x/Me CD?" 0 0;then
			touch "${TAGS}"/9xextras
		fi
	fi
	if [ $(find "${TAGS}"/puppies -maxdepth 1 -type f|wc -l) -gt 1 ] && which dialog &> /dev/null;then
		echo "dialog --radiolist \"Which Puppy variant would you like to be installable to HD from the disc?\" 13 45 6 \\">puppychooser
		for i in "${TAGS}"/puppies/*;do
			echo $(basename $i) \"\" off \\ >> puppychooser
		done
		echo "2> puppyresult" >> puppychooser
		sh puppychooser
		touch "${TAGS}"/puppies/$(cat puppyresult).inroot
		rm puppychooser puppyresult
	elif [ $(find "${TAGS}"/puppies -maxdepth 1 -type f|wc -l) -eq 1 ];then
		NAME=$(ls "${TAGS}"/puppies)
		true>$(find "${TAGS}"/puppies -maxdepth 1 -type f).inroot
	fi
	if [ $(find "${TAGS}"/debians -maxdepth 1 -type f|wc -l) -gt 1 ] && which dialog &> /dev/null;then
		echo "dialog --radiolist \"Which Debian-Live variant would you like to be installable to HD from the disc?\" 13 45 6 \\">debianschooser
		for i in "${TAGS}"/debians/*;do
			echo $(basename $i) \"\" off \\ >> debianschooser
		done
		echo "2> debiansresult" >> debianschooser
		sh debianschooser
		touch "${TAGS}"/debians/$(cat debiansresult).inroot
		rm debianschooser debiansresult
	elif [ $(find "${TAGS}"/debians -maxdepth 1 -type f|wc -l) -eq 1 ];then
		NAME=$(ls "${TAGS}"/debians)
		TAG_TO_TOUCH=$(find "${TAGS}"/debians -maxdepth 1 -type f).inroot
		true>"$TAG_TO_TOUCH"
	fi
	if which dialog &> /dev/null;then
		find "${TAGS}" -maxdepth 1 -name \*.needsname|while read i;do
			BASENAME=$(basename "$i"|sed -e 's/\.needsname//g')
			if [ -f $BASENAME.defaultname ];then
				DEFUALTTEXT=$(cat $BASENAME.defaultname)
			else
				DEFAULTTEXT=""
			fi
			NAME_FILE=$(echo $i|sed -e 's/needsname/name/g')
			dialog --inputbox "What would you like $BASENAME to be called on the CD boot menu?\n(Leave blank for the default.)" 10 70 \
			2> "$NAME_FILE"
			if [ "$(cat "${TAGS}"/$BASENAME.name)" = "" ] && [ -f $BASENAME.defaultname ];then
				cp $BASENAME.defaultname "${TAGS}"/$BASENAME.name
			fi
		done
	else
		for i in $(find "${TAGS}" -maxdepth 1 -name \*.needsname);do
			BASENAME=$(basename $i|sed -e 's/\.needsname//g')
			if [ -f $BASENAME.defaultname ];then
				cp $BASENAME.defaultname "${TAGS}"/$BASENAME.name
			fi
		done
	fi
else
	#Do these things if interactive options are not enabled with "-i"
	CDTITLE="MultiCD - Created $(LANG=C date +"%b %d, %Y")"
	export CDLABEL=MultiCD
	MENUCOLOR=44
	TEXTCOLOR=37
	if [ "$LANGFULL" ] && [ "$LANGFULL" != "C" ];then
		echo "$LANGFULL" > "${TAGS}"/lang-full
	fi
	if [ $COUNTRY ];then
		echo "$COUNTRY" > "${TAGS}"/country
	fi
	touch "${TAGS}"/9xextras
	for i in puppies debians;do
		if [ $(find "${TAGS}"/$i -maxdepth 1 -type f|wc -l) -ge 1 ] && which dialog &> /dev/null;then #Greater or equal to 1 puppy installed
			FILE=$(find "${TAGS}"/$i -maxdepth 1 -type f|head -n 1)
			touch "$FILE.inroot" #This way, the first one alphabetically will be in the root dir
		fi
	done
	for i in $(find "${TAGS}" -maxdepth 1 -name \*.needsname);do
		BASENAME=$(basename $i|sed -e 's/\.needsname//g')
		if [ -f $BASENAME.defaultname ];then
			cp $BASENAME.defaultname "${TAGS}"/$BASENAME.name
		fi
	done
fi

for i in lang-full country;do
	if [ -f "${TAGS}"/$i ] && ( [ -z $(cat "${TAGS}"/$i) ] || [ $(cat "${TAGS}"/$i) = "C" ] ); then
		rm "${TAGS}"/$i #The user didn't enter anything - removing this tag file will let the plugin decide which language to use.
	fi
done
if [ -f "${TAGS}"/lang-full ];then
	#Get two-letter code (e.g. the first part) for plugins that only use that part of the lang code
	cut -c1-2 < "${TAGS}"/lang-full > "${TAGS}"/lang
fi

if [ -d "${WORK}" ];then
 rm -r "${WORK}"/*
else
 mkdir "${WORK}"
fi

#Make sure it exists, you need to put stuff there later
mkdir -p "${WORK}"/boot/isolinux

#START COPY
	if [ -f antix.iso ];then
		echo "Copying AntiX..."
		mcdmount antix
		cp -r "${MNT}"/antix/antiX "${WORK}"/ #Everything in antiX but the kernel and initrd
		mkdir -p "${WORK}"/boot/antix
		cp "${MNT}"/antix/boot/vmlinuz "${WORK}"/boot/antix/vmlinuz #Kernel
		cp "${MNT}"/antix/boot/initrd.gz "${WORK}"/boot/antix/initrd.gz #Initrd
		umcdmount antix
	fi
	if [ -f arch.iso ];then
		echo "Copying Arch Linux..."
		mcdmount arch
		cp -r "${MNT}"/arch/arch "${WORK}"
		umcdmount arch
	fi
	if [ -f archboot.iso ];then
		echo "Copying Arch Linux Installer..."
		mcdmount archboot
		mkdir -p "${WORK}"/boot/archboot
		for i in vmlinuz_i686 vmlinuz_i686_lts vmlinuz_x86_64 vmlinuz_x86_64_lts initramfs_i686.img initramfs_x86_64.img;do
			cp "${MNT}"/archboot/boot/$i "${WORK}"/boot/archboot/$i
		done
		cp -r "${MNT}"/archboot/packages "${WORK}"/ #packages
		umcdmount archboot
	fi
	if [ -f archiso-live.iso ];then
		echo "Copying Archiso-live..."
		mcdmount archiso-live
		mkdir "${WORK}"/boot/archiso-live
		cp "${MNT}"/archiso-live/boot/vmlinuz "${WORK}"/boot/archiso-live/vmlinuz
		cp "${MNT}"/archiso-live/boot/initrd.img "${WORK}"/boot/archiso-live/initrd.img
		cp -r "${MNT}"/archiso-live/archiso-live "${WORK}"/ #Compressed filesystems
		umcdmount archiso-live
	fi
	if [ -f austrumi.iso ];then
		mcdmount austrumi
		cp -r "${MNT}"/austrumi/austrumi "${WORK}"/ #This folder also has the kernel and initrd
		cp "${MNT}"/austrumi/isolinux.cfg "${WORK}"/boot/isolinux/al.menu
		umcdmount austrumi
	fi
	if [ -f avg.iso ];then
		echo "Copying AVG Rescue CD..."
		mcdmount avg
		mkdir "${WORK}"/boot/avg
		cp "${MNT}"/avg/isolinux/vmlinuz "${WORK}"/boot/avg/
		cp "${MNT}"/avg/isolinux/initrd.lzm "${WORK}"/boot/avg/
		cp "${MNT}"/avg/CHANGELOG "${WORK}"/boot/avg/
		cp "${MNT}"/avg/arl-version "${WORK}"/
		umcdmount avg
	fi
	if [ -f avira.iso ];then
		echo "Copying Avira Rescue CD..."
		mcdmount avira
		cp -r "${MNT}"/avira/* "${WORK}"/
				
		mv "${WORK}"/vmlinuz "${WORK}"/boot/isolinux/aviravmlinuz #Kernel
		mv "${WORK}"/initrd.gz "${WORK}"/boot/isolinux/avirainitrd.gz #Initial ramdisk. See above.
		mv "${WORK}"/welcome.msg "${WORK}"/licenses/welcome.msg
		mv "${WORK}"/license.txt "${WORK}"/licenses/license.txt
		mv "${WORK}"/licenses "${WORK}"/aviralicenses
		rm "${WORK}"/boot.cat "${WORK}"/isolinux.bin "${WORK}"/isolinux.cfg 		
		umcdmount avira
	fi
	if [ -f backtrack.iso ];then
		echo "Copying BackTrack..."
		ubuntucommon backtrack
	fi
    if [ -f caine.iso ];then
        echo "Copying Caine..."
        mcdmount caine
        cp -r "${MNT}"/caine/casper "${WORK}"/boot/caine #Live system
        cp "${MNT}"/caine/README.diskdefines "${WORK}"/
        mkdir "${WORK}"/CaineFiles
        for item in AutoPlay autorun.exe autorun.inf comdlg32.ocx files license.txt page5 preseed Programs RegOcx4Vista.bat rw_common tabctl32.ocx vbrun60.exe WinTaylor.exe; do
            [[ -a "${MNT}"/caine/$item ]] && cp -r "${MNT}"/caine/$item "${WORK}"/CaineFiles
        done
        umcdmount caine
    fi
	if [ -f cdl.iso ];then
		echo "Copying CDlinux..."
		mcdmount cdl
		cp -r "${MNT}"/cdl/CDlinux "${WORK}"/CDlinux #Everything in one folder
		rm "${WORK}"/CDlinux/boot/memtest.bin.gz #Remove redundant memtest
		umcdmount cdl
	fi
	if [ -f centos-boot.iso ];then
		echo "Copying CentOS netboot installer..."
		mcdmount centos-boot
		mkdir "${WORK}"/boot/centos
		if [ -f "${MNT}"/centos-boot/isolinux/vmlinuz ];then
			cp "${MNT}"/centos-boot/isolinux/vmlinuz "${WORK}"/boot/centos/vmlinuz
			cp "${MNT}"/centos-boot/isolinux/initrd.img "${WORK}"/boot/centos/initrd.img
		elif [ -f "${MNT}"/centos-boot/isolinux/vmlinuz0 ];then
			cp "${MNT}"/centos-boot/isolinux/vmlinuz0 "${WORK}"/boot/centos/vmlinuz
			cp "${MNT}"/centos-boot/isolinux/initrd0.img "${WORK}"/boot/centos/initrd.img
		fi
		if [ -d "${WORK}"/images ];then
			echo "There is already an \"images\" folder on the multicd. You might have another Red Hat-based distro on it."
			echo "CentOS's \"images\" folder won't be copied; instead, these files will be downloaded before the installer starts."
		else
			#Commenting out the below line will save about 100MB on the CD, but it will have to be downloaded when you install Scientific Linux
			cp -r "${MNT}"/centos-boot/images "${WORK}"/
		fi
		umcdmount centos-boot
	fi
	if [ -f clonezilla$2.iso ];then
		echo "Copying Clonezilla $2..."
		mcdmount clonezilla$2
		cp "${MNT}"/clonezilla$2/isolinux/ocswp.png "${WORK}"/boot/isolinux/ocswp.png #Boot menu logo
		cp -r "${MNT}"/clonezilla$2/live "${WORK}"/boot/clonezilla$2 #Another Debian Live-based ISO
		cp "${MNT}"/clonezilla$2/C* "${WORK}"/boot/clonezilla$2 #PDV Clonezilla-Live-Version and COPYING files
		cp "${MNT}"/clonezilla$2/isolinux/isolinux.cfg "${WORK}"/boot/isolinux/clonezil$2.cfg #PDV
		umcdmount clonezilla$2
	fi
	if [ -f connos.iso ];then
		echo "Copying ConnochaetOS..."
		mcdmount connos
		mkdir -p "${WORK}/boot/connos"
		cp "${MNT}/connos/boot/isolinux/vmlinuz" "${WORK}/boot/connos"
		cp "${MNT}/connos/boot/isolinux/initrd.img" "${WORK}/boot/connos"
		mkdir -p "${WORK}/os"
		cp "${MNT}"/connos/os/* "${WORK}/os"
		umcdmount connos
	fi
	if [ -f dban.iso ];then
		echo "Copying DBAN..."
		mcdmount dban
		mkdir -p "${WORK}"/boot/dban1
		cp "${MNT}"/dban/dban.bzi "${WORK}"/boot/dban1/dban.bzi
		umcdmount dban
	fi
	if [ -f debian-install.iso ];then
		echo "Copying Debian netinst..."
		mcdmount debian-install
		if [ ! -d "${WORK}"/.disk ];then
			cp -r "${MNT}"/debian-install/.disk "${WORK}"
		else
			echo "Debian GNU/Linux (MultiCD) $(date -u)" > "${WORK}"/.disk/info
		fi
		cp -r "${MNT}"/debian-install/dists "${WORK}"
		cp -r "${MNT}"/debian-install/install.386 "${WORK}"
		cp -r "${MNT}"/debian-install/pool "${WORK}"
		umcdmount debian-install
	fi
	if [ -f debian-install64.iso ];then
		echo "Copying Debian netinst (amd64)..."
		mcdmount debian-install64
		if [ ! -d "${WORK}"/.disk ];then
			cp -r "${MNT}"/debian-install64/.disk "${WORK}"
		else
			echo "Debian GNU/Linux - Unofficial Installation Media (MultiCD) $(date -u)" > "${WORK}"/.disk/info
		fi
		cp -r "${MNT}"/debian-install64/dists "${WORK}"
		cp -r "${MNT}"/debian-install64/install.amd "${WORK}"
		cp -r "${MNT}"/debian-install64/pool "${WORK}"
		umcdmount debian-install64
	fi
	if $(debianExists);then
		for i in *.debian.iso; do
			echo "Copying $(getDebianName)..."
			BASENAME=$(echo $i|sed -e 's/\.iso//g')
			mcdmount $BASENAME
			cp "${MNT}"/$BASENAME/isolinux/live.cfg "${WORK}"/boot/isolinux/$BASENAME.cfg
			if [ -f "$TAGS"/debians/$BASENAME.inroot ];then
				cp -r "${MNT}"/$BASENAME/live "${WORK}"/live
				if [ -d "${MNT}"/$BASENAME/install ];then
					cp -r "${MNT}"/$BASENAME/install "${WORK}"/
					cp -r "${MNT}"/$BASENAME/.disk "${WORK}"/ || true
					cp -r "${MNT}"/$BASENAME/dists "${WORK}"/ || true
					cp -r "${MNT}"/$BASENAME/pool "${WORK}"/ || true
				else
					echo "Warning: You selected $BASENAME to be installable, but there is no \"install\" folder on the disk."
				fi
			else
				cp -r "${MNT}"/$BASENAME/live "${WORK}"/$BASENAME
			fi
			umcdmount $BASENAME
		done
		rm "${WORK}"/live/memtest||true
	fi
	if [ -f debian-mini.iso ];then
		echo "Copying Debian netboot installer..."
		mcdmount debian-mini
		mkdir "${WORK}"/boot/debian
		cp "${MNT}"/debian-mini/linux "${WORK}"/boot/debian/linux
		cp "${MNT}"/debian-mini/initrd.gz "${WORK}"/boot/debian/initrd.gz
		umcdmount debian-mini
	fi
	if [ -f deli.iso ];then
		echo "Copying DeLi Linux..."
		mcdmount deli
		cp -r "${MNT}"/deli/isolinux "${WORK}"/ #Kernel and filesystem
		cp -r "${MNT}"/deli/pkg "${WORK}"/ #Packages
		umcdmount deli
	fi
	if [ -f diskcopy.iso ];then
		echo "Copying EASUS Disk Copy..."
		mcdmount diskcopy
		mkdir -p "${WORK}"/boot/diskcopy
		cp "${MNT}"/diskcopy/bzImage "${WORK}"/boot/diskcopy/bzImage
		cp "${MNT}"/diskcopy/initrd.img "${WORK}"/boot/diskcopy/initrd.img
		umcdmount diskcopy
	fi
	if [ -f doudoulinux.iso ];then
		echo "Copying DoudouLinux..."
		mcdmount doudoulinux
		cp -r "${MNT}"/doudoulinux/live "${WORK}"/boot/doudou #Copy live folder - usually all that is needed
		cp "${MNT}"/doudoulinux/isolinux/live.cfg "${TAGS}"/doudou.cfg
		umcdmount doudoulinux
		rm "${WORK}"/live/memtest||true
	fi
	if [ -f drweb.iso ];then
		echo "Copying Dr.Web LiveCD..."
		mcdmount drweb
		mkdir "${WORK}"/boot/drweb
		cp "${MNT}"/drweb/boot/vmlinuz "${WORK}"/boot/drweb/
		cp "${MNT}"/drweb/boot/initrd "${WORK}"/boot/drweb/
		cp "${MNT}"/drweb/boot/config "${WORK}"/boot
		cp -r "${MNT}"/drweb/boot/module "${WORK}"/boot
		cp "${MNT}"/drweb/boot/DrWebLiveCD-* "${WORK}"/boot/drweb/
		umcdmount drweb
	fi
	if [ -f dsl.iso ];then
		echo "Copying Damn Small Linux..."
		mcdmount dsl
		mkdir "${WORK}"/KNOPPIX
		cp -r "${MNT}"/dsl/KNOPPIX/* "${WORK}"/KNOPPIX/ #Compressed filesystem. We put it here so DSL's installer can find it.
		cp "${MNT}"/dsl/boot/isolinux/linux24 "${WORK}"/boot/isolinux/linux24 #Kernel. See above.
		cp "${MNT}"/dsl/boot/isolinux/minirt24.gz "${WORK}"/boot/isolinux/minirt24.gz #Initial ramdisk. See above.
		umcdmount dsl
	fi
	if [ -f dvl.iso ];then
		echo "Copying Damn Vulnerable Linux..."
		mcdmount dvl
		cp -r "${MNT}"/dvl/BT "${WORK}"/
		mkdir "${WORK}"/boot/dvl
		cp "${MNT}"/dvl/boot/vmlinuz "${WORK}"/boot/dvl/vmlinuz
		cp "${MNT}"/boot/initrd.gz "${WORK}"/boot/dvl/initrd.gz
		umcdmount dvl
	fi
	if [ -f efw.iso ];then
		echo "Copying Endian Firewall..."
		mcdmount efw
		mkdir -p "${WORK}"/boot/endian/
		cp "${MNT}"/efw/boot/isolinux/vmlinuz "${WORK}"/boot/endian/ #Kernel
		cp "${MNT}"/efw/boot/isolinux/instroot.gz "${WORK}"/boot/endian/ #Filesystem
		cp -r "${MNT}"/efw/data "${WORK}"/ #data and rpms folders are located
		cp -r "${MNT}"/efw/rpms "${WORK}"/ #at the root of the original CD
		cp "${MNT}"/efw/LICENSE.txt "${WORK}"/EFW-LICENSE.txt #License terms
		cp "${MNT}"/efw/README.txt "${WORK}"/EFW-README.txt
		umcdmount efw
	fi
	if [ -f elastix.iso ];then
		echo "Copying Elastix..."
		mcdmount elastix
		cp -r "${MNT}"/elastix/isolinux "${WORK}"/boot/elastix
		cp -r "${MNT}"/elastix/Elastix "${WORK}"/
		if [ -d "${WORK}"/images ];then
			echo "There is already a folder called \"images\". Are you adding another Red Hat-based distro?"
			echo "Copying anyway - be warned that on the final CD, something might not work properly."
		fi
		cp -r "${MNT}"/elastix/images "${WORK}"/
		cp -r "${MNT}"/elastix/repodata "${WORK}"/
		cp "${MNT}"/elastix/.discinfo "${WORK}"/
		cp "${MNT}"/elastix/* "${WORK}"/ 2>/dev/null || true
		umcdmount elastix
	fi
	if [ -f feather.iso ];then
		echo "Copying Feather..."
		mcdmount feather
		mkdir "${WORK}"/FEATHER
		cp -r "${MNT}"/feather/KNOPPIX/* "${WORK}"/FEATHER/ #Compressed filesystem
		mkdir "${WORK}"/boot/feather
		cp "${MNT}"/feather/boot/isolinux/linux24 "${WORK}"/boot/feather/linux24
		cp "${MNT}"/feather/boot/isolinux/minirt24.gz "${WORK}"/boot/feather/minirt24.gz
		umcdmount feather
	fi
	if [ -f fedora-boot.iso ];then
		echo "Copying Fedora netboot installer..."
		mcdmount fedora-boot
		mkdir "${WORK}"/boot/fedora
		if [ -f "${MNT}"/fedora-boot/isolinux/vmlinuz ];then
			cp "${MNT}"/fedora-boot/isolinux/vmlinuz "${WORK}"/boot/fedora/vmlinuz
			cp "${MNT}"/fedora-boot/isolinux/initrd.img "${WORK}"/boot/fedora/initrd.img
		elif [ -f "${MNT}"/fedora-boot/isolinux/vmlinuz0 ];then
			cp "${MNT}"/fedora-boot/isolinux/vmlinuz0 "${WORK}"/boot/fedora/vmlinuz
			cp "${MNT}"/fedora-boot/isolinux/initrd0.img "${WORK}"/boot/fedora/initrd.img
		fi
		if [ -d "${WORK}"/images ];then
			echo "There is already an \"images\" folder on the multicd. You might have another Red Hat-based distro on it."
			echo "Fedora's \"images\" folder won't be copied; instead, these files will be downloaded before the installer starts."
		else
			#Commenting out the below line will save about 100MB on the CD, but it will have to be downloaded when you install Fedora
			cp -r "${MNT}"/fedora-boot/images "${WORK}"/
		fi
		umcdmount fedora-boot
	fi
	if [ -f fedora-boot64.iso ];then
		echo "Copying Fedora 64-bit netboot installer..."
		mcdmount fedora-boot64
		mkdir "${WORK}"/boot/fedora64
		if [ -f "${MNT}"/fedora-boot64/isolinux/vmlinuz ];then
			cp "${MNT}"/fedora-boot64/isolinux/vmlinuz "${WORK}"/boot/fedora64/vmlinuz
			cp "${MNT}"/fedora-boot64/isolinux/initrd.img "${WORK}"/boot/fedora64/initrd.img
		elif [ -f "${MNT}"/fedora-boot64/isolinux/vmlinuz0 ];then
			cp "${MNT}"/fedora-boot64/isolinux/vmlinuz0 "${WORK}"/boot/fedora64/vmlinuz
			cp "${MNT}"/fedora-boot64/isolinux/initrd0.img "${WORK}"/boot/fedora64/initrd.img
		fi
		if [ -d "${WORK}"/images ];then
			echo "There is already an \"images\" folder on the multicd. You might have another Red Hat-based distro on it."
			echo "64-bit Fedora's \"images\" folder won't be copied; instead, these files will be downloaded before the installer starts."
		else
			#Commenting out the below line will save about 100MB on the CD, but it will have to be downloaded when you install Fedora
			cp -r "${MNT}"/fedora-boot64/images "${WORK}"/
		fi
		umcdmount fedora-boot64
	fi
	if [ -f finnix.iso ];then
		echo "Copying Finnix..."
		mcdmount finnix
		# Copies compressed filesystem
		cp -r "${MNT}"/finnix/finnix "${WORK}"/
		# Copies kernel, and initramdisk
		mkdir "${WORK}"/boot/finnix
		cp "${MNT}"/finnix/isolinux/linux "${WORK}"/boot/finnix/
		cp "${MNT}"/finnix/isolinux/linux64 "${WORK}"/boot/finnix/
		cp "${MNT}"/finnix/isolinux/initrd.xz "${WORK}"/boot/finnix/
		# Copies memdisk and Smart Boot Manager
		cp "${MNT}"/finnix/isolinux/memdisk "${WORK}"/boot/finnix/
		cp "${MNT}"/finnix/isolinux/sbm.imz "${WORK}"/boot/finnix/
		umcdmount finnix
	fi
	if [ -f freedos.iso ];then
		echo "Copying FreeDOS..."
		mcdmount freedos
		mkdir "${WORK}"/boot/freedos
		cp -r "${MNT}"/freedos/FREEDOS "${WORK}"/ #Core directory with the packages
		cp "${MNT}"/freedos/SETUP.BAT "${WORK}"/setup.bat #FreeDOS setup
		if [ -f "${MNT}"/freedos/ISOLINUX/FDBOOT.IMG ];then
			cp "${MNT}"/freedos/ISOLINUX/FDBOOT.IMG "${WORK}"/boot/freedos/fdboot.img #Initial DOS boot image
		else
			cp "${MNT}"/freedos/DATA/FDBOOT.IMG "${WORK}"/boot/freedos/fdboot.img
		fi
		if [ -d "${MNT}"/freedos/FDOS ];then
			cp -r "${MNT}"/freedos/FDOS "${WORK}"/ #Live CD
		fi
		if [ -d "${MNT}"/freedos/GEMAPPS ];then
			cp -r "${MNT}"/freedos/GEMAPPS "${WORK}"/ #OpenGEM
		fi
		if [ -f "${MNT}"/freedos/GEM.BAT ];then
			cp -r "${MNT}"/freedos/GEM.BAT "${WORK}"/ #OpenGEM setup
		fi
		umcdmount freedos
	fi
	if [ -f fusion.iso ];then
		echo "Copying Fusion Linux..."
		mcdmount fusion
		if [ -d "${WORK}"/LiveOS ];then
			echo "Warning: \$WORK/LiveOS exists. Fusion Linux conflicts with another CD on the ISO."
		fi
		cp -r "${MNT}"/fusion/LiveOS "${WORK}"/
		mkdir -p "${WORK}"/boot/fusion
		cp "${MNT}"/fusion/isolinux/vmlinuz* "${WORK}"/boot/fusion
		cp "${MNT}"/fusion/isolinux/initrd* "${WORK}"/boot/fusion
		cp "${MNT}"/fusion/isolinux/isolinux.cfg "${WORK}"/boot/fusion/fusion.cfg
		cp "${MNT}"/fusion/isolinux/splash.jpg "${WORK}"/boot/fusion/
		umcdmount fusion
	fi
	if [ -f geexbox.iso ];then
		echo "Copying GeeXboX..."
		mcdmount geexbox
		cp -r "${MNT}"/geexbox/GEEXBOX "${WORK}"/ #Everything GeeXbox has is in one folder. :)
		umcdmount geexbox
	fi
	if $(genericExists);then for i in *.generic.iso;do
		echo "Copying $(getGenericName)..."
		mkdir -p "${WORK}"/generic
		cp "$i" "${WORK}"/generic
	done;fi
	if [ -f gparted.iso ];then
		echo "Copying GParted Live..."
		mcdmount gparted
		cp -r "${MNT}"/gparted/live "${WORK}"/boot/gparted #Compressed filesystem and kernel/initrd
		rm "${WORK}"/boot/gparted/memtest || true #Remember how we needed to do this with Debian Live? They use the same framework
		umcdmount gparted
	fi
	if [ -f grml.iso ];then
		echo "Copying GRML..."
		mcdmount grml
		mkdir "${WORK}"/grml
		mkdir "${WORK}"/conf
		mkdir "${WORK}"/boot/grml
		cp -r "${MNT}"/grml/live/* "${WORK}"/grml #Compressed filesystem.
		cp "${MNT}"/grml/boot/grml32full/vmlinuz "${WORK}"/boot/grml/ #Kernel. See above.
		cp "${MNT}"/grml/boot/grml32full/initrd.img "${WORK}"/boot/grml/initrd.img #Initial ramdisk. See above.
		cp "${MNT}"/grml/GRML/grml32-full/grml-version "${WORK}"/boot/grml/grml-version
		#cp "${MNT}"/grml/conf/bootid.txt "${WORK}"/conf/ #not needed for booting with ignore_bootid
#getting  files into one and with write access:
		cp "${MNT}"/grml/boot/isolinux/default.cfg "${WORK}"/boot/grml/grml.cfg #isolinux menufile - temporary
		cat "${MNT}"/grml/boot/isolinux/grml.cfg >> "${WORK}"/boot/grml/grml.cfg #adding to menufile
		umcdmount grml
	fi
	if [ -f grml64.iso ];then
		echo "Copying GRML64..."
		mcdmount grml64
		mkdir "${WORK}"/grml64
		#mkdir "${WORK}"/conf
		mkdir "${WORK}"/boot/grml64
		cp -r "${MNT}"/grml64/live/* "${WORK}"/grml64 #Compressed filesystem.
		cp "${MNT}"/grml64/boot/grml64full/vmlinuz "${WORK}"/boot/grml64/ #Kernel. See above.
		cp "${MNT}"/grml64/boot/grml64full/initrd.img "${WORK}"/boot/grml64/ #Initial ramdisk. See above.
		cp "${MNT}"/grml64/GRML/grml64-full/grml-version "${WORK}"/boot/grml64/grml-version
		#cp "${MNT}"/grml64/conf/bootid.txt "${WORK}"/conf/ #not needed for booting with ignore_bootid
#getting  files into one and with write access:
		cp "${MNT}"/grml64/boot/isolinux/default.cfg "${WORK}"/boot/grml64/grml.cfg #isolinux menufile - temporary
		cat "${MNT}"/grml64/boot/isolinux/grml.cfg >> "${WORK}"/boot/grml64/grml.cfg #adding to menufile
		umcdmount grml64
	fi
	if [ -f hirens.iso ];then
		echo "Copying Hiren's BootCD..."
		mcdmount hirens
		if [ -f hirens/BootCD.txt ];then
			head -n 1 "${MNT}"/hirens/BootCD.txt |sed -e 's/\t//g'>"${TAGS}"/hirens.name
		else
			echo "Warning: No BootCD.txt in hirens.iso" 1>&2
			echo "Hiren's BootCD" > "${TAGS}"/hirens.name
		fi
		cp -r "${MNT}"/hirens/HBCD "${WORK}"/
		umcdmount hirens
	fi
	if [ -f insert.iso ];then
		echo "Copying INSERT..."
		mcdmount insert
		cp -r "${MNT}"/insert/INSERT "${WORK}"/ #Compressed filesystem
		mkdir "${WORK}"/boot/insert
		cp "${MNT}"/insert/isolinux/vmlinuz "${WORK}"/boot/insert/vmlinuz
		cp "${MNT}"/insert/isolinux/miniroot.lz "${WORK}"/boot/insert/miniroot.lz
		umcdmount insert
	fi
	if [ -f ipcop.iso ];then
		echo "Copying IPCop..."
		mcdmount ipcop
		cp -r "${MNT}"/ipcop/boot/isolinux "${WORK}"/boot/ipcop
		if [ -d "${WORK}"/images ];then
			echo "There is already a folder called \"images\". Are you adding another Red Hat-based distro?"
			echo "Copying anyway - be warned that on the final CD, something might not work properly."
		fi
		cp -r "${MNT}"/ipcop/images "${WORK}"/
		cp "${MNT}"/ipcop/*.tgz "${WORK}" 2> /dev/null || true #for version 1
		cp "${MNT}"/ipcop/*.tar.gz "${WORK}" 2> /dev/null || true #for version 2
		cp -r "${MNT}"/ipcop/doc "${WORK}"/boot/ipcop/ || true
		cp "${MNT}"/ipcop/*.txt "${WORK}"/boot/ipcop/ || true
		umcdmount ipcop
	fi
	if [ -f kav.iso ];then
		echo "Copying Kapersky Rescue Disk..."
		mcdmount kav
		mkdir "${WORK}"/boot/rescue
		# Kernel, initrd
		cp -r "${MNT}"/kav/boot/rescue "${WORK}"/boot/rescue/rescue
		cp -r "${MNT}"/kav/boot/rescue.igz "${WORK}"/boot/rescue/rescue.igz
		# Filesystem
		cp -r "${MNT}"/kav/rescue "${WORK}"
		umcdmount kav
	fi
	if [ -f kdusmall.iso ];then
		echo "Copying KDu-Small..."
		ubuntucommon kdusmall
	fi
	if [ -f kduxp.iso ];then
		echo "Copying KDuXP..."
		ubuntucommon kduxp
	fi
	if [ -f knoppix.iso ];then
		echo "Copying Knoppix..."
		mcdmount knoppix
		mkdir "${WORK}"/KNOPPIX6
		#Compressed filesystem and docs. We have to call it KNOPPIX6 because DSL uses KNOPPIX, and if we change that DSL's installer won't work.
		for i in $(ls "${MNT}"/knoppix/KNOPPIX*|grep -v '^KNOPPIX2$');do
			cp -r "${MNT}"/knoppix/KNOPPIX/$i "${WORK}"/KNOPPIX6/
		done
		mkdir -p "${WORK}"/boot/knoppix
		cp "${MNT}"/knoppix/boot/isolinux/linux "${WORK}"/boot/knoppix/linux
		cp "${MNT}"/knoppix/boot/isolinux/minirt.gz "${WORK}"/boot/knoppix/minirt.gz
		umcdmount knoppix
	fi
	if $(linuxmintExists);then
		for i in *.linuxmint.iso; do
			echo "Copying $(getLinuxmintName)..."
			ubuntucommon $(echo $i|sed -e 's/\.iso//g')
		done
	fi
	if [ -f macpup.iso ];then
		echo "Copying Macpup..."
		puppycommon macpup
	fi
	if [ -f mandriva-boot.iso ];then
		echo "Copying Mandriva netboot installer..."
		mcdmount mandriva-boot
		mkdir "${WORK}"/boot/mandriva
		cp -r "${MNT}"/mandriva-boot/isolinux/alt0 "${WORK}"/boot/mandriva/
		cp -r "${MNT}"/mandriva-boot/isolinux/alt1 "${WORK}"/boot/mandriva/
		umcdmount mandriva-boot
	fi
	if [ -f mandriva.iso ];then
		echo "Copying Mandriva Linux..."
		mcdmount mandriva
		if [ -d "${WORK}"/LiveOS ];then
			echo "Warning: \$WORK/LiveOS exists. Mandriva Linux conflicts with another CD on the ISO."
		fi
		cp -r "${MNT}"/mandriva/LiveOS "${WORK}"/
		mkdir -p "${WORK}"/boot/mandriva
		cp "${MNT}"/mandriva/isolinux/vmlinuz* "${WORK}"/boot/mandriva
		cp "${MNT}"/mandriva/isolinux/initrd* "${WORK}"/boot/mandriva
		cp "${MNT}"/mandriva/isolinux/isolinux.cfg "${WORK}"/boot/mandriva/mandriva.cfg
		cp "${MNT}"/mandriva/isolinux/splash.jpg "${WORK}"/boot/mandriva/
		umcdmount mandriva
	fi
	if [ -f mepis.iso ];then
		echo "Copying Mepis..."
		mcdmount mepis
		cp -r "${MNT}"/mepis/mepis "${WORK}"/ #Everything in Mepis but the kernel and initrd
		mkdir -p "${WORK}"/boot/mepis
		cp "${MNT}"/mepis/boot/vmlinuz "${WORK}"/boot/mepis/vmlinuz #Kernel
		cp "${MNT}"/mepis/boot/initrd.gz "${WORK}"/boot/mepis/initrd.gz #Initrd
		umcdmount mepis
	fi
	if [ -f mintdebian.iso ];then
		echo "Copying Linux Mint Debian Edition..."
		ubuntucommon mintdebian
	fi
	if [ -f netbootcd.iso ];then
		echo "Copying NetbootCD..."
		mcdmount netbootcd
		mkdir -p "${WORK}"/boot/nbcd
		cp "${MNT}"/netbootcd/boot/kexec.bzI "${WORK}"/boot/nbcd/kexec.bzI
		cp "${MNT}"/netbootcd/boot/nbinit4.gz "${WORK}"/boot/nbcd/nbinit4.gz
		if [ -d "${MNT}"/netbootcd/cde ];then #combined cd with CorePlus
			if [ -d "${WORK}"/cde ];then
				echo "NOTE: combining TCZ folders of TinyCore and NetbootCD+CorePlus."
			fi
			cp -r "${MNT}"/netbootcd/cde "${WORK}"
			for i in `ls -1 *.tcz 2> /dev/null;true`;do
				echo "Copying: $i"
				cp $i "${WORK}"/cde/optional/"$i"
			done
			#regenerate onboot.lst
			true > "${WORK}"/cde/onboot.lst
			for i in "${WORK}"/cde/optional/*.tcz;do
				echo $(basename "$i") >> "${WORK}"/cde/onboot.lst
			#	cd $(dirname "$i")
			#	VAR="$(md5sum $i)"
			#	cd -
			#	echo "$VAR" > $i.md5.txt
			#	echo > $i.dep
			done
			cp "${MNT}"/netbootcd/boot/core.gz "${WORK}"/boot/nbcd/
			echo "LABEL nbcd-tinycore
			menu label Start CorePlus 4.2.1 on top of NetbootCD 4.8
			kernel /boot/nbcd/kexec.bzI
			initrd /boot/nbcd/nbinit4.gz
			append quiet cde showapps
			text help
	Uses the initrd of NetbootCD with the TCZ extensions of
	CorePlus. The result is that CorePlus is loaded first,
	and NetbootCD is run when you choose \"Exit To Prompt\".
			endtext
			
			LABEL nbcd
			menu label Start ^NetbootCD 4.8
			kernel /boot/nbcd/kexec.bzI
			initrd /boot/nbcd/nbinit4.gz
			append quiet showapps
			
			LABEL core-kexec
			menu label Start ^Core 4.2.1
			kernel /boot/nbcd/kexec.bzI
			initrd /boot/nbcd/core.gz
			append quiet showapps
			
			LABEL tinycore-kexec
			menu label Start Core^Plus 4.2.1 (with desktop)
			kernel /boot/nbcd/kexec.bzI
			initrd /boot/nbcd/core.gz
			append quiet cde showapps" > "${WORK}"/boot/nbcd/include.cfg
		else
			echo "LABEL nbcd
			menu label Start ^NetbootCD 4.8
			kernel /boot/nbcd/kexec.bzI
			initrd /boot/nbcd/nbinit4.gz
			append quiet showapps" > "${WORK}"/boot/nbcd/include.cfg
		fi
		sleep 1;umcdmount netbootcd
	fi
	if [ -f ntpasswd.iso ];then
		mcdmount ntpasswd
		mkdir "${WORK}"/boot/ntpasswd
		cp "${MNT}"/ntpasswd/[Vv][Mm][Ll][Ii][Nn][Uu][Zz] "${WORK}"/boot/ntpasswd/vmlinuz
		cp "${MNT}"/ntpasswd/[Ii][Nn][Ii][Tt][Rr][Dd].[Cc][Gg][Zz] "${WORK}"/boot/ntpasswd/initrd.cgz
		cp "${MNT}"/ntpasswd/[Ss][Cc][Ss][Ii].[Cc][Gg][Zz] "${WORK}"/boot/ntpasswd/scsi.cgz #Alternate initrd
		umcdmount ntpasswd
	fi
	if [ -f opensuse-gnome.iso ];then
		echo "Copying openSUSE GNOME Live CD..."
		mcdmount opensuse-gnome
		mkdir -p "${WORK}"/boot/opensuse-gnome
		cp "${MNT}"/opensuse-gnome/openSUSE* "${WORK}"/
		cp "${MNT}"/opensuse-gnome/config.isoclient "${WORK}"/
		mkdir "${WORK}"/boot/susegnom
		cp "${MNT}"/opensuse-gnome/boot/i386/loader/linux "${WORK}"/boot/susegnom/linux
		cp "${MNT}"/opensuse-gnome/boot/i386/loader/initrd "${WORK}"/boot/susegnom/initrd
		umcdmount opensuse-gnome
	fi
	if [ -f opensuse-net.iso ];then
		echo "Copying openSUSE netboot installer..."
		mcdmount opensuse-net
		mkdir -p "${WORK}"/boot/opensuse
		awk '/^VERSION/ {print $2}' "${MNT}"/opensuse-net/content > "${TAGS}"/opensuse-net.version
		cp "${MNT}"/opensuse-net/boot/i386/loader/linux "${WORK}"/boot/opensuse/linux
		cp "${MNT}"/opensuse-net/boot/i386/loader/initrd "${WORK}"/boot/opensuse/initrd
		umcdmount opensuse-net
	fi
	if [ -f opensuse-net64.iso ];then
		echo "Copying openSUSE 64-bit netboot installer..."
		mcdmount opensuse-net64
		mkdir -p "${WORK}"/boot/opensuse
		awk '/^VERSION/ {print $2}' "${MNT}"/opensuse-net64/content > "${TAGS}"/opensuse-net.version
		cp "${MNT}"/opensuse-net64/boot/x86_64/loader/linux "${WORK}"/boot/opensuse/linux64
		cp "${MNT}"/opensuse-net64/boot/x86_64/loader/initrd "${WORK}"/boot/opensuse/initrd64
		umcdmount opensuse-net64
	fi
	if [ -f ophxp.iso ];then
		echo "Copying OPH Crack XP..."
		mcdmount ophxp
		mkdir "${WORK}"/boot/ophcrack/
		cp -r "${MNT}"/ophxp/tables "${WORK}"/tables
		cp "${MNT}"/ophxp/boot/bzImage "${WORK}"/boot/ophcrack/bzImage
		cp "${MNT}"/ophxp/boot/ophcrack.cfg "${WORK}"/boot/ophcrack/ophcrack.cfg
		cp "${MNT}"/ophxp/boot/splash.png "${WORK}"/boot/ophcrack/splash.png
		cp "${MNT}"/ophxp/boot/rootfs.gz "${WORK}"/boot/ophcrack/rootfs.gz
		umcdmount ophxp
	fi
	if [ -f ophvista.iso ] && [ ! -f ophxp.iso ];then
		echo "Copying OPH Crack Vista..."
		mcdmount ophvista
		mkdir "${WORK}"/boot/ophcrack/
		cp -r "${MNT}"/ophvista/tables "${WORK}"/tables
		cp "${MNT}"/ophvista/boot/bzImage "${WORK}"/boot/ophcrack/bzImage
		cp "${MNT}"/ophvista/boot/ophcrack.cfg "${WORK}"/boot/ophcrack/ophcrack.cfg
		cp "${MNT}"/ophvista/boot/splash.png "${WORK}"/boot/ophcrack/splash.png
		cp "${MNT}"/ophvista/boot/rootfs.gz "${WORK}"/boot/ophcrack/rootfs.gz
		umcdmount ophvista
	fi
	if [ -f ophvista.iso ] && [ -f ophxp.iso ];then
		echo "Getting OPH Crack Vista tables..."
		mcdmount ophvista
		cp -r "${MNT}"/ophvista/tables "${WORK}"
		umcdmount ophvista
	fi
	if [ -f pclos.iso ];then
		echo "Copying PCLinuxOS..."
		mcdmount pclos
		mkdir "${WORK}"/PCLinuxOS
		# Kernel, initrd
		cp -r "${MNT}"/pclos/isolinux "${WORK}"/PCLinuxOS/isolinux
		# Filesystem
		cp "${MNT}"/pclos/livecd.sqfs "${WORK}"/PCLinuxOS/livecd.sqfs
		# Remove memtest and mediacheck
		if [ -f "${WORK}"/PCLinuxOS/isolinux/memtest ];then
			rm "${WORK}"/PCLinuxOS/isolinux/memtest
		fi
		if [ -f "${WORK}"/PCLinuxOS/isolinux/mediacheck ];then
			rm "${WORK}"/PCLinuxOS/isolinux/mediacheck
		fi
		umcdmount pclos
	fi
	if [ -f pclx.iso ];then
		echo "Copying PCLinuxOS LXDE..."
		mcdmount pclx
		mkdir "${WORK}"/pclosLXDE
		# Kernel, initrd
		cp -r "${MNT}"/pclx/isolinux "${WORK}"/pclosLXDE/isolinux
		# Empty boot folder, don't ask me...
		# cp -r pclinuxos/boot "${WORK}"/pclosLXDE/boot
		# Filesystem
		cp "${MNT}"/pclx/livecd.sqfs "${WORK}"/pclosLXDE/livecd.sqfs
		# Remove memtest and mediacheck
		if [ -f "${WORK}"/pclosLXDE/isolinux/memtest ];then
			rm "${WORK}"/pclosLXDE/isolinux/memtest 
		fi
		if [ -f "${WORK}"/pclosLXDE/isolinux/mediacheck ];then
			rm "${WORK}"/pclosLXDE/isolinux/mediacheck
		fi
		umcdmount pclx
	fi
    if [ -f pentoo.iso ];then
        echo "Copying Pentoo Linux..."
        mcdmount pentoo

        mkdir -p "${WORK}"/boot/pentoo
        for item in modules tools win32 image.squashfs livecd; do
            cp -r "${MNT}"/pentoo/$item "${WORK}"/boot/pentoo
        done
        for item in pentoo isolinux.cfg pentoo.igz; do
            cp -r "${MNT}"/pentoo/isolinux/$item "${WORK}"/boot/pentoo
        done

        # Fix the isolinux.cfg
        sed -i 's@loop=/image.squashfs@loop=/boot/pentoo/image.squashfs subdir=/boot/pentoo@' "${WORK}"/boot/pentoo/isolinux.cfg
        sed -i 's@kernel @kernel /boot/pentoo/@' "${WORK}"/boot/pentoo/isolinux.cfg
        sed -i 's@initrd=@initrd=/boot/pentoo/@' "${WORK}"/boot/pentoo/isolinux.cfg

        umcdmount pentoo
    fi
	if [ -f ping.iso ];then
		echo "Copying PING..."
		mcdmount ping
		mkdir -p "${WORK}"/boot/ping
		cp "${MNT}"/ping/kernel "${WORK}"/boot/ping/kernel
		cp "${MNT}"/ping/initrd.gz "${WORK}"/boot/ping/initrd.gz
		umcdmount ping
	fi
	if [ -f pinguy.iso ];then
		echo "Copying Pinguy OS..."
		ubuntucommon pinguy
	fi
	if [ -f pmagic.iso ];then
		echo "Copying Parted Magic..."
		mcdmount pmagic
		cp -r "${MNT}"/pmagic/pmagic "${WORK}"/boot/ #kernel/initrd & modules
		if [ ! -f "${WORK}"/boot/isolinux/linux.c32 ];then
			cp "${MNT}"/pmagic/boot/syslinux/linux.c32 "${WORK}"/boot/isolinux
		fi
		if [ ! -f "${WORK}"/boot/isolinux/reboot.c32 ];then #PDV
			cp "${MNT}"/pmagic/boot/syslinux/reboot.c32 "${WORK}"/boot/isolinux
		fi
		cp -r "${MNT}"/pmagic/boot/* "${WORK}"/boot/pmagic #PDV Extras
		cp "${MNT}"/pmagic/boot/syslinux/hdt* "${WORK}"/boot/pmagic #PDV add hdt
		if [ $MEMTEST = "false" ]; then #PDV add memtest
			cp "${MNT}"/pmagic/boot/syslinux/memtest "${WORK}"/boot/pmagic
		fi
		rm -r "$WORK"/boot/pmagic/syslinux #PDV remove syslinux
		cp "${MNT}"/pmagic/boot/syslinux/syslinux.cfg "${WORK}"/boot/isolinux/pmagic.cfg
		cp "${MNT}"/pmagic/boot/syslinux/*.txt "${WORK}"/boot/isolinux #PDV
		#if [ -f "${MNT}"/pmagic/mkgriso ];then cp "${MNT}"/pmagic/mkgriso "${WORK}";fi
		umcdmount pmagic
	fi
	if [ -f porteus.iso ];then
		echo "Copying Porteus..."
		mcdmount porteus
		if [ -f "${TAGS}"/porteuslist ];then
			mkdir "${WORK}"/porteus
			for i in `ls "${MNT}"/porteus/porteus|sed -e '/^base$/ d'`;do
				cp -r "${MNT}"/porteus/porteus/$i "${WORK}"/porteus/ #Copy everything but the base modules
			done
			mkdir "${WORK}"/porteus/base
			for i in `cat "${TAGS}"/porteuslist`;do
				cp "${MNT}"/porteus/porteus/base/${i}* "${WORK}"/porteus/base/ #Copy only the modules you wanted
			done
			cp "${MNT}"/porteus/porteus/base/000-* "${WORK}"/porteus/base/ #kernel is required
			cp "${MNT}"/porteus/porteus/base/001-* "${WORK}"/porteus/base/ #core module is required
			rm "${TAGS}"/porteuslist
		else
			cp -r "${MNT}"/porteus/porteus "${WORK}"/ #Copy everything
		fi
		mkdir -p "${WORK}"/boot/porteus
		cp "${MNT}"/porteus/boot/vmlinuz "${WORK}"/boot/porteus/vmlinuz
		cp "${MNT}"/porteus/boot/initrd.xz "${WORK}"/boot/porteus/initrd.xz
		umcdmount porteus
		##########
		if [ "$(ls -1 *.xzm 2> /dev/null;true)" != "" ];then
			echo "Copying Porteus modules..."
			mkdir -p "${WORK}/porteus/modules"
		fi
		for i in `ls -1 *.xzm 2> /dev/null;true`; do
			cp "${i}" "${WORK}"/porteus/modules/ #Copy the .xzm module to the modules folder
			if $VERBOSE;then
				echo \(Copied $i\)
			fi
		done
	fi
	if $(puppyExists);then for i in *.puppy.iso;do
		echo "Copying Puppy..."
		puppycommon $(echo $i|sed -e 's/\.puppy\.iso//g')
	done;fi
	if [ -f puppy2.iso ];then
		echo "Copying Puppy #2..."
		puppycommon puppy2
	fi
	if [ -f redobackup.iso ];then
		echo "Copying Redo Backup OS..."
		ubuntucommon redobackup
	fi
	if [ -f rescatux.iso ];then
		RESCATUX_NEW=rescatux-new
		echo "Copying Rescatux..."
		mcdmount rescatux
		if [ -h $RESCATUX_NEW.iso ];then rm $RESCATUX_NEW.iso;fi
		ln -s "${MNT}"/rescatux/boot/boot-isos/rescatux*.iso $RESCATUX_NEW.iso
		mcdmount $RESCATUX_NEW
		cp "${MNT}"/$RESCATUX_NEW/isolinux/live.cfg "${WORK}"/boot/isolinux/rescatux.cfg
		cp -r "${MNT}"/$RESCATUX_NEW/live "${WORK}"/rescatux
		umcdmount $RESCATUX_NEW
		rm $RESCATUX_NEW.iso
		umcdmount rescatux
	fi
	if [ -f riplinux.iso ];then
		echo "Copying RIP Linux..."
		mcdmount riplinux
		mkdir -p "${WORK}"/boot/riplinux
		cp -r "${MNT}"/riplinux/boot/doc "${WORK}"/boot/ #Documentation
		cp -r "${MNT}"/riplinux/boot/grub4dos "${WORK}"/boot/riplinux/ #GRUB4DOS :)
		cp "${MNT}"/riplinux/boot/kernel32 "${WORK}"/boot/riplinux/kernel32 #32-bit kernel
		cp "${MNT}"/riplinux/boot/kernel64 "${WORK}"/boot/riplinux/kernel64 #64-bit kernel
		cp "${MNT}"/riplinux/boot/rootfs.cgz "${WORK}"/boot/riplinux/rootfs.cgz #Initrd
		cp "${MNT}"/riplinux/boot/isolinux/isolinux.cfg "${WORK}"/boot/isolinux/riplinux.cfg
		sed -i -e 's/\/boot\/kernel/\/boot\/riplinux\/kernel/g' "${WORK}"/boot/isolinux/riplinux.cfg #Fix the riplinux.cfg
		sed -i -e 's/\/boot\/rootfs.cgz/\/boot\/riplinux\/rootfs.cgz/g' "${WORK}"/boot/isolinux/riplinux.cfg
		sed -i -e 's/\/boot\/kernel/\/boot\/riplinux\/kernel/g' "${WORK}"/boot/riplinux/grub4dos/menu-cd.lst #Fix the menu.lst
		sed -i -e 's/\/boot\/rootfs.cgz/\/boot\/riplinux\/rootfs.cgz/g' "${WORK}"/boot/riplinux/grub4dos/menu-cd.lst
		umcdmount riplinux
	fi
	if [ -f sabayon.iso ];then
		echo "Copying Sabayon Linux..."
		mcdmount sabayon
		mkdir "${WORK}"/boot/sabayon
		cp "${MNT}"/sabayon/boot/sabayon "${WORK}"/boot/sabayon/sabayon
		cp "${MNT}"/sabayon/boot/sabayon.igz "${WORK}"/boot/sabayon/sabayon.igz
		cp "${MNT}"/sabayon/livecd "${WORK}"/livecd #Not sure if this is needed
		cp "${MNT}"/sabayon/livecd.squashfs "${WORK}"/boot/sabayon/livecd.squashfs
		cp "${MNT}"/sabayon/pkglist "${WORK}"/pkglist #Not sure if this is needed
		cp "${MNT}"/sabayon/isolinux/txt.cfg "${WORK}"/boot/sabayon/sabayon.cfg
		umcdmount sabayon
	fi
	if [ -f scientific-boot.iso ];then
		echo "Copying Scientific Linux netboot installer..."
		mcdmount scientific-boot
		mkdir "${WORK}"/boot/sci
		if [ -f "${MNT}"/scientific-boot/isolinux/vmlinuz ];then
			cp "${MNT}"/scientific-boot/isolinux/vmlinuz "${WORK}"/boot/sci/vmlinuz
			cp "${MNT}"/scientific-boot/isolinux/initrd.img "${WORK}"/boot/sci/initrd.img
		elif [ -f "${MNT}"/scientific-boot/isolinux/vmlinuz0 ];then
			cp "${MNT}"/scientific-boot/isolinux/vmlinuz0 "${WORK}"/boot/sci/vmlinuz
			cp "${MNT}"/scientific-boot/isolinux/initrd0.img "${WORK}"/boot/sci/initrd.img
		fi
		if [ -d "${WORK}"/images ];then
			echo "There is already an \"images\" folder on the multicd. You might have another Red Hat-based distro on it."
			echo "Scientific Linux's \"images\" folder won't be copied; instead, these files will be downloaded before the installer starts."
		else
			#Commenting out the below line will save about 100MB on the CD, but it will have to be downloaded when you install Scientific Linux
			cp -r "${MNT}"/scientific-boot/images "${WORK}"/
		fi
		umcdmount scientific-boot
	fi
	if [ -f slax.iso ];then
		echo "Copying Slax..."
		mcdmount slax
		if [ -f "${TAGS}"/slaxlist ];then
			mkdir "${WORK}"/slax
			for i in `ls "${MNT}"/slax/slax|sed -e '/^base$/ d'`;do
				cp -r "${MNT}"/slax/slax/$i "${WORK}"/slax/ #Copy everything but the base modules
			done
			mkdir "${WORK}"/slax/base
			for i in `cat "${TAGS}"/slaxlist`;do
				cp "${MNT}"/slax/slax/base/${i}* "${WORK}"/slax/base/ #Copy only the modules you wanted
			done
			cp "${MNT}"/slax/slax/base/001-*.lzm "${WORK}"/slax/base/ #Don't forget the core module!
			rm "${TAGS}"/slaxlist
		else
			cp -r "${MNT}"/slax/slax "${WORK}"/ #Copy everything
		fi
		mkdir -p "${WORK}"/boot/slax
		cp "${MNT}"/slax/boot/vmlinuz "${WORK}"/boot/slax/vmlinuz
		if [ -f "${MNT}"/slax/boot/initrd.lz ];then
			SUFFIX=lz
		else
			SUFFIX=gz
		fi
		cp "${MNT}"/slax/boot/initrd.$SUFFIX "${WORK}"/boot/slax/initrd.$SUFFIX
		umcdmount slax
		##########
		if [ "`ls -1 *.lzm 2> /dev/null;true`" != "" ];then
			echo "Copying Slax modules..."
		fi
		for i in `ls -1 *.lzm 2> /dev/null;true`; do
			if (! echo $i|grep -q ".sq4.lzm");then
				cp $i "${WORK}"/slax/modules/ #Copy the .lzm module to the modules folder
				if $VERBOSE;then
					echo \(Copied $i\)
				fi
			fi
		done
	fi
	if [ -f slitaz.iso ];then
		echo "Copying SliTaz..."
		mcdmount slitaz
		mkdir -p "${WORK}"/boot/slitaz
		cp "${MNT}"/slitaz/boot/bzImage "${WORK}"/boot/slitaz/bzImage #Kernel
		cp "${MNT}"/slitaz/boot/rootfs1.gz "${WORK}"/boot/slitaz/rootfs1.gz #Root filesystem 1
		cp "${MNT}"/slitaz/boot/rootfs2.gz "${WORK}"/boot/slitaz/rootfs2.gz #Root filesystem 2
		cp "${MNT}"/slitaz/boot/rootfs3.gz "${WORK}"/boot/slitaz/rootfs3.gz #Root filesystem 3
		cp "${MNT}"/slitaz/boot/rootfs4.gz "${WORK}"/boot/slitaz/rootfs4.gz #Root filesystem 4
		cp "${MNT}"/slitaz/boot/gpxe "${WORK}"/boot/slitaz/gpxe #PXE bootloader
		umcdmount slitaz
	fi
	if [ -f sysrcd.iso ];then
		echo "Copying SystemRescueCd..."
		mcdmount sysrcd
		mkdir "${WORK}"/boot/sysrcd
		cp "${MNT}"/sysrcd/sysrcd.* "${WORK}"/boot/sysrcd/ #Compressed filesystem
		cp -r "${MNT}"/sysrcd/bootdisk "${WORK}"/boot/sysrcd/ #PDV system tools from floppy disk image
		cp -r "${MNT}"/sysrcd/ntpasswd "${WORK}"/boot/sysrcd/ #PDV NTPASSWD
		cp "${MNT}"/sysrcd/isolinux/altker* "${WORK}"/boot/sysrcd/ #Kernels
		cp "${MNT}"/sysrcd/isolinux/rescue* "${WORK}"/boot/sysrcd/ #Kernels
		cp "${MNT}"/sysrcd/isolinux/initram.igz "${WORK}"/boot/sysrcd/initram.igz #Initrd
		cp "${MNT}"/sysrcd/version "${WORK}"/boot/sysrcd/version
		cp "${MNT}"/sysrcd/isolinux/isolinux.cfg "${WORK}"/boot/isolinux/sysrcd.cfg #PDV
		cp "${MNT}"/sysrcd/isolinux/*.msg "${WORK}"/boot/isolinux #PDV
		umcdmount sysrcd
	fi
	if [ -f tc+nb.iso ];then
		echo "Copying NetbootCD / Tiny Core / GRUB4DOS..."
		mcdmount tc+nb
		mkdir -p "${WORK}"/boot/tc+nb
		cp "${MNT}"/tc+nb/isolinux/kexec.bzI "${WORK}"/boot/tc+nb/
		cp "${MNT}"/tc+nb/isolinux/nbinit*.gz "${WORK}"/boot/tc+nb/nbinit.gz
		cp "${MNT}"/tc+nb/isolinux/tinycore.gz "${WORK}"/boot/tc+nb/
		cp "${MNT}"/tc+nb/isolinux/grub.exe "${WORK}"/boot/tc+nb/
		sleep 1;umcdmount tc+nb
	fi
	if [ -f tinycore.iso ];then
		echo "Copying Tiny Core..."
		tinycorecommon tinycore
		#--------------------#
		for i in `ls -1 *.tcz 2> /dev/null;true`;do
			mkdir -p "${WORK}"/cde
			echo "Copying: $i"
			cp $i "${WORK}"/cde/optional/"$i"
		done
		#regenerate onboot.lst
		true > "${WORK}"/cde/onboot.lst
		for i in "${WORK}"/cde/optional/*;do
			echo $(basename "$i") >> "${WORK}"/cde/onboot.lst
		done
	fi
	if [ -f tinyme.iso ];then
		echo "Copying TinyMe..."
		mcdmount tinyme
		cp "${MNT}"/tinyme/livecd.sqfs "${WORK}"/livecd.sqfs #Compressed filesystem
		mkdir -p "${WORK}"/boot/tinyme
		cp "${MNT}"/tinyme/isolinux/vmlinuz "${WORK}"/boot/tinyme/vmlinuz
		cp "${MNT}"/tinyme/isolinux/initrd.gz "${WORK}"/boot/tinyme/initrd.gz
		umcdmount tinyme
	fi
	if [ -f trk.iso ];then
		echo "Copying Trinity Rescue Kit..."
		mcdmount trk
		cp -r "${MNT}"/trk/trk3 "${WORK}"/ #TRK files
		mkdir "${WORK}"/boot/trinity
		cp "${MNT}"/trk/isolinux.cfg "${WORK}"/boot/isolinux/trk.menu
		cp "${MNT}"/trk/kernel.trk "${WORK}"/boot/trinity/kernel.trk
		cp "${MNT}"/trk/initrd.trk "${WORK}"/boot/trinity/initrd.trk
		cp "${MNT}"/trk/bootlogo.jpg "${WORK}"/boot/isolinux/trklogo.jpg #Boot logo
		umcdmount trk
	fi
	set -e
	if [ -f ubcd.iso ];then
		echo "Copying Ultimate Boot CD..."
		mcdmount ubcd
		cp -r "${MNT}"/ubcd/ubcd "${WORK}"/
		cp -r "${MNT}"/ubcd/pmagic "${WORK}"/
		mv "${WORK}"/pmagic/boot/syslinux "${WORK}"/pmagic/boot/isolinux
		if [ -d "${MNT}"/ubcd/antivir ];then
			cp -r "${MNT}"/ubcd/antivir "${WORK}"/
		fi
		cp "${MNT}"/ubcd/license.txt "${WORK}"/ubcd-license.txt
		for i in econfig whichsys hdt;do
			if [ -f "${MNT}"/ubcd/boot/syslinux/${i}.c32 ];then
				cp "${MNT}"/ubcd/boot/syslinux/${i}.c32 "${WORK}"/boot/isolinux/
			fi
		done
		cp "${MNT}"/ubcd/boot/syslinux/reboot.c32 "${WORK}"/boot/isolinux/
		for i in "${WORK}"/ubcd/menus/*/*.cfg "${WORK}"/ubcd/menus/*/*/*.cfg "${WORK}"/pmagic/boot/*/*.cfg;do
			sed -i -e 's/\/boot\/syslinux/\/boot\/isolinux/g' $i
		done
		sed -i -e 's/MENU LABEL GRUB4DOS menu/MENU LABEL Back to main menu/g' -e 's/This entry will bring you to the GRUB4DOS menu./Returns to the MultiCD menu./g' -e 's^BOOT /boot/grub/grldr^COM32 menu.c32\nAPPEND /boot/isolinux/isolinux.cfg^g' "${WORK}"/ubcd/menus/syslinux/main.cfg
		head -n 1 "${MNT}"/ubcd/ubcd/menus/syslinux/defaults.cfg | awk '{ print $6 }'>"${TAGS}"/ubcdver.tmp.txt
		#echo "$VERSION" > "${WORK}"/boot/ubcd/version
		umcdmount ubcd
	fi
	if [ -f ubuntu-alternate.iso ];then
		if [ -d "${WORK}"/pool ];then
			echo "NOT copying Ubuntu alternate installer - some sort of Ubuntu/Debian installer is already present."
			touch "${TAGS}"/ubuntu-not-copied
		else
			echo "Copying Ubuntu alternate installer..."
			mcdmount ubuntu-alternate
			cp "${MNT}"/ubuntu-alternate/cdromupgrade "${WORK}" 2>&1 || true #Not essential
			cp -r "${MNT}"/ubuntu-alternate/.disk "${WORK}"
			cp -r "${MNT}"/ubuntu-alternate/dists "${WORK}"
			cp -r "${MNT}"/ubuntu-alternate/doc "${WORK}" || true
			cp -r "${MNT}"/ubuntu-alternate/install "${WORK}"
			cp -r "${MNT}"/ubuntu-alternate/pool "${WORK}"
			cp -r "${MNT}"/ubuntu-alternate/preseed "${WORK}"
			cp -r "${MNT}"/ubuntu-alternate/README.diskdefines "${WORK}"
			#cp -r "${MNT}"/ubuntu-alternate/ubuntu "${WORK}"
			if [ ! -e "${MNT}"/ubuntu-alternate/ubuntu ];then
				ln -s . "${MNT}"/ubuntu-alternate/ubuntu
			fi
			umcdmount ubuntu-alternate
		fi
	fi
	if [ -f ubuntu-mini.iso ];then
		echo "Copying Ubuntu netboot installer..."
		mcdmount ubuntu-mini
		mkdir "${WORK}"/boot/ubuntu
		cp "${MNT}"/ubuntu-mini/linux "${WORK}"/boot/ubuntu/linux
		cp "${MNT}"/ubuntu-mini/initrd.gz "${WORK}"/boot/ubuntu/initrd.gz
		umcdmount ubuntu-mini
	fi
	if $(ubuntuExists);then
		for i in *.ubuntu.iso; do
			echo "Copying $(getUbuntuName)..."
			ubuntucommon $(echo $i|sed -e 's/\.iso//g')
		done
	fi
	if [ -f vyatta.iso ];then
		echo "Copying Vyatta..."
		mcdmount vyatta
		cp -r "${MNT}"/vyatta/live "${WORK}"/Vyatta #Pretty much everything except documentation/help
		umcdmount vyatta
	fi
	if [ -f weaknet.iso ];then
		echo "Copying WeakNet Linux..."
		ubuntucommon weaknet
	fi
	if [ -f win7recovery.iso ];then
		echo "Copying Windows 7 Recovery Disc..."
		mcdmount win7recovery
		cp "${MNT}"/win7recovery/boot/* "${WORK}"/boot/
		cp -r "${MNT}"/win7recovery/sources "${WORK}"/
		cp "${MNT}"/win7recovery/bootmgr "${WORK}"/
		umcdmount win7recovery
	fi
	if [ -f win98se.iso ];then
		echo "Copying Windows 98 SE..."
		mcdmount win98se
		cp -r "${MNT}"/win98se/win98 "${WORK}"/
		rm -r "${WORK}"/win98/ols
		if [ -f "${TAGS}"/9xextras ];then
			cp -r "${MNT}"/win98se/add-ons "${WORK}"/win98/add-ons
			cp -r "${MNT}"/win98se/tools "${WORK}"/win98/tools
		fi
		umcdmount win98se
		dd if=win98se.iso bs=43008 skip=1 count=35 of=/tmp/dat
		dd if=/tmp/dat bs=1474560 count=1 of="${WORK}"/boot/win98se.img
		rm /tmp/dat
		if which mdel > /dev/null;then
			mdel -i "${WORK}"/boot/win98se.img ::JO.SYS #Disable HD/CD boot prompt - not needed, but a nice idea
		fi
	fi
	if [ -f winme.iso ];then
		echo "Copying Windows Me..."
		mcdmount winme
		cp -r "${MNT}"/winme/win9x "${WORK}"/
		rm -r "${WORK}"/win9x/ols
		if [ -f "${TAGS}"/9xextras ];then
			cp -r "${MNT}"/winme/add-ons "${WORK}"/win9x/add-ons
			cp -r "${MNT}"/winme/tools "${WORK}"/win9x/tools
		fi
		umcdmount winme
		dd if=winme.iso bs=716800 skip=1 count=3 of=/tmp/dat
		dd if=/tmp/dat bs=1474560 count=1 of="${WORK}"/boot/winme.img
		rm /tmp/dat
	fi
	if [ -f wolvix.iso ];then
		echo "Copying Wolvix..."
		mcdmount wolvix
		cp -r "${MNT}"/wolvix/wolvix "${WORK}"/ #The Wolvix folder with all its files
		#The kernel/initrd must be here for the installer
		if [ ! -f "${WORK}"/boot/vmlinuz ]] && [ ! -f "${WORK}"/boot/initrd.gz ];then
			cp "${MNT}"/wolvix/boot/vmlinuz "${WORK}"/boot/vmlinuz
			cp "${MNT}"/wolvix/boot/initrd.gz "${WORK}"/boot/initrd.gz
		else
			mkdir -p "${WORK}"/boot/wolvix
			cp "${MNT}"/wolvix/boot/vmlinuz "${WORK}"/boot/wolvix/vmlinuz
			cp "${MNT}"/wolvix/boot/initrd.gz "${WORK}"/boot/wolvix/initrd.gz
		fi
		umcdmount wolvix
	fi
	if [ -f xbmc.iso ];then
		echo "Copying XBMC..."
		mcdmount xbmc
		cp -r "${MNT}"/xbmc/live "${WORK}"/boot/xbmc
		umcdmount xbmc
		rm "${WORK}"/live/memtest||true
	fi
	if [ -f zorin.iso ];then
		echo "Copying Zorin OS..."
		ubuntucommon zorin
	fi
#END COPY

#The below chunk copies floppy images.
j="0"
for i in *.im[agz]; do
	test -r "$i" || continue
	cp "$i" "${WORK}"/boot/$j.img
	echo -n Copying $(echo $i|sed 's/\.im.//')"... "
	if $VERBOSE;then
		echo "Saved as "$j".img."
	else
		echo
	fi
	j=$( expr $j + 1 )
done

#This chunk copies floppy images in the "games" folder. They will have their own submenu.
if [ $GAMES = 1 ];then
	k="0"
	mkdir -p "${WORK}"/boot/games
	for i in games/*.im[agz]; do
		test -r "$i" || continue
		echo -n Copying $(echo $i|sed 's/\.im.//'|sed 's/games\///')"... "
		cp "$i" "${WORK}"/boot/games/$k.img
		if $VERBOSE;then
			echo "Saved as games/"$k".img."
		else
			echo
		fi
		k=$( expr $k + 1 )
	done
fi

if [ -f grub.exe ];then
 echo "Copying GRUB4DOS..."
 cp grub.exe "${WORK}"/boot/grub.exe
fi

if [ -f syslinux-4.03.tar.gz ] && [ ! -f syslinux.tar.gz ];then
	ln -s syslinux-4.03.tar.gz syslinux.tar.gz #Link newest version
fi

if [ -f syslinux.tar.gz ];then
	echo "Unpacking and copying SYSLINUX files..."
	tar -C /tmp -xzf syslinux.tar.gz
	cp /tmp/syslinux-*/core/isolinux.bin "${WORK}"/boot/isolinux/
	cp /tmp/syslinux-*/memdisk/memdisk "${WORK}"/boot/isolinux/
	cp /tmp/syslinux-*/com32/menu/menu.c32 "${WORK}"/boot/isolinux/
	cp /tmp/syslinux-*/com32/menu/vesamenu.c32 "${WORK}"/boot/isolinux/
	cp /tmp/syslinux-*/com32/modules/chain.c32 "${WORK}"/boot/isolinux/
	cp /tmp/syslinux-*/utils/isohybrid "${TAGS}"/isohybrid
	chmod -R +w "$WORK/boot/isolinux"
	chmod +x "${TAGS}"/isohybrid
	rm -r /tmp/syslinux-*/
fi
if [ ! -f "${WORK}"/boot/isolinux/isolinux.bin ];then
	echo "Downloading SYSLINUX..."
	if $VERBOSE ;then #These will only be run if there is no syslinux.tar.gz
		#Both of these need to be changed when a new version of syslinux comes out.
		if ! wget -t 1 -O syslinux.tar.gz https://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-$RECENT_SYSLINUX.tar.gz;then
			echo "Error: could not download SYSLINUX. Please update the URL in $0."
			rm syslinux.tar.gz
			false #quits script
		fi
	else
		if ! wget -t 1 -qO syslinux.tar.gz https://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-$RECENT_SYSLINUX.tar.gz;then
			echo "Error: could not download SYSLINUX. Please update the URL in $0."
			rm syslinux.tar.gz
			false #quits script
		fi
	fi
	echo "Unpacking and copying files..."
	tar -C /tmp -xzf syslinux.tar.gz
	cp /tmp/syslinux-*/core/isolinux.bin "${WORK}"/boot/isolinux/
	cp /tmp/syslinux-*/memdisk/memdisk "${WORK}"/boot/isolinux/
	cp /tmp/syslinux-*/com32/menu/menu.c32 "${WORK}"/boot/isolinux/
	cp /tmp/syslinux-*/com32/menu/vesamenu.c32 "${WORK}"/boot/isolinux/
	cp /tmp/syslinux-*/com32/modules/chain.c32 "${WORK}"/boot/isolinux/
	cp /tmp/syslinux-*/utils/isohybrid "${TAGS}"/isohybrid
	chmod +x "${TAGS}"/isohybrid
	rm -r /tmp/syslinux-*/
fi

if $MEMTEST;then
	if [ -f memtest ] && [ "$(wc -c memtest)" != "0" ];then
		cp memtest "${WORK}"/boot/memtest
	else
		echo "Downloading memtest86+ 4.20 from memtest.org..."
		if $VERBOSE;then
			wget -O- http://memtest.org/download/4.20/memtest86+-4.20.bin.gz|gzip -cd>memtest
		else
			wget -qO- http://memtest.org/download/4.20/memtest86+-4.20.bin.gz|gzip -cd>memtest
		fi
		if [ -f memtest ] && [ "$(wc -c memtest)" != "0 memtest" ];then
			cp memtest "${WORK}"/boot/memtest
			echo 'v4.20' > memtestver
		else
			echo "Download of memtest failed."
		fi
	fi
fi

echo "Writing isolinux.cfg..."

##BEGIN ISOLINUX MENU CODE##
#The ISOLINUX menu can be rearranged by renaming your plugin scripts - they are processed in alphabetical order.

#BEGIN HEADER#
#Don't move this part. You can change the timeout and menu title, however.
echo "DEFAULT menu.c32
TIMEOUT 0
PROMPT 0" > "${WORK}"/boot/isolinux/isolinux.cfg
#Changed to use $TAGS/country instead of the old $ccTLD
if [ -f "${TAGS}/country" ];then #PDV
	cp -r maps "${WORK}"/boot/isolinux
	echo "KBDMAP maps/$(cat "${TAGS}"/country).ktl" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
echo "menu title $CDTITLE" >> "${WORK}"/boot/isolinux/isolinux.cfg
#END HEADER#

#BEGIN COLOR CODE#
	if [ $MENUCOLOR = 40 ];then
		BORDERCOLOR=37 #white border
	else
		BORDERCOLOR=30 #black border
	fi
	echo "	menu color screen 37;40
	menu color border 30;44
	menu color title 1;36;44
	menu color unsel 37;44
	menu color hotkey 1;37;44
	menu color sel 7;37;40
	menu color hotsel 1;7;37;40
	menu color disabled 1;30;44
	menu color scrollbar 30;44
	menu color tabmsg 31;40
	menu color cmdmark 1;36;40
	menu color cmdline 37;40
	menu color pwdborder 30;47
	menu color pwdheader 31;47
	menu color pwdentry 30;47
	menu color timeout_msg 37;40
	menu color timeout 1;37;40
	menu color help 37;40
	menu color msg07 37;40"|sed \
	-e "s/30/$BORDERCOLOR/g" -e "s/44/$MENUCOLOR/g"|sed \
	-e "s/unsel 37/unsel $TEXTCOLOR/g" >>"${WORK}"/boot/isolinux/isolinux.cfg
#END COLOR CODE#

#BEGIN HD BOOT OPTION#
#If this bugs you, get rid of it.
echo "label local
menu label Boot from ^hard drive
kernel chain.c32
append hd0" >> "${WORK}"/boot/isolinux/isolinux.cfg
#END HD BOOT OPTION#
#START WRITE
if [ -f antix.iso ];then
echo "label anitX
menu label ^antiX
com32 menu.c32
append antix.menu" >> "${WORK}"/boot/isolinux/isolinux.cfg
echo "DEFAULT menu.c32
TIMEOUT 0
PROMPT 0
menu title AntiX Options

label  antiX-Default
menu label ^antiX-Default
kernel /boot/antix/vmlinuz
append SELINUX_INIT=NO init=/etc/init quiet nosplash vga=791 aufs  initrd=/boot/antix/initrd.gz

label  antiX-Lite-noNet
kernel /boot/antix/vmlinuz
append SELINUX_INIT=NO init=/etc/init quiet nosplash vga=791 aufs mean lean initrd=/boot/antix/initrd.gz

label  antiX-Vesa
menu label antiX-Vesa (display problem or virtualbox)
kernel /boot/antix/vmlinuz
append SELINUX_INIT=NO init=/etc/init vga=normal quiet nosplash drvr=vesa aufs lean initrd=/boot/antix/initrd.gz

label  antiX-UltraLite-Vesa
menu label antiX-UltraLite-Vesa (Fast boot)
kernel /boot/antix/vmlinuz
append SELINUX_INIT=NO init=/etc/init vga=normal quiet nosplash drvr=vesa aufs lean Xtralean initrd=/boot/antix/initrd.gz

label  antiX-Failsafe
menu label antiX-Failsafe (minimum options, small display)
kernel /boot/antix/vmlinuz
append SELINUX_INIT=NO init=/etc/init quiet nosplash vga=normal nosound noapic noscsi nodma noapm nousb nopcmcia nofirewire noagp nomce nodhcp nodbus nocpufreq nobluetooth drvr=fbdev aufs res=800x600v initrd=/boot/antix/initrd.gz

label  antiX-60Hz
menu label antiX-60Hz (force monitor to 58-62 Hz)
kernel /boot/antix/vmlinuz
append SELINUX_INIT=NO init=/etc/init vga=791 quiet nosplash vsync=58-62 aufs initrd=/boot/antix/initrd.gz

label  antiX-75Hz
menu label antiX-75Hz (force monitor to 73-77 Hz)
kernel /boot/antix/vmlinuz
append SELINUX_INIT=NO init=/etc/init vga=791 quiet nosplash vsync=73-77 aufs initrd=/boot/antix/initrd.gz

label back
menu label ^Back to main menu
com32 menu.c32
append isolinux.cfg
" > "${WORK}"/boot/isolinux/antix.menu
fi
if [ -f arch.iso ];then
	if [ -f "${MNT}"/boot/syslinux/syslinux_arch32.cfg ] && [ -f "${MNT}"/boot/syslinux/syslinux_arch64.cfg ];then
		echo "label arch
		menu label --> ^Arch Linux ($(getVersion arch))
		KERNEL /arch/boot/syslinux/ifcpu64.c32
		APPEND have64 -- nohave64
	
		LABEL have64
		MENU HIDE
		CONFIG /arch/boot/syslinux/syslinux_both.cfg
		APPEND /arch/boot/syslinux/
	
		LABEL nohave64
		MENU HIDE
		CONFIG /arch/boot/syslinux/syslinux_32only.cfg
		APPEND /arch/boot/syslinux/
		" >> "${WORK}"/boot/isolinux/isolinux.cfg
		for i in 32 64;do
		    sed -i -e "s/archisolabel=[A-Za-z0-9_]*/archisolabel=${CDLABEL}/" \
		    "${WORK}"/arch/boot/syslinux/syslinux_arch${i}.cfg
		done
		echo "
		label back
		menu label ^Back to main menu
		config /boot/isolinux/isolinux.cfg
		append /boot/isolinux
		" >> "${WORK}"/arch/boot/syslinux/syslinux_tail.cfg
	else
		echo "LABEL arch
		MENU LABEL --> ^Arch Linux ($(getVersion arch))
		CONFIG /arch/boot/syslinux/syslinux.cfg
		APPEND /arch/boot/syslinux/
		" >> "${WORK}"/boot/isolinux/isolinux.cfg
		for i in "${WORK}"/arch/boot/syslinux/*.cfg;do
		    sed -i -e "s/archisolabel=[A-Za-z0-9_]*/archisolabel=${CDLABEL}/" \
		    "$i"
		done
		echo "
		LABEL back
		MENU LABEL ^Back to main menu..
		CONFIG /boot/isolinux/isolinux.cfg
		APPEND /boot/isolinux
		" >> "${WORK}"/arch/boot/syslinux/syslinux_tail.cfg
	fi
fi
	if [ -f archboot.iso ];then
		if [ -f "${TAGS}"/lang-full ];then
			LANG="$(cat "${TAGS}"/lang-full)"
		else
			LANG="en_US"
		fi
		if [ -f archboot.version ];then
			VERSION="$(cat archboot.version)"
		else
			VERSION=""
		fi
		echo "menu begin --> ^Arch Linux$VERSION Installer

		LABEL arch
		TEXT HELP
		Boot the Arch Linux (i686) archboot medium. 
		It allows you to install Arch Linux or perform system maintenance.
		ENDTEXT
		MENU LABEL Boot Arch Linux (i686)
		LINUX /boot/archboot/vmlinuz_i686
		APPEND initrd=/boot/archboot/initramfs_i686.img rootdelay=10

		LABEL arch64
		TEXT HELP
		Boot the Arch Linux (x86_64) archboot medium. 
		It allows you to install Arch Linux or perform system maintenance.
		ENDTEXT
		MENU LABEL Boot Arch Linux (x86_64)
		LINUX /boot/archboot/vmlinuz_x86_64
		APPEND initrd=/boot/archboot/initramfs_x86_64.img rootdelay=10

		LABEL arch-lts
		TEXT HELP
		Boot the Arch Linux LTS (i686) archboot medium. 
		It allows you to install Arch Linux or perform system maintenance.
		ENDTEXT
		MENU LABEL Boot Arch Linux LTS (i686)
		LINUX /boot/archboot/vmlinuz_i686_lts
		APPEND initrd=/boot/archboot/initramfs_i686.img rootdelay=10

		LABEL arch64-lts
		TEXT HELP
		Boot the Arch Linux LTS (x86_64) archboot medium. 
		It allows you to install Arch Linux or perform system maintenance.
		ENDTEXT
		MENU LABEL Boot Arch Linux LTS (x86_64)
		LINUX /boot/archboot/vmlinuz_x86_64_lts
		APPEND initrd=/boot/archboot/initramfs_x86_64.img rootdelay=10
	
		menu end" >> "${WORK}"/boot/isolinux/isolinux.cfg
	fi
if [ -f archiso-live.iso ];then
if [ -f archiso-live.version ] && [ "$(cat archiso-live.version)" != "" ];then
	VERSION=" ($(cat archiso-live.version))" #Version based on isoaliases()
else
	VERSION=""
fi
echo "LABEL archiso-live
TEXT HELP
Boot the Arch Linux live medium. It allows you to install Arch Linux or
perform system maintenance.
ENDTEXT
MENU LABEL Boot ^archiso-live$VERSION
KERNEL /boot/archiso-live/vmlinuz
APPEND initrd=/boot/archiso-live/initrd.img locale=en_US.UTF-8 load=overlay cdname=archiso-live session=xfce
IPAPPEND 0

LABEL archiso-livebaseonly
TEXT HELP
Boot the Arch Linux live medium. It allows you to install Arch Linux or
perform system maintenance. Basic LXDE desktop and apps.
ENDTEXT
MENU LABEL Boot archiso-live with baseonly$VERSION
KERNEL /boot/archiso-live/vmlinuz
APPEND initrd=/boot/archiso-live/initrd.img locale=en_US.UTF-8 load=overlay cdname=archiso-live session=lxde baseonly
" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
if [ -f austrumi.iso ];then
echo "label austrumilinux
	menu label ^Austrumi
	com32 vesamenu.c32
	append al.menu
" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
if [ -f avg.iso ];then
#if [ -f avg.version ] && [ "$(cat avg.version)" != "" ];then
#	AVGVER=" (avg_$(cat avg.version))"
#else
#	AVGVER=""
#fi
AVGVER=" ($(cat "${WORK}"/arl-version))"
echo "MENU BEGIN --> AVG Rescue CD$AVGVER

label arl
	menu label AVG Rescue CD
	menu default
	kernel /boot/avg/vmlinuz
	initrd /boot/avg/initrd.lzm
	append max_loop=255 vga=791 init=linuxrc

label nofb
	menu label AVG Rescue CD with Disabled Framebuffer
	kernel /boot/avg/vmlinuz
	initrd /boot/avg/initrd.lzm
	append max_loop=255 video=vesafb:off init=linuxrc

label vgask
	menu label AVG Rescue CD with Resolution Selection
	kernel /boot/avg/vmlinuz
	initrd /boot/avg/initrd.lzm
	append max_loop=255 init=linuxrc vga=ask

label back
	menu label Back to main menu
	com32 menu.c32
	append isolinux.cfg
menu end" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
if [ -f avira.iso ];then
VERSION=$(sed -n '/AVIRA/p' "${WORK}"/aviralicenses/welcome.msg | awk '{print substr($5,1,7)}') #extract Avira Version from file
echo "menu begin --> Avira Rescue CD $VERSION

label 1
 menu label Boot AntiVir Rescue System (default)
    kernel /boot/isolinux/aviravmlinuz
    append nofb initrd=/boot/isolinux/avirainitrd.gz ramdisk_size=108178 root=/dev/ram0 rw  console=/dev/vc/4

label 2
 menu label Advanced Users Antivir Rescue System VGA=ask
    kernel /boot/isolinux/aviravmlinuz
    append vga=ask initrd=/boot/isolinux/avirainitrd.gz ramdisk_size=108178 root=/dev/ram0 rw  console=/dev/vc/4

label debug
 menu label debug
    kernel /boot/isolinux/aviravmlinuz
    append vga=ask initrd=/boot/isolinux/avirainitrd.gz ramdisk_size=108178 root=/dev/ram0 rw

label nogui
 menu label NoGUI
    kernel /boot/isolinux/aviravmlinuz
    append nofb initrd=/boot/ixolinux/initrd.gz ramdisk_size=108178 root=/dev/ram0 rw  console=/dev/vc/4 av-nogui

label back
   menu label Back to main menu...
   com32 menu.c32

MENU END
" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
	if [ -f backtrack.iso ];then
		if [ -f backtrack.version ] && [ "$(cat backtrack.version)" != "" ];then
			VERSION=" $(cat backtrack.version)" #Version based on isoaliases()
		else
			VERSION=""
		fi

		echo "label backtrack
		menu label --> BackTrack$VERSION Menu
		com32 menu.c32
		append /boot/backtrack/backtrack.cfg
		" >> "${WORK}"/boot/isolinux/isolinux.cfg
	fi
    if [ -f "${TAGS}"/lang ];then
        LANGCODE=$(cat "${TAGS}"/lang)
    else
        LANGCODE=en
    fi
    if [ -f caine.iso ];then
        echo "label caine2 (Computer Aided Investigative Environment)
        kernel /boot/caine/vmlinuz
        initrd /boot/caine/initrd.gz
        append live-media-path=/boot/caine ignore_uuid noprompt persistent BOOT_IMAGE=/casper/vmlinuz file=/cdrom/CaineFiles/custom.seed boot=casper -- debian-installer/language=$LANGCODE console-setup/layoutcode=$LANGCODE
        " >> "${WORK}"/boot/isolinux/isolinux.cfg
    fi
if [ -f cdl.iso ];then
#CDLinux uses country codes longer than two letters, so I don't think I'll get much out of "${TAGS}"/lang here.
echo "menu begin --> ^CDlinux

label cdlinux-en_US
	menu label ^CDlinux (en_US) English
	kernel /CDlinux/bzImage
	append quiet CDL_LANG=en_US.UTF-8
	initrd /CDlinux/initrd
label cdlinux-de_DE
	menu label ^CDlinux (de_DE) Deutsch
	kernel /CDlinux/bzImage
	append quiet CDL_LANG=de_DE.UTF-8
	initrd /CDlinux/initrd
label cdlinux-en_CA
	menu label ^CDlinux (en_CA) English
	kernel /CDlinux/bzImage
	append quiet CDL_LANG=en_CA.UTF-8
	initrd /CDlinux/initrd
label cdlinux-en_GB
	menu label ^CDlinux (en_GB) English
	kernel /CDlinux/bzImage
	append quiet CDL_LANG=en_GB.UTF-8
	initrd /CDlinux/initrd
label cdlinux-fr_CA
	menu label ^CDlinux (fr_CA) French
	kernel /CDlinux/bzImage
	append quiet CDL_LANG=fr_CA.UTF-8
	initrd /CDlinux/initrd
label cdlinux-fr_CH
	menu label ^CDlinux (fr_CH) French
	kernel /CDlinux/bzImage
	append quiet CDL_LANG=fr_CH.UTF-8
	initrd /CDlinux/initrd
label cdlinux-fr_FR
	menu label ^CDlinux (fr_FR) French
	kernel /CDlinux/bzImage
	append quiet CDL_LANG=fr_FR.UTF-8
	initrd /CDlinux/initrd
label cdlinux-ja_JP
	menu label ^CDlinux (ja_JP) Japanese
	kernel /CDlinux/bzImage
	append quiet CDL_LANG=ja_JP.UTF-8
	initrd /CDlinux/initrd
label cdlinux-ru_RU
	menu label ^CDlinux (ru_RU) Russian
	kernel /CDlinux/bzImage
	append quiet CDL_LANG=ru_RU.UTF-8
	initrd /CDlinux/initrd
label cdlinux-zh_CN
	menu label ^CDlinux (zh_CN) Chinese
	kernel /CDlinux/bzImage
	append quiet CDL_LANG=zh_CN.UTF-8
	initrd /CDlinux/initrd
label cdlinux-zh_TW
	menu label ^CDlinux (zh_TW) Chinese
	kernel /CDlinux/bzImage
	append quiet CDL_LANG=zh_TW.UTF-8
	initrd /CDlinux/initrd
label cdlinux-sfg
	menu label ^CDlinux Safe Graphics Mode
	kernel /CDlinux/bzImage
	append quiet CDL_SAFEG=yes
	initrd /CDlinux/initrd 
label back
	menu label Back to Main Menu
	com32 menu.c32
	append isolinux.cfg
menu end
" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
	if [ -f centos-boot.iso ];then
		if [ -f centos-boot.version ] && [ "$(cat centos-boot.version)" != "" ];then
			VERSION=" $(cat centos-boot.version)" #Version based on isoaliases()
		fi
		echo "label centos-mirror
		menu label ^Install CentOS from UW-Madison's mirror (assuming SciLinux 6)
		kernel /boot/centos/vmlinuz
		append initrd=/boot/centos/initrd.img method=http://mirror.cs.wisc.edu/pub/mirrors/linux/centos/6/os/i386/
		label centos
		menu label ^Install or upgrade CentOS (enter mirror manually)
		kernel /boot/centos/vmlinuz
		append initrd=/boot/centos/initrd.img
		label centosvesa
		menu label Install CentOS system with ^basic video driver
		kernel /boot/centos/vmlinuz
		append initrd=/boot/centos/initrd.img xdriver=vesa nomodeset
		label centosrescue
		menu label ^Rescue installed CentOS system
		kernel /boot/centos/vmlinuz
		append initrd=/boot/centos/initrd.img rescue" >> "${WORK}"/boot/isolinux/isolinux.cfg
	fi
if [ -f clonezilla$2.iso ];then
VERSION=$(sed -e 's/^.*[^0-9]\([0-9]*\.[0-9]*\.[0-9]*-[0-9]*\).*$/\1/' "${WORK}"/boot/clonezilla$2/Clonezilla-Live-Version | head -n1)
echo "label clonezilla$2" >> "${WORK}"/boot/isolinux/isolinux.cfg
if [ -z $2 ];then
	echo "menu label --> ^Clonezilla Live $VERSION" >> "${WORK}"/boot/isolinux/isolinux.cfg
else
	echo "menu label --> Clonezilla Live $VERSION for ^$2 CPU" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
echo "com32 vesamenu.c32
append clonezil$2.cfg
" >> "${WORK}"/boot/isolinux/isolinux.cfg
#GNU sed syntax
sed -i -e 's/\/live\//\/boot\/clonezilla'$2'\//g' "${WORK}"/boot/isolinux/clonezil$2.cfg #Change directory to /boot/clonezilla
sed -i -e 's/append initrd=/append live-media-path=\/boot\/clonezilla'$2' initrd=/g' "${WORK}"/boot/isolinux/clonezil$2.cfg #Tell the kernel we moved it
if [ -f "${TAGS}"/country ]; then #PDV
	if [ $(cat "${TAGS}"/country) = "be" ];then
		sed -i -e 's/ocs_live_keymap=""/ocs_live_keymap="\/usr\/share\/keymaps\/i386\/azerty\/be2-latin1.kmap.gz"/' "${WORK}"/boot/isolinux/clonezil$2.cfg #set keymap
	fi
fi
if [ -f "${TAGS}"/lang-full ]; then #PDV
	sed -i -e 's/ocs_lang=""/ocs_lang="'$(cat "${TAGS}"/lang-full)'.UTF-8"/' "${WORK}"/boot/isolinux/clonezil$2.cfg #menu language
fi
##sed -i -e 's/[[:blank:]]ip=frommedia[[:blank:]]/ /' "${WORK}"/boot/isolinux/clonezil$2.cfg #PDV get ip via dhcp
if $MEMTEST; then #PDV remove memtest if already in main menu
	sed -i -e '/MENU BEGIN Memtest/,/MENU END/ s/MENU END//' -e '/MENU BEGIN Memtest/,/ENDTEXT/d' -e '/./,/^$/!d' "${WORK}"/boot/isolinux/clonezil$2.cfg
	rm "${WORK}"/boot/clonezilla$2/memtest
fi
echo "
MENU SEPARATOR

label back
menu label Back to main menu
com32 menu.c32
append isolinux.cfg" >> "${WORK}"/boot/isolinux/clonezil$2.cfg
fi
if [ -f connos.iso ];then
echo "label connos
menu label ^ConnochaetOS
kernel /boot/connos/vmlinuz
initrd /boot/connos/initrd.img" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
#BEGIN DBAN ENTRY#
if [ -f dban.iso ];then
echo "#Most of the DBAN options are commented out on the menu because they're so dangerous.
#Even if you uncomment them, they won't appear on the menu unless you also remove MENU HIDE (you can still press Esc and enter them to boot.)

LABEL  dban
MENU LABEL ^DBAN
KERNEL /boot/dban1/dban.bzi
APPEND nuke=\"dwipe --method prng --rounds 8 --verify off\" floppy=0,16,cmos

#LABEL  autonuke
#MENU HIDE
#KERNEL /boot/dban1/kernel.bzi
#APPEND initrd=/boot/dban1/initrd.gz root=/dev/ram0 init=/rc nuke=\"dwipe --autonuke\" silent
#
#LABEL  dod
#MENU HIDE
#KERNEL /boot/dban1/kernel.bzi
#APPEND initrd=/boot/dban1/initrd.gz root=/dev/ram0 init=/rc nuke=\"dwipe --autonuke --method dod522022m\" silent
#
#LABEL  dod3pass
#MENU HIDE
#KERNEL /boot/dban1/kernel.bzi
#APPEND initrd=/boot/dban1/initrd.gz root=/dev/ram0 init=/rc nuke=\"dwipe --autonuke --method dod3pass\" silent
#
#LABEL  dodshort
#MENU HIDE
#KERNEL /boot/dban1/kernel.bzi
#APPEND initrd=/boot/dban1/initrd.gz root=/dev/ram0 init=/rc nuke=\"dwipe --autonuke --method dodshort\" silent
#
#LABEL  gutmann
#MENU HIDE
#KERNEL /boot/dban1/kernel.bzi
#APPEND initrd=/boot/dban1/initrd.gz root=/dev/ram0 init=/rc nuke=\"dwipe --autonuke --method gutmann\" silent
#
#LABEL  ops2
#MENU HIDE
#KERNEL /boot/dban1/kernel.bzi
#APPEND initrd=/boot/dban1/initrd.gz root=/dev/ram0 init=/rc quiet nuke=\"dwipe --autonuke --method ops2\" silent
#
#LABEL  paranoid
#MENU HIDE
#KERNEL /boot/dban1/kernel.bzi
#APPEND initrd=/boot/dban1/initrd.gz root=/dev/ram0 init=/rc quiet nuke=\"dwipe --autonuke --method prng --rounds 8 --verify all\" silent
#
#LABEL  prng
#MENU HIDE
#KERNEL /boot/dban1/kernel.bzi
#APPEND initrd=/boot/dban1/initrd.gz root=/dev/ram0 init=/rc quiet nuke=\"dwipe --autonuke --method prng --rounds 8\" silent
#
#LABEL  quick
#MENU HIDE
#KERNEL /boot/dban1/kernel.bzi
#APPEND initrd=/boot/dban1/initrd.gz root=/dev/ram0 init=/rc quiet nuke=\"dwipe --autonuke --method quick\" silent
#
#LABEL  zero
#MENU HIDE
#KERNEL /boot/dban1/kernel.bzi
#APPEND initrd=/boot/dban1/initrd.gz root=/dev/ram0 init=/rc quiet nuke=\"dwipe --autonuke --method zero\" silent
#
#LABEL  nofloppy
#MENU HIDE
#KERNEL /boot/dban1/kernel.bzi
#APPEND initrd=/boot/dban1/initrd.gz root=/dev/ram0 init=/rc quiet nuke=\"dwipe\" floppy=0,16,cmos
#
#LABEL  nosilent
#MENU HIDE
#KERNEL /boot/dban1/kernel.bzi
#APPEND initrd=/boot/dban1/initrd.gz root=/dev/ram0 init=/rc quiet nuke=\"dwipe\"
#
#LABEL  noverify
#MENU HIDE
#KERNEL /boot/dban1/kernel.bzi
#APPEND initrd=/boot/dban1/initrd.gz root=/dev/ram0 init=/rc quiet nuke=\"dwipe --verify off\"
#
#LABEL  debug
#MENU HIDE
#KERNEL /boot/dban1/kernel.bzi
#APPEND initrd=/boot/dban1/initrd.gz root=/dev/ram0 init=/rc nuke=\"exec ash\" debug
#
#LABEL  shell
#MENU HIDE
#KERNEL /boot/dban1/kernel.bzi
#APPEND initrd=/boot/dban1/initrd.gz root=/dev/ram0 init=/rc nuke=\"exec ash\"
#
#LABEL  verbose
#MENU HIDE
#KERNEL /boot/dban1/kernel.bzi
#APPEND initrd=/boot/dban1/initrd.gz root=/dev/ram0 init=/rc nuke=\"dwipe --method quick\"
" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
#END DBAN ENTRY#
	if [ -f debian-install.iso ];then
		DEBNAME="Debian GNU/Linux netinst (i386)"
		if [ -f debian-install.version ] && [ "$(cat debian-install.version)" != "" ];then
			DEBNAME="$DEBNAME $(cat debian-install.version)"
		fi

		DIR="install.386"

		echo "menu begin --> ^$DEBNAME

		label install
			menu label ^Install
			menu default
			kernel /$DIR/vmlinuz
			append vga=normal initrd=/$DIR/initrd.gz -- quiet 
		label expert
			menu label ^Expert install
			kernel /$DIR/vmlinuz
			append priority=low vga=normal initrd=/$DIR/initrd.gz -- 
		label rescue
			menu label ^Rescue mode
			kernel /$DIR/vmlinuz
			append vga=normal initrd=/$DIR/initrd.gz rescue/enable=true -- quiet 
		label auto
			menu label ^Automated install
			kernel /$DIR/vmlinuz
			append auto=true priority=critical vga=normal initrd=/$DIR/initrd.gz -- quiet 
		label installgui
			menu label ^Graphical install
			kernel /$DIR/vmlinuz
			append video=vesa:ywrap,mtrr vga=788 initrd=/$DIR/gtk/initrd.gz -- quiet 
		label expertgui
			menu label Graphical expert install
			kernel /$DIR/vmlinuz
			append priority=low video=vesa:ywrap,mtrr vga=788 initrd=/$DIR/gtk/initrd.gz -- 
		label rescuegui
			menu label Graphical rescue mode
			kernel /$DIR/vmlinuz
			append video=vesa:ywrap,mtrr vga=788 initrd=/$DIR/gtk/initrd.gz rescue/enable=true -- quiet  
		label autogui
			menu label Graphical automated install
			kernel /$DIR/vmlinuz
			append auto=true priority=critical video=vesa:ywrap,mtrr vga=788 initrd=/$DIR/gtk/initrd.gz -- quiet 
		label Back to main menu
			com32 menu.c32
			append isolinux.cfg

		menu end" >> "${WORK}"/boot/isolinux/isolinux.cfg
	fi
	if [ -f debian-install64.iso ];then
		DEBNAME="Debian GNU/Linux netinst (amd64)"
		if [ -f debian-install64.version ] && [ "$(cat debian-install64.version)" != "" ];then
			DEBNAME="$DEBNAME $(cat debian-install64.version)"
		fi

		DIR="install.amd"

		echo "menu begin --> ^$DEBNAME

		label install
			menu label ^Install
			menu default
			kernel /$DIR/vmlinuz
			append vga=normal initrd=/$DIR/initrd.gz -- quiet 
		label expert
			menu label ^Expert install
			kernel /$DIR/vmlinuz
			append priority=low vga=normal initrd=/$DIR/initrd.gz -- 
		label rescue
			menu label ^Rescue mode
			kernel /$DIR/vmlinuz
			append vga=normal initrd=/$DIR/initrd.gz rescue/enable=true -- quiet 
		label auto
			menu label ^Automated install
			kernel /$DIR/vmlinuz
			append auto=true priority=critical vga=normal initrd=/$DIR/initrd.gz -- quiet 
		label installgui
			menu label ^Graphical install
			kernel /$DIR/vmlinuz
			append video=vesa:ywrap,mtrr vga=788 initrd=/$DIR/gtk/initrd.gz -- quiet 
		label expertgui
			menu label Graphical expert install
			kernel /$DIR/vmlinuz
			append priority=low video=vesa:ywrap,mtrr vga=788 initrd=/$DIR/gtk/initrd.gz -- 
		label rescuegui
			menu label Graphical rescue mode
			kernel /$DIR/vmlinuz
			append video=vesa:ywrap,mtrr vga=788 initrd=/$DIR/gtk/initrd.gz rescue/enable=true -- quiet  
		label autogui
			menu label Graphical automated install
			kernel /$DIR/vmlinuz
			append auto=true priority=critical video=vesa:ywrap,mtrr vga=788 initrd=/$DIR/gtk/initrd.gz -- quiet 
		label Back to main menu
			com32 menu.c32
			append isolinux.cfg

		menu end" >> "${WORK}"/boot/isolinux/isolinux.cfg
	fi
	if $(debianExists);then
		for i in *.debian.iso; do
			BASENAME=$(echo $i|sed -e 's/\.iso//g')
			DEBNAME=$(getDebianName)

			echo "label $BASENAME
			menu label >> ^$DEBNAME
			com32 menu.c32
			append $BASENAME.cfg" >> "${WORK}"/boot/isolinux/isolinux.cfg

			sed -i -e '/memtest/d' -e '/Memory test/d' "${WORK}"/boot/isolinux/$BASENAME.cfg

			if [ ! -f "$TAGS"/debians/$BASENAME.inroot ];then
				sed -i -e "s^/live/^/$BASENAME/^g" \
				-e "s/boot=live/boot=live live-media-path=\/$BASENAME/g" \
				-e '/\/install\//d' "${WORK}"/boot/isolinux/$BASENAME.cfg
			fi

			echo "label back
			menu label Back to main menu
			com32 menu.c32
			append /boot/isolinux/isolinux.cfg
			" >> "${WORK}"/boot/isolinux/$BASENAME.cfg
		done
	fi
if [ -f debian-mini.iso ];then
echo "LABEL dinstall
menu label ^Install Debian
	kernel /boot/debian/linux
	append vga=normal initrd=/boot/debian/initrd.gz -- quiet 
LABEL dexpert
menu label Install Debian - expert mode
	kernel /boot/debian/linux
	append priority=low vga=normal initrd=/boot/debian/initrd.gz -- 
" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
if [ -f deli.iso ];then
echo "label deli-ide
	menu label ^DeLi Linux
	kernel /isolinux/bzImage
	append initrd=/isolinux/initrd.gz load_ramdisk=1 prompt_ramdisk=0 ramdisk_size=6464 rw root=/dev/ram

label deli-scsi
	menu label ^DeLi Linux - SCSI
	kernel /isolinux/scsi
	append initrd=/isolinux/initrd.gz load_ramdisk=1 prompt_ramdisk=0 ramdisk_size=6464 rw root=/dev/ram" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
if [ -f diskcopy.iso ];then
echo "label diskcopy
menu label ^EASEUS Disk Copy
kernel /boot/diskcopy/bzImage
append initrd=/boot/diskcopy/initrd.img
" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
	if [ -f doudoulinux.iso ];then
		if [ -f doudoulinux.version ] && [ "$(cat doudoulinux.version)" != "" ];then
			DOUDOUVER=" $(cat doudoulinux.version)"
		else
			DOUDOUVER=""
		fi
		sed -i -e "s/DoudouLinux/DoudouLinux $DOUDOUVER/g" "${TAGS}"/doudou.cfg
		sed -i -e "s^/live/^/boot/doudou/^g" "${TAGS}"/doudou.cfg
		sed -i -e "s^boot=live^boot=live live-media-path=/boot/doudou^g" "${TAGS}"/doudou.cfg
		cat "${TAGS}"/doudou.cfg >> "${WORK}"/boot/isolinux/isolinux.cfg
		rm "${TAGS}"/doudou.cfg
	fi
if [ -f drweb.iso ];then
DRWEBMAJORVER="$(awk 'BEGIN { RS="" ;  FS="=" } ; { print $2 }' "${WORK}"/boot/config)"
DRWEBMINORVER="$(awk 'BEGIN { RS="" ;  FS="=" } ; { print $4 }' "${WORK}"/boot/config)"
DRWEBID="$(awk 'BEGIN { RS="";  FS="=" } ; { print $8 }' "${WORK}"/boot/config)"
echo "MENU BEGIN --> Dr.Web LiveCD $DRWEBMAJORVER.$DRWEBMINORVER

label drweb
	menu label Dr.Web LiveCD (Default)
	menu default
	kernel /boot/drweb/vmlinuz
	initrd /boot/drweb/initrd
	append ID=$DRWEBID root=/dev/ram0 init=linuxrc init_opts=4 quiet vga=791 splash=silent,theme:drweb CONSOLE=/dev/tty1

label drwebadv
	menu label Dr.Web LiveCD (Advanced)
	kernel /boot/drweb/vmlinuz
	initrd /boot/drweb/initrd
	append ID=$DRWEBID root=/dev/ram0 init=linuxrc init_opts=3 quiet CONSOLE=/dev/tty1

label back
	menu label Back to main menu
	com32 menu.c32
	append isolinux.cfg
menu end" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
if [ -f dsl.iso ];then
echo "menu begin --> ^DSL

LABEL dsl
MENU LABEL DSL
KERNEL /boot/isolinux/linux24
APPEND ramdisk_size=100000 init=/etc/init lang=us apm=power-off vga=791 initrd=/boot/isolinux/minirt24.gz nomce noapic quiet BOOT_IMAGE=knoppix

LABEL dsl-toram
MENU LABEL DSL (load to RAM)
KERNEL /boot/isolinux/linux24
APPEND ramdisk_size=100000 init=/etc/init lang=us apm=power-off vga=791 initrd=/boot/isolinux/minirt24.gz nomce noapic quiet toram BOOT_IMAGE=knoppix

LABEL dsl-2
MENU LABEL DSL (boot to command line)
KERNEL /boot/isolinux/linux24
APPEND ramdisk_size=100000 init=/etc/init lang=us apm=power-off vga=791 initrd=/boot/isolinux/minirt24.gz nomce noapic quiet 2 BOOT_IMAGE=knoppix

LABEL dsl-expert
MENU LABEL DSL (expert mode)
KERNEL /boot/isolinux/linux24
APPEND ramdisk_size=100000 init=/etc/init lang=us apm=power-off vga=791 initrd=/boot/isolinux/minirt24.gz nomce BOOT_IMAGE=expert

LABEL dsl-fb1280x1024
MENU LABEL DSL (1280x1024 framebuffer)
KERNEL /boot/isolinux/linux24
APPEND ramdisk_size=100000 init=/etc/init lang=us apm=power-off vga=794 xmodule=fbdev initrd=/boot/isolinux/minirt24.gz nomce noapic quiet BOOT_IMAGE=knoppix

LABEL dsl-fb1024x768
MENU LABEL DSL (1024x768 framebuffer)
KERNEL /boot/isolinux/linux24
APPEND ramdisk_size=100000 init=/etc/init lang=us apm=power-off vga=791 xmodule=fbdev initrd=/boot/isolinux/minirt24.gz nomce noapic quiet BOOT_IMAGE=knoppix

LABEL dsl-fb800x600
MENU LABEL DSL (800x600 framebuffer)
KERNEL /boot/isolinux/linux24
APPEND ramdisk_size=100000 init=/etc/init lang=us apm=power-off vga=788 xmodule=fbdev initrd=/boot/isolinux/minirt24.gz nomce noapic quiet BOOT_IMAGE=knoppix

LABEL dsl-lowram
MENU LABEL DSL (for low RAM)
KERNEL /boot/isolinux/linux24
APPEND ramdisk_size=100000 init=/etc/init lang=us apm=power-off vga=normal initrd=/boot/isolinux/minirt24.gz noscsi noideraid nosound nousb nofirewire noicons minimal nomce noapic noapm lowram quiet BOOT_IMAGE=knoppix

LABEL dsl-install
MENU LABEL Install DSL
KERNEL /boot/isolinux/linux24
APPEND ramdisk_size=100000 init=/etc/init lang=us apm=power-off vga=normal initrd=/boot/isolinux/minirt24.gz noscsi noideraid nosound nofirewire legacy base norestore _install_ nomce noapic noapm quiet BOOT_IMAGE=knoppix

LABEL dsl-failsafe
MENU LABEL DSL (failsafe)
KERNEL /boot/isolinux/linux24
APPEND ramdisk_size=100000 init=/etc/init 2 lang=us vga=normal atapicd nosound noscsi nousb nopcmcia nofirewire noagp nomce nodhcp xmodule=vesa initrd=/boot/isolinux/minirt24.gz BOOT_IMAGE=knoppix base norestore legacy

label back
menu label ^Back to main menu
com32 menu.c32
append isolinux.cfg

MENU END
" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
if [ -f dvl.iso ];then
echo "label dvl
menu label Damn ^Vulnerable Linux
kernel /boot/dvl/vmlinuz
initrd /boot/dvl/initrd.gz
append vga=0x317 max_loop=255 init=linuxrc load_ramdisk=1 prompt_ramdisk=0 ramdisk_size=4444 root=/dev/ram0 rw

label dvlsafe
menu label Damn Vulnerable Linux (dvlsafe)
kernel /boot/dvl/vmlinuz
initrd /boot/dvl/initrd.gz
append vga=769 max_loop=255 init=linuxrc load_ramdisk=1 prompt_ramdisk=0 ramdisk_size=4444 root=/dev/ram0 rw
" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
if [ -f efw.iso ];then
echo "menu begin ^Endian Firewall

label endianfirewall
	menu label ^Endian Firewall - Default
	kernel /boot/endian/vmlinuz 
	append initrd=/boot/endian/instroot.gz root=/dev/ram0 rw
label endianfirewall_unattended 
	menu label ^Endian Firewall - Unattended
	kernel /boot/endian/vmlinuz
	append initrd=/boot/endian/instroot.gz root=/dev/ram0 rw unattended
label endianfirewall_nopcmcia 
	menu label ^Endian Firewall - No PCMCIA
	kernel /boot/endian/vmlinuz
	append ide=nodma initrd=/boot/endian/instroot.gz root=/dev/ram0 rw nopcmcia
label endianfirewall_nousb
	menu label ^Endian Firewall - No USB
	kernel /boot/endian/vmlinuz
	append ide=nodma initrd=/boot/endian/instroot.gz root=/dev/ram0 rw nousb
label endianfirewall_nousborpcmcia
	menu label ^Endian Firewall - No USB nor PCMCIA
	kernel /boot/endian/vmlinuz
	append ide=nodma initrd=/boot/endian/instroot.gz root=/dev/ram0 rw nousb nopcmcia
label back
	menu label ^Back to main menu
	com32 menu.c32
	append isolinux.cfg
menu end
" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
	if [ -f elastix.iso ];then
		echo "label elastixmenu
		menu label --> ^Elastix
		config /boot/isolinux/elastix.cfg
		" >> "${WORK}"/boot/isolinux/isolinux.cfg
		echo "default linux
		prompt 1
		timeout 600
		display /boot/elastix/boot.msg
		F1 /boot/elastix/boot.msg
		F2 /boot/elastix/options.msg
		F3 /boot/elastix/general.msg
		F4 /boot/elastix/param.msg
		F5 /boot/elastix/rescue.msg
		F7 /boot/elastix/snake.msg
		label advanced
		  kernel /boot/elastix/vmlinuz
		  append ks=cdrom:/ks_advanced.cfg initrd=/boot/elastix/initrd.img ramdisk_size=8192
		label elastix
		  kernel /boot/elastix/vmlinuz
		  append initrd=/boot/elastix/initrd.img ramdisk_size=8192
		label linux
		  kernel /boot/elastix/vmlinuz
		  append ks=cdrom:/ks.cfg initrd=/boot/elastix/initrd.img ramdisk_size=8192
		label rhinoraid
		  kernel /boot/elastix/vmlinuz
		  append ks=cdrom:/ks_rhinoraid.cfg initrd=/boot/elastix/initrd.img ramdisk_size=8192
		label local
		  localboot 1
		label back
		menu label Back to main menu
		com32 menu.c32
		append /boot/isolinux/isolinux.cfg
		" > "${WORK}"/boot/isolinux/elastix.cfg
	fi
if [ -f feather.iso ];then
if [ $(cat "${TAGS}"/lang) ];then
	LANGCODE=$(cat "${TAGS}"/lang)
else
	LANGCODE=us
fi
echo "LABEL feather
MENU LABEL ^Feather Linux
KERNEL /boot/feather/linux24
APPEND ramdisk_size=100000 init=/etc/init lang=$LANGCODE apm=power-off vga=791 initrd=/boot/feather/minirt24.gz knoppix_dir=FEATHER nomce quiet BOOT_IMAGE=knoppix
LABEL feather-toram
MENU LABEL Feather Linux (load to RAM)
KERNEL /boot/feather/linux24
APPEND ramdisk_size=100000 init=/etc/init lang=$LANGCODE apm=power-off vga=791 initrd=/boot/feather/minirt24.gz knoppix_dir=FEATHER nomce quiet toram BOOT_IMAGE=knoppix
LABEL feather-2
MENU LABEL Feather Linux (boot to command line)
KERNEL /boot/feather/linux24
APPEND ramdisk_size=100000 init=/etc/init lang=$LANGCODE apm=power-off vga=791 initrd=/boot/feather/minirt24.gz knoppix_dir=FEATHER nomce quiet 2 BOOT_IMAGE=knoppix
" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
	if [ -f fedora-boot.iso ];then
		if [ -f fedora-boot.version ] && [ "$(cat fedora-boot.version)" != "" ];then
			VERSION=" $(cat fedora-boot.version)" #Version based on isoaliases()
		fi
		echo "label flinux
		  #TIP: If you change the method= entry in the append line, you can change the mirror and version installed.
		  menu label ^Install Fedora$VERSION from UW-Madison's mirror (assuming Fedora 15)
		  kernel /boot/fedora/vmlinuz
		  append initrd=/boot/fedora/initrd.img stage2=hd:LABEL=\"Fedora\" http://mirror.cs.wisc.edu/pub/mirrors/linux/download.fedora.redhat.com/pub/fedora/linux/releases/15/Everything/i386/os
		label flinux
		  menu label ^Install or upgrade Fedora$VERSION (enter mirror manually)
		  kernel /boot/fedora/vmlinuz
		  append initrd=/boot/fedora/initrd.img stage2=hd:LABEL=\"Fedora\"
		label ftext
		  menu label Install or upgrade Fedora$VERSION with basic video driver
		  kernel /boot/fedora/vmlinuz
		  append initrd=/boot/fedora/initrd.img stage2=hd:LABEL=\"Fedora\" xdriver=vesa nomodeset
		label frescue
		  menu label Rescue installed Fedora$VERSION system
		  kernel /boot/fedora/vmlinuz
		  append initrd=/boot/fedora/initrd.img stage2=hd:LABEL=\"Fedora\" rescue
		" >> "${WORK}"/boot/isolinux/isolinux.cfg
	fi
	if [ -f fedora-boot64.iso ];then
		if [ -f fedora-boot64.version ] && [ "$(cat fedora-boot64.version)" != "" ];then
			VERSION=" $(cat fedora-boot64.version)" #Version based on isoaliases()
		fi
		echo "label flinux64
		  #TIP: If you change the method= entry in the append line, you can change the mirror and version installed.
		  menu label ^Install 64-bit Fedora$VERSION from mirrors.kernel.org (Fedora 13 only)
		  kernel /boot/fedora64/vmlinuz
		  append initrd=/boot/fedora64/initrd.img method=http://mirrors.kernel.org/fedora/releases/13/Fedora/x86_64/os
		label flinux64
		  menu label ^Install or upgrade 64-bit Fedora$VERSION from another mirror
		  kernel /boot/fedora64/vmlinuz
		  append initrd=/boot/fedora64/initrd.img
		label ftext64
		  menu label Install or upgrade 64-bit Fedora$VERSION (text mode)
		  kernel /boot/fedora64/vmlinuz
		  append initrd=/boot/fedora64/initrd.img text
		label frescue64
		  menu label Rescue installed 64-bit Fedora$VERSION system
		  kernel /boot/fedora64/vmlinuz
		  append initrd=/boot/fedora64/initrd.img rescue
		" >> "${WORK}"/boot/isolinux/isolinux.cfg
	fi
if [ -f finnix.iso ];then
echo "menu begin --> ^Finnix

label Finnix
  MENU LABEL ^Finnix (32-bit)
  kernel /boot/finnix/linux
  append finnixfile=/finnix/finnix initrd=/boot/finnix/initrd.xz apm=power-off vga=791 quiet

label Finnix64
  MENU LABEL Finnix (64-bit)
  kernel /boot/finnix/linux64
  append finnixfile=/finnix/finnix initrd=/boot/finnix/initrd.xz apm=power-off vga=791 quiet

label FinnixText
  MENU LABEL ^Finnix (32-bit, textmode)
  kernel /boot/finnix/linux
  append finnixfile=/finnix/finnix initrd=/boot/finnix/initrd.xz apm=power-off vga=normal quiet

label FinnixDebug
  MENU LABEL ^Finnix (32-bit, debug mode)
  kernel /boot/finnix/linux
  append finnixfile=/finnix/finnix initrd=/boot/finnix/initrd.xz apm=power-off vga=normal debug

label Finnix64Text
  MENU LABEL Finnix (64-bit, textmode)
  kernel /boot/finnix/linux64
  append finnixfile=/finnix/finnix initrd=/boot/finnix/initrd.xz apm=power-off vga=normal quiet

label Finnix64Debug
  MENU LABEL Finnix (64-bit, debug mode)
  kernel /boot/finnix/linux64
  append finnixfile=/finnix/finnix initrd=/boot/finnix/initrd.xz apm=power-off vga=normal debug

label FinnixFailsafe
  MENU LABEL ^Finnix (failsafe)
  kernel /boot/finnix/linux
  append finnixfile=/finnix/finnix initrd=/boot/finnix/initrd.xz vga=normal noapic noacpi pnpbios=off acpi=off nofstab nodma noapm nodhcp nolvm nomouse noeject

label FinnixSBM
  MENU LABEL Smart Boot Manager
  kernel /boot/finnix/memdisk
  append initrd=/boot/finnix/sbm.imz

menu end
" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
	if [ -f freedos.iso ];then
		if [ -f freedos.defaultname ] && [ "$(cat freedos.defaultname)" != "" ];then
			NAME=$(cat freedos.defaultname) #Default name based on the automatic links made in isoaliases()
		else
			NAME="FreeDOS CD" #Fallback name
		fi
		echo "label fdos
		menu label ^$NAME
		kernel memdisk
		append initrd=/boot/freedos/fdboot.img
		" >> "${WORK}"/boot/isolinux/isolinux.cfg
	fi
	if [ -z "$CDLABEL" ];then
		CDLABEL=MCDtest
		echo "$0: warning: \$CDLABEL is empty."
	fi
	if [ -f fusion.iso ];then
		BASENAME=fusion

		echo "label $BASENAME
		menu label --> ^Fusion Linux$(getVersion) Menu
		com32 vesamenu.c32
		append /boot/$BASENAME/$BASENAME.cfg
		" >> "${WORK}"/boot/isolinux/isolinux.cfg

		echo "label back
		menu label --> ^Back to main menu
		com32 menu.c32
		append /boot/isolinux/isolinux.cfg
		" >> "${WORK}"/boot/$BASENAME/$BASENAME.cfg
		sed -i -e 's^menu background splash^menu background /boot/fusion/splash^g' "${WORK}"/boot/$BASENAME/$BASENAME.cfg
		sed -i -e 's^kernel vmlinuz^kernel /boot/fusion/vmlinuz^g' "${WORK}"/boot/$BASENAME/$BASENAME.cfg
		sed -i -e 's^initrd=initrd^initrd=/boot/fusion/initrd^g' "${WORK}"/boot/$BASENAME/$BASENAME.cfg
		sed -i -e "s/CDLABEL=[^ ]*/CDLABEL=${CDLABEL}/g" "${WORK}"/boot/$BASENAME/$BASENAME.cfg
	fi
if [ -f geexbox.iso ];then
echo "label gbox
	menu label ^GeeXboX
	com32 vesamenu.c32
	append gbox.menu
" >> "${WORK}"/boot/isolinux/isolinux.cfg
echo "PROMPT 0

TIMEOUT 20

MENU BACKGROUND /GEEXBOX/boot/splash.png
MENU TITLE Welcome to GeeXboX i386 (C) 2002-2009
MENU VSHIFT 11
MENU ROWS 6
MENU TABMSGROW 15
MENU CMDLINEROW 14
MENU HELPMSGROW 16
MENU TABMSG Press [Tab] to edit options, [F1] for boot options.
MENU COLOR sel 7;37;40 #e0000000 #fa833b all
MENU COLOR border 30;44 #00000000 #00000000 none

LABEL geexbox
  MENU LABEL Start GeeXboX ...
  KERNEL /GEEXBOX/boot/vmlinuz
  APPEND initrd=/GEEXBOX/boot/initrd.gz root=/dev/ram0 rw rdinit=linuxrc boot=cdrom lang=en remote=atiusb receiver=atiusb keymap=qwerty splash=silent vga=789 video=vesafb:ywrap,mtrr quiet

LABEL hdtv
  MENU DEFAULT
  MENU LABEL Start GeeXboX for HDTV ...
  KERNEL /GEEXBOX/boot/vmlinuz
  APPEND initrd=/GEEXBOX/boot/initrd.gz root=/dev/ram0 rw rdinit=linuxrc boot=cdrom lang=en remote=atiusb receiver=atiusb keymap=qwerty splash=silent vga=789 video=vesafb:ywrap,mtrr hdtv quiet

LABEL install
  MENU LABEL Install GeeXboX to disk ...
  KERNEL /GEEXBOX/boot/vmlinuz
  APPEND initrd=/GEEXBOX/boot/initrd.gz root=/dev/ram0 rw rdinit=linuxrc boot=cdrom lang=en remote=atiusb receiver=atiusb keymap=qwerty splash=silent vga=789 video=vesafb:ywrap,mtrr installator quiet

#CFG#LABEL configure
#CFG#  MENU LABEL Reconfigure a GeeXboX installation ...
#CFG#  KERNEL /GEEXBOX/boot/vmlinuz
#CFG#  APPEND initrd=/GEEXBOX/boot/initrd.gz root=/dev/ram0 rw rdinit=linuxrc boot=cdrom lang=en remote=atiusb receiver=atiusb keymap=qwerty splash=silent vga=789 video=vesafb:ywrap,mtrr configure

MENU SEPARATOR

LABEL debug
  MENU LABEL Start in debugging mode ...
  KERNEL /GEEXBOX/boot/vmlinuz
  APPEND initrd=/GEEXBOX/boot/initrd.gz root=/dev/ram0 rw rdinit=linuxrc boot=cdrom lang=en remote=atiusb receiver=atiusb keymap=qwerty splash=0 vga=789 video=vesafb:ywrap,mtrr debugging

LABEL hdtvdebug
  MENU LABEL Start HDTV edition in debugging mode ...
  KERNEL /GEEXBOX/boot/vmlinuz
  APPEND initrd=/GEEXBOX/boot/initrd.gz root=/dev/ram0 rw rdinit=linuxrc boot=cdrom lang=en remote=atiusb receiver=atiusb keymap=qwerty splash=0 vga=789 video=vesafb:ywrap,mtrr hdtv debugging

F1 help.msg #00000000
" > "${WORK}"/boot/isolinux/gbox.menu
fi
	COUNTER=0
	if $(genericExists);then for i in *.generic.iso;do
		echo "label generic-$COUNTER
		menu label ^$(getGenericName)
		kernel memdisk
		append iso
		initrd /generic/$i
		" >> "${WORK}"/boot/isolinux/isolinux.cfg
		COUNTER=$(($COUNTER+1))
	done;fi
if [ -f gparted.iso ];then
	if [ -f "${WORK}"/gparted/vmlinuz1 ];then
		AP="1"
	else
		AP=""
	fi
echo "menu begin >> GParted Live

# Since no network setting in the squashfs image, therefore if ip=frommedia, the network is disabled. That's what we want.
label GParted Live
  # MENU HIDE
  MENU LABEL GParted Live (Default settings)
  # MENU PASSWD
  kernel /boot/gparted/vmlinuz$AP
  append initrd=/boot/gparted/initrd$AP.img boot=live config i915.modeset=0 xforcevesa radeon.modeset=0 noswap nomodeset vga=788 ip=frommedia nosplash live-media-path=/boot/gparted
  TEXT HELP
  * GParted live version: $(cat gparted.version). Live version maintainer: Steven Shiau
  * Disclaimer: GParted live comes with ABSOLUTELY NO WARRANTY
  ENDTEXT

label GParted Live (To RAM)
  # MENU DEFAULT
  # MENU HIDE
  MENU LABEL GParted Live (To RAM. Boot media can be removed later)
  # MENU PASSWD
  kernel /boot/gparted/vmlinuz$AP
  append initrd=/boot/gparted/initrd$AP.img boot=live config i915.modeset=0 xforcevesa radeon.modeset=0 noswap nomodeset noprompt vga=788 toram=filesystem.squashfs live-media-path=/boot/gparted ip=frommedia  nosplash
  TEXT HELP
  All the programs will be copied to RAM, so you can
  remove boot media (CD or USB flash drive) later
  ENDTEXT

label GParted Live without framebuffer
  # MENU DEFAULT
  # MENU HIDE
  MENU LABEL GParted Live (Safe graphic settings, vga=normal)
  # MENU PASSWD
  kernel /boot/gparted/vmlinuz$AP
  append initrd=/boot/gparted/initrd$AP.img boot=live config i915.modeset=0 xforcevesa radeon.modeset=0 noswap nomodeset ip=frommedia vga=normal nosplash live-media-path=/boot/gparted
  TEXT HELP
  Disable console frame buffer support
  ENDTEXT

label GParted Live failsafe mode
  # MENU DEFAULT
  # MENU HIDE
  MENU LABEL GParted Live (Failsafe mode)
  # MENU PASSWD
  kernel /boot/gparted/vmlinuz$AP
  append initrd=/boot/gparted/initrd$AP.img boot=live config i915.modeset=0 xforcevesa radeon.modeset=0 noswap nomodeset acpi=off irqpoll noapic noapm nodma nomce nolapic nosmp ip=frommedia vga=normal nosplash live-media-path=/boot/gparted
  TEXT HELP
  acpi=off irqpoll noapic noapm nodma nomce nolapic 
  nosmp vga=normal nosplash
  ENDTEXT
MENU END
" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
if [ -f grml.iso ];then
	VERSION=$(awk '{print substr($2,1,7)}' "${WORK}"/boot/grml/grml-version) #Getting grml Version
	echo "menu begin --> GRML $VERSION
	" >> "${WORK}"/boot/isolinux/isolinux.cfg

	sed -i".bak" '1d' "${WORK}"/boot/grml/grml.cfg #deleting some lines we don't want
	sed -i".bak" '2d' "${WORK}"/boot/grml/grml.cfg
	sed -i".bak" '/menu end/ i\label back\n   menu label Back to main menu...\n   com32 menu.c32\n'  "${WORK}"/boot/grml/grml.cfg #insert back to main menu

	sed -i -e 's^boot=live live-media-path=/live/grml32-full/^boot=live live-media-path=/grml/grml32-full/ ignore_bootid^g' "${WORK}"/boot/grml/grml.cfg
	sed -i -e 's^/boot/grml32full/^/boot/grml/^g' "${WORK}"/boot/grml64/grml.cfg

	if [ -f "${WORK}"/boot/grml/grml.cfg.bak ];then
		rm "${WORK}"/boot/grml/grml.cfg.bak #bak file from sed not needed
	fi

	cat "${WORK}"/boot/grml/grml.cfg >> "${WORK}"/boot/isolinux/isolinux.cfg #putting everything together

	rm "${WORK}"/boot/grml/grml.cfg #not needed any longer
fi
if [ -f grml64.iso ];then
	VERSION=$(awk '{print substr($2,1,7)}' "${WORK}"/boot/grml64/grml-version) #Getting grml Version
	echo "menu begin --> GRML64 $VERSION
	" >> "${WORK}"/boot/isolinux/isolinux.cfg

	sed -i".bak" '1d' "${WORK}"/boot/grml64/grml.cfg #deleting some lines we don't want
	sed -i".bak" '2d' "${WORK}"/boot/grml64/grml.cfg
	sed -i".bak" '/menu end/ i\label back\n   menu label Back to main menu...\n   com32 menu.c32\n'  "${WORK}"/boot/grml64/grml.cfg #insert back to main menu

	sed -i -e 's^boot=live live-media-path=/live/grml64-full/^boot=live live-media-path=/grml64/grml64-full/ ignore_bootid^g' "${WORK}"/boot/grml64/grml.cfg
	sed -i -e 's^/boot/grml64full/^/boot/grml64/^g' "${WORK}"/boot/grml64/grml.cfg

	if [ -f "${WORK}"/boot/grml64/grml.cfg.bak ];then
		rm "${WORK}"/boot/grml64/grml.cfg.bak #bak file from sed not needed
	fi

	cat "${WORK}"/boot/grml64/grml.cfg >> "${WORK}"/boot/isolinux/isolinux.cfg #putting everything together

	rm "${WORK}"/boot/grml64/grml.cfg #not needed any longer
fi
if [ -f hirens.iso ];then
echo "label hirens
menu label --> ^$(cat "${TAGS}"/hirens.name) - main menu
com32 menu.c32
append /HBCD/isolinux.cfg" >> "${WORK}"/boot/isolinux/isolinux.cfg
rm "${TAGS}"/hirens.name
fi
if [ -f insert.iso ];then
echo "LABEL insert
menu label ^INSERT
KERNEL /boot/insert/vmlinuz
APPEND ramdisk_size=100000 init=/etc/init lang=en apm=power-off vga=773 initrd=/boot/insert/miniroot.lz nomce noapic dma BOOT_IMAGE=insert
LABEL insert-txt
menu label INSERT (vga=normal)
KERNEL /boot/insert/vmlinuz
APPEND ramdisk_size=100000 init=/etc/init lang=en apm=power-off vga=normal initrd=/boot/insert/miniroot.lz nomce noapic dma BOOT_IMAGE=insert
LABEL expert
menu label INSERT (expert mode)
KERNEL /boot/insert/vmlinuz
APPEND ramdisk_size=100000 init=/etc/init lang=en apm=power-off vga=773 initrd=/boot/insert/miniroot.lz nomce noapic dma BOOT_IMAGE=expert
LABEL failsafe
menu label INSERT (failsafe)
KERNEL /boot/insert/vmlinuz
APPEND ramdisk_size=100000 init=/etc/init lang=en vga=normal atapicd nosound noapic noacpi pnpbios=off acpi=off nofstab noscsi nodma noapm nousb nopcmcia nofirewire noagp nomce nodhcp xmodule=vesa initrd=/boot/insert/miniroot.lz BOOT_IMAGE=insert
" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
	if [ -f ipcop.iso ];then
		if [ -f "${WORK}"/boot/ipcop/instroot.img ];then
			INSTROOT="instroot.img"
		else
			INSTROOT="instroot.gz"
		fi
		echo "label ipcopmenu
		menu label --> ^IPCop
		config /boot/isolinux/ipcop.cfg
		" >> "${WORK}"/boot/isolinux/isolinux.cfg
		echo "TIMEOUT 5000
		F1 /boot/ipcop/f1.txt
		F2 /boot/ipcop/f2.txt
		F3 /boot/ipcop/f3.txt
		DISPLAY /boot/ipcop/f1.txt
		PROMPT 1
		DEFAULT /boot/ipcop/vmlinuz
		APPEND ide=nodma initrd=/boot/ipcop/$INSTROOT root=/dev/ram0 rw
		LABEL nopcmcia 
		  KERNEL /boot/ipcop/vmlinuz
		  APPEND ide=nodma initrd=/boot/ipcop/$INSTROOT root=/dev/ram0 rw nopcmcia
		LABEL noscsi
		  KERNEL /boot/ipcop/vmlinuz
		  APPEND ide=nodma initrd=/boot/ipcop/$INSTROOT root=/dev/ram0 rw scsi=none
		LABEL nousb
		  KERNEL /boot/ipcop/vmlinuz
		  APPEND ide=nodma initrd=/boot/ipcop/$INSTROOT root=/dev/ram0 rw nousb
		LABEL nousborpcmcia
		  KERNEL v/boot/ipcop/mlinuz
		  APPEND ide=nodma initrd=/boot/ipcop/$INSTROOT root=/dev/ram0 rw nousb nopcmcia
		LABEL dma
		  KERNEL /boot/ipcop/vmlinuz
		  APPEND initrd=/boot/ipcop/$INSTROOT root=/dev/ram0 rw
		LABEL memtest
		  KERNEL /boot/memtest
		  APPEND -
		" > "${WORK}"/boot/isolinux/ipcop.cfg
	fi
	if [ -f kav.iso ];then
		#note: $CDLABEL is set [exported] in multicd.sh
		if [ -f "${TAGS}"/lang ];then
			LANGCODE=$(cat "${TAGS}"/lang)
		else
			LANGCODE=en
		fi
		echo "menu begin --> ^Kapersky Rescue Disk

		label kav
		menu label ^Kaspersky Rescue Disk - Graphic Mode
		kernel /boot/rescue/rescue
		initrd /boot/rescue/rescue.igz
		append root=live:CDLABEL=$CDLABEL rootfstype=auto vga=791 init=/init initrd=rescue.igz kav_lang=$LANGCODE udev liveimg splash quiet doscsi nomodeset

		label kav-rescue-text
		menu label ^Kaspersky Rescue Disk - Text Mode
		kernel /boot/rescue/rescue
		initrd /boot/rescue/rescue.igz
		append root=live:CDLABEL=$CDLABEL rootfstype=auto vga=791 init=/init initrd=rescue.igz kav_lang=$LANGCODE udev liveimg quiet nox kavshell noresume doscsi nomodeset

		label hardware-info
		menu label (Kapersky) Hardware Info
		kernel /boot/rescue/rescue
		initrd /boot/rescue/rescue.igz
		append root=live:CDLABEL=$CDLABEL rootfstype=auto vga=791 init=/init initrd=rescue.igz kav_lang=$LANGCODE udev liveimg quiet softlevel=boot nox hwinfo noresume doscsi nomodeset

		label back
		menu label ^Back to main menu
		com32 menu.c32
		append isolinux.cfg

		menu end" >> "${WORK}"/boot/isolinux/isolinux.cfg
	fi
	 if [ -f kdusmall.iso ];then
		if [ -f kdusmall.version ];then
			KDUVER=" $(cat kdusmall.version)"
			if [ "$KDUVER" == "" ];then
				KDUVER=""
			fi
		else
			KDUVER=""
		fi
		echo "label kdusmall
		menu label --> KDu-Small$KDUVER Menu
		com32 menu.c32
		append /boot/kdusmall/kdusmall.cfg
		" >> "${WORK}"/boot/isolinux/isolinux.cfg
	fi
	 if [ -f kduxp.iso ];then
		if [ -f kduxp.version ];then
			KDUVER=" $(cat kduxp.version)"
			if [ "$KDUVER" == "" ];then
				KDUVER=""
			fi
		else
			KDUVER=""
		fi
		echo "label kduxp
		menu label --> KDuXP$KDUVER Menu
		com32 menu.c32
		append /boot/kduxp/kduxp.cfg
		" >> "${WORK}"/boot/isolinux/isolinux.cfg
	fi
	if [ -f knoppix.iso ];then
		if [ -f knoppix.version ] && [ "$(cat knoppix.version)" != "" ];then
			KNOPPIXVER=" $(cat knoppix.version)"
		else
			KNOPPIXVER=""
		fi
		if [ -f "${TAGS}"/lang ];then
			LANGCODE=$(cat "${TAGS}"/lang)
		else
			if echo $KNOPPIXVER|grep DE;then
				LANGCODE=de
			else
				LANGCODE=en
			fi
		fi
		echo "MENU BEGIN --> ^Knoppix$KNOPPIXVER

		LABEL knoppix
		MENU LABEL Knoppix
		KERNEL /boot/knoppix/linux
		INITRD /boot/knoppix/minirt.gz
		APPEND ramdisk_size=100000 lang=$LANGCODE vt.default_utf8=0 apm=power-off vga=791 nomce quiet loglevel=0 tz=localtime knoppix_dir=KNOPPIX6

		LABEL adriane
		MENU LABEL Adriane (Knoppix)
		KERNEL /boot/knoppix/linux
		INITRD /boot/knoppix/minirt.gz
		APPEND ramdisk_size=100000 lang=$LANGCODE vt.default_utf8=0 apm=power-off vga=791 nomce quiet loglevel=0 tz=localtime knoppix_dir=KNOPPIX6 adriane

		LABEL knoppix-2
		MENU LABEL Knoppix (boot to command line)
		KERNEL /boot/knoppix/linux
		INITRD /boot/knoppix/minirt.gz
		APPEND ramdisk_size=100000 lang=$LANGCODE vt.default_utf8=0 apm=power-off vga=791 nomce quiet loglevel=0 tz=localtime knoppix_dir=KNOPPIX6 2

		LABEL fb1024x768
		KERNEL linux
		APPEND ramdisk_size=100000 lang=$LANGCODE vt.default_utf8=0 apm=power-off vga=791 xmodule=fbdev initrd=minirt.gz nomce quiet loglevel=0 tz=localtime
		LABEL fb1280x1024
		KERNEL linux
		APPEND ramdisk_size=100000 lang=$LANGCODE vt.default_utf8=0 apm=power-off vga=794 xmodule=fbdev initrd=minirt.gz nomce quiet loglevel=0 tz=localtime
		LABEL fb800x600
		KERNEL linux
		APPEND ramdisk_size=100000 lang=$LANGCODE vt.default_utf8=0 apm=power-off vga=788 xmodule=fbdev initrd=minirt.gz nomce quiet loglevel=0 tz=localtime

		label back
		menu label Back to main menu
		com32 menu.c32
		append isolinux.cfg

		MENU END" >> "${WORK}"/boot/isolinux/isolinux.cfg
	fi
	if $(linuxmintExists);then
		for i in *.linuxmint.iso; do
			BASENAME=$(echo $i|sed -e 's/\.iso//g')
			UBUNAME=$(getLinuxmintName)

			echo "label $BASENAME
			menu label --> $UBUNAME Menu
			com32 menu.c32
			append /boot/$BASENAME/$BASENAME.cfg
			" >> "${WORK}"/boot/isolinux/isolinux.cfg
		done
	fi
	if [ -f macpup.iso ];then
		if [ -f "${TAGS}"/macpup.name ] && [ "$(cat "${TAGS}"/macpup.name)" != "" ];then
			PUPNAME=$(cat "${TAGS}"/macpup.name)
		else
			PUPNAME="Macpup"
		fi
		if [ -d "${WORK}"/macpup ];then
			EXTRAARGS="psubdir=macpup"
		fi
		if [ -d "${WORK}"/macpup ];then
			EXTRAARGS="psubdir=macpup"
			KERNELPATH="/macpup"
		else
			EXTRAARGS=""
			KERNELPATH=""
		fi
		echo "label macpup
		menu label ^$PUPNAME
		kernel $KERNELPATH/vmlinuz
		append pmedia=cd $EXTRAARGS
		initrd $KERNELPATH/initrd.gz
		#label macpup-nox
		#menu label $PUPNAME (boot to command line)
		#kernel $KERNELPATH/vmlinuz
		#append pmedia=cd pfix=nox $EXTRAARGS
		#initrd $KERNELPATH/initrd.gz
		#label macpup-noram
		#menu label $PUPNAME (don't load to RAM)
		#kernel $KERNELPATH/vmlinuz
		#append pmedia=cd pfix=noram $EXTRAARGS
		#initrd $KERNELPATH/initrd.gz
		" >> "${WORK}"/boot/isolinux/isolinux.cfg
	fi
if [ -f mandriva-boot.iso ];then
cat >> "${WORK}"/boot/isolinux/isolinux.cfg << "EOF"
label alt0
  menu label Install ^Mandriva
  kernel /boot/mandriva/alt0/vmlinuz
  append initrd=/boot/mandriva/alt0/all.rdz  vga=788 splash=silent
label alt0-vgahi
  menu label Install Mandriva (hi-res installer)
  kernel /boot/mandriva/alt0/vmlinuz
  append initrd=/boot/mandriva/alt0/all.rdz  vga=791
label alt0-text
  menu label Install Mandriva (text-mode installer)
  kernel /boot/mandriva/alt0/vmlinuz
  append initrd=/boot/mandriva/alt0/all.rdz  text
label alt1
  menu label Install Mandriva (server kernel)
  kernel /boot/mandriva/alt1/vmlinuz
  append initrd=/boot/mandriva/alt1/all.rdz vga=788 splash=silent
EOF
fi
	if [ -z "$CDLABEL" ];then
		#this should not happen
		CDLABEL=MCDtest
		echo "$0: warning: \$CDLABEL is empty."
	fi
	if [ -f mandriva.iso ];then
		BASENAME=mandriva

		echo "label $BASENAME
		menu label --> ^Mandriva$(getVersion) Menu
		com32 vesamenu.c32
		append /boot/$BASENAME/$BASENAME.cfg
		" >> "${WORK}"/boot/isolinux/isolinux.cfg

		echo "label back
		menu label --> ^Back to main menu
		com32 menu.c32
		append /boot/isolinux/isolinux.cfg
		" >> "${WORK}"/boot/$BASENAME/$BASENAME.cfg
		sed -i -e 's^menu background splash^menu background /boot/mandriva/splash^g' "${WORK}"/boot/$BASENAME/$BASENAME.cfg
		sed -i -e 's^kernel vmlinuz^kernel /boot/mandriva/vmlinuz^g' "${WORK}"/boot/$BASENAME/$BASENAME.cfg
		sed -i -e 's^initrd=initrd^initrd=/boot/mandriva/initrd^g' "${WORK}"/boot/$BASENAME/$BASENAME.cfg
		sed -i -e "s/CDLABEL=[^ ]*/CDLABEL=${CDLABEL}/g" "${WORK}"/boot/$BASENAME/$BASENAME.cfg
	fi
if [ -f mepis.iso ];then
echo "label Mepis
menu label ^mepis
com32 menu.c32
append mepis.menu" >> "${WORK}"/boot/isolinux/isolinux.cfg
echo "DEFAULT menu.c32
TIMEOUT 0
PROMPT 0
menu title Mepis Options

label  Mepis-Default
menu label ^Mepis-Default
kernel /boot/mepis/vmlinuz
append SELINUX_INIT=NO init=/etc/init quiet nosplash vga=791 aufs  initrd=/boot/mepis/initrd.gz

label  Mepis-Lite-noNet
kernel /boot/mepis/vmlinuz
append SELINUX_INIT=NO init=/etc/init quiet nosplash vga=791 aufs mean lean initrd=/boot/mepis/initrd.gz

label  Mepis-Vesa
menu label Mepis-Vesa (display problem or virtualbox)
kernel /boot/mepis/vmlinuz
append SELINUX_INIT=NO init=/etc/init vga=normal quiet nosplash drvr=vesa aufs lean initrd=/boot/mepis/initrd.gz

label  Mepis-UltraLite-Vesa
menu label Mepis-UltraLite-Vesa (Fast boot)
kernel /boot/mepis/vmlinuz
append SELINUX_INIT=NO init=/etc/init vga=normal quiet nosplash drvr=vesa aufs lean Xtralean initrd=/boot/mepis/initrd.gz

label  Mepis-Failsafe
menu label Mepis-Failsafe (minimum options, small display)
kernel /boot/mepis/vmlinuz
append SELINUX_INIT=NO init=/etc/init quiet nosplash vga=normal nosound noapic noscsi nodma noapm nousb nopcmcia nofirewire noagp nomce nodhcp nodbus nocpufreq nobluetooth drvr=fbdev aufs res=800x600v initrd=/boot/mepis/initrd.gz

label  Mepis-60Hz
menu label Mepis-60Hz (force monitor to 58-62 Hz)
kernel /boot/mepis/vmlinuz
append SELINUX_INIT=NO init=/etc/init vga=791 quiet nosplash vsync=58-62 aufs initrd=/boot/mepis/initrd.gz

label  Mepis-75Hz
menu label Mepis-75Hz (force monitor to 73-77 Hz)
kernel /boot/mepis/vmlinuz
append SELINUX_INIT=NO init=/etc/init vga=791 quiet nosplash vsync=73-77 aufs initrd=/boot/mepis/initrd.gz

label back
menu label ^Back to main menu
com32 menu.c32
append isolinux.cfg
" > "${WORK}"/boot/isolinux/mepis.menu
fi
if [ -f mintdebian.iso ];then
cat >> "${WORK}"/boot/isolinux/isolinux.cfg << EOF
label mintdebian
menu label --> Linux Mint ^Debian Edition Menu
com32 vesamenu.c32
append /boot/mintdebian/mintdebian.cfg

EOF
fi
	if [ -f netbootcd.iso ];then
		echo "INCLUDE /boot/nbcd/include.cfg" >> "${WORK}"/boot/isolinux/isolinux.cfg
	fi
if [ -f ntpasswd.iso ];then
echo "label ntpasswd
menu label ^NT Offline Password & Registry Editor
kernel /boot/ntpasswd/vmlinuz
append rw vga=1 init=/linuxrc initrd=/boot/ntpasswd/initrd.cgz,/boot/ntpasswd/scsi.cgz
" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
if [ -f opensuse-gnome.iso ];then
	if [ -f "${TAGS}"/lang-full ];then
		LANGADD="lang=$(cat "${TAGS}"/lang-full)"
	fi
	echo "label openSUSE_Live_(GNOME)
	  menu label ^openSUSE Live (GNOME)
	  kernel /boot/susegnom/linux
	  initrd /boot/susegnom/initrd
	  append ramdisk_size=512000 ramdisk_blocksize=4096 splash=silent quiet preloadlog=/dev/null showopts $LANGADD
	label linux
	  menu label Install openSUSE (GNOME)
	  kernel /boot/susegnom/linux
	  initrd /boot/susegnom/initrd
	  append ramdisk_size=512000 ramdisk_blocksize=4096 splash=silent quiet preloadlog=/dev/null liveinstall showopts $LANGADD
	" >> "${WORK}"/boot/isolinux/isolinux.cfg
	fi
if [ -f opensuse-net.iso ];then
echo "menu begin --> ^openSUSE netboot

label opensuse-kernel
  menu label Install ^openSUSE $(cat "${TAGS}"/opensuse-net.version) (from mirrors.kernel.org)
  kernel /boot/opensuse/linux
  append initrd=/boot/opensuse/initrd splash=silent showopts install=ftp://mirrors.kernel.org/opensuse/distribution/"$(cat "${TAGS}"/opensuse-net.version)"/repo/oss
label opensuse
  menu label Install openSUSE $(cat "${TAGS}"/opensuse-net.version) (specify mirror)
  kernel /boot/opensuse/linux
  append initrd=/boot/opensuse/initrd splash=silent showopts
label opensuse-repair
  menu label Repair an installed openSUSE system
  kernel /boot/opensuse/linux
  append initrd=/boot/opensuse/initrd splash=silent repair=1 showopts
label opensuse-rescue
  menu label openSUSE rescue system
  kernel /boot/opensuse/linux
  append initrd=/boot/opensuse/initrd splash=silent rescue=1 showopts
label back
  menu label ^Back to main menu
  com32 menu.c32
  append isolinux.cfg

menu end
" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
if [ -f opensuse-net64.iso ];then
echo "menu begin --> ^openSUSE netboot (x86_64)

label opensuse-kernel
  menu label Install ^openSUSE $(cat "${TAGS}"/opensuse-net.version) x86_64 (from mirrors.kernel.org)
  kernel /boot/opensuse/linux64
  append initrd=/boot/opensuse/initrd64 splash=silent showopts install=ftp://mirrors.kernel.org/opensuse/distribution/"$(cat "${TAGS}"/opensuse-net.version)"/repo/oss
label opensuse
  menu label Install openSUSE $(cat "${TAGS}"/opensuse-net.version) x86_64 (specify mirror)
  kernel /boot/opensuse/linux64
  append initrd=/boot/opensuse/initrd64 splash=silent showopts
label opensuse-repair
  menu label Repair an installed openSUSE x86_64 system
  kernel /boot/opensuse/linux64
  append initrd=/boot/opensuse/initrd64 splash=silent repair=1 showopts
label opensuse-rescue
  menu label openSUSE x86_64 rescue system
  kernel /boot/opensuse/linux64
  append initrd=/boot/opensuse/initrd64 splash=silent rescue=1 showopts
label back
  menu label ^Back to main menu
  com32 menu.c32
  append isolinux.cfg

menu end
" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
	name=""
	if [ -f ophxp.iso ] && [ ! -f ophvista.iso ];then
		name="XP"
	fi
	if [ ! -f ophxp.iso ] && [ -f ophvista.iso ];then
		name="Vista"
	fi
	if [ -f ophxp.iso ] && [ -f ophvista.iso ];then
		name="XP/Vista"
	fi

	if [ -f ophxp.iso ] || [ -f ophvista.iso ];then
		echo "label ophcrack
		menu label --> ophcrack $name
		com32 vesamenu.c32
		append ophcrack.menu" >> "${WORK}"/boot/isolinux/isolinux.cfg

		sed 's/\/boot\//\/boot\/ophcrack\//g' "${WORK}"/boot/ophcrack/ophcrack.cfg > "${WORK}"/boot/isolinux/ophcrack.menu
		
		echo "
		label back
		menu label Back to main menu
		com32 menu.c32
		append /boot/isolinux/isolinux.cfg" >> "${WORK}"/boot/isolinux/ophcrack.menu

		rm "${WORK}"/boot/ophcrack/ophcrack.cfg
	fi
#elif [ $1 = category ];then
#	echo "tools"
if [ -f pclos.iso ];then
echo "menu begin --> ^PCLinuxOS

label LiveCD
    menu label ^PCLinuxOS Live
    kernel /PCLinuxOS/isolinux/vmlinuz
    append livecd=/PCLinuxOS/livecd initrd=/PCLinuxOS/isolinux/initrd.gz root=/dev/rd/3 acpi=on vga=788 keyb=us splash=silent fstab=rw,auto noscsi
label LiveCD_sata_probe
    menu label ^PCLinuxOS Live - SATA probe
    kernel /PCLinuxOS/isolinux/vmlinuz
    append livecd=/PCLinuxOS/livecd initrd=/PCLinuxOS/isolinux/initrd.gz root=/dev/rd/3 acpi=on vga=788 keyb=us splash=silent fstab=rw,auto
label Video_SafeMode_FBDevice
    menu label ^PCLinuxOS Live - SafeMode FBDevice
    kernel /PCLinuxOS/isolinux/vmlinuz
    append livecd=/PCLinuxOS/livecd initrd=/PCLinuxOS/isolinux/initrd.gz root=/dev/rd/3 acpi=on vga=788 keyb=us splash=silent fstab=rw,auto framebuffer
label Video_SafeMode_Vesa
    menu label ^PCLinuxOS Live - SafeMode VESA
    kernel /PCLinuxOS/isolinux/vmlinuz
    append livecd=/PCLinuxOS/livecd initrd=/PCLinuxOS/isolinux/initrd.gz root=/dev/rd/3 acpi=on vga=788 keyb=us splash=silent fstab=rw,auto vesa
label Safeboot
    menu label ^PCLinuxOS Live - Safeboot
    kernel /PCLinuxOS/isolinux/vmlinuz
    append livecd=/PCLinuxOS/livecd initrd=/PCLinuxOS/isolinux/initrd.gz root=/dev/rd/3 acpi=off vga=normal keyb=us noscsi nopcmcia
label Console
    menu label ^PCLinuxOS Live - Console
    kernel /PCLinuxOS/isolinux/vmlinuz
    append livecd=/PCLinuxOS/livecd 3 initrd=/PCLinuxOS/isolinux/initrd.gz root=/dev/rd/3 acpi=on vga=788 keyb=us splash=silent fstab=rw,auto
label Copy_to_ram
    menu label ^PCLinuxOS Live - Copy to RAM
    kernel /PCLinuxOS/isolinux/vmlinuz
    append livecd=/PCLinuxOS/livecd copy2ram initrd=/PCLinuxOS/isolinux/initrd.gz root=/dev/rd/3 acpi=on vga=788 keyb=us splash=silent fstab=rw,auto splash=verbose
label back
    menu label ^Back to main menu
    com32 menu.c32
    append isolinux.cfg
menu end" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
if [ -f pclx.iso ];then
cat >> "${WORK}"/boot/isolinux/isolinux.cfg << "EOF"
label LiveCD
    menu label ^PCLinuxOS LXDE Live
    kernel /pclosLXDE/isolinux/vmlinuz
    append livecd=/pclosLXDE/livecd initrd=/pclosLXDE/isolinux/initrd.gz root=/dev/rd/3 acpi=on vga=788 keyb=us splash=silent fstab=rw,auto noscsi
label LiveCD_sata_probe
    menu label ^PCLinuxOS LXDE Live - SATA probe
    kernel /pclosLXDE/isolinux/vmlinuz
    append livecd=/pclosLXDE/livecd initrd=/pclosLXDE/isolinux/initrd.gz root=/dev/rd/3 acpi=on vga=788 keyb=us splash=silent fstab=rw,auto
label Video_SafeMode_FBDevice
    menu label ^PCLinuxOS LXDE Live - SafeMode FBDevice
    kernel /pclosLXDE/isolinux/vmlinuz
    append livecd=/pclosLXDE/livecd initrd=/pclosLXDE/isolinux/initrd.gz root=/dev/rd/3 acpi=on vga=788 keyb=us splash=silent fstab=rw,auto framebuffer
label Video_SafeMode_Vesa
    menu label ^PCLinuxOS LXDE Live - SafeMode VESA
    kernel /pclosLXDE/isolinux/vmlinuz
    append livecd=/pclosLXDE/livecd initrd=/pclosLXDE/isolinux/initrd.gz root=/dev/rd/3 acpi=on vga=788 keyb=us splash=silent fstab=rw,auto vesa
label Safeboot
    menu label ^PCLinuxOS LXDE Live - Safeboot
    kernel /pclosLXDE/isolinux/vmlinuz
    append livecd=/pclosLXDE/livecd initrd=/pclosLXDE/isolinux/initrd.gz root=/dev/rd/3 acpi=off vga=normal keyb=us noscsi nopcmcia
label Console
    menu label ^PCLinuxOS LXDE Live - Console
    kernel /pclosLXDE/isolinux/vmlinuz
    append livecd=/pclosLXDE/livecd 3 initrd=/pclosLXDE/isolinux/initrd.gz root=/dev/rd/3 acpi=on vga=788 keyb=us splash=silent fstab=rw,auto
label Copy_to_ram
    menu label ^PCLinuxOS LXDE Live - Copy to RAM
    kernel /pclosLXDE/isolinux/vmlinuz
    append livecd=/pclosLXDE/livecd copy2ram initrd=/pclosLXDE/isolinux/initrd.gz root=/dev/rd/3 acpi=on vga=788 keyb=us splash=silent fstab=rw,auto splash=verbose
EOF
fi
if [ -f pentoo.iso ];then
cat >> "${WORK}"/boot/isolinux/isolinux.cfg << EOF
label pentoo
menu label ---> ^Pentoo Menu
com32 menu.c32
append /boot/pentoo/isolinux.cfg

EOF

cat >> "${WORK}"/boot/pentoo/isolinux.cfg << EOF

label back
menu label Back to main menu
com32 menu.c32
append /boot/isolinux/isolinux.cfg

EOF

fi
if [ -f ping.iso ];then
cat >> "${WORK}"/boot/isolinux/isolinux.cfg << "EOF"
label ping
menu label ^PING (Partimage Is Not Ghost)
kernel /boot/ping/kernel
append vga=normal devfs=nomount pxe ramdisk_size=33000 load_ramdisk=1 init=/linuxrc prompt_ramdisk=0 initrd=/boot/ping/initrd.gz root=/dev/ram0 rw noapic nolapic lba combined_mode=libata ide0=noprobe nomce pci=nommconf pci=nomsi irqpoll
EOF
fi
	if [ -f pinguy.iso ];then
		BASENAME=pinguy

		echo "label pinguy
		menu label --> ^Pinguy OS$(getVersion) Menu
		com32 menu.c32
		append /boot/$BASENAME/$BASENAME.cfg
		" >> "${WORK}"/boot/isolinux/isolinux.cfg
	fi
if [ -f pmagic.iso ];then
	if [ -f "${WORK}"/boot/pmagic/pmodules/*.SQFS ];then #PDV
		cd "${WORK}"/boot/pmagic/pmodules/
		VERSION=" $(ls *.SQFS | sed -e 's/PMAGIC_//' -e 's/.SQFS//')"
	else
		VERSION=""
	fi
	echo "label pmagic
	menu label --> ^Parted Magic$VERSION
	com32 menu.c32
	append /boot/isolinux/pmagic.cfg
	" >> "${WORK}"/boot/isolinux/isolinux.cfg
	#<PDV>
	#GNU sed syntax
	sed -i -e 's/\/boot/\/boot\/pmagic/g' -e 's/\/pmagic/\/boot\/pmagic/g' -e 's/\/boot\/boot/\/boot/g' "${WORK}"/boot/isolinux/pmagic.cfg #Change directory to /boot/pmagic
	sed -i -e 's/\/boot\/pmagic\/syslinux/\/boot\/isolinux/g' "${WORK}"/boot/isolinux/pmagic.cfg #Change directory to /boot/isolinux
	sed -i -e 's/APPEND \/boot\/pmagic\/bzImage/APPEND \/boot\/pmagic\/bzImage directory=\/boot/g' "${WORK}"/boot/isolinux/pmagic.cfg #SQFS moved
	sed -i -e 's/\/boot\/isolinux\/hdt/\/boot\/pmagic\/hdt/' "${WORK}"/boot/isolinux/pmagic.cfg #Change directory to /boot/pmagic
	if [ -f "${TAGS}"/country ];then
		sed -i -e 's/APPEND \/boot\/pmagic\/bzImage\([[:print:]]*keymap\)/append \/boot\/pmagic\/bzImage\1/g' "${WORK}"/boot/isolinux/pmagic.cfg #don't change APPEND lines that already have keymap and language
		if [ -f "${TAGS}"/lang-full ]; then
			LNG=$(cat "${TAGS}"/lang-full)
		else
			LNG=""
		fi
		if [ $(cat "${TAGS}"/country) = "be" ];then
			sed -i -e 's/APPEND \/boot\/pmagic\/bzImage/APPEND \/boot\/pmagic\/bzImage keymap=be-latin1 '$LNG'/' "${WORK}"/boot/isolinux/pmagic.cfg #set keymap and language
		fi
		sed -i -e 's/append \/boot\/pmagic\/bzImage\([[:print:]]*keymap\)/APPEND \/boot\/pmagic\/bzImage\1/g' "${WORK}"/boot/isolinux/pmagic.cfg #revert changes
	fi
	if $MEMTEST;then
		sed -i -e '/LABEL memtest/,/^$/d' "${WORK}"/boot/isolinux/pmagic.cfg #remove memtest if already in main menu
	else
		sed -i -e 's/\/boot\/isolinux\/memtest/\/boot\/pmagic\/memtest/g' "${WORK}"/boot/isolinux/pmagic.cfg #Change directory to /boot/pmagic
	fi
	#</PDV>
	echo "
MENU SEPARATOR

label back
menu label Back to main menu
com32 menu.c32
append /boot/isolinux/isolinux.cfg" >> "${WORK}"/boot/isolinux/pmagic.cfg
fi
	if [ -f porteus.iso ];then
		if [ -f "${WORK}"/porteus/base/002-xorg.xzm ];then
			if [ -f porteus.version ] && [ "$(cat porteus.version)" != "" ];then
				PORTEUSVER=" $(cat porteus.version)"
			else
				PORTEUSVER=""
			fi
			echo "LABEL p-xconf
			MENU LABEL ^Porteus$PORTEUSVER Graphics mode (KDE).
			KERNEL /boot/porteus/vmlinuz
			APPEND initrd=/boot/porteus/initrd.xz vga=791 splash=silent quiet autoexec=xconf;telinit~4 changes=/porteus/
			TEXT HELP
			    Run Porteus the best way we can.
			    Try to autoconfigure graphics
			    card and use the maximum
			    allowed resolution
			ENDTEXT

			LABEL p-lxde
			MENU LABEL Porteus$PORTEUSVER Graphics mode (LXDE).
			KERNEL /boot/porteus/vmlinuz
			APPEND initrd=/boot/porteus/initrd.xz vga=791 splash=silent quiet autoexec=lxde;xconf;telinit~4 changes=/porteus/
			TEXT HELP
			    Run Porteus the same as above.
			    Lightweight LXDE to be
			    launched as default desktop
			ENDTEXT

			LABEL p-fresh
			MENU LABEL Porteus$PORTEUSVER Always Fresh
			KERNEL /boot/porteus/vmlinuz
			APPEND initrd=/boot/porteus/initrd.xz autoexec=xconf;telinit~4
			TEXT HELP
			    Normally Porteus saves all changes
			    to the /porteus/changes/ directory
			    on the boot media (if writable)
			    and restores them next boot.
			    Use this option to start a fresh
			    system, no changes are neither
			    read nor written anywhere
			ENDTEXT

			LABEL p-cp2ram
			MENU LABEL Porteus$PORTEUSVER Copy To RAM
			KERNEL /boot/porteus/vmlinuz
			APPEND initrd=/boot/porteus/initrd.xz vga=791 splash=silent quiet copy2ram autoexec=xconf;telinit~4
			TEXT HELP
			    Run Porteus the same as above,
			    but first copy all data to RAM
			    to get huge speed (needs >300MB)
			ENDTEXT

			LABEL p-startx
			MENU LABEL Porteus$PORTEUSVER Graphics VESA mode
			KERNEL /boot/porteus/vmlinuz
			APPEND initrd=/boot/porteus/initrd.xz autoexec=telinit~4 changes=/poreus/
			TEXT HELP
			    Run Porteus with KDE, but skip
			    gfx-card config. Force 1024x768
			    using standard VESA driver
			ENDTEXT

			LABEL p-text
			MENU LABEL Porteus$PORTEUSVER Text mode
			KERNEL /boot/porteus/vmlinuz
			APPEND initrd=/boot/initrd.xz
			TEXT HELP
			    Run Porteus in textmode and start
			    command prompt only
			ENDTEXT

			LABEL p-pxe
			MENU LABEL Porteus$PORTEUSVER Porteus as PXE server
			KERNEL /boot/porteus/vmlinuz
			APPEND initrd=/boot/porteus/initrd.xz autoexec=pxe-boot;xconf;telinit~4
			TEXT HELP
			    Run Porteus as usual, but also
			    initialize PXE server.
			    This will allow you to boot Porteus
			    on other computers over network
			ENDTEXT

			LABEL p-plop
			MENU LABEL PLoP BootManager
			KERNEL /boot/porteus/plpbt
			TEXT HELP
			    Run the plop boot manager.
			    This utility provides handy boot-USB options for
			    machines with vintage/defective BIOS
			ENDTEXT" >> "${WORK}"/boot/isolinux/isolinux.cfg
		else
			echo "LABEL p-text
			MENU LABEL Porteus$PORTEUSVER Text mode
			KERNEL /boot/porteus/vmlinuz
			APPEND initrd=/boot/initrd.xz
			TEXT HELP
			    Run Porteus in textmode and start
			    command prompt only
			ENDTEXT
			
			LABEL p-cp2ram
			MENU LABEL Porteus$PORTEUSVER Text mode
			KERNEL /boot/porteus/vmlinuz
			APPEND initrd=/boot/initrd.xz copy2ram
			TEXT HELP
			    Run Porteus the same as above,
			    but first copy all data to RAM
			    to get huge speed
			ENDTEXT" >> "${WORK}"/boot/isolinux/isolinux.cfg
		fi
	fi
#BEGIN PUPPY ENTRY#
	if $(puppyExists);then for i in *.puppy.iso;do
		BASENAME=$(echo $i|sed -e 's/\.puppy\.iso//g')
		if [ -f "${TAGS}"/puppy.name ] && [ "$(cat "${TAGS}"/puppy.name)" != "" ];then
			PUPNAME=$(cat "${TAGS}"/puppy.name) #User-entered name
		elif [ -f puppy.defaultname ] && [ "$(cat puppy.defaultname)" != "" ];then
			PUPNAME=$(cat puppy.defaultname) #Default name based on the automatic links made in isoaliases()
		else
			PUPNAME="Puppy Linux $BASENAME" #Fallback name
		fi
		if [ -f puppy.version ] && [ "$(cat puppy.version)" != "" ];then
			PUPNAME="$PUPNAME $(cat puppy.version)" #Version based on isoaliases()
		fi
		if [ -d "${WORK}"/$BASENAME ];then
			EXTRAARGS="psubdir=$BASENAME"
			KERNELPATH="/$BASENAME"
		else
			EXTRAARGS=""
			KERNELPATH=""
		fi
		echo "label puppy
		menu label ^$PUPNAME
		kernel $KERNELPATH/vmlinuz
		append pmedia=cd $EXTRAARGS
		initrd $KERNELPATH/initrd.gz
#		label puppy-nox
#		menu label $PUPNAME (boot to command line)
#		kernel $KERNELPATH/vmlinuz
#		append pmedia=cd pfix=nox $EXTRAARGS
#		initrd $KERNELPATH/initrd.gz
#		label puppy-noram
#		menu label $PUPNAME (don't load to RAM)
#		kernel $KERNELPATH/vmlinuz
#		append pmedia=cd pfix=noram $EXTRAARGS
#		initrd $KERNELPATH/initrd.gz
		" >> "${WORK}"/boot/isolinux/isolinux.cfg
	done;fi
#END PUPPY ENTRY#
#BEGIN PUPPY2 ENTRY#
if [ -f puppy2.iso ];then
if [ -f "${TAGS}"/puppy2.name ] && [ "$(cat "${TAGS}"/puppy2.name)" != "" ];then
	PUPNAME=$(cat "${TAGS}"/puppy2.name)
elif [ -f puppy2.defaultname ] && [ "$(cat puppy2.defaultname)" != "" ];then
	PUPNAME=$(cat puppy2.defaultname)
else
	PUPNAME="Puppy Linux #2"
fi
if [ -d "${WORK}"/puppy2 ];then
	EXTRAARGS="psubdir=puppy2"
	KERNELPATH="/puppy2"
else
	EXTRAARGS=""
	KERNELPATH=""
fi
echo "label puppy2
menu label ^$PUPNAME
kernel $KERNELPATH/vmlinuz
append pmedia=cd $EXTRAARGS
initrd $KERNELPATH/initrd.gz
#label puppy2-nox
#menu label $PUPNAME (boot to command line)
#kernel $KERNELPATH/vmlinuz
#append pmedia=cd pfix=nox $EXTRAARGS
#initrd $KERNELPATH/initrd.gz
#label puppy2-noram
#menu label $PUPNAME (don't load to RAM)
#kernel $KERNELPATH/vmlinuz
#append pmedia=cd pfix=noram $EXTRAARGS
#initrd $KERNELPATH/initrd.gz
" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
#END PUPPY2 ENTRY#
	if [ -f redobackup.iso ];then
		BASENAME=redobackup

		echo "label redobackup
		menu label --> ^Redo Backup$(getVersion) Menu
		com32 vesamenu.c32
		append /boot/$BASENAME/$BASENAME.cfg
		" >> "${WORK}"/boot/isolinux/isolinux.cfg
	fi
	if [ -f rescatux.iso ];then
		echo "label rescatux
		menu label >> ^Rescatux
		com32 menu.c32
		append rescatux.cfg" >> "${WORK}"/boot/isolinux/isolinux.cfg
		sed -i -e 's^/live/^/rescatux/^g' "${WORK}"/boot/isolinux/rescatux.cfg
		sed -i -e 's^boot=live^boot=live live-media-path=/rescatux^g' "${WORK}"/boot/isolinux/rescatux.cfg
		echo "label back
		menu label Back to main menu
		com32 menu.c32
		append /boot/isolinux/isolinux.cfg
		" >> "${WORK}"/boot/isolinux/rescatux.cfg
	fi
	if [ -f riplinux.iso ];then
		echo "label riplinux
		menu label ^RIPLinuX
		com32 menu.c32
		append riplinux.cfg
		" >> "${WORK}"/boot/isolinux/isolinux.cfg
		echo "label back
		menu label Back to main menu
		com32 menu.c32
		append isolinux.cfg
		" >> "${WORK}"/boot/isolinux/riplinux.cfg
	fi
	if [ -f sabayon.iso ];then
		echo "label sabayon
		menu label --> ^Sabayon Linux$(getVersion) Menu
		com32 menu.c32
		append /boot/sabayon/sabayon.cfg
		" >> "${WORK}"/boot/isolinux/isolinux.cfg
		sed -i -e 's@default sabayon@default menu\.c32@g' "${WORK}"/boot/sabayon/sabayon.cfg
		sed -i -e 's@/boot/sabayon@/boot/sabayon/sabayon@g' "${WORK}"/boot/sabayon/sabayon.cfg
		sed -i -e 's@/livecd.squashfs@/boot/sabayon/livecd.squashfs@g' "${WORK}"/boot/sabayon/sabayon.cfg
		sed -i -e 's@cdroot_type=udf@cdroot_type=iso9660@g' "${WORK}"/boot/sabayon/sabayon.cfg #MultiCD doesn't use UDF, so this needs to be changed
		echo "label back
		menu label ^Back to main menu
		com32 menu.c32
		append /boot/isolinux/isolinux.cfg
		" >> "${WORK}"/boot/sabayon/sabayon.cfg
	fi
	if [ -f scientific-boot.iso ];then
		if [ -f scientific-boot.version ] && [ "$(cat scientific-boot.version)" != "" ];then
			VERSION=" $(cat scientific-boot.version)" #Version based on isoaliases()
		fi
		echo "label scilinux-mirror
		menu label ^Install Scientific Linux from UW-Madison's mirror (assuming SciLinux 6)
		kernel /boot/sci/vmlinuz
		append initrd=/boot/sci/initrd.img method=http://mirror.cs.wisc.edu/pub/mirrors/linux/scientificlinux.org/6/i386/os/
		text help
		Scientific Linux version: $VERSION
		endtext

		label scilinux
		menu label ^Install or upgrade Scientific Linux (enter mirror manually)
		kernel /boot/sci/vmlinuz
		append initrd=/boot/sci/initrd.img
		label scivesa
		menu label Install system with ^basic video driver
		kernel /boot/sci/vmlinuz
		append initrd=/boot/sci/initrd.img xdriver=vesa nomodeset
		label scirescue
		menu label ^Rescue installed system
		kernel /boot/sci/vmlinuz
		append initrd=/boot/sci/initrd.img rescue" >> "${WORK}"/boot/isolinux/isolinux.cfg
	fi
#BEGIN SLAX ENTRY#
if [ -f slax.iso ];then
	if [ -f "${MNT}"/slax/boot/initrd.lz ];then
		SUFFIX=lz
	else
		SUFFIX=gz
	fi
	if [ -f slax.version ] && [ "$(cat slax.version)" != "" ];then
		SLAXVER=" $(cat slax.version)"
	else
		SLAXVER=""
	fi
	if [ -f "${WORK}"/slax/base/002-xorg.lzm ];then
		echo "LABEL xconf
		MENU LABEL ^Slax$SLAXVER Graphics mode (KDE)
		KERNEL /boot/slax/vmlinuz
		APPEND initrd=/boot/slax/initrd.$SUFFIX ramdisk_size=6666 root=/dev/ram0 rw vga=791 splash=silent quiet autoexec=xconf;telinit~4  changes=/slax/

		LABEL lxde
		MENU LABEL Slax$SLAXVER (LXDE) (if available)
		KERNEL /boot/slax/vmlinuz
		APPEND initrd=/boot/slax/initrd.$SUFFIX ramdisk_size=6666 root=/dev/ram0 rw vga=791 splash=silent quiet autoexec=lxde;xconf;telinit~4 changes=/slax/

		LABEL copy2ram
		MENU LABEL Slax$SLAXVER Graphics mode, Copy To RAM
		KERNEL /boot/slax/vmlinuz
		APPEND initrd=/boot/slax/initrd.$SUFFIX ramdisk_size=6666 root=/dev/ram0 rw vga=791 splash=silent quiet copy2ram autoexec=xconf;telinit~4

		LABEL startx
		MENU LABEL Slax$SLAXVER Graphics VESA mode
		KERNEL /boot/slax/vmlinuz
		APPEND initrd=/boot/slax/initrd.$SUFFIX ramdisk_size=6666 root=/dev/ram0 rw autoexec=telinit~4  changes=/slax/

		LABEL slax
		MENU LABEL Slax$SLAXVER Text mode
		KERNEL /boot/slax/vmlinuz
		APPEND initrd=/boot/slax/initrd.$SUFFIX ramdisk_size=6666 root=/dev/ram0 rw  changes=/slax/" >> "${WORK}"/boot/isolinux/isolinux.cfg
	else
		echo "LABEL slax
		MENU LABEL ^Slax$SLAXVER Text mode
		KERNEL /boot/slax/vmlinuz
		APPEND initrd=/boot/slax/initrd.$SUFFIX ramdisk_size=6666 root=/dev/ram0 rw  changes=/slax/

		LABEL slax2ram
		MENU LABEL Slax$SLAXVER Text mode, Copy To RAM
		KERNEL /boot/slax/vmlinuz
		APPEND initrd=/boot/slax/initrd.$SUFFIX ramdisk_size=6666 root=/dev/ram0 rw copy2ram" >> "${WORK}"/boot/isolinux/isolinux.cfg
	fi
fi
#END SLAX ENTRY#
if [ -f slitaz.iso ];then
cat >> "${WORK}"/boot/isolinux/isolinux.cfg << "EOF"
menu begin --> SliTaz GNU/Linux

label core
	menu label SliTaz core Live
	kernel /boot/slitaz/bzImage
	append initrd=/boot/slitaz/rootfs4.gz,/boot/slitaz/rootfs3.gz,/boot/slitaz/rootfs2.gz,/boot/slitaz/rootfs1.gz rw root=/dev/null vga=normal autologin

label gtkonly
	menu label SliTaz gtkonly Live
	kernel /boot/slitaz/bzImage
	append initrd=/boot/slitaz/rootfs4.gz,/boot/slitaz/rootfs3.gz,/boot/slitaz/rootfs2.gz rw root=/dev/null vga=normal autologin

label justx
	menu label SliTaz justx Live
	kernel /boot/slitaz/bzImage
	append initrd=/boot/slitaz/rootfs4.gz,/boot/slitaz/rootfs3.gz rw root=/dev/null vga=normal autologin

label base
	menu label SliTaz base Live
	kernel /boot/slitaz/bzImage
	append initrd=/boot/slitaz/rootfs4.gz rw root=/dev/null vga=normal autologin

label web zeb
	menu label Web Boot
	kernel /boot/slitaz/gpxe

label back
	menu label Back to main menu
	com32 menu.c32

menu end
EOF
fi
if [ -f sysrcd.iso ];then
#<PDV>
VERSION=$(cat "${WORK}"/boot/sysrcd/version)
echo "label sysrcd
menu label --> ^SystemRescueCd $VERSION
com32 vesamenu.c32
append sysrcd.cfg
" >> "${WORK}"/boot/isolinux/isolinux.cfg
#GNU sed syntax
sed -i -e 's/LINUX /LINUX \/boot\/sysrcd\//g' -e 's/INITRD /INITRD \/boot\/sysrcd\//g' -e 's/\/bootdisk/\/boot\/sysrcd\/bootdisk/g' -e 's/\/ntpasswd/\/boot\/sysrcd\/ntpasswd/g' "${WORK}"/boot/isolinux/sysrcd.cfg #PDV Change directory to /boot/sysrcd
sed -i -e 's/APPEND maps/append maps/g' "${WORK}"/boot/isolinux/sysrcd.cfg #PDV don't change APPEND maps lines
sed -i -e 's/APPEND rescue64.*rescue32/APPEND initrd=\/boot\/sysrcd\/initram.igz/g' -e 's/ifcpu64.c32/\/boot\/sysrcd\/rescue32/g' "${WORK}"/boot/isolinux/sysrcd.cfg # Remove ifcpu64.c32; just use 32-bit kernel by default
sed -i -e 's/APPEND/APPEND subdir=\/boot\/sysrcd/g' "${WORK}"/boot/isolinux/sysrcd.cfg #PDV Tell the kernel we moved it
if [ -f "${TAGS}"/country ];then #PDV
	sed -i -e 's/APPEND\([[:print:]]*setkmap\)/append\1/g' "${WORK}"/boot/isolinux/sysrcd.cfg #don't change APPEND lines with setkmap
	sed -i -e 's/APPEND/APPEND setkmap='$(cat "${TAGS}"/country)'/g' "${WORK}"/boot/isolinux/sysrcd.cfg #add setkmap=[language]
	sed -i -e 's/append\([[:print:]]*setkmap\)/APPEND\1/g' -e 's/append maps/APPEND maps/g' "${WORK}"/boot/isolinux/sysrcd.cfg #revert changes
fi
sed -i -e '/LABEL local2/,/^$/d' "${WORK}"/boot/isolinux/sysrcd.cfg #PDV remove Boot from second hard disk entry to avoid scrolling
if $MEMTEST; then #PDV remove memtest if already in main menu
	sed -i -e '/LABEL memtest/,/^$/d' "${WORK}"/boot/isolinux/sysrcd.cfg
	rm "${WORK}"/boot/sysrcd/bootdisk/memtestp
fi
echo "label back
menu label Back to main menu
com32 menu.c32
append isolinux.cfg" >> "${WORK}"/boot/isolinux/sysrcd.cfg
#</PDV>
fi
	if [ -f tc+nb.iso ];then
		echo "LABEL tc+nb
		MENU LABEL ^NetbootCD (tc+nb.iso)
		KERNEL /boot/tc+nb/kexec.bzI
		initrd /boot/tc+nb/nbinit.gz
		APPEND quiet
		" >> "${WORK}"/boot/isolinux/isolinux.cfg
		if [ -f "${WORK}"/boot/tc+nb/tinycore.gz ];then
			echo "LABEL tc+nb-tinycore
			MENU LABEL ^Tiny Core Linux (tc+nb.iso)
			KERNEL /boot/tc+nb/kexec.bzI
			INITRD /boot/tc+nb/tinycore.gz
			APPEND quiet
			" >> "${WORK}"/boot/isolinux/isolinux.cfg
		fi
		if [ -f "${WORK}"/boot/tc+nb/grub.exe ];then
			echo "LABEL tc+nb-grub
			MENU LABEL ^GRUB4DOS (tc+nb.iso)
			KERNEL /boot/tc+nb/grub.exe
			" >> "${WORK}"/boot/isolinux/isolinux.cfg
		fi
	fi
#BEGIN TINY CORE ENTRY#
if [ -f tinycore.iso ];then
	if [ -f "${TAGS}"/tinycore.name ] && [ "$(cat "${TAGS}"/tinycore.name)" != "" ];then
		TCNAME=$(cat "${TAGS}"/tinycore.name)
	elif [ -f tinycore.defaultname ] && [ "$(cat tinycore.defaultname)" != "" ];then
		TCNAME=$(cat tinycore.defaultname)
	else
		TCNAME="Tiny Core Linux"
	fi
	if [ -f tinycore.version ] && [ "$(cat tinycore.version)" != "" ];then
		TCNAME="$TCNAME $(cat tinycore.version)"
	fi
	for i in $(ls "${WORK}"/boot/tinycore|grep '\.gz');do
		echo "label tinycore-$i
		menu label ^$TCNAME ($(basename $i))
		kernel /boot/tinycore/vmlinuz
		append quiet cde showapps
		initrd /boot/tinycore/$(basename $i)">>"${WORK}"/boot/isolinux/isolinux.cfg
	done
fi
#END TINY CORE ENTRY#
if [ -f tinyme.iso ];then
cat >> "${WORK}"/boot/isolinux/isolinux.cfg << "EOF"
label LiveCD
    menu label ^TinyMe - LiveCD
    kernel /boot/tinyme/vmlinuz
    append livecd=livecd initrd=/boot/tinyme/initrd.gz root=/dev/rd/3 acpi=on vga=788 keyb=us splash=silent fstab=rw,noauto
label VideoSafeModeFBDev
    menu label TinyMe - VideoSafeModeFBDev
    kernel /boot/tinyme/vmlinuz
    append livecd=livecd initrd=/boot/tinyme/initrd.gz root=/dev/rd/3 acpi=on vga=788 keyb=us splash=silent fstab=rw,noauto framebuffer
label VideoSafeModeVesa
    menu label TinyMe - VideoSafeModeVesa
    kernel /boot/tinyme/vmlinuz
    append livecd=livecd initrd=/boot/tinyme/initrd.gz root=/dev/rd/3 acpi=on vga=788 keyb=us splash=silent fstab=rw,noauto vesa
label Safeboot
    menu label TinyMe - Safeboot
    kernel /boot/tinyme/vmlinuz
    append livecd=livecd initrd=/boot/tinyme/initrd.gz root=/dev/rd/3 acpi=off vga=normal keyb=us noapic nolapic noscsi nopcmcia
label Console
    menu label TinyMe - Console
    kernel /boot/tinyme/vmlinuz
    append livecd=livecd 3 initrd=/boot/tinyme/initrd.gz root=/dev/rd/3 acpi=on vga=788 keyb=us splash=silent fstab=rw,noauto
label Copy2ram
    menu label TinyMe - Copy2ram
    kernel /boot/tinyme/vmlinuz
    append livecd=livecd copy2ram initrd=/boot/tinyme/initrd.gz root=/dev/rd/3 acpi=on vga=788 keyb=us splash=silent fstab=rw,noauto splash=verbose
EOF
fi
if [ -f trk.iso ];then
echo "label trk
menu label --> ^Trinity Rescue Kit
com32 vesamenu.c32
append trk.menu
" >> "${WORK}"/boot/isolinux/isolinux.cfg
#REQUIRES GNU sed to work (usage of -i option.)
sed -i -e 's^bootlogo.jpg^trklogo.jpg^g' "${WORK}"/boot/isolinux/trk.menu
sed -i -e 's^kernel kernel.trk^kernel /boot/trinity/kernel.trk^g' "${WORK}"/boot/isolinux/trk.menu
sed -i -e "s^initrd=initrd.trk^initrd=/boot/trinity/initrd.trk vollabel=$CDLABEL^g" "${WORK}"/boot/isolinux/trk.menu #This line both changes the initrd path and adds the volume label argument ($CDLABEL is set [exported] in multicd.sh)
sed -i '/^label t$/d' "${WORK}"/boot/isolinux/trk.menu #Remove memtest part1
sed -i '/Memory tester/d' "${WORK}"/boot/isolinux/trk.menu #Remove memtest part2
sed -i '/memtest/d' "${WORK}"/boot/isolinux/trk.menu #Remove memtest part3
echo "
label back
menu label ^Back to main menu
com32 menu.c32
append isolinux.cfg" >> "${WORK}"/boot/isolinux/trk.menu
fi
if [ -f ubcd.iso ];then
	VERSION=$(cat "${TAGS}"/ubcdver.tmp.txt)
	rm "${TAGS}"/ubcdver.tmp.txt
	if [ -d "${WORK}"/ubcd/menus/isolinux ];then
		MENUFOLDER=isolinux #older versions
	else
		MENUFOLDER=syslinux #v5.1
	fi
	echo "label ubcd
	menu label --> ^Ultimate Boot CD ($VERSION) - Main menu
	com32 menu.c32
	append /ubcd/menus/${MENUFOLDER}/main.cfg" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
if [ -f ubuntu-alternate.iso ] && [ ! -f "${TAGS}"/ubuntu-not-copied ];then
cd "$WORK"
PRESEED=$(echo preseed/*ubuntu*|awk '{print $1}')
cd -
if [ -f "${WORK}"/README.diskdefines ];then
	CDNAME="$(grep DISKNAME "${WORK}"/README.diskdefines|awk '{for (i=3; i<NF+1; i++) { printf $i; printf " " } printf "\n" }')"
else
	CDNAME="Ubuntu alternate installer"
fi
echo "menu begin --> ^$CDNAME

label install
  menu label ^Install Ubuntu
  kernel /install/vmlinuz
  append  file=/cdrom/$PRESEED vga=788 initrd=/install/initrd.gz quiet --

label expert
  menu label ^Expert install
  kernel /install/vmlinuz
  append  file=/cdrom/$PRESEED priority=low vga=788 initrd=/install/initrd.gz --
label rescue
  menu label ^Rescue a broken system
  kernel /install/vmlinuz
  append  rescue/enable=true vga=788 initrd=/install/initrd.gz --

menu end" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
if [ -f ubuntu-mini.iso ];then
	echo "LABEL uinstall
	menu label Install ^Ubuntu
		kernel /boot/ubuntu/linux
		append vga=normal initrd=/boot/ubuntu/initrd.gz -- 
	LABEL ucli
	menu label Install Ubuntu (CLI)
		kernel /boot/ubuntu/linux
		append tasks=standard pkgsel/language-pack-patterns= pkgsel/install-language-support=false vga=normal initrd=/boot/ubuntu/initrd.gz -- 

	LABEL uexpert
	menu label Install Ubuntu - expert mode
		kernel /boot/ubuntu/linux
		append priority=low vga=normal initrd=/boot/ubuntu/initrd.gz -- 
	LABEL ucli-expert
	menu label Install Ubuntu (CLI) - expert mode
		kernel /boot/ubuntu/linux
		append tasks=standard pkgsel/language-pack-patterns= pkgsel/install-language-support=false priority=low vga=normal initrd=/boot/ubuntu/initrd.gz -- 
	" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
	if $(ubuntuExists);then
		for i in *.ubuntu.iso; do
			BASENAME=$(echo $i|sed -e 's/\.iso//g')
			UBUNAME=$(getUbuntuName)

			echo "label $BASENAME
			menu label --> $UBUNAME Menu
			com32 menu.c32
			append /boot/$BASENAME/$BASENAME.cfg
			" >> "${WORK}"/boot/isolinux/isolinux.cfg
		done
	fi
if [ -f vyatta.iso ];then
cat >> "${WORK}"/boot/isolinux/isolinux.cfg << "EOF"
label vyatta-live
	menu label ^Vyatta - Live
	kernel /Vyatta/vmlinuz1
	append console=ttyS0 console=tty0 quiet initrd=/Vyatta/initrd1.img boot=live nopersistent noautologin nonetworking nouser hostname=vyatta live-media-path=/Vyatta
label vyatta-console
	menu label ^Vyatta - VGA Console
	kernel /Vyatta/vmlinuz1
	append quiet initrd=/Vyatta/initrd1.img boot=live nopersistent noautologin nonetworking nouser hostname=vyatta live-media-path=/Vyatta
label vyatta-serial
	menu label ^Vyatta - Serial Console
	kernel /Vyatta/vmlinuz1
	append console=ttyS0 quiet initrd=/Vyatta/initrd1.img boot=live nopersistent noautologin nonetworking nouser hostname=vyatta live-media-path=/Vyatta
label vyatta-debug
	menu label ^Vyatta - Debug
	kernel /Vyatta/vmlinuz1
	append console=ttyS0 console=tty0 debug verbose initrd=/Vyatta/initrd1.img boot=live nopersistent noautologin nonetworking nouser hostname=vyatta  live-media-path=/Vyatta
EOF
fi
if [ -f weaknet.iso ];then
	if [ -f weaknet.defaultname ] && [ "$(cat weaknet.defaultname)" != "" ];then
		WKNAME=$(cat weaknet.defaultname)
	else
		WKNAME="WeakNet Linux"
	fi

	echo "label
	menu label --> $WKNAME Menu
	com32 vesamenu.c32
	append /boot/weaknet/weaknet.cfg
	" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
if [ -f win7recovery.iso ];then
	if which isoinfo &> /dev/null;then
		if isoinfo -d -i win7recovery.iso;then
			TYPE=" 64-bit"
		else
			TYPE=" 32-bit"
		fi
	else
		TYPE=""
	fi
	echo "label win7recovery
	menu label Windows ^7$TYPE Recovery Disc (direct from CD)
	kernel chain.c32
	append boot ntldr=/bootmgr">>"${WORK}"/boot/isolinux/isolinux.cfg
fi
if [ -f win98se.iso ];then
echo "label win98se
menu label ^Windows 98 Second Edition Setup
kernel memdisk
initrd /boot/win98se.img">>"${WORK}"/boot/isolinux/isolinux.cfg
fi
if [ -f winme.iso ];then
echo "label winme
menu label ^Windows Me Setup
kernel memdisk
initrd /boot/winme.img">>"${WORK}"/boot/isolinux/isolinux.cfg
fi
if [ -f wolvix.iso ];then
	if [ -f "${WORK}"/boot/wolvix/vmlinuz ];then
		KERNELPATH="/boot/wolvix"
	else
		KERNELPATH="/boot"
	fi
	echo "label wolvix
	menu label ^Wolvix GNU/Linux (login as root, password is toor)
	kernel $KERNELPATH/vmlinuz
	append changes=wolvixsave.xfs max_loop=255 initrd=$KERNELPATH/initrd.gz ramdisk_size=6666 root=/dev/ram0 rw vga=791 splash=silent
	" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
if [ -f xbmc.iso ];then
	VERSION=$(getVersion xbmc)
	echo "menu begin >> ^XBMC$VERSION

	label XBMCLive
	menu label ^XBMC Live
	kernel /boot/xbmc/vmlinuz
	initrd /boot/xbmc/initrd.img
	append video=vesafb boot=live xbmc=autostart,nodiskmount splash quiet loglevel=0 persistent quickreboot quickusbmodules notimezone noaccessibility noapparmor noaptcdrom noautologin noxautologin noconsolekeyboard nofastboot nognomepanel nohosts nokpersonalizer nolanguageselector nolocales nonetworking nopowermanagement noprogramcrashes nojockey nosudo noupdatenotifier nouser nopolkitconf noxautoconfig noxscreensaver nopreseed union=aufs live-media-path=/boot/xbmc

	label XBMCLiveSafeMode
	menu label XBMC Live (^Safe Mode)
	kernel /boot/xbmc/vmlinuz
	initrd /boot/xbmc/initrd.img
	append boot=live xbmc=nodiskmount quiet loglevel=0 persistent quickreboot quickusbmodules notimezone noaccessibility noapparmor noaptcdrom noautologin noxautologin noconsolekeyboard nofastboot nognomepanel nohosts nokpersonalizer nolanguageselector nolocales nonetworking nopowermanagement noprogramcrashes nojockey nosudo noupdatenotifier nouser nopolkitconf noxautoconfig noxscreensaver nopreseed union=aufs live-media-path=/boot/xbmc

	menu end" >> "${WORK}"/boot/isolinux/isolinux.cfg
fi
	if [ -f zorin.iso ];then
		BASENAME=zorin

		echo "label zorin
		menu label --> ^Zorin OS$(getVersion) Menu
		com32 vesamenu.c32
		append /boot/$BASENAME/$BASENAME.cfg
		" >> "${WORK}"/boot/isolinux/isolinux.cfg
	fi
#END WRITE

#BEGIN DISK IMAGE ENTRY#
j="0"
for i in *.im[agz]; do
	test -r "$i" || continue
	BASICNAME=$(echo $i|sed 's/\.im.//')
	echo label "$BASICNAME" >> "${WORK}"/boot/isolinux/isolinux.cfg
	echo kernel memdisk >> "${WORK}"/boot/isolinux/isolinux.cfg
	echo initrd /boot/$j.img >> "${WORK}"/boot/isolinux/isolinux.cfg
	j=$( expr $j + 1 )
done
#END DISK IMAGE ENTRY#

#BEGIN GRUB4DOS ENTRY#
if [ -f "${WORK}"/boot/grub.exe ];then
echo "label grub4dos
menu label ^GRUB4DOS
kernel /boot/grub.exe">>"${WORK}"/boot/isolinux/isolinux.cfg
elif [ -f "${WORK}"/boot/riplinux/grub4dos/grub.exe ];then
echo "label grub4dos
menu label ^GRUB4DOS
kernel /boot/riplinux/grub4dos/grub.exe">>"${WORK}"/boot/isolinux/isolinux.cfg
fi
#END GRUB4DOS ENTRY#

#BEGIN GAMES ENTRY#
if [ $GAMES = 1 ];then
echo "label games
menu label ^Games on disk images
com32 menu.c32
append games.cfg">>"${WORK}"/boot/isolinux/isolinux.cfg
fi
#END GAMES ENTRY#

#BEGIN MEMTEST ENTRY#
if [ -f "${WORK}"/boot/memtest ];then
echo "label memtest
menu label ^Memtest86+ $(cat memtestver)
kernel /boot/memtest">>"${WORK}"/boot/isolinux/isolinux.cfg
fi
#END MEMTEST ENTRY#
##END ISOLINUX MENU CODE##

if [ $GAMES = 1 ];then
k="0"
cat > "${WORK}"/boot/isolinux/games.cfg << "EOF"
default menu.c32
timeout 300

menu title "Choose a game to play:"
EOF
for i in games/*.im[agz]; do
	test -r "$i" || continue
	BASICNAME=$(echo $i|sed 's/\.im.//'|sed 's/games\///')
	echo label "$BASICNAME" >> "${WORK}"/boot/isolinux/games.cfg
	echo kernel memdisk >> "${WORK}"/boot/isolinux/games.cfg
	echo initrd /boot/games/$k.img >> "${WORK}"/boot/isolinux/games.cfg
	k=$( expr $k + 1 )
done
echo "label back
menu label Back to main menu
com32 menu.c32
append isolinux.cfg">>"${WORK}"/boot/isolinux/games.cfg
fi

if [ -d includes ] && [ "$(echo empty/.* empty/*)" != 'empty/. empty/.. empty/*' ] ;then
 echo "Copying includes..."
 cp -r includes/* "${WORK}"/
fi

if $DEBUG;then
	chmod -R a+w "${WORK}"/boot/isolinux #So regular users can edit menus
	echo "    Dropping to $(whoami) prompt. Type \"exit\" to build the ISO image."
	echo "    Don't do anything hasty."
	echo "PS1=\"    mcd debug# \"">/tmp/mcdprompt
	bash --rcfile /tmp/mcdprompt
	rm /tmp/mcdprompt || true
fi

if $MD5;then
	echo "Generating MD5 checksums..."
	if which md5sum &> /dev/null;then
		MD5SUM=md5sum
	else
		MD5SUM=md5
	fi
	if $VERBOSE;then
		find "${WORK}"/ -type f -not -name md5sum.txt -not -name boot.cat -not -name isolinux.bin \
		-exec $MD5SUM '{}' \; | sed "s^"${WORK}"^^g" | tee "${WORK}"/md5sum.txt
	else
		find "${WORK}"/ -type f -not -name md5sum.txt -not -name boot.cat -not -name isolinux.bin\
		-exec $MD5SUM '{}' \; | sed "s^"${WORK}"^^g" > "${WORK}"/md5sum.txt
	fi
fi

if which genisoimage > /dev/null;then
 GENERATOR="genisoimage"
elif which mkisofs > /dev/null;then
 GENERATOR="mkisofs"
else
 echo "Neither genisoimage nor mkisofs was found."
 exit 1
fi
EXTRAARGS=""
if ! $VERBOSE;then
	EXTRAARGS="$EXTRAARGS -quiet"
fi
if [ ! -f "${TAGS}"/win9x ];then
	EXTRAARGS="$EXTRAARGS -iso-level 4" #To ensure that Windows 9x installation CDs boot properly
fi
echo "Building CD image..."
$GENERATOR -o ""${OUTPUT}"" \
-b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat \
-no-emul-boot -boot-load-size 4 -boot-info-table \
-r -J $EXTRAARGS \
-V "$CDLABEL" "${WORK}"/
rm -rf "${WORK}"/

echo "Running isohybrid..."
#if which isohybrid > /dev/null;then
#	isohybrid ""${OUTPUT}"" 2> /dev/null || echo "The installed isohybrid gave an error status of $?. The ISO might not work on a flash drive."
#else
	"${TAGS}"/isohybrid ""${OUTPUT}"" 2> /dev/null || echo "isohybrid gave an error status of $?. The ISO might not work on a flash drive."
	rm "${TAGS}"/isohybrid
#fi
if [ $(whoami) == "root" ];then
	chmod 666 ""${OUTPUT}""
fi
rm -r "${TAGS}" "${MNT}"

if $TESTISO;then
	RAM_FREE=$(free -m|awk 'NR == 3 {print $4}') #Current free RAM in MB, without buffers/cache
	#Determine how much RAM to use. There is no science to this; I just arbitrarily chose these cutoff points.
	if [ $RAM_FREE -ge 2048 ];then
		RAM_TO_USE=1024
	elif [ $RAM_FREE -ge 1024 ];then
		RAM_TO_USE=512
	elif [ $RAM_FREE -ge 512 ];then
		RAM_TO_USE=256
	else
		RAM_TO_USE=128
	fi
	if which kvm &> /dev/null;then
		kvm -m $RAM_TO_USE -cdrom ""${OUTPUT}""&
	elif which qemu &> /dev/null;then
		qemu -m $RAM_TO_USE -cdrom ""${OUTPUT}""&
	else
		echo "Cannot test "${OUTPUT}" in a VM. Please install qemu or qemu-kvm."
	fi
fi

echo "Cleaning current directory..."
mcdclean

if $WAIT;then
	echo "Done. Press ENTER to exit."
	read
fi
#END SCRIPT
