/[clonezilla-sysresccd]/trunk/create-clonezilla-sysresccd/patch-clonezilla-sysresccd.sh
ViewVC logotype

Diff of /trunk/create-clonezilla-sysresccd/patch-clonezilla-sysresccd.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 62 by sng, Wed May 26 13:14:04 2010 UTC revision 93 by sng, Fri Aug 13 08:30:37 2010 UTC
# Line 52  Available options are: Line 52  Available options are:
52    
53  function printVersion(){  function printVersion(){
54  echo "$(basename $0) - v $version  echo "$(basename $0) - v $version
55  (C) 2008-2009, Spiros Georgaras <sng@hellug.gr>  (C) 2008-2010, Spiros Georgaras <sng@hellug.gr>
56    
57  A utility to personalize Clonezilla-SysRescCD  A utility to personalize Clonezilla-SysRescCD
58  "  "
# Line 94  fi Line 94  fi
94  function cleanUp(){  function cleanUp(){
95  cd  cd
96  echo -n "Cleanning up...   "  echo -n "Cleanning up...   "
 [ -z "$inputFileMounted" ] || umount "$mountPoint" 2>/dev/null  
97  [ -z "$mountPointCreated" ] || rmdir "$mountPoint" 2>/dev/null  [ -z "$mountPointCreated" ] || rmdir "$mountPoint" 2>/dev/null
 [ -z "$savePartitionMounted" ] || umount "$savePartition" 2>/dev/null  
98  [ -z "$newIsoCreated" ] || {  [ -z "$newIsoCreated" ] || {
99    [ -z "$keepFiles" ] && rm -rf "$savePartitionMountPoint"/new-iso 2>/dev/null    [ -z "$keepFiles" ] && rm -rf "$savePartitionMountPoint"/new-iso 2>/dev/null
100  }  }
# Line 104  echo -n "Cleanning up...   " Line 102  echo -n "Cleanning up...   "
102    rmdir "$savePartitionMountPoint"/new-iso 2>/dev/null    rmdir "$savePartitionMountPoint"/new-iso 2>/dev/null
103    rmdir "$savePartitionMountPoint" 2>/dev/null    rmdir "$savePartitionMountPoint" 2>/dev/null
104  }  }
105    [ -z "$inputFileMounted" ] || umount "$mountPoint" 2>/dev/null
106    [ -z "$savePartitionMounted" ] || umount "$savePartition" 2>/dev/null
107    echo "done"
108    }
109    
110    function doMountPartition(){
111    ##############################################################################
112    #                                                                            #
113    #                             Find mount command                             #
114    #                                                                            #
115    ##############################################################################
116    partitionType="$(fdisk -l | grep "$savePartition" | grep ^/dev| sed 's|*||' | sed 's|.*[0-9]  *||')"
117    mountCommand=mount
118    if [ "$partitionType" = "" ];then
119      echo
120      echo "    Error: Partition $savePartition does not exist"
121      cleanUp
122            exit 1
123    elif [ "$partitionType" = "Extended" ];then
124      echo
125      echo "    Error: $savePartition is an Extended partition"
126      cleanUp
127            exit 1
128    elif [ "$partitionType" = "Linux swap / Solaris" ];then
129      echo
130      echo "    Error: $savePartition is a swap partition"
131      cleanUp
132            exit 1
133    elif [ "$partitionType" = "HPFS/NTFS" ];then
134      mountCommand=ntfs-3g
135    fi
136    
137    
138    
139    
140    ##############################################################################
141    #                                                                            #
142    #                            Create mount point                              #
143    #                                                                            #
144    ##############################################################################
145    if [ -z "$workingFromCD" ];then
146            genisoimage --version >/dev/null 2>&1 && MKISO=genisoimage || MKISO=mkisofs
147      savePartitionMountPoint=/root/tmp/savePartition.$$
148    else
149      MKISO=genisoimage
150      savePartitionMountPoint=/savePartition.$$
151    fi
152    mkdir -p "$savePartitionMountPoint" 2>/dev/null && savePartitionMountPointCreated='y' || {
153        echo
154        echo "    Error: Temp folder \"$savePartitionMountPoint\" cannot be created!!!"
155        cleanUp
156        exit 1
157      }
158    
159    ##############################################################################
160    
161    
162    ##############################################################################
163    #                                                                            #
164    #                              Mount partition                               #
165    #                                                                            #
166    ##############################################################################
167    unset savePartitionMounted
168    # mount partition
169    $mountCommand "$savePartition" "$savePartitionMountPoint" 2>/dev/null && savePartitionMounted='y'
170    # is it mounted?
171    if [ -z "$savePartitionMounted" ];then
172      echo
173      echo "    Error: \"$savePartition\" cannot be mounted!!!"
174      cleanUp
175      exit 1
176    fi
177    # is it writeable?
178      rm -rf "$savePartitionMountPoint"/new-iso 2>/dev/null
179            mkdir "$savePartitionMountPoint"/new-iso 2>/dev/null && newIsoCreated='y' || {
180        echo
181              echo "    Error: Partition $savePartition is mounted read-only"
182                    exit 1
183            }
184  echo "done"  echo "done"
185    ##############################################################################
186  }  }
187    
188    
189    
190  ####### Script starts here #######  ####### Script starts here #######
191    
192  # set -x  # set -x
# Line 123  do Line 203  do
203    ;;    ;;
204   i) # input file or cdrom device   i) # input file or cdrom device
205      test "$(whoami)" = "root" || noRoot      test "$(whoami)" = "root" || noRoot
206      [ -s "$OPTARG" ] || {      [ -e "$OPTARG" ] || {
207        echo "    Error: The specified file \"$OPTARG\" cannot be found"        echo "    Error: The specified file \"$OPTARG\" cannot be found"
208        exit 1        exit 1
209      }      }
# Line 138  do Line 218  do
218        echo "    Error: The specified file \"$OPTARG\" cannot be created!!!"        echo "    Error: The specified file \"$OPTARG\" cannot be created!!!"
219        exit 1        exit 1
220      }      }
221      outputFile="$OPTARG"      outputFile="$(basename "$OPTARG")"
222      ;;      ;;
223   s) # boot splash screen   s) # boot splash screen
224      test "$(whoami)" = "root" || noRoot      test "$(whoami)" = "root" || noRoot
# Line 162  do Line 242  do
242      ;;      ;;
243   p) # storage partition   p) # storage partition
244      if [ -z $(echo "$OPTARG" | grep '/dev/') ];then      if [ -z $(echo "$OPTARG" | grep '/dev/') ];then
245        echo "    Error: Parameter -c (storage partition) is not a valid partition"        echo "    Error: Parameter -p (storage partition) is not a valid partition"
246        exit 1        exit 1
247      fi      fi
248      if [ -z "$(fdisk -l "$OPTARG" 2>/dev/null)" ];then      if [ -z "$(fdisk -l "$OPTARG" 2>/dev/null)" ];then
249        echo "    Error: Parameter -c (storage partition) is not a a valid partition"        echo "    Error: Parameter -p (storage partition) is not a a valid partition"
250        exit 1        exit 1
251      fi      fi
252      savePartition="$OPTARG"      savePartition="$OPTARG"
# Line 245  test "$(whoami)" = "root" || noRoot Line 325  test "$(whoami)" = "root" || noRoot
325      exit 1      exit 1
326    }    }
327  }  && {  }  && {
328    if [-n "$boot" ];then    if [ -n "$boot" ];then
329      echo "    Error: Parameter -r (restore splash screen) not specified!!!"      echo "    Error: Parameter -r (restore splash screen) not specified!!!"
330      exit 1      exit 1
331    fi    fi
# Line 262  test "$(whoami)" = "root" || noRoot Line 342  test "$(whoami)" = "root" || noRoot
342  }  }
343    
344  [ -z "$savePartition" ] && {  [ -z "$savePartition" ] && {
345    echo "    Error: Parameter -c (storage partition) not specified!!!"    echo "    Error: Parameter -p (storage partition) not specified!!!"
346    exit 1    exit 1
347  }  }
348    
349  [ -z "$burnISO" ] || {  [ -n "$burnISO" ] || {
350    [ -z "$cdWritter" ] && {    [ -z "$cdWritter" ] && {
351      WHAT_CD=$(which what-cd)      WHAT_CD=$(which what-cd)
352      [ -z "$WHAT_CD" ] && {      [ -z "$WHAT_CD" ] && {
353        [ -e /root/.clonezilla-sysresccd/files/what-cd ] && {        [ -e /root/.clonezilla-sysresccd/files/what-cd ] && {
354          WHAT_CD=/root/.clonezilla-sysresccd/files/what-cd          WHAT_CD=/root/.clonezilla-sysresccd/files/what-cd
355          cdWritter=$(sh "$WHAT_CD" -bw)                                  chmod +x "$WHAT_CD"
356          [ -z "$cdWritter" ] && {          cdWritter=$("$WHAT_CD" -bw)
357            [ -w "$cdWritter" ] || {
358            echo "    Error: Cannot determine your writter device name!!!"            echo "    Error: Cannot determine your writter device name!!!"
359            exit 1            exit 1
360          }          }
# Line 290  printVersion Line 371  printVersion
371  echo -n "Mounting files...   "  echo -n "Mounting files...   "
372  isClonezillaSysRescCDRunning  isClonezillaSysRescCDRunning
373    
374  # umount "$inputFile" 2>/dev/null  ##############################################################################
375    #                                                                            #
376    #                Mount inputFile (ISO file or actual CD)                     #
377    #                                                                            #
378    ##############################################################################
379  if [ -z $(mount | grep "$inputFile" | sed "s|\(^[^ ]*\).*|\1|" | uniq) ];then  if [ -z $(mount | grep "$inputFile" | sed "s|\(^[^ ]*\).*|\1|" | uniq) ];then
380    # mount the inputFile    # mount the inputFile
381    if [ -z "$ClonezillaSysRescCDRunning" ];then    if [ -z "$ClonezillaSysRescCDRunning" ];then
# Line 323  else Line 408  else
408    # our inputFile is mounted!!!    # our inputFile is mounted!!!
409    mountPoint=$(mount | grep "$inputFile" | grep 's|.* on \(.*\) type .*)|\1|')    mountPoint=$(mount | grep "$inputFile" | grep 's|.* on \(.*\) type .*)|\1|')
410  fi  fi
411    ##############################################################################
412    
413    
414    
415    
416  # set -x  ##############################################################################
417  if [ -z $(mount | grep "$savePartition" | sed "s|\(^[^ ]*\).*|\1|" | uniq) ];then  #                                                                            #
418    if [ -z "$workingFromCD" ];then  #                Check if savePartition is already mounted                   #
419      savePartitionMountPoint=/root/tmp/savePartition.$$  #                                                                            #
420    else  ##############################################################################
421      savePartitionMountPoint=/savePartition.$$  if [ -n "$(mount | grep "$savePartition")" ];then
422    fi    # it is mounted!!!
423            # can i write to it?
424    mkdir -p "$savePartitionMountPoint" 2>/dev/null && savePartitionMountPointCreated='y' || {    savePartitionMountPoint=$(mount | grep "$savePartition" | sed "s|"$savePartition" on \(.*\) type .*)|\1|")
425      echo "failed"          rm -rf "$savePartitionMountPoint"/new-iso 2>/dev/null
426            mkdir "$savePartitionMountPoint"/new-iso 2>/dev/null || {
427      echo      echo
428      echo "    Error: Temp folder \"$savePartitionMountPoint\" cannot be created!!!"            echo "    Error: Partition $savePartition is already mounted read-only"
429      cleanUp                  exit 1
430      exit 1          }
431    }    echo 'done'
432    else
433    ntfs-3g "$savePartition" "$savePartitionMountPoint" 2>/dev/null && savePartitionMounted='y'    doMountPartition
   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|')  
434  fi  fi
435    ##############################################################################
436    # echo "mountPoint=$mountPoint"
437    # echo "workingFromCD=$workingFromCD"
438    # echo "ClonezillaSysRescCDRunning=$ClonezillaSysRescCDRunning"
439    # echo "savePartition=$savePartition"
440    # echo "savePartitionMountPoint=$savePartitionMountPoint"
441    # umount /dev/loop0
442    # exit
443    
444    echo -n "Copying files...   "
445    
 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"  
446    
447  # set +x  if [ -z "$workingFromCD" ];then
 echo -n "Copying files...   "  
448    
449  cp -r "$mountPoint"/* "$savePartitionMountPoint"/new-iso 2>/dev/null && {  cp -r "$mountPoint"/* "$savePartitionMountPoint"/new-iso 2>/dev/null && {
450    echo "done"    echo "done"
# Line 384  cp -r "$mountPoint"/* "$savePartitionMou Line 456  cp -r "$mountPoint"/* "$savePartitionMou
456  }  }
457    
458    
459  # echo  else
 # echo -n "Press ENTER to continue...   "  
 # read  
 # cleanUp  
 # exit  
   
460    
461    for n in "$mountPoint"/*;do
462    if [ "$n" != "$savePartitionMountPoint" ] && [ "$n" != "/proc" \ && [ "$n" != "/sys" ];then
463      cp -r "mountPoint"/"$n" "$savePartitionMountPoint"/new-iso 2>/dev/null || {
464        echo "failed"
465        echo
466        cleanUp
467        exit 1
468      }
469    fi
470    done
471    fi
472    
473  echo -n "Installing new files...   "  echo -n "Installing new files...   "
474  if [ ! -z "$mainTitle" ];then  if [ ! -z "$mainTitle" ];then
475    for n in $(find "$savePartitionMountPoint"/new-iso -iname "*.cfg");do    for n in $(find "$savePartitionMountPoint"/new-iso -iname "*.cfg");do
476      sed "s|^MENU TITLE.*|MENU TITLE $mainTitle|" "$n"  > "$n".$$      sed "s/^MENU TITLE  *Clonezilla-SysRescCD .*$/MENU TITLE $mainTitle/" "$n"  > "$n".$$
477      mv "$n".$$ "$n"      mv "$n".$$ "$n"
478    done    done
479  fi  fi
480  if [ -e "$mainSplash" ];then  if [ -e "$mainSplash" ];then
481    cp "$mainSplash" "$savePartitionMountPoint"/new-iso/isolinux/ocswp.png    cp "$mainSplash" "$savePartitionMountPoint"/new-iso/isolinux/ocswp.png
482  fi    if [ -e "$restoreSplash" ];then
483  if [ -e "$restoreSplash" ];then      cp "$restoreSplash" "$savePartitionMountPoint"/new-iso/restorecd/default-restore-ocswp.png
484  cp "$restoreSplash" "$savePartitionMountPoint"/new-iso/restorecd/default-restore-ocswp.png      cp "$restoreSplash" "$savePartitionMountPoint"/new-iso/restorecd/ocswp.png
485  cp "$restoreSplash" "$savePartitionMountPoint"/new-iso/restorecd/ocswp.png    fi
486  fi  fi
487    
488  cd "$savePartitionMountPoint"/new-iso  cd "$savePartitionMountPoint"/new-iso
# Line 426  if [ ! -z "$theKeymap" ];then Line 504  if [ ! -z "$theKeymap" ];then
504    done    done
505  fi  fi
506    
507  tar czf menu-iso.tar.gz $(find . -iname "*.cfg")  tar czf menu-for-iso.tar.gz $(find . -iname "*.cfg")
508  mv menu-iso.tar.gz restorecd  mv menu-for-iso.tar.gz restorecd
509  echo "done"  echo "done"
510    
511  [ -z "$keepFiles" ] || {  [ -z "$keepFiles" ] || {
# Line 444  read Line 522  read
522    
523  outputFile="$savePartitionMountPoint"/"$outputFile"  outputFile="$savePartitionMountPoint"/"$outputFile"
524    
525  mkisofs -r -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat \  $MKISO -r -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat \
526  -no-emul-boot -boot-load-size 4 -boot-info-table \  -no-emul-boot -boot-load-size 4 -boot-info-table \
527  "$savePartitionMountPoint"/new-iso \  "$savePartitionMountPoint"/new-iso \
528  | \  | \
# Line 481  mkisofs -r -J -l -b isolinux/isolinux.bi Line 559  mkisofs -r -J -l -b isolinux/isolinux.bi
559        fi        fi
560        [ -z "$deleteISO" ] && {        [ -z "$deleteISO" ] && {
561          echo          echo
562            echo -n "Looking for iohybrid executable...   "
563            chIsoHyb=`type isohybrid 2>/dev/null`
564            if [ -n "$chIsoHyb" ];then
565                                      echo found
566              echo -n "Isohybriding  $outFile...  "
567              isohybrid "$outFile"
568              echo 'done'
569                                    else
570                                      echo not found
571            fi
572          echo "ISO file: \"$outputFile\""          echo "ISO file: \"$outputFile\""
573        };;        };;
574     esac     esac
# Line 509  mkisofs -r -J -l -b isolinux/isolinux.bi Line 597  mkisofs -r -J -l -b isolinux/isolinux.bi
597    echo -n "Deleting ISO file...   "    echo -n "Deleting ISO file...   "
598    rm -rf "$outputFile" 2>/dev/null &&  echo "done" || echo "failed"    rm -rf "$outputFile" 2>/dev/null &&  echo "done" || echo "failed"
599  }  }
600  echo  # echo
601  echo -n "Press ENTER to continue...   "  # echo -n "Press ENTER to continue...   "
602  read  # read
603  cleanUp  cleanUp

Legend:
Removed from v.62  
changed lines
  Added in v.93

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26