--- trunk/create-clonezilla-sysresccd/patch-clonezilla-sysresccd.sh 2010/05/26 13:14:04 62 +++ trunk/create-clonezilla-sysresccd/patch-clonezilla-sysresccd.sh 2010/05/26 20:30:21 63 @@ -52,7 +52,7 @@ function printVersion(){ echo "$(basename $0) - v $version -(C) 2008-2009, Spiros Georgaras +(C) 2008-2010, Spiros Georgaras A utility to personalize Clonezilla-SysRescCD " @@ -107,6 +107,84 @@ echo "done" } +function doMountPartition(){ +############################################################################## +# # +# Find mount command # +# # +############################################################################## +partitionType="$(fdisk -l | grep "$savePartition" | grep ^/dev| sed 's|*||' | sed 's|.*[0-9] *||')" +mountCommand=mount +if [ "$partitionType" = "" ];then + echo + echo " Error: Partition $savePartition does not exist" + cleanUp + exit 1 +elif [ "$partitionType" = "Extended" ];then + echo + echo " Error: $savePartition is an Extended partition" + cleanUp + exit 1 +elif [ "$partitionType" = "Linux swap / Solaris" ];then + echo + echo " Error: $savePartition is a swap partition" + cleanUp + exit 1 +elif [ "$partitionType" = "HPFS/NTFS" ];then + mountCommand=ntfs-3g +fi + + + + +############################################################################## +# # +# Create mount point # +# # +############################################################################## +if [ -z "$workingFromCD" ];then + savePartitionMountPoint=/root/tmp/savePartition.$$ +else + savePartitionMountPoint=/savePartition.$$ +fi +mkdir -p "$savePartitionMountPoint" 2>/dev/null && savePartitionMountPointCreated='y' || { + echo + echo " Error: Temp folder \"$savePartitionMountPoint\" cannot be created!!!" + cleanUp + exit 1 + } + +############################################################################## + + +############################################################################## +# # +# Mount partition # +# # +############################################################################## +unset savePartitionMounted +# mount partition +$mountCommand "$savePartition" "$savePartitionMountPoint" 2>/dev/null && savePartitionMounted='y' +# is it mounted? +if [ -z "$savePartitionMounted" ];then + echo + echo " Error: \"$savePartition\" cannot be mounted!!!" + cleanUp + exit 1 +fi +# is it writeable? + rm -rf "$savePartitionMountPoint"/new-iso 2>/dev/null + mkdir "$savePartitionMountPoint"/new-iso 2>/dev/null || { + echo + echo " Error: Partition $savePartition is mounted read-only" + exit 1 + } +echo "done" +############################################################################## +} + + + ####### Script starts here ####### # set -x @@ -138,7 +216,7 @@ echo " Error: The specified file \"$OPTARG\" cannot be created!!!" exit 1 } - outputFile="$OPTARG" + outputFile="$(basename "$OPTARG")" ;; s) # boot splash screen test "$(whoami)" = "root" || noRoot @@ -162,7 +240,7 @@ ;; p) # storage partition if [ -z $(echo "$OPTARG" | grep '/dev/') ];then - echo " Error: Parameter -c (storage partition) is not a valid partition" + echo " Error: Parameter -p (storage partition) is not a valid partition" exit 1 fi if [ -z "$(fdisk -l "$OPTARG" 2>/dev/null)" ];then @@ -245,7 +323,7 @@ exit 1 } } && { - if [-n "$boot" ];then + if [ -n "$boot" ];then echo " Error: Parameter -r (restore splash screen) not specified!!!" exit 1 fi @@ -262,18 +340,19 @@ } [ -z "$savePartition" ] && { - echo " Error: Parameter -c (storage partition) not specified!!!" + echo " Error: Parameter -p (storage partition) not specified!!!" exit 1 } -[ -z "$burnISO" ] || { +[ -n "$burnISO" ] || { [ -z "$cdWritter" ] && { WHAT_CD=$(which what-cd) [ -z "$WHAT_CD" ] && { [ -e /root/.clonezilla-sysresccd/files/what-cd ] && { WHAT_CD=/root/.clonezilla-sysresccd/files/what-cd - cdWritter=$(sh "$WHAT_CD" -bw) - [ -z "$cdWritter" ] && { + chmod +x "$WHAT_CD" + cdWritter=$("$WHAT_CD" -bw) + [ -w "$cdWritter" ] || { echo " Error: Cannot determine your writter device name!!!" exit 1 } @@ -290,7 +369,11 @@ echo -n "Mounting files... " isClonezillaSysRescCDRunning -# umount "$inputFile" 2>/dev/null +############################################################################## +# # +# Mount inputFile (ISO file or actual CD) # +# # +############################################################################## if [ -z $(mount | grep "$inputFile" | sed "s|\(^[^ ]*\).*|\1|" | uniq) ];then # mount the inputFile if [ -z "$ClonezillaSysRescCDRunning" ];then @@ -323,55 +406,39 @@ # our inputFile is mounted!!! mountPoint=$(mount | grep "$inputFile" | grep 's|.* on \(.*\) type .*)|\1|') fi +############################################################################## -# set -x -if [ -z $(mount | grep "$savePartition" | sed "s|\(^[^ ]*\).*|\1|" | uniq) ];then - if [ -z "$workingFromCD" ];then - savePartitionMountPoint=/root/tmp/savePartition.$$ - else - savePartitionMountPoint=/savePartition.$$ - fi - - mkdir -p "$savePartitionMountPoint" 2>/dev/null && savePartitionMountPointCreated='y' || { - echo "failed" +############################################################################## +# # +# Check if savePartition is already mounted # +# # +############################################################################## +if [ -n "$(mount | grep "$savePartition")" ];then + # it is mounted!!! + # can i write to it? + savePartitionMountPoint=$(mount | grep "$savePartition" | sed "s|"$savePartition" on \(.*\) type .*)|\1|") + rm -rf "$savePartitionMountPoint"/new-iso 2>/dev/null + mkdir "$savePartitionMountPoint"/new-iso 2>/dev/null || { echo - echo " Error: Temp folder \"$savePartitionMountPoint\" cannot be created!!!" - cleanUp - exit 1 - } - - ntfs-3g "$savePartition" "$savePartitionMountPoint" 2>/dev/null && savePartitionMounted='y' - if [ -z "$savePartitionMounted" ];then - savePartitionMounted='' - mount "$savePartition" "$savePartitionMountPoint" 2>/dev/null && savePartitionMounted='y' - if [ -z "$savePartitionMounted" ];then - echo "failed" - echo - echo " Error: \"$savePartition\" cannot be mounted!!!" - cleanUp - exit 1 - fi - fi -else - savePartitionMountPoint=$(mount | grep "$savePartition" | uniq | sed 's|.*on \(.*\) type.*|\1|') + echo " Error: Partition $savePartition is already mounted read-only" + exit 1 + } + echo 'done' +else + doMountPartition fi +############################################################################## +# echo "mountPoint=$mountPoint" +# echo "workingFromCD=$workingFromCD" +# echo "ClonezillaSysRescCDRunning=$ClonezillaSysRescCDRunning" +# echo "savePartition=$savePartition" +# echo "savePartitionMountPoint=$savePartitionMountPoint" +# umount /dev/loop0 +# exit - -mkdir "$savePartitionMountPoint"/new-iso 2>/dev/null && newIsoCreated='y' || { - [ -z "$savePartitionMounted" ] || umount "$savePartition" 2>/dev/null - savePartitionMounted='' - echo "failed" - echo - echo " Error: Partition \"$savePartition\ is mounted read-only!!!" - cleanUp - exit 1 -} -echo "done" - -# set +x echo -n "Copying files... " cp -r "$mountPoint"/* "$savePartitionMountPoint"/new-iso 2>/dev/null && { @@ -384,27 +451,19 @@ } -# echo -# echo -n "Press ENTER to continue... " -# read -# cleanUp -# exit - - - echo -n "Installing new files... " if [ ! -z "$mainTitle" ];then for n in $(find "$savePartitionMountPoint"/new-iso -iname "*.cfg");do - sed "s|^MENU TITLE.*|MENU TITLE $mainTitle|" "$n" > "$n".$$ + sed "0,/^MENU TITLE.*/s//MENU TITLE $mainTitle/" "$n" > "$n".$$ mv "$n".$$ "$n" done fi if [ -e "$mainSplash" ];then cp "$mainSplash" "$savePartitionMountPoint"/new-iso/isolinux/ocswp.png -fi -if [ -e "$restoreSplash" ];then -cp "$restoreSplash" "$savePartitionMountPoint"/new-iso/restorecd/default-restore-ocswp.png -cp "$restoreSplash" "$savePartitionMountPoint"/new-iso/restorecd/ocswp.png + if [ -e "$restoreSplash" ];then + cp "$restoreSplash" "$savePartitionMountPoint"/new-iso/restorecd/default-restore-ocswp.png + cp "$restoreSplash" "$savePartitionMountPoint"/new-iso/restorecd/ocswp.png + fi fi cd "$savePartitionMountPoint"/new-iso @@ -509,7 +568,7 @@ echo -n "Deleting ISO file... " rm -rf "$outputFile" 2>/dev/null && echo "done" || echo "failed" } -echo -echo -n "Press ENTER to continue... " -read +# echo +# echo -n "Press ENTER to continue... " +# read cleanUp