#!/bin/bash ########################################################################### # Copyright (C) 2007 by Spiros Georgaras # # continue-multi-cd: Continue a multi session CD # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation; either version 2 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program; if not, write to the # # Free Software Foundation, Inc., # # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # ########################################################################### myVers=2.0.0 function printVersion(){ echo "$(basename "$0") - v $myVers - S. Georgaras " } function usage(){ printVersion echo echo "Usage: $(basename "$0") [options] " echo echo "Available options are: d Specify write device (in case auto detection does not work) c Close the CD. No more burning will be possible Default is to leave it open l Don't burn the CD after image creation o Save the image file as r Remove the image file after burning f On the fly burning of the CD. No image file will be created v Print version info and exit h Print this screen and exit " } function findCDRECORD(){ [ -z $(which cdrecord 2>/dev/null) ] && { echo "Error: cdrecord not found!!!" exit 1 } } function findMKISOFS(){ [ -z $(which mkisofs 2>/dev/null) ] && { echo "Error: mkisofs not found!!!" exit 1 } } function longHelp(){ echo longHelp } # while [ ! -z "$1" ];do # case "$1" in # --long-help) longHelp # shift # exit;; # esac # done BURN_CD=1 REMOVE_IMAGE=0 SAVE_MULTI='-multi' while getopts fcrd:lo:hv name do case "$name" in f) output_mode=cdwriter;; d) dev="$OPTARG";; r) REMOVE_IMAGE=1;; c) SAVE_MULTI='';; l) BURN_CD=0;; o) img="$OPTARG" ;; h) usage exit;; v) printVersion exit;; *) exit;; esac done shift $(($OPTIND - 1)) [ -z "$1" ] && { usage echo "Error: not specified!!!" exit 1 } [ ! -d "$1" ]&& { usage echo "Error: is not a directory!!!" exit 1 } pathToAdd="$1" [ -d "$img" ] && { usage echo "Error: is a directory!!!" exit 1 } [ -e "$img" ] && { usage echo "Error: already exists!!!" exit 1 } [ ! -w $(dirname "$img") ] && { usage echo "Error: No write permission for !!!" exit 1 } [ -z $(echo "$img" | grep "$pathToAdd") ] || { usage echo "Error: cannot be under !!!" exit 1 } findMKISOFS if [ $BURN_CD -eq 1 ];then findCDRECORD;fi if [ -z "$dev" ];then theCD=$(what-cd -wb 2>/dev/null) # theCD=/dev/hda else theCD="$dev" fi [ -z "$theCD" ] && { echo " Error: Cannot determine your CD writer!!!" exit 1 } [ -z "$(mount |grep "$theCD")" ] || { umount "$theCD" || { echo echo echo " Error: Your CD writer cannot be unmounted!!!" exit 1 } } cont=$(cdrecord -msinfo dev="$theCD" 2>/dev/null) [ -z "$cont" ] && { echo " Error: The media in $theCD is not a CD/RW!!!" exit 1 } [ -z "$img" ] && img="/tmp/multi-session-cd-$$.iso" mkisofs -r -J -l -f -M "$theCD" -C "$cont" "$pathToAdd" | \ { case "$output_mode" in "cdwriter") cdrecord -v "$SAVE_MULTI" driveropts=burnfree -data -eject dev="$theCD" - exit ;; *) # use /dev/stdout as the bridge cat - > "$img" && { # set -x if [ "$BURN_CD" -eq 1 ];then cdrecord -v "$SAVE_MULTI" driveropts=burnfree -data -eject dev="$theCD" "$img" && { if [ "$REMOVE_IMAGE" -eq 0 ];then echo echo echo " The image file has been saved as: $img" else rm -r "$img" fi } else echo echo echo " The image file has been saved as: $img" fi } || { printVersion echo echo " Error: Image file creation failed!!!" exit 1 } ;; esac } # echo "Data to continue: $cont" # echo "img=$img"