Friday, July 25, 2008

Script To Convert cd's to Dvd

#!/bin/bash
# convert cd's into single DVD
#

#functions

iso_fn () {
disc
cp -r /tmp/cd1/.discinfo /tmp/isoimage
OUT=`cat /tmp/stdout1 | grep 1`
sed '4s/1/'$OUT'/g' /tmp/isoimage/.discinfo > /tmp/stdout2
mv -f /tmp/stdout2 /tmp/isoimage/.discinfo
cd /tmp/isoimage

echo " Enter the label for DVD"
read name
echo " Enter the name & location to store the image example /DVD1.iso"
read locate
mkisofs -v -r -T -J -V "$name" -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot \
-boot-load-size 4 -boot-info-table -o "$locate" /tmp/isoimage
echo " successfuly completed now burn the "$locate" image into DVD"
echo " Do you want to create another image [y/n]"
read -n 1 CH
if [ "$CH" -eq "y" ]; then clean ;. testlap2.sh; else echo " Try later"; fi
cd $OLDPWD
}

clean () {
umount /tmp/cd* 2> /dev/null
rm -rf /tmp/isoimage /tmp/cd* 2> /dev/null
}

disc () {

echo > /tmp/stdout1 2> /dev/null
while [ "$J" -le "$C" ]
do
if [ "$J" -eq "$C" ]; then printf "$J" >> /tmp/stdout1 ; else printf "$J," >> /tmp/stdout1; fi
let "J +=1"
done

}

sync_fn () {

E=$D
while [ "$E" -ge "$J" ]
do
rsync -rv /tmp/cd"$E"/* /tmp/isoimage
let "E -=1"
done
iso_fn
}

#starting from here
#declaration
I=1
J=1
echo " Give the appropriate source you have "
echo " 1.cdrom 2.iso images 3.clean"
read NUM
mkdir -p /tmp/isoimage
rm -rf /tmp/cd* 2>/dev/null
case $NUM in

1)echo " Enter total no of cds"
read C

while [ "$I" -le "$C" ]
do
mkdir -p /tmp/cd$I
echo " Insert the $I cd "
eject && sleep 20 && eject -t && \
dd if=/dev/cdrom of=/tmp/cd"$I".iso && \
mount -o,loop /tmp/cd"$I".iso /tmp/cd"$I" && \
let "I += 1"
done
sync_fn
;;

2)echo " Enter the total no of isoimages"
read C
D=$C
while [ "$I" -le "$C" ]
do
mkdir -p /tmp/cd$I
echo " Give the path for isoimage $I for example /misc/cd$I.iso "
read SPATH
mount -o,loop "$SPATH" /tmp/cd"$I"
let "I +=1"
done
sync_fn
;;

3)
clean
clear
echo "cleaned"
. testlap2.sh
;;

*)echo " you have pressed invalid key"
#2> /dev/null
;;

esac

2 comments:

Chirag "Cheezo" Jog said...

Hey Varun, Good scipt!
But please credit the original author if you aren't it :)

varun said...

i dont know the original author, otherwise i would have done it. It was passed down by a friend of mine