#bash

# CDDOIT 1.1
# Written by Jose L. Diaz.
# July/2001
# Homepage: http://www.geocities.com/cddoit/index.html
# This software comes with NO warranty of any kind. Use at your own risk.
# Report bugs or suggestions to: cddoit@yahoo.com
#=======================================================




#******************************************************************************
# FUNCTIONS
#******************************************************************************


#******************************************************************************

CancelProgramRecordStarted () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Cancel an audio recording program already started" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo "" ;
	echo "Active audio recording program:" ;
	echo " " ;
	ps -u "$USER" | grep 'sox';
	if [ "$?" = "1" ]
	then
		echo "" ;
		echo "Now, there is not CDDOIT recording program started.";
	else
		echo " " ;
		echo -n "Enter the first number of line above: ";
		read numpid;
		kill $numpid;
		if [ "$?" = "1" ]
		then
			echo " " ;
			echo "ERROR. The number is invalid.".
			Beep;
		else
			echo " " ;
			echo "Audio recording canceled." ;
		fi
	fi
	PressAnyKey;
	return;
}

#******************************************************************************

ViewAtJobs () {
	echo "WARNING: Maybe some programs (AT jobs) are not from CDDOIT. " ;
	echo " " ;
	echo "An CDDOIT audio recording program consist in two numbers (in two" ;
	echo "consecutives lines),one for the start and the second for the" ;
	echo "finish program." ;
	echo "If your program make the audio conversion too, then, a third number" ;
	echo "(the third line) is added." ;
	echo " " ;
	echo "List of active programs:" ;
	echo " " ;
	atq;
	echo " " ;
	return;
}


#******************************************************************************

ViewProgramRecords () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "View audio recording programs" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	ViewAtJobs;
	PressAnyKey;
	return;
}


#******************************************************************************

DelProgramRecord () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Delete an audio recording program" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	ViewAtJobs;
	echo "CAUTION: Be carefull, check the correct CDDOIT program (see" ;
	echo "         time period) before delete it" ;
	echo " " ;
	echo -n "Enter the number of the init program [0 Exit]: " ;
	read numjobinit;
	if [ $numjobinit = 0 ]
	then
		return;
	fi
	echo -n "Enter the number of the finish program: " ;
	read numjobend;
	echo " " ;
	echo -n "The audio conversion is programmed too? y/n: " ;
	read opc;
	if [ "$opc" = "y" ]
	then
		echo " " ;
		echo -n "Enter the number of the audio conversion: " ;
		read numjobconv;
	fi
	echo " " ;
	echo " " ;
	echo -n "Are you sure? y/n: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		atrm $numjobinit;
		atrm $numjobend;
		atrm $numjobconv;
		echo " " ;
		echo "$numjobinit, $numjobend, $numjobconv deleted.";
	fi
	PressAnyKey;
	return;
}


#******************************************************************************

ProgramRecord () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "Program an audio recording" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo " " ;
		echo " " ;
		echo "Recording is in WAV format, Stereo, 16 bits & 44.101 Hz." ;
		echo " " ;
		echo " " ;
		echo -n "Recording title [0 Exit]: " ;
		read file;
		if [ "$file" = "0" ]
		then
			return;
		fi
		if [ ! -d "$HOME/cddoit/$file" ]
		then
			mkdir --verbose "$HOME/cddoit/$file" ;
			cd "$HOME/cddoit/$file";
			break ;
		else
			echo " " ;
			Beep;
			echo "WARNING: The file already exist. Enter a diferent name.";
			PressAnyKey;
		fi
	done	
	clear;
	echo "PROGRAMMING OF AUDIO RECORDING";
	echo "------------------------------";
	echo "";	
	echo "WARNING: Be carefull and check:";	
	echo "         - Date & time is correct in your host!";	
	echo "         - When program start the audio source must be active!";	
	echo "";	
	echo -n "1. Enter the date and time to start audio recording, now is ";	
	date +[%d/%m/%y][%H:%M];
	echo -n "        Year [YY]: ";
	read syear;
	echo -n "        Month [MM]: ";
	read smonth;
	echo -n "        Day [DD]: ";
	read sday;
	echo -n "        Hour [HH]: ";
	read shour;
	echo -n "        Minute [MM]: ";	
	read sminute;
	echo "";	
	echo "";	
	echo -n "2. Enter the Day and time to finish audio recording, now is ";
	date +[%d/%m/%y][%H:%M];
	echo -n "        Day [DD]: ";
	read fday;
	echo -n "        Hour [HH]: ";
	read fhour;
	echo -n "        Minute [MM]: ";	
	read fminute;
	PressAnyKey;
	echo "";	
	echo "Saving start recording parameters...";	
	echo "sox -V -r 44101 -c 2 -t ossdsp -w -s /dev/dsp -t wav -r 44101 -c 2 -w -s \""$file.44101.wav"\"" > "$HOME/cddoit/$file/$file.start.at";
	at -f "$HOME/cddoit/$file/$file.start.at" -m $shour:$sminute $sday.$smonth.$syear;
	if [ "$?" = "1" ]   # AT command is not correct
	then
		echo "ERROR: the format of the start parameters is not correct.";
		rm -fr "$HOME/cddoit/$file";
		PressAnyKey;
		return;
	fi
	echo "";
	echo "";	
	echo "Saving finish recording parameters...";
	echo 'numpid=`ps -u "$USER" | grep 'sox'`' > "$HOME/cddoit/$file/$file.finish.at";
	echo 'kill $numpid' >> "$HOME/cddoit/$file/$file.finish.at";
	at -f "$HOME/cddoit/$file/$file.finish.at" -m $fhour:$fminute $fday.$smonth.$syear;
	if [ "$?" = "1" ]   # AT command is not correct
	then
		echo "ERROR: the format of the finish parameters is not correct.";
		rm -fr "$HOME/cddoit/$file";
		PressAnyKey;
		return;
	fi
	echo "";	
	echo "";	
	echo "The start and finish parameters were saved OK.";	
	echo "The audio recording is scheduled OK.";
	PressAnyKey;
	clear;
	echo "" ;
	echo "" ;
	echo " WARNING: The sample rate in WAV files to CD-R copy is 44.100 Hz and" ;
	echo "  *****   this recording is in 44.101 Hz." ;
	echo " ** | **  You must convert to this sample rate before the CD-R copy." ;
	echo " ** 0 **  You can do it now or convert later in menu AUDIO, option n 10." ;
	echo "  *****   In big files this action is going to take a long time" ;
	echo "" ;
	echo -n "Do you like perform conversion to 44.100 Hz after the recording? [y/n]: " ;
	read opc;
	if [ "$opc" = "y" ]
	then
		echo "";
		echo "";
		echo "sox -V -r 44101 -c 2 -t wav -w -s \""$file.44101.wav"\" -t wav -r 44100 -c 2 -w -s \""$file.44100.wav"\"" > "$HOME/cddoit/$file/$file.conv.at";
		echo "";
		echo -n "Remove old audio 44.101 Hz file after the conversion? [y/n]: " ;
		read opc;
		if [ "$opc" = "y" ]
		then
			echo "";
			echo "rm -f \"$file.44101.wav\"" >> "$HOME/cddoit/$file/$file.conv.at";
		fi
		echo "";	
		echo "Saving conversion parameters...";
		at -f "$HOME/cddoit/$file/$file.conv.at" -m $fhour:`expr $fminute + 1` $fday.$smonth.$syear;
		if [ "$?" = "1" ]   # AT command is not correct
		then
			echo "ERROR: the format of the conversion program parameters is not correct.";
			PressAnyKey;
			return;
		fi
		echo "";	
		echo "";	
		echo "The conversion program parameters were saved OK.";	
		echo "The conversion will be started 1 minute after the recording has finished.";
	fi
	rm -f "$HOME/cddoit/$file/$file.conv.at";
	rm -f "$HOME/cddoit/$file/$file.start.at";
	rm -f "$HOME/cddoit/$file/$file.finish.at";
	echo "" ;
	echo "" ;
	echo "After the recording, you can check the output messages in your mail!";
	echo -n "The audio recording will be found in: " ;
	echo "$HOME/cddoit/$file" ;
	PressAnyKey;
	return;
}



#******************************************************************************

GetMP3fromCD () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Get MP3 files from Audio-CD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetDirWavTracks;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	GetOriginalCD;
	while true;
	do
		echo "" ;
		echo "" ;
		echo "Enter the MP3 Kb/Seg quality :" ;
		echo "" ;
		echo "   1. 128 Kb/Seg, 44.1 KHz, 16 Bits, Stereo" ;
		echo "   2. 320 Kb/Seg, 44.1 KHz, 16 Bits, Stereo" ;
		echo "" ;
		echo -n "Value: " ;
		read value;
		echo "" ;
		if [ "$value" != "1" ] && [ "$value" != "2" ]
		then
			echo "Error. Incorrect value.";
		else
			break;
		fi
	done
	echo "" ;
	echo "" ;
	echo "Enter audio extraction type:" ;
	echo " " ;
	echo "	1. Maximum quality -Slow extraction-" ;
	echo "	2. Good quality, no errors -Quick extraction-" ;
	echo "	3. Regular quality, possible errors -Very quick extraction-" ;
	echo " " ;
	echo -n "Type: " ;
	read type;
	echo " " ;
	echo " " ;
	echo "Enter tracks to extract from audio CD:" ;
	echo " " ;
	echo " " ;
	echo "	Examples of audio tracks extracting:" ;
	echo " " ;
	echo "	1-   All CD tracks";
	echo "	2    Extract only track 2";
	echo "	-2   Extract from track 1 to 2";
	echo "	2-   Extract from track 2 to the last track of the CD";
	echo "	2-7  Extract tracks 2 to 7";
	echo "	1:[20.35]   Extract from second 20, sector 35 of track 1 to the end of track 1";
	echo "	1:[20.35]-  Extract from second 20, sector 35 of track 1 to the last track od CD";
	echo "" ;
	echo "" ;
	echo -n "Tracks (1-  All CD tracks): " ;
	read tracks;
	del="-del";
	empty="";
	if [ "$tracks" = "1-" ]
	then
		echo "" ;
		cdparanoia -Q;
		if [ "$?" = "1" ]
		then
			PressAnyKey;
			return 1;
		fi
		echo " " ;
		echo " " ;
		echo -n "Enter the number of tracks contained in the CD: " ;
		read numtracks;
		echo " " ;
		echo " " ;
		track=1;
		while [ "$track" -le "$numtracks" ];
		do
			case $type in
			1) cdparanoia -B "$track";;
			2) cdparanoia -Y -B "$track";;
			3) cdparanoia -Z -B "$track";;
			esac;
			if [ "$?" = "1" ]
			then
				PressAnyKey;
				return 1;
			fi
			track=`expr ${track} + 1`;
			WAV2MP3Conversion $value *.wav $empty $del;
		done
	else
		echo " " ;
		echo " " ;
		case $type in
			1) cdparanoia -B "$tracks";;
			2) cdparanoia -Y -B "$tracks";;
			3) cdparanoia -Z -B "$tracks";;
		esac;
		if [ "$?" = "1" ]
		then
			PressAnyKey;
			return 1;
		fi
		for wavfile in *.wav;
		do
			WAV2MP3Conversion $value "$wavfile" $empty $del;
		done;
	fi
	Beep;
	GetSizeInMB;
	PressAnyKey;
	return ;
}



#******************************************************************************
GetWAVfromCD () {
	clear;	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Get WAV files from Audio-CD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetDirWavTracks;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo " " ;
	echo " " ;
	echo "Enter tracks to extract from audio CD:" ;
	echo " " ;
	echo " " ;
	echo "	Examples of audio tracks extracting:" ;
	echo " " ;
	echo "	1-   All CD tracks";
	echo "	2    Extract only track 2";
	echo "	-2   Extract from track 1 to 2";
	echo "	2-   Extract from track 2 to the last track of the CD";
	echo "	2-7  Extract tracks 2 to 7";
	echo "	1:[20.35]   Extract from second 20, sector 35 of track 1 to the end of track 1";
	echo "	1:[20.35]-  Extract from second 20, sector 35 of track 1 to the last track od CD";
	echo "" ;
	echo "" ;
	echo -n "Tracks (1-  All CD tracks): " ;
	read tracks;
	if [ "$tracks" = "1-" ]
	then
		GetWavTrackByTrack;
	else
		echo " " ;
		echo " " ;
		echo "Enter audio extraction type:" ;
		echo " " ;
		echo "	1. Maximum quality -Slow extraction-" ;
		echo "	2. Good quality, no errors -Quick extraction-" ;
		echo "	3. Regular quality, possible errors -Very quick extraction-" ;
		echo " " ;
		echo -n "Type: " ;
		read type;
		case $type in
			1) cdparanoia -B "$tracks";;
			2) cdparanoia -Y -B "$tracks";;
			3) cdparanoia -Y -B "$tracks";;
		esac;
		if [ "$?" = "1" ]
		then
			PressAnyKey;
			return 1;
		fi
	fi
	GetSizeInMB;
	PressAnyKey;
	return ;
}


#******************************************************************************

AudioRecord () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "Record audio in WAV format" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo " " ;
		echo " " ;
		echo "Recording is in WAV format, Stereo, 16 bits & 44.101 Hz." ;
		echo " " ;
		echo " " ;
		echo -n "Recording title [0 Exit]: " ;
		read file;
		export file;
		if [ "$file" = "0" ]
		then
			return;
		fi
		if [ ! -d "$HOME/cddoit/$file" ]
		then
			mkdir --verbose "$HOME/cddoit/$file" ;
			cd "$HOME/cddoit/$file";
			break ;
		else
			echo " " ;
			Beep;
			echo "WARNING: The file already exist. Enter a diferent name.";
			PressAnyKey;
		fi
	done	
	echo " " ;
	echo " " ;
	echo -n "Do you like perform the recording under ROOT? [maximum priority] y/n: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		echo "Enter the ROOT password." ;
		su -c '
		echo " " ;
		echo "Press ENTER to start the recording." ;
		read;
		echo " " ;
		echo " " ;
		echo "Enter CTRL+C to finish the recording." ;
		echo "RECORDING WITH MAXIMUM PRIORITY [ROOT]...";
		echo " " ;
		sox -V -r 44101 -c 2 -t ossdsp -w -s /dev/dsp -t wav -r 44101 -c 2 -w -s "$file.44101.wav"';
		if [ "$?" = "1" ]   # if SU return bad code...
		then
			PressAnyKey;
			return;
		fi
	else
		echo " " ;
		echo "Press ENTER to start the recording." ;
		read;
		echo " " ;
		echo " " ;
		echo "Enter CTRL+C to finish the recording." ;
		echo "RECORDING...";
		echo " " ;
		sox -V -r 44101 -c 2 -t ossdsp -w -s /dev/dsp -t wav -r 44101 -c 2 -w -s "$file.44101.wav";
	fi
	echo "" ;
	echo "" ;
	echo " WARNING: The sample rate in WAV files to CD-R copy is 44.100 Hz and" ;
	echo "  *****   this recording is in 44.101 Hz." ;
	echo " ** | **  You must convert to this sample rate before the CD-R copy." ;
	echo " ** 0 **  You can do it now or convert later in menu AUDIO, option n 10." ;
	echo "  *****   In big files this action is going to take a long time" ;
	echo "" ;
	Beep;
	echo -n "Do you like perform conversion to 44.100 Hz now? [y/n]: " ;
	read opc;
	if [ "$opc" = "y" ]
	then
		echo "";
		echo "";
		sox -V -r 44101 -c 2 -t wav -w -s "$file".44101.wav -t wav -r 44100 -c 2 -w -s "$file".44100.wav;
		echo "";
		echo "Sample rate conversion finished.";
		echo "";
		Beep;
		echo -n "Remove old audio 44.101 Hz file after the conversion? [y/n]: " ;
		read opc;
		if [ "$opc" = "y" ]
		then
			echo "";
			rm -vf "$file.44101.wav";
		fi
	fi
	echo "" ;
	echo "" ;
	echo -n "The recording is found in: " ;
	echo "$HOME/cddoit/$file" ;
	GetSizeInMB;
	PressAnyKey;
	return;
}

#******************************************************************************

DataDirectCopy () {
	cd "$HOME/cddoit/cddata";
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	#copia real (no dummy)
	then
		echo "Data-CD direct copy to CD-R (Get data image and copy)";
	else
		echo "Data-CD direct dummy copy to CD-R (Get data image and dummy copy)";
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "";
	echo "Insert the source and target CDs.";
	Beep;
	PressAnyKey;
	CleanDataTempDir;
	echo "";
	echo "";
	echo "The copy must be performed under ROOT. Enter the password." ;
	if [ "${1}" = "1" ]	# copia real
	then
		su -c 'mount /dev/cdrom /mnt/cdrom ; mkisofs -R -J -f -o image.raw /mnt/cdrom ; cdrecord -v -eject image.raw ; umount /dev/cdrom' ;
	else	# mode dummy
		su -c 'mount /dev/cdrom /mnt/cdrom ; mkisofs -R -J -f -o image.raw /mnt/cdrom ; cdrecord -v -dummy -eject image.raw ; umount /dev/cdrom' ;
	fi			
	echo "";
	PressAnyKey;
	return ;
}




#******************************************************************************

