有一段时间我经常需要刻录ISO进行测试
k3b, gnomebaker等GUI刻录工具当然都是很不错的
但我还是很喜欢cdrecord这个命令行工具
cdrcord使用时需要至少打上两行的命令
如果还需要先擦盘就得3行了
为了偷懒就写了这个小脚本
(Perl程序员的三种美德?
)
经过一台ide cdrw一台先锋usb dvdrw的测试
欢迎任何使用反馈或是建议,bug报告等
很抱歉没写注释
不过应该看起来没什么困难
[php]
#! /bin/bash
# 用途: cdrecored刻ISO
# 用法: mycdrecord.sh xxx.iso
# huanlf <huanlf @ gmail.com>
ERASE= # blank the disk
BURN= # burn the disk
which cdrecord &>/dev/null || {
echo "cdrecord not installed"
exit 127
}
usage () {
cat <<- EOF '
Founction: use cdrecord to burn ISO'
Usage: mycdrecord.sh [ options ] [ xxx.iso ]
options:
-e erase the disk
-b burn iso into disk
-h print this help message
EOF
exit
}
while getopts 'ebh' opt; do
case $opt in
e)
ERASE=true;;
b)
BURN=true;;
*)
usage;;
esac
done
shift $(( OPTIND -1 ))
iso=$1
[[ -n $iso ]] && {
file $iso | grep -q 'ISO 9660'; RC=$?
[[ $RC != 0 ]] && {
echo "Tatge is not ISO file, aborting ..."
exit 127
}
}
if [[ -e /dev/cdrw ]]; then
rw_dev=/dev/cdrw
elif [[ -e /dev/dvdrw ]]; then
rw_dev=/dvdrw
else
modprobe sg 2>/dev/null
rw_dev=$( cdrecord -scanbus 2>/dev/null | awk '/RW/ {print $1}' )
fi
[[ -z $rw_dev ]] && {
echo "Can not found RW device, aborting ..."
exit 127
}
echo "Found RW device: $rw_dev"
umount $rw_dev 2>/dev/null
RC=0
if [[ -z "$ERASE$BURN" ]]; then
cdrecord dev=$rw_dev blank=fast && cdrecord dev=$rw_dev $iso;
else
[[ -n $ERASE ]] && { cdrecord dev=$rw_dev blank=fast; RC=$?; }
[[ -n $BURN ]] && (( RC == 0 )) && [[ -n $iso ]] && cdrecord dev=$rw_dev $iso
fi
{ eject && sleep 5 && eject -t; } &
[/php]