#!/bin/bash

# Script to automate the copying of an audio cd

# Determine how many copies to make
logfile=`echo ~/cdtools_log`;
touch $logfile;
copies=1;
echo "How many copies of this cd do you want?";
read copies;
echo `date` ":" $copies "copies requested" >> $logfile;

# Prep copying process. Make a temp directory and rip the cd.

if
	mkdir /backupa/cdrip;
	ripaudiocd /backupa/cdrip;
then
	echo `date` ":" "Rip completed" >> $logfile;
else
	echo `date` ":" "Rip failed.  Exiting." >> $logfile;
	exit 0;
fi

# Issue the command to copy the cd 'n' times

for ((i=0;i<$copies;i++));
do
	if
		eject /dev/cdrom1;
		echo `date` ":" "Please insert a blank cdr.  Press <Enter> to continue...";
		read;
		burnaudiocd /backupa/cdrip;
		r=$(($i+1));
	then
		echo `date` ":" "Burn completed for copy $r" >> $logfile;
	else
		echo `date` ":" "Burn failed on iteration" $r >> $logfile;
		exit 0;
	fi
done

# Clean up
if
	rm -Rf /backupa/cdrip;
then
	echo `date` ":" "Removed rip directories" >> $logfile;
else
	echo `date` ":" "Rip directory unable to be removed. Exiting." >> $logfile;
	exit 0;
fi