OntheflyDataCopy () {
#arguments: 1:  real copy, rest: dummy copy
	cd "$HOME/cddoit/cddata";
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "On-the-fly Data-CD copy to CD-R";
	else
		echo "On-the-fly Data-CD dummy copy to CD-R";
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "****************************************************************************";
	echo "CAUTION:";
	echo "" ;
	echo "Risk of buffer underrun on 'On-the-fly' data copy!";
	echo "" ;
	echo "First, make a dummy copy to check the buffer size is OK.";
	echo "If the current buffer size is not enough, increase the";
	echo "FIFO size in the CDRECORD configuration file.";
	echo "See menu OTHERS, option n 10." ;
	echo "Also you can low the copy speed." ;
	echo "****************************************************************************";
	Beep;
	echo "" ;
	echo "" ;
	echo "Insert the source and target CDs.";
	PressAnyKey;
	if [ "${1}" = "1" ]	#copia real (no dummy)
	then
		echo "" ;
		echo "" ;
		echo -n "Do you wish to perform On-the-fly data copy? y/n: " ;
		read opc;
		if [ "$opc" = "y" ]
		then
			CopyCD 8;
		fi
	else	# copia modo dummy
		CopyCD 9
	fi		
	PressAnyKey;
	return ;
}



#******************************************************************************

Image2cd () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "Copy data image file to CD-R";
	else
		echo "Dummy copy data image file to CD-R";
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo "" ;
	echo "WARNING:  MULTISESSION does not close recordable CD and allows copy" ;
	echo "  *****   of data to recordable CD on several ocasions." ;
	echo " ** | **  Remember: The first data image to CD-R for multisession" ;
	echo " ** 0 **  are different from second and followings data image files." ;
	echo "  *****   See menu DATA, option n 2" ;
	echo "" ;
	echo "" ;
	echo -n "Do you wish to select MULTISESSION option? y/n: ";
	read multi;
	GetCDRecordable;
	if [ "$multi" = "y" ]
	then
		if [ "${1}" = "1" ]
		then
			CopyCD 3; # multisesion copy
		else
			CopyCD 7; # multisession dummy copy
		fi		
	else
		if [ "${1}" = "1" ]
		then
			CopyCD 2; # copy
		else
			CopyCD 6; # dummy copy
		fi		
	fi
	PressAnyKey;
	return ;
}

#******************************************************************************

GetImage () {
	cd "$HOME/cddoit/cddata";
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "Get data image file" ;
	else
		echo "Get multisession data image file" ;
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	DirOrg=$PWD;
	DirDest=$PWD;
	HomeUser=$HOME;
	echo " " ;
	echo "-By default data image file will be stored in the selected directory-" ;
	echo -n "Create new directory for image file? y/n: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		CreateDirectory;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		DirDest=$PWD;
	fi
	CleanDataTempDir;
	echo " " ;
	echo " " ;
	if [ "${1}" = "2" ]  # multisession
	then
		echo "ATTENTION  IN MULTISESSION DATA IMAGE FILES:";
		echo "           If this is the first data image file to the CD-R (The CD-R";
		echo "  *****    is blank yet), you must enter 'y' in the next question.";
		echo " ** | **   In the second and followings data images files to multisession";
		echo " ** o **   CD-R (multisession CD-R not blank) must be created with";
		echo "  *****    special features so enter 'n' in next question.";
		mkdir "$HOME/cddoit/dirmulti";
		ln -s "$DirOrg" "$HOME/cddoit/dirmulti";
		Beep;
		echo "";
		echo -n "This is the first data image file to CD-R? [y/n]: ";
		read opc;
		if [ "$opc" = "y" ]
		then
			echo "";
			echo "";
			echo "Creating first multisession data image file...";
			echo "";
			mkisofs -R -J -f -o "$DirDest/image.raw" "$HOME/cddoit/dirmulti";
		else
			export DirOrg;
			export DirDest;
			export HomeUser;
			echo "";
			echo "";
			echo "To create a no-first multisession data image file,";
			echo "first, you must known some information under ROOT.";
			echo "";
			echo "Please, insert the multisession CD-R in the CD-Recorder (not CD-ROM).";
			PressAnyKey;
			echo "The operation must be performed under ROOT. Enter the password.";
			su -c '
echo "";
echo "1. Getting the MSINFO number of CD-R ...";
msinfo=`cdrecord -msinfo`;
echo "";
echo "2. Getting SCSI CD-Recorder devices for CDRECORD.";
echo "";
cdrecord -scanbus;
echo "";
echo -n "Enter the SCSI CD-Recorder device [X,Y,Z], e.g. 0,1,0: ";
read cdrdevice;
#create a temporary directory to move the data and create a data image file.
echo "";
echo "";
echo "Creating multisession data image file...";
echo "";
mkisofs -R -J -f -o "$DirDest/image.raw" -C $msinfo -M $cdrdevice "$HomeUser/cddoit/dirmulti";'
			if [ "$?" = "1" ]
			then
				PressAnyKey;
				return ;
			fi
		fi
		rm -fr "$HOME/cddoit/dirmulti";
	else    # no multisession
		echo "Creating data image file..." ;
		echo " " ;
		mkisofs -R -J -f -o "$DirDest/image.raw" "$DirOrg" ;
	fi
	cd "$DirDest";
	GetSizeInMB;
	echo -n "Data image file is found in: ";
	pwd;
	PressAnyKey;
	return ;
}


#******************************************************************************

MP3toCD () {
	CleanAudioTempDir;
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		if [ "${1}" = "1" ]	# real copy (no dummy)
		then
			echo "MP3 files to CD-R copy" ;
		else
			echo "MP3 files to CD-R DUMMY copy" ;
		fi	
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		echo " " ;
		echo " " ;
		echo -n "Select the file [* All, f Finish selection, 0 Exit]: " ;
		read archvmp3;
		echo " " ;
		echo " " ;
		if [ "$archvmp3" = "f" ]
		then
			break;
		fi
		if [ "$archvmp3" = "0" ]
		then
			return;
		fi
		if [ "$archvmp3" = "*" ]
		then
			for archv in *.mp3;
			do
				mpg123 -s -r 44100 "$archv" > "$HOME/cddoit/cdaudio/$archv.raw";
				sox -t raw -r 44100 -c 2 -w -s "$HOME/cddoit/cdaudio/$archv.raw"  -r 44100 -c 2 -t wav -w -s "$HOME/cddoit/cdaudio/$archv.wav" ;
				rm -f "$HOME/cddoit/cdaudio/$archv.raw" ;
			done ;
			GetSizeInMB;
			break;
		else
			if [ -f "$HOME/cddoit/cdaudio/$archvmp3.wav" ]
			then
				Beep;
				echo -n "WARNING: ";
				echo -n "$archvmp3";
				echo " was converted before.";
				PressAnyKey;
			else
				if [ ! -f "$archvmp3" ]
				then
					Beep;
					echo "ERROR: File not found.";
					PressAnyKey;
				else
					mpg123 -s -r 44100 "$archvmp3" > "$HOME/cddoit/cdaudio/$archvmp3.raw" ;
		  		  sox -t raw -r 44100 -c 2 -w -s "$HOME/cddoit/cdaudio/$archvmp3.raw"  -r 44100 -c 2 -t wav -w -s "$HOME/cddoit/cdaudio/$archvmp3.wav";
					rm -f "$HOME/cddoit/cdaudio/$archvmp3.raw" ;
					GetSizeInMB;
					PressAnyKey;
				fi
			fi
		fi
	done
	echo " " ;
	echo "WARNING:" ;
	echo "	74 minutes audio CD capacity (aprox.): 650 Mb." ;
	echo "	80 minutes audio CD capacity (aprox.): 700 Mb." ;
	GetCDRecordable;
	cd "$HOME/cddoit/cdaudio" ;
	CopyCD ${1};
	Beep;
	PressAnyKey;
	CleanAudioTempDir;
	return;
}

#******************************************************************************

AudioCopy () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "WAV files to CD-R copy" ;
	else
		echo "WAV files to CD-R DUMMY copy" ;
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo " " ;
	echo " " ;
	echo -n "Enter speed of copy (INTRO, Default speed): " ;
	read speed;
	export speed;
	GetCDRecordable;
	CopyCD ${1};
	PressAnyKey;
	return 0;
}

#******************************************************************************

AudioDirectCopy () {
	cd "$HOME/cddoit/cdaudio"
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]
	then
		echo "Direct Audio CD copy to CD-R" ;
	else
		echo "Direct Audio CD DUMMY copy to CD-R" ;
	fi
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetOriginalCD;
	GetCDRecordable;
	CleanAudioTempDir;
	if [ "${1}" = "1" ]
	then
		CopyCD 5;
	else
		CopyCD 14; # dummy copy
	fi
	PressAnyKey;
	CleanAudioTempDir;
	return;
}


#******************************************************************************

CreateDirByDefault () {
# go to CDDOIT directory and if it is not found, create it
	if [ ! -d "$HOME/cddoit" ]
	then
		clear;
		echo "\

Welcome to CDDOIT 1.1!

Written by Jose L. Diaz.
July/2001

Homepage: http://www.geocities.com/cddoit/index.html

This is free software.
Only, I would like to know in many countries of the world CDDOIT is being
used, for that reason would be thankful to you that you sent me a mail
(cddoit@yahoo.com) indicating only your country, city and the date.
Thanks.

Well, well... I am from Madrid, Spain.

Report bugs or suggestions to: cddoit@yahoo.com
This software comes with NO warranty of any kind. Use at your own risk.


--------------------------------------------------------------
WARNING: For a correct CDDOIT funcionality, you must
         configure properly the CDRECORD configuration file in
         menu OTHERS, option n 10.
--------------------------------------------------------------";
		Beep;
		PressAnyKey;
		mkdir "$HOME/cddoit";
	fi

	if [ ! -d "$HOME/cddoit/cdaudio" ]
	then
		mkdir "$HOME/cddoit/cdaudio";
	fi

	if [ ! -d "$HOME/cddoit/cddata" ]
	then
		mkdir "$HOME/cddoit/cddata";
	fi
}

#******************************************************************************

GetDirWavTracks () {
# show the existing directories
	echo "" ;
	echo "" ;
	echo "CDDOIT directories:" ;
	echo "______________________________________________________________________" ;
	ls -C --color "$HOME/cddoit" ;
	echo "______________________________________________________________________" ;
	echo "" ;
	echo "Enter directory name already exist or new" ;
	echo -n "where the audio files will be stored [0 Exit]: "
	read nomdir ;
	if [ "$nomdir" = "0" ]
	then
		return 1;
	fi
	if [ ! -d "$HOME/cddoit/$nomdir" ]
	then
		mkdir --verbose "$HOME/cddoit/$nomdir" ;
	else
		echo " " ;
		echo "WARNING: The directory already exist and may contain files.";
		echo " " ;
	fi
	cd "$HOME/cddoit/$nomdir";
}

#******************************************************************************

GetWavTrackByTrack () {
# extract tracks running cdparanoia once per track. A better quality is obtained
	clear;
	cdparanoia -Q;
	if [ "$?" = "1" ]
	then
		PressAnyKey;
		return 1;
	fi
	echo " " ;
	echo " " ;
	echo -n "Enter the number of tracks contained in the CD: " ;
	read numtracks;
	echo " " ;
	echo " " ;
	echo "Enter audio extraction type:" ;
	echo " " ;
	echo "	1. Maximum quality -Slow extraction-" ;
	echo "	2. Good quality, no errors -Quick extraction-" ;
	echo "	3. Regular quality, possible errors -Very quick extraction-" ;
	echo " " ;
	echo -n "Type: " ;
	read type;
	echo " " ;
	echo " " ;
	echo -n "Extracting CD tracks... ";
	echo " " ;
	echo " " ;
	track=1;
	while [ "$track" -le "$numtracks" ];
	do
		case $type in
			1) cdparanoia -B "$track";;
			2) cdparanoia -Y -B "$track";;
			3) cdparanoia -Z -B "$track";;
		esac;
		if [ "$?" = "1" ]
		then
			PressAnyKey;
			return 1;
		fi
		track=`expr ${track} + 1`;
	done
	Beep;
}

#******************************************************************************

GetSizeInMB () {
# argument:  ${1}  a directory
# if argument is not included, the actual directory size is view.

	echo " " ;
	echo " " ;
	echo -n "Size in MBytes: "
	if [ "${1}" != "" ]
	then
		du -h "${1}";
	else
		pwd | du -h;
	fi
}

#******************************************************************************

PressAnyKey () {
	Beep ;
	echo "Press ENTER to continue." ;
	read ;
	return ;
}

#******************************************************************************

GoToDir () {
	while true;
	do
		echo "" ;
		echo "" ;
		echo "CDDOIT directories:" ;
		echo "______________________________________________________________________" ;
		ls -C --color "$HOME/cddoit" ;
		echo "______________________________________________________________________" ;
		echo "-Select with mouse and paste the directory or enter the complete path-";
		echo " " ;
		echo -n "Enter the directory where the original files are [0 Exit]: " ;
		read nomdir;
		if [ "$nomdir" != "0" ] && [  "$nomdir" != "" ]
		then
			if [ -d "$HOME/cddoit/$nomdir" ]
			then
				cd "$HOME/cddoit/$nomdir" ;
				break;
			else
				if [ -d "$nomdir" ]
				then
					cd "$nomdir" ;
					break;
				else
					echo " " ;
					echo " " ;
					Beep;
					echo "ERROR: The directory is not found.";
					echo "       Write the complete path. E.g.: /usr/users1/audio";
					PressAnyKey;
					clear;
				fi
			fi
		else
			return 1
		fi
	done
	echo "";
	echo "Directory files:";
	echo "";
	ls -C --color *;
	GetSizeInMB;
	return 0;
}

#******************************************************************************

GetCDRecordable () {
	echo " " ;
	echo " " ;
	echo "Insert CD-R Recordable." ;
	echo "Press any key to continue." ;
	read ;
}
#******************************************************************************

GetOriginalCD() {
	echo " " ;
	echo " " ;
	echo "Insert Audio or Data CD." ;
	echo "Press any key to continue." ;
	read ;
}

#******************************************************************************

CopyCD () {
	echo " " ;
	echo " " ;
	echo "The copy must be performed under ROOT. Enter the password." ;
	case ${1} in
		1) su -c '
if [ "$speed" = "" ]
then
	cdrecord -dao -eject -shorttrack -pad -audio *.wav;
else
	cdrecord -dao -eject speed=$speed -shorttrack -pad -audio *.wav;
fi';;
		2) su -c 'cdrecord -v -eject image.raw' ;;     # data copy
		3) su -c 'cdrecord -v -eject -multi image.raw' ;;  # multisession copy data
		4) su -c '
if [ "$speed" = "" ]
then
	cdrecord -dummy -dao -eject dev=0,0,0 -shorttrack -pad -audio *.wav;
else
	cdrecord -dummy -dao -eject speed=$speed dev=0,0,0 -shorttrack -pad -audio *.wav;
fi';;
		5) su -c '
clear;
cdparanoia -Q;
if [ "$?" = "1" ]
then
	PressAnyKey;
	return 1;
fi
echo " " ;
echo " " ;
echo -n "Enter the number of tracks contained in the CD: " ;
read numtracks;
echo " " ;
echo "Enter audio extraction type:" ;
echo " " ;
echo "	1. Maximum quality -Slow extraction-" ;
echo "	2. Good quality, no errors -Quick extraction-" ;
echo "	3. Regular quality, possible errors -Very quick extraction-" ;
echo " " ;
echo -n "Type: " ;
read type;
echo " " ;
echo -n "Enter speed of copy (INTRO, Default speed): " ;
read speed;
echo " " ;
echo " " ;
echo -n "Extracting CD tracks... ";
echo " " ;
echo " " ;
track=1;
while [ "$track" -le "$numtracks" ];
do
	case $type in
		1) cdparanoia -B "$track";;
		2) cdparanoia -Y -B "$track";;
		3) cdparanoia -Z -B "$track";;
	esac;
	if [ "$?" = "1" ]
	then
		PressAnyKey;
		return 1;
	fi
	track=`expr ${track} + 1`;
done
if [ "$speed" = "" ]
then
	cdrecord -dao -eject -shorttrack -pad -audio *.wav;
else
	cdrecord -dao -eject speed=$speed -shorttrack -pad -audio *.wav;
fi';;
		6) su -c 'cdrecord -v -dummy -eject image.raw' ;;     # dummy audio copy
		7) su -c 'cdrecord -v -dummy -eject -multi image.raw' ;;  # dummy multisession copy data
		8) su -c 'mount /dev/cdrom /mnt/cdrom; mkisofs -R -J -f /mnt/cdrom | cdrecord -v - ; umount /dev/cdrom';;  # onthefly copy
		9) su -c 'mount /dev/cdrom /mnt/cdrom; mkisofs -R -J -f /mnt/cdrom | cdrecord -v -dummy - ; umount /dev/cdrom';;   # onthefly dummy copy
		10) su -c 'cdrecord -v -dao -eject -shorttrack -pad image.raw -audio *.wav';;  # audio + data copy
		11) su -c 'cdrecord -v -dummy -dao -eject -shorttrack -pad image.raw -audio *.wav';; # audio + data  dummy copy
		12) su -c '
if [ "$speed" = "" ]
then
	cdrecord -v -eject -nofix -pad -audio "$archwav";
else
	cdrecord -v -eject speed=$speed -nofix -pad -audio "$archwav";
fi';;
		13) su -c '
if [ "$speed" = "" ]
then
	cdrecord -v -eject -nofix -pad -dummy -audio "$archwav";
else
	cdrecord -v -eject speed=$speed -nofix -pad -dummy -audio "$archwav";
fi';;
		14) su -c '
clear;
cdparanoia -Q;
if [ "$?" = "1" ]
then
	PressAnyKey;
	return 1;
fi
echo " " ;
echo " " ;
echo -n "Enter the number of tracks contained in the CD: " ;
read numtracks;
echo " " ;
echo "Enter audio extraction type:" ;
echo " " ;
echo "	1. Maximum quality -Slow extraction-" ;
echo "	2. Good quality, no errors -Quick extraction-" ;
echo "	3. Regular quality, possible errors -Very quick extraction-" ;
echo " " ;
echo -n "Type: " ;
read type;
echo " " ;
echo -n "Enter speed of copy (INTRO, Default speed): " ;
read speed;
echo " " ;
echo " " ;
echo -n "Extracting CD tracks... ";
echo " " ;
echo " " ;
track=1;
while [ "$track" -le "$numtracks" ];
do
	case $type in
		1) cdparanoia -B "$track";;
		2) cdparanoia -Y -B "$track";;
		3) cdparanoia -Z -B "$track";;
	esac;
	if [ "$?" = "1" ]
	then
		PressAnyKey;
		return 1;
	fi
	track=`expr ${track} + 1`;
done
if [ "$speed" = "" ]
then
	cdrecord -dao -eject -dummy -shorttrack -pad -audio *.wav;
else
	cdrecord -dao -eject -dummy speed=$speed -shorttrack -pad -audio *.wav;
fi';;
	esac;
	if [ "$?" = "1" ]   # if SU return an error code, CopyCD return 1
	then
		return 1;
	fi
}


#******************************************************************************

CleanAudioTempDir () {
	echo " " ;
	echo "Cleaning CDDOIT temporary directories..." ;
	rm -f "$HOME"/cddoit/cdaudio/* ;
}

#******************************************************************************

CleanDataTempDir () {
	echo " " ;
	echo "Cleaning CDDOIT temporary directories..." ;
	rm -f "$HOME"/cddoit/cddata/* ;
}

#******************************************************************************

CreateDirectory () {
	while true;
	do
		echo " " ;
		echo " " ;
		echo "Directory creation:" ;
		echo "Enter directory name" ;
		echo -n "where the files will be stored [0 Exit]: "
		read nomdir;
		if [ "$nomdir" = "0" ]
		then
			return 1;
		fi
		if [ ! -d "$HOME/cddoit/$nomdir" ]
		then
			echo "" ;
			mkdir --verbose "$HOME/cddoit/$nomdir" ;
			cd "$HOME/cddoit/$nomdir";
			break ;
		else
			echo " " ;
			Beep;
			echo "WARNING: The directory already exist. Enter a diferent name.";
			PressAnyKey;
		fi
	done
}

#******************************************************************************

Beep () { echo -e "\a"; }    # a beep sound

#******************************************************************************

WAV2MP3Conversion () {
# MP3 creation with error check.
# After the conversion the original WAV files are deleted
# arguments:
#	${1} MP3 quality -Kb/seg-
#	${2} the original file to convert
#    ${3} the output file (optional)
#    ${4} flag: the original WAV file will be removed after the conversion

	echo "Init MP3 conversion..." ;
	case ${1} in
		1) bladeenc ${4} -br 128 -crc "${2}" "${3}";;
		2) bladeenc ${4} -br 320 -crc "${2}" "${3}";;
	esac;
	echo "" ;
	echo "MP3 conversion finished." ;
}


#******************************************************************************

DelAll () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Delete ALL CDDOIT directories" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "";
	echo "CDDOIT directories:" ;
	echo "______________________________________________________________________" ;
	ls -C --color "$HOME/cddoit" ;
	echo "______________________________________________________________________" ;
	echo "";
	echo "WARNING: CDDOIT audio and data files will be lost!.";
	echo "";
	echo -n "Are you sure? y/n: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		echo "";
		rm -rvf "$HOME"/cddoit/*;
		# creating CDDOIT standard temporary files
		mkdir "$HOME"/cddoit/cdaudio;
		mkdir "$HOME"/cddoit/cddata;
		PressAnyKey;
	fi
	return;
}

#******************************************************************************

GetWAVfromSeveralCD () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Get WAV files from several Audio-CD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetDirWavTracks;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo "" ;
	echo "" ;
	echo "Insert Audio CD";
	echo -n "and enter the CD track number [0 Exit]: ";
	read track;
	if [ "$track" = "0" ]
	then
		break;
	fi
	numtrack=1;
	while true ;
	do
		echo " " ;
		echo -n "Enter a title for the CD track: ";
		read nametrack;
		echo " " ;
		echo "Extracting CD track to audio CD quality..." ;
		echo " " ;
		cdparanoia -B "$track" "$nametrack".wav;
		if [ "$?" = "1" ]
		then
			PressAnyKey;
			return 1;
		fi
		if [ "$numtrack" -lt "10" ]
		then
			mv track*."$nametrack".wav 0$numtrack-"$nametrack".wav;
		else
			mv track*."$nametrack".wav $numtrack-"$nametrack".wav;
		fi
		numtrack=`expr $numtrack + 1`;
		Beep;
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "Get WAV files from several Audio-CD" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GetSizeInMB;
		echo " " ;
		echo "Enter a new CD track number or";
		echo -n "insert new Audio CD and enter the CD track number [0 Exit]: ";
		read track;
		if [ "$track" = "0" ]
		then
			break;
		fi
	done
	Beep;
	echo "WAV conversion finished. " ;
	echo -n "WAV files from Audio-CD are found in: " ;
	pwd;
	return ;
}

#******************************************************************************

GetMP3fromSeveralCD () {

	del="-del";
	empty="";

	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Get MP3 files from several Audio-CD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetDirWavTracks;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo "" ;
	echo "" ;
	echo "Insert Audio CD";
	echo -n "and enter the CD track number [0 Exit]: ";
	read track;
	if [ "$track" = "0" ]
	then
		break;
	fi
	numtrack=1;
	while true ;
	do
		echo " " ;
		echo -n "Enter a title for the CD track: ";
		read nametrack;
		echo " " ;
		echo "Extracting CD track..." ;
		echo " " ;
		cdparanoia -B "$track" "$nametrack".wav;
		if [ "$?" = "1" ]
		then
			PressAnyKey;
			return 1;
		fi
		if [ "$numtrack" -lt "10" ]
		then
			mv track*."$nametrack".wav 0$numtrack-"$nametrack".wav;
		else
			mv track*."$nametrack".wav $numtrack-"$nametrack".wav;
		fi
		numtrack=`expr $numtrack + 1`;
		Beep;
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "Get MP3 files from several Audio-CD" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GetSizeInMB;
		echo " " ;
		echo "Enter a new CD track number or";
		echo -n "insert new Audio CD and enter the CD track number [0 Exit]: ";
		read track;
		if [ "$track" = "0" ]
		then
			break;
		fi
	done
	Beep;
	echo "Tracks selection finished." ;
	while true;
	do
		echo "" ;
		echo "" ;
		echo "Enter the MP3 Kb/Seg quality :" ;
		echo "" ;
		echo "   1. 128 Kb/Seg, 44.1 KHz, 16 Bits, Stereo" ;
		echo "   2. 320 Kb/Seg, 44.1 KHz, 16 Bits, Stereo" ;
		echo "" ;
		echo -n "Value: " ;
		read value;
		echo "" ;
		if [ "$value" != "1" ] && [ "$value" != "2" ]
		then
			echo "Error. Incorrect value.";
		else
			break;
		fi
	done
	echo "MP3 conversion..." ;
	echo "";
	for wavfile in *.wav;
	do
		WAV2MP3Conversion $value "$wavfile" $empty $del;
	done;
	echo " " ;
	echo -n "MP3 files from Audio-CD are found in: " ;
	pwd;
	PressAnyKey;
	return ;
}

#******************************************************************************

DelDir () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Delete a CDDOIT directory" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo "";
	echo "WARNING: Audio or data files will be lost!.";
	echo "";
	echo -n "Are you sure? y/n: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		echo "";
		rm -rvf "$PWD";
		# creating CDDOIT standard temporary files
		if [ ! -d "$HOME/cddoit/cdaudio" ]
		then
			mkdir "$HOME/cddoit/cdaudio";
		fi

		if [ ! -d "$HOME/cddoit/cddata" ]
		then
			mkdir "$HOME/cddoit/cddata";
		fi
		Beep;
		PressAnyKey;
	fi
	return;
}


#******************************************************************************

DelTemp () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Delete files of CDDOIT temporary directories [AUDIOCD & DATACD]" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "";
	echo "WARNING: CDDOIT temporary audio and data files will be lost!.";
	echo "";
	echo -n "Are you sure? y/n: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		echo "";
		rm -fv "$HOME"/cddoit/cdaudio/*;
		echo "";
		echo "";
		rm -fv "$HOME"/cddoit/cddata/*;
		PressAnyKey;
	fi
	return;
}

#******************************************************************************

PlayWAV () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "Play WAV files [WAV, 44.100 Hz, 16 bits, Stereo]" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		echo " " ;
		echo " " ;
		echo -n "Select file to play [* All, 0 Exit]: " ;
		read archv;
		if [ "$archv" = "0" ]
		then
			return;
		fi
		if [ "$archv" = "*" ]
		then
			for archv in *.wav;
			do
				clear;
				echo "Play WAV files" ;
				echo "_____________________________________" ;
				echo " " ;
				echo " " ;
				echo " " ;
				echo -n "You are listening: ";
				echo "$archv";
				echo " " ;
				echo " " ;
				echo " " ;
				echo " " ;
				sox -t wav -r 44100 -c 2 -w -s "$archv"  -r 44100 -c 2 -t ossdsp -w -s /dev/dsp ;
			done ;
			break;
		fi
		echo " " ;
		if [ -f "$archv" ]
		then
			echo -n "You are listening: ";
			echo "$archv";
			echo " " ;
			sox -t wav -r 44100 -c 2 -w -s "$archv"  -r 44100 -c 2 -t ossdsp -w -s /dev/dsp;
		else
			Beep;
			echo "ERROR: File not found.";
			PressAnyKey;
		fi
		echo " " ;
		echo " " ;
		echo -n "Play new file? y/n: " ;
		read opc;
		if [ "$opc" != "y" ]
		then
			break;
		fi		
	done
	return;
}	

#******************************************************************************

PlayMP3 () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "Play MP3/MPEG files" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		echo " " ;
		echo " " ;
		echo -n "Select the file to play [* All, 0 Exit]: " ;
		read archv;
		if [ "$archv" = "0" ]
		then
			return;
		fi
		if [ "$archv" = "*" ]
		then
			for archv in *.mp3;
			do
				clear;
				echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
				echo "Play MP3/MPEG files" ;
				echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
				echo " " ;
				echo " " ;
				echo " " ;
				echo -n "You are listening: ";
				echo "$archv";
				echo " " ;
				echo " " ;
				echo " " ;
				echo " " ;
				mpg123 "$archv";
			done ;
			break;
		fi
		echo " " ;
		if [ -f "$archv" ]
		then
			echo -n "You are listening: ";
			echo "$archv";
			echo " " ;
			mpg123 "$archv";
		else
			Beep;
			echo "ERROR: File not found.";
			PressAnyKey;
		fi
		echo " " ;
		echo " " ;
		echo -n "Play new file? y/n: " ;
		read opc;
		if [ "$opc" != "y" ]
		then
			break;
		fi		
	done
	return;
}	

#******************************************************************************

WAVtoMP3 () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "Convert WAV files to MP3 format" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GetDirWavTracks;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		DirDest=$PWD;
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		DirOrg=$PWD;
		echo " " ;
		echo " " ;
		echo -n "Select the file [* All, 0 Exit]: " ;
		read archvwav;
		if [ "$archvwav" = "0" ]
		then
			return;
		fi
		echo "" ;
		echo "" ;
		echo -n "Do you wish to remove the original WAV files after the conversion? [y/n]: ";
		read opc;
		if [ "$opc" = "y" ]
		then
			DelWav="-del";
		else
			DelWav="";
		fi
		while true;
		do
			echo "" ;
			echo "" ;
			echo "Enter the MP3 Kb/Seg quality :" ;
			echo "" ;
			echo "   1. 128 Kb/Seg, 44.1 KHz, 16 Bits, Stereo" ;
			echo "   2. 320 Kb/Seg, 44.1 KHz, 16 Bits, Stereo" ;
			echo "" ;
			echo -n "Value: " ;
			read value;
			echo "" ;
			if [ "$value" != "1" ] && [ "$value" != "2" ] 
			then
				echo "Error. Incorrect value.";
			else
				break;
			fi
		done
		cd "$DirDest";
		echo " " ;
		echo " " ;
		if [ "$archvwav" = "*" ]
		then
			cd "$DirOrg";
			for archv in *.wav;
			do
				WAV2MP3Conversion $value "$DirOrg/$archv" "$DirDest/$archv.mp3" "$DelWav";
			done ;
			break;
		else
			if [ -f "$DirDest/$archvwav.mp3" ]
			then
				Beep;
				echo -n "WARNING: ";
				echo -n "$archvwav";
				echo "  was converted before.";
				PressAnyKey;
			else
				if [ ! -f "$DirOrg/$archvwav" ]
				then
					Beep;
					echo "ERROR: File not found.";
					PressAnyKey;
				else
					WAV2MP3Conversion $value "$DirOrg/$archvwav" "$DirDest/$archvwav.mp3" "$DelWav";
					break;
				fi
			fi
		fi
	done
	echo " " ;
	echo " " ;
	echo -n "The MP3 files are found in: " ;
	echo "$DirDest";
	PressAnyKey;
	return;
}


#******************************************************************************

MP3toWAV () {
	while true;
	do
		clear ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		echo "Convert MP3/MPEG files to WAV format" ;
		echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
		GetDirWavTracks;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		DirDest=$PWD;
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		while true;
		do
			echo " " ;
			echo " " ;
			echo -n "Select the file [* All, 0 Exit]: " ;
			read archvmp3;
			if [ "$archvmp3" = "0" ]
			then
				return;
			fi
			echo "" ;
			echo "" ;
			echo -n "Do you wish to remove the original MP3 files after the conversion? [y/n]: ";
			read opc;
			echo " " ;
			echo " " ;
			if [ "$archvmp3" = "*" ]
			then
				for archv in *.mp3;
				do
					mpg123 -s -r 44100 "$archv" > "$DirDest/$archv.raw" ;
					sox -t raw -r 44100 -c 2 -w -s "$DirDest/$archv.raw"  -r 44100 -c 2 -t wav -w -s "$DirDest/$archv.wav" ;
					rm -f "$DirDest/$archv.raw" ;
					if [ "$opc" = "y" ]
					then
						rm -f "$archv" ; # delete the MP3 file
					fi
				done ;
			else
				if [ -f "$archvmp3.wav" ]
				then
					Beep;
					echo -n "WARNING: ";
					echo -n "$archvmp3";
					echo " was converted before.";
					PressAnyKey;
				else
					if [ ! -f "$archvmp3" ]
					then
						Beep;
						echo "ERROR: File not found.";
						PressAnyKey;
					else
						mpg123 -s -r 44100 "$archvmp3" > "$DirDest/$archvmp3.raw" ;
						sox -t raw -r 44100 -c 2 -w -s "$DirDest/$archvmp3.raw"  -r 44100 -c 2 -t wav -w -s "$DirDest/$archvmp3.wav" ;
						rm -f "$DirDest/$archvmp3.raw" ;
						if [ "$opc" = "y" ]
						then
							rm -f "$archvmp3" ; # delete the MP3 file
						fi
					fi
				fi
			fi
			echo " " ;
			echo " " ;
			echo "Conversin finished." ;
			GetSizeInMB "$DirDest";
			Beep;
			PressAnyKey;
			clear ;
			echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
			echo "Convert MP3/MPEG files to WAV format" ;
			echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
			echo " " ;
			echo " " ;
			echo "Select again? -The source and target directories will not changed-" ;
			echo " " ;
			ls -C --color;
		done
	done
	echo " " ;
	echo " " ;
	echo -n "The WAV files are found in: " ;
	echo "$DirDest";
	PressAnyKey;
	return;
}

#******************************************************************************

ConvertCdrCopyFormat () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Convert audio file formats to CD-R copy file format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "The CD-R copy format is:" ;
	echo "WAV format, 16 bits, Stereo & 44.100 Hz" ;
	echo " " ;
	echo " WARNING:" ;
	echo "  *****   In big files this action is going to take a long time." ;
	echo " ** | **  Some audio formats are not compatible in some conversions." ;
	echo " ** 0 **  The final quality sound from poor quality formats maybe" ;
	echo "  *****   not good." ;
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	echo " " ;
	echo " " ;
	echo -n "Select the file [0 Exit]: " ;
	read archv;
	if [ "$archv" = "0" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Convert audio file formats to CD-R copy file format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "ENTER THE AUDIO PARAMETERS OF THE ORIGINAL AUDIO FILE:" ;
	echo "====================================================== " ;
	echo " " ;
	echo " " ;
	echo "\
1. Enter the audio format of the original audio file.

The formats supported are:

       8svx     Amiga 8SVX musical instrument description.
       aiff     AIFF  files  used  on  Apple  IIc/IIgs  and SGI.
       au       SUN Microsystems AU files.
       cdr      CD-R.
       cvs      Continuously Variable Slope Delta modulation.
       dat      Text Data files.
       gsm      GSM 06.10 Lossy Speech Compression.
       hcom     Macintosh  HCOM  files.
       maud     An Amiga format.
       ossdsp   OSS /dev/dsp device driver.
       sf       IRCAM Sound Files.
       smp      Turtle Beach SampleVision files.
       sunau    Sun /dev/audio device driver.
       txw      Yamaha TX-16W sampler.
       vms      Used to compress speech audio such as voice mail.
       voc      Sound Blaster VOC files.
       wav      Microsoft .WAV RIFF files.
       wve      Psion 8-bit alaw.
       raw      Raw files (no header).
       ub, sb, uw, sw, ul
                These  are  several  suffices  which  serve as a
                shorthand for raw files with a  given  size  and
                style.   Thus, ub, sb, uw, sw, and ul correspond
                to 'unsigned  byte',  'signed  byte', 'unsigned
                word',  'signed  word',  and 'ulaw' (byte).
       auto     This is a ``meta-type'' format.
";
	echo "-You can select & paste-";
	echo -n "Enter audio format [0 Exit]: " ;
	read format;
	if [ "$format" = "0" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Convert audio file formats to CD-R copy file format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo -n "2. Enter the original sample rate (E.g: 44101 or 8000) [0 Exit]: " ;
	read rate;
	if [ "$rate" = "0" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Convert audio file formats to CD-R copy file format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "\
3. Enter the bits resolution of the original audio file.

The bits resolution supported types are:

	b : 8-bit  bytes.
	w : 16-bit words.
	l : 32-bit long words.
	f : 32-bit floats.
	d : 64-bit double floats.
	D : 80-bit IEEE floats.
	    [Floats and double floats are in native machine format]

";
	echo "-You can select & paste-";
	echo -n "Bits resolution [0 Exit]: " ;
	read bits;
	if [ "$bits" = "0" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Convert audio file formats to CD-R copy file format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo " " ;
	echo " " ;
	echo "\
4. Enter the audio channels of the original audio file.

The most common number of audio channels are:

	1: Mono.
	2: Stereo.
	4: Four audio channels.
";
	echo -n "Audio channels [0 Exit]: " ;
	read channel;
	if [ "$channel" = "0" ]
	then
		return;
	fi
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Convert audio file formats to CD-R copy file format" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	echo -n "Press ENTER to convert to WAV format, 16 bits, Stereo & 44.100 Hz." ;
	read;
	echo "" ;
	echo "" ;
	echo -n "Converting the file: " ;
	echo "$archv";
	echo " " ;
	echo "WARNING: In big files this action is going to take a long time." ;
	echo "" ;
	sox -V -t $format -r $rate -c $channel -$bits -s "$archv" -t wav -r 44100 -c 2 -w -s "$archv".cdformat.wav;
	Beep;
	echo "";
	echo -n "The file is found in: " ;
	pwd;
	GetSizeInMB;
	echo "";
	echo "";
	echo -n "Do you wish to delete the original file? y/n: ";
	read opc;
	if [ "$opc" = "y" ]
	then
		echo "";
		rm -fv "$archv";
	fi
	PressAnyKey;
	return ;
}

#******************************************************************************

Scanbus () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "View SCSI devices for CDRECORD" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	echo "The operation must be performed under ROOT. Enter the password.";
	su -c 'cdrecord -scanbus' root;
	PressAnyKey;
	return;
}

#******************************************************************************

ViewAllDir () {
	cd "$HOME/cddoit";
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "View contents of all CDDOIT directories" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	echo "Press 'q' to stop." ;
	echo "" ;
	echo "____________________________________________________________________________" ;
	pwd;
	echo "" ;
	ls -Rhl|more;
	PressAnyKey;
	return ;
}

#******************************************************************************

FreeSizeHD () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "View free space in Hard Disks" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	echo "Free space:" ;
	echo " " ;
	df -hT;
	PressAnyKey;
	return ;
}

#******************************************************************************

InfoAudioCd () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "View Audio-CD information" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetOriginalCD;
	cdparanoia -Q;
	PressAnyKey;
	return ;
}

#******************************************************************************

ViewSizeDir () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "View size of a directory [in MB]" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "       |-----------------------------------------|" ;
	echo "       | WAV size <===> audio time relationship: |" ;
	echo "       |                                         |" ;
	echo "       |    8.75 MB  <===>  1 Minute             |" ;
	echo "       |    650 MB   <===>  74 Minutes           |" ;
	echo "       |    700 MB   <===>  80 Minutes           |" ;
	echo "       |-----------------------------------------|" ;
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	PressAnyKey;
	return ;
}

#******************************************************************************

AudioDataCD () {
	clear ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "1" ]	# real copy (no dummy)
	then
		echo "Audio+Data CD copy" ;
	else
		echo "Audio+Data CD DUMMY copy" ;
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "";
	echo "WARNING: In Audio+Data CD, the data will be stored in the first track";
	echo "         of the CD-R and the next tracks will be the audio tracks.";
	echo "         You can't hear the track n 1, is silence.";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	if [ ! -f image.raw ]
	then
		Beep;
		echo "";
		echo "";
		echo "ERROR: Data image file (image.raw) not found!";
		echo "       Create it before! (see main menu, option 5)";
	else
		GetCDRecordable;
		if [ "${1}" = "1" ]	# real copy (no dummy)
		then
			CopyCD 10;
		else
			CopyCD 11;
		fi	
	fi
	PressAnyKey;
	return;
}

#******************************************************************************

AboutCDDOIT () {
clear;
echo "\
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
About CDDOIT
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Version 1.1
Written by Jose L. Diaz.
July/2001

Homepage: http://www.geocities.com/cddoit/index.html

This is free software.
Only, I would like to know in many countries of the world CDDOIT is being
used, for that reason would be thankful to you that you sent me a mail
(cddoit@yahoo.com) indicating only your country, city and the date.
Thanks.

Well, well... I am from Madrid, Spain.

Report bugs or suggestions to: cddoit@yahoo.com
This software comes with NO warranty of any kind. Use at your own risk.";

PressAnyKey;
return;
}

#******************************************************************************

MountDataImage () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "View data image content" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ -b /dev/loop0 ]
	then
		GoToDir;
		if [ "$?" = "1" ]
		then
			return 1;
		fi
		echo "" ;
		echo "" ;
		if [ ! -f image.raw ]
		then
			echo "WARNING: Data image file 'image.raw' not found!";
			Beep;
		else
			echo "This operation must be performed under ROOT. Enter the password.";
			su -c 'mount image.raw -r -v -t iso9660 -o loop /mnt ; ls -lChR /mnt | more ; umount /mnt';
		fi
	else
		Beep;
		echo "ERROR: The LOOP device [/dev/loop0] not exist.";
		echo "       To create it go to menu OTHERS, option n 9.";
	fi
	PressAnyKey;
	return;
}

#******************************************************************************

CreateLoopDev () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Create a LOOP device" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	if [ -b /dev/loop0 ]
	then
		Beep;
		echo "WARNING: The LOOP device [/dev/loop0] is already created!";
	else
		echo -n "Create the /dev/loop0 device? y/n : ";
		read opc;
		if [ "$opc" = "y" ]
		then
			echo "" ;
			echo "This operation must be performed under ROOT. Enter the password.";
			su -c 'mknod /dev/loop0 b 7 0';
		fi
	fi
	PressAnyKey;
	return;
}

#******************************************************************************

ConfCdrecord () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Modify CDRECORD configuration file [/etc/cdrecord.conf]" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "" ;
	echo "" ;
	if [ ! -f /etc/cdrecord.conf ]
	then
		if [ ! -f /usr/bin/cdrecord ]
		then
			Beep;
			echo "WARNING: CDRECORD is not installed properly in your system!";
			echo "         Please, install it.";
			PressAnyKey;
			return;
		fi
	fi
	echo "You must enter the values of your CR-R Recorder,maximum speed" ;
	echo "recording and buffer, if you know it. Otherwise enter e.g. values." ;
	echo "" ;
	echo "This operation must be performed under ROOT. Enter the password.";
	su -c '
echo "" ;
echo "Getting SCSI CD-Recorder devices for CDRECORD...";
echo "" ;
cdrecord -scanbus;
echo "" ;
echo -n "Enter the CD-R Recorder device view above [X,Y,Z], e.g. 0,1,0: ";
read device;
echo "" ;
echo -n "Enter the default speed copy, e.g. 2: ";
read speed;
echo "" ;
echo -n "Enter the fifo size [Default enter 4m]: ";
read fifosize;
echo "" ;
echo "" ;
echo -e "\a";
echo -n "Modify the /etc/cdrecord.conf file. Are you sure? y/n : ";
read opc;
if [ "$opc" = "y" ]
then
	mv /etc/cdrecord.conf /etc/cdrecord.conf.old ;
	echo "\
#ident @(#)cdrecord.dfl	Copyr. J. Schilling
#
# This file is /etc/cdrecord.conf
# It contains defaults that are used if no command line option
# or environment is present.
# 
# The default device, if not specified elswhere
#
CDR_DEVICE=$device
# 
# The default speed, if not specified elswhere
#
CDR_SPEED=$speed

# 
# The default FIFO size if, not specified elswhere
#
CDR_FIFOSIZE=$fifosize

#
# The following definitions allow abstract device names.
# They are used if the device name does not contain the
# the characters ',', ':', '/' and '@'
#
# drive name	device	speed	fifosize driveropts
#
# teac=		1,3,0	-1	-1	""
# panasonic=	1,4,0	-1	-1	""
# plextor=	1,4,0	12	-1	""
# sanyo=	1,4,0	12	-1	burnproof
# yamaha=	1,5,0	-1	-1	""
# cdrom=	0,6,0	2	1m	""
#
#***********************************
# This file was created by CDDOIT
#***********************************
" > /etc/cdrecord.conf ;
		echo "" ;
		echo "/etc/cdrecord.conf was changed.";
		echo "The original file was saved to /etc/cdrecord.conf.old";
else
	echo "" ;
	echo "/etc/cdrecord.conf NOT changed.";
	
fi';
	PressAnyKey;
	return;
}

#******************************************************************************
	
MultiAudio () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	if [ "${1}" = "12" ]	# real copy (no dummy)
	then
		echo "Multisession audio CD-R copy" ;
	else
		echo "Multisession audio CD-R DUMMY copy" ;
	fi	
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GoToDir;
	if [ "$?" = "1" ]
	then
		return 1;
	fi
	track=1;
	while true;
	do
		echo " " ;
		echo -n "Select the file [0 Exit]: " ;
		read archwav;
		if [ "$archwav" = "0" ]
		then
			return;
		fi
		export archwav;
		echo " " ;
		echo -n "Enter speed of copy (INTRO, Default speed): " ;
		read speed;
		export speed;
		CopyCD ${1};
		Beep;
		echo " " ;
		echo " " ;
		echo -n "Select new file? [y/n]: ";
		read opc;
		if [ "$opc" = "y" ]
		then
			if [ -f "$PWD"/cdtracklist.txt ]
			then
				rm -f "$PWD"/cdtracklist.txt;
			fi
			echo $track."$archwav" >> "$PWD"/cdtracklist.txt;
			track=`expr ${track} + 1`;
			echo "";
			echo "The audio files:";
			echo "";
			ls -C --color *;
			echo "";
			echo "Insert again the CD-R and select the audio file.";
		else
			track=`expr ${track} + 1`;
			echo $track."$archwav" >> "$PWD"/cdtracklist.txt;
			echo "The tracks written to CD-R in this last session are:";
			echo "";
			cat "$PWD"/cdtracklist.txt;
			echo "";
			echo "";
			echo -n "Also, the track list are in the file: ";
			echo "$PWD"/cdtracklist.txt;
			break;
		fi
	done
	echo "";
	echo "REMEMBER: Before listen your CD-R you must to close it.";
	echo "          See menu AUDIO CD-R, option n8.";
	PressAnyKey;
	return;
}

#******************************************************************************

CloseMultiAudio () {
	clear;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "Close multisession audio CD-R" ;
	echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	GetOriginalCD;
	echo "";
	echo "";
	echo "This operation must be performed under ROOT. Enter the password.";
	su -c 'cdrecord -v -eject -fix; echo ""; echo "The audio CD is close."';
	Beep;
	PressAnyKey;
	return;
}




#******************************************************************************
# MAIN MENU FUNCTIONS ---------------------------------
#******************************************************************************

menuaudiocd () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :::::::::::::::::::::::::::::::::::::::::::::::: Jose L. Diaz";
	echo "========================================================================";
	echo "";
	echo "::: AUDIO CD-R :::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Direct Audio CD copy to CD-R (Get WAV files and copy)";
	echo "    2. Direct Audio CD DUMMY copy to CD-R";
	echo "    3. WAV files to CD-R copy";
	echo "    4. MP3/MPEG files to CD-R copy";
	echo "    5. WAV files to CD-R DUMMY copy";
	echo "    6. MP3/MPEG files to CD-R DUMMY copy";
	echo "    7. Multisession audio CD-R copy";
	echo "    8. Multisession audio CD-R DUMMY copy";
	echo "    9. Close a multisession audio CD-R";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		0) break;;
		1) AudioDirectCopy 1;;
		2) AudioDirectCopy 2;; # dummy
		3) AudioCopy 1;;
		4) MP3toCD 1;;
		5) AudioCopy 4;;	# dummy
		6) MP3toCD 4;;	# dummy
		7) MultiAudio 12;;
		8) MultiAudio 13;; #dummy
		9) CloseMultiAudio;;
	esac;
done
}

#******************************************************************************

menudatacd () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :::::::::::::::::::::::::::::::::::::::::::::::: Jose L. Diaz";
	echo "========================================================================";
	echo "";
	echo "::: DATA CD-R ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Data-CD direct copy to CD-R (Get data image file and copy)";
	echo "    2. Data-CD direct dummy copy to CD-R";
	echo "    3. On-the-fly Data-CD copy to CD-R";
	echo "    4. On-the-fly Data-CD dummy copy to CD-R";
	echo "    5. Copy data image file to CD-R";
	echo "    6. Dummy copy data image file to CD-R";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		0) break;;
		1) DataDirectCopy 1;;
		2) DataDirectCopy 2;;  # dummy
		3) OntheflyDataCopy 1;;
		4) OntheflyDataCopy 2;;  # dummy
		5) Image2cd 1;;
		6) Image2cd 2;;  # dummy
	esac;
done
}

#******************************************************************************

menumixcd () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :::::::::::::::::::::::::::::::::::::::::::::::: Jose L. Diaz";
	echo "========================================================================";
	echo "";
	echo "::: AUDIO + DATA CD-R ::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Audio+Data CD copy";
	echo "    2. Audio+Data CD DUMMY copy";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		0) break;;
		1) AudioDataCD 1;;
		2) AudioDataCD 2;;
	esac;
done
}

#******************************************************************************

menuaudio () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :::::::::::::::::::::::::::::::::::::::::::::::: Jose L. Diaz";
	echo "========================================================================";
	echo "";
	echo "::: AUDIO ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Get WAV files from Audio-CD";
	echo "    2. Get MP3 files from Audio-CD";
	echo "    3. Get WAV files from several Audio-CD";
	echo "    4. Get MP3 files from several Audio-CD";
	echo "    5. Record audio in WAV format";
	echo "    6. Play WAV files";
	echo "    7. Play MP3/MPEG files";
	echo "    8. Convert MP3/MPEG files to WAV format";
	echo "    9. Convert WAV files to MP3 format";
	echo "   10. Convert audio file formats to CD-R copy file format";
	echo "   11. Program an audio recording";
	echo "   12. Delete an audio recording program";
	echo "   13. View audio recording programs";
	echo "   14. Cancel an audio recording program already started.";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		0) break;;
		1) GetWAVfromCD;;
		2) GetMP3fromCD;;
		3) GetWAVfromSeveralCD;;
		4) GetMP3fromSeveralCD;;
		5) AudioRecord;;
		6) PlayWAV;;
		7) PlayMP3;;
		8) MP3toWAV;;
		9) WAVtoMP3;;
		10) ConvertCdrCopyFormat;;
		11) ProgramRecord;;
		12) DelProgramRecord;;
		13) ViewProgramRecords;;
		14) CancelProgramRecordStarted;;
	esac;
done
}

#******************************************************************************

menuothers () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :::::::::::::::::::::::::::::::::::::::::::::::: Jose L. Diaz";
	echo "========================================================================";
	echo "";
	echo "::: OTHERS :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. View contents of all CDDOIT directories";
	echo "    2. View size of a directory in MB";
	echo "    3. View SCSI devices for CDRECORD";
	echo "    4. Delete a CDDOIT directory";
	echo "    5. Delete files of CDDOIT temporary directories [AUDIOCD & DATACD]";
	echo "    6. Delete ALL CDDOIT directories";
	echo "    7. View free space in Hard Disks";
	echo "    8. View Audio-CD information";
	echo "    9. Create a LOOP device";
	echo "   10. Modify CDRECORD configuration file [cdrecord.conf]";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		0) break;;
		1) ViewAllDir;;
		2) ViewSizeDir;;
		3) Scanbus;;
		4) DelDir;;
		5) DelTemp;;
		6) DelAll;;
		7) FreeSizeHD;;
		8) InfoAudioCd;;
		9) CreateLoopDev;;
		10) ConfCdrecord;;
	esac;
done
}

#******************************************************************************

menudata () {
while true;
do
	clear;
	echo "========================================================================";
	echo "::: CDDOIT :::::::::::::::::::::::::::::::::::::::::::::::: Jose L. Diaz";
	echo "========================================================================";
	echo "";
	echo "::: DATA :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
	echo "";
	echo "    1. Get data image file";
	echo "    2. Get data image for Multisession copy";
	echo "    3. Mount/View data image";
	echo "";
	echo "    0. Back to main menu";
	echo "";
	echo -n "Choose option: ";
	read opc;
	case $opc in
		0) break;;
		1) GetImage 1;;
		2) GetImage 2;;
		3) MountDataImage;;
	esac;
done
}


#******************************************************************************
# MAIN MENU ------------------------------
#******************************************************************************

CreateDirByDefault;
while true;
do
	clear;
	echo "=======================================================================";
	echo "::: CDDOIT :::::::::::::::::::::::::::::::::::::::::::: By Jose L. Diaz";
	echo "=======================================================================";
	echo "    CD Creation & Sound                                    Version: 1.1";
	echo "";
	echo "";
	echo "";
	echo "    1. Audio CD-R";
	echo "    2. Data CD-R";
	echo "    3. Audio+Data CD-R";
	echo "    4. Audio";
	echo "    5. Data" ;
	echo "    6. Others";
	echo "    7. About CDDOIT" ;
	echo "" ;
	echo "    0. Exit CDDOIT" ;
	echo "" ;
	echo "" ;
	echo -n "Choose option: ";
	read opc;
	case $opc in
		0) clear; exit 0;;
		1) menuaudiocd;;
		2) menudatacd;;
		3) menumixcd;;
		4) menuaudio;;
		5) menudata;;
		6) menuothers;;
		7) AboutCDDOIT;;
	esac;
done