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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 64 - (hide annotations)
Fri May 28 09:47:17 2010 UTC (13 years, 10 months ago) by sng
File MIME type: application/x-sh
File size: 18517 byte(s)
more work done on scripts
1 sng 62 ##############################################################################
2     # #
3     # patch-clonezilla-sysresccd, (C) 2007-2010 S. Georgaras <sng@hellug.gr> #
4     # #
5     # This file is part of Clonezilla-SysRescCD. #
6     # #
7     # Clonezilla-SysRescCD is free software: you can redistribute it and/or #
8     # modify it under the terms of the GNU General Public License as published #
9     # by the Free Software Foundation, either version 2 of the License, or #
10     # (at your option) any later version. #
11     # #
12     # Clonezilla-SysRescCD is distributed in the hope that it will be useful, #
13     # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15     # GNU General Public License for more details. #
16     # #
17     # You should have received a copy of the GNU General Public License along #
18     # with Clonezilla-SysRescCD. If not, see <http://www.gnu.org/licenses/>. #
19     # #
20     ##############################################################################
21     function noRoot(){
22     echo " Error: You must be root to execute this script"
23     exit 1
24     }
25    
26     function printHelp(){
27     printVersion
28     echo "Usage: $(basename $0) [options]
29    
30     Available options are:
31     i [file / device] input file or cdrom device
32     o [iso file] outpup ISO file. If not specified, implies burn ISO file (-b)
33     and delete ISO file (-d)
34     s [png image] boot splash screen
35     r [png image] restore splash screen
36     t [title] boot screen title
37     p [partition] partition to be used as temporary storage location and/or final
38     ISO file creation location (e.g -p hda)
39     l [language] Change default language to [language]
40     k [keymap] Change default keymap to [keymap]
41     n Do not create/burn the ISO file. Just make the modified files
42     available for further customization (optional)
43     b burn ISO file to CD (optional)
44     f burn ISO file to CD on the fly (optional)
45     w writter device to use (optional)
46     d delete ISO file after burning to CD.
47     Implies burn ISO file (-b) (optional)
48     v print version and exit
49     h print this screen and exit
50     "
51     }
52    
53     function printVersion(){
54     echo "$(basename $0) - v $version
55 sng 63 (C) 2008-2010, Spiros Georgaras <sng@hellug.gr>
56 sng 62
57     A utility to personalize Clonezilla-SysRescCD
58     "
59     }
60    
61     function rotate_line(){
62     INTERVAL=1 # Sleep time between “twirls"
63     TCOUNT=0 # For each TCOUNT the line twirls one increment
64     echo -n '('
65     while : # Loop forever...until this function is killed
66     do
67     TCOUNT=$((TCOUNT+1)) # Increment the TCOUNT
68     case $TCOUNT in
69     "1") echo -e '-)'"\b\b\c"
70     COUNTER_ACTIVE='y'
71     sleep $INTERVAL
72     ;;
73     "2") echo -e '\\)'"\b\b\c"
74     sleep $INTERVAL
75     ;;
76     "3") echo -e "|)\b\b\c"
77     sleep $INTERVAL
78     ;;
79     "4") echo -e "/)\b\b\c"
80     sleep $INTERVAL
81     ;;
82     *) TCOUNT=0 ;; # Reset the TCOUNT to “0", zero.
83     esac
84     done
85     }
86    
87     function isClonezillaSysRescCDRunning(){
88     if [ -e /live/image/README.txt ] || [ -e /mnt/livecd/README.txt ];then
89     ClonezillaSysRescCDRunning='y'
90     fi
91     }
92    
93    
94     function cleanUp(){
95     cd
96     echo -n "Cleanning up... "
97     [ -z "$mountPointCreated" ] || rmdir "$mountPoint" 2>/dev/null
98     [ -z "$newIsoCreated" ] || {
99     [ -z "$keepFiles" ] && rm -rf "$savePartitionMountPoint"/new-iso 2>/dev/null
100     }
101     [ -z "$savePartitionMountPointCreated" ] || {
102     rmdir "$savePartitionMountPoint"/new-iso 2>/dev/null
103     rmdir "$savePartitionMountPoint" 2>/dev/null
104     }
105 sng 64 [ -z "$inputFileMounted" ] || umount "$mountPoint" 2>/dev/null
106     [ -z "$savePartitionMounted" ] || umount "$savePartition" 2>/dev/null
107 sng 62 echo "done"
108     }
109    
110 sng 63 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 sng 64 genisoimage --version >/dev/null 2>&1 && MKISO=genisoimage || MKISO=mkisofs
147 sng 63 savePartitionMountPoint=/root/tmp/savePartition.$$
148     else
149 sng 64 MKISO=genisoimage
150 sng 63 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 sng 64 mkdir "$savePartitionMountPoint"/new-iso 2>/dev/null && newIsoCreated='y' || {
180 sng 63 echo
181     echo " Error: Partition $savePartition is mounted read-only"
182     exit 1
183     }
184     echo "done"
185     ##############################################################################
186     }
187    
188    
189    
190 sng 62 ####### Script starts here #######
191    
192     # set -x
193     while getopts ":i:o:s:r:t:fp:bdwnvhl:k:" Option
194     do
195     case $Option in
196     h)
197     printHelp
198     exit
199     ;;
200     v)
201     printVersion
202     exit
203     ;;
204     i) # input file or cdrom device
205     test "$(whoami)" = "root" || noRoot
206 sng 64 [ -e "$OPTARG" ] || {
207 sng 62 echo " Error: The specified file \"$OPTARG\" cannot be found"
208     exit 1
209     }
210     inputFile="$OPTARG"
211     if [ ! -z $(echo "$inputFile" | grep '/dev/') ];then
212     workingFromCD=1
213     fi
214     ;;
215     o) # output file
216     test "$(whoami)" = "root" || noRoot
217     touch "$OPTARG" 2>/dev/null || {
218     echo " Error: The specified file \"$OPTARG\" cannot be created!!!"
219     exit 1
220     }
221 sng 63 outputFile="$(basename "$OPTARG")"
222 sng 62 ;;
223     s) # boot splash screen
224     test "$(whoami)" = "root" || noRoot
225     [ -s "$OPTARG" ] || {
226     echo " Error: The specified file \"$OPTARG\" cannot be found"
227     exit 1
228     }
229     mainSplash="$OPTARG"
230     ;;
231     r) # restore splash screen
232     test "$(whoami)" = "root" || noRoot
233     [ -s "$OPTARG" ] || {
234     echo " Error: The specified file \"$OPTARG\" cannot be found"
235     exit 1
236     }
237     restoreSplash="$OPTARG"
238     ;;
239     t) # boot screen title (boot screen)
240     test "$(whoami)" = "root" || noRoot
241     mainTitle="$OPTARG"
242     ;;
243     p) # storage partition
244     if [ -z $(echo "$OPTARG" | grep '/dev/') ];then
245 sng 63 echo " Error: Parameter -p (storage partition) is not a valid partition"
246 sng 62 exit 1
247     fi
248     if [ -z "$(fdisk -l "$OPTARG" 2>/dev/null)" ];then
249 sng 64 echo " Error: Parameter -p (storage partition) is not a a valid partition"
250 sng 62 exit 1
251     fi
252     savePartition="$OPTARG"
253     ;;
254     b) # burn image to CD
255     test "$(whoami)" = "root" || noRoot
256     burnISO='y'
257     ;;
258     f) # burn ISO to CD on the fly
259     test "$(whoami)" = "root" || noRoot
260     onTheFly='y'
261     ;;
262     d) # delete image after burning to CD
263     test "$(whoami)" = "root" || noRoot
264     deleteISO='y'
265     burnISO='y'
266     ;;
267     w) # CD writter device
268     test "$(whoami)" = "root" || noRoot
269     if [ -z $(echo "$OPTARG" | grep '/dev/') ];then
270     echo " Error: Parameter -w (writter device) is not valid"
271     exit 1
272     fi
273     tmpDev=$(echo "$OPTARG" | sed 's|^/dev/||')
274     if [ $(cat /proc/sys/dev/cdrom/info | grep "$tmpDev" | wc -l) -ne 0 ];then
275     # not found as dev name
276     # is it a link?
277     tmpDev=$(ls -la "$OPTARG" | sed 's|.*-> ||')
278     if [ $(cat /proc/sys/dev/cdrom/info | grep "$tmpDev" | wc -l) -eq 0 ];then
279     echo " Error: Parameter -w (writter device) is not valid"
280     exit 1
281     fi
282     fi
283     cdWritter="$OPTARG"
284     ;;
285     t) # boot screen title (boot screen)
286     test "$(whoami)" = "root" || noRoot
287     mainTitle="$OPTARG"
288     ;;
289     n) # boot screen title (boot screen)
290     test "$(whoami)" = "root" || noRoot
291     keepFiles='y'
292     ;;
293     l)
294     test "$(whoami)" = "root" || noRoot
295     theLang="$OPTARG"
296     ;;
297     k)
298     test "$(whoami)" = "root" || noRoot
299     theKeymap="$OPTARG"
300     ;;
301     esac
302     done
303     shift $(($OPTIND - 1))
304     test "$(whoami)" = "root" || noRoot
305    
306     # Check parameters
307     [ -z "$inputFile" ] && {
308     echo " Error: Parameter -i (input file) not specified!!!"
309     exit 1
310     }
311     [ -z "$mainSplash" ] || {
312     [ -z $(echo "$mainSplash" | grep -e '\.png$') ] && {
313     echo " Error: Boot splash screen (parameter -s) is not a png file!!!"
314     exit 1
315     }
316     boot=1
317     }
318     # } && {
319     # echo " Error: Parameter -s (boot splash screen) not specified!!!"
320     # exit 1
321     # }
322     [ -z "$restoreSplash" ] || {
323     [ -z $(echo "$restoreSplash" | grep -e '\.png$') ] && {
324     echo " Error: Restore splash screen (parameter -r) is not a png file!!!"
325     exit 1
326     }
327     } && {
328 sng 63 if [ -n "$boot" ];then
329 sng 62 echo " Error: Parameter -r (restore splash screen) not specified!!!"
330     exit 1
331     fi
332     }
333     # [ -z "$mainTitle" ] && {
334     # echo " Error: Parameter -t (boot screen title) not specified!!!"
335     # exit 1
336     # }
337    
338     [ -z "$outputFile" ] && {
339     outputFile=$(basename "$0").$$.iso
340     burnISO='y'
341     deleteISO='y'
342     }
343    
344     [ -z "$savePartition" ] && {
345 sng 63 echo " Error: Parameter -p (storage partition) not specified!!!"
346 sng 62 exit 1
347     }
348    
349 sng 63 [ -n "$burnISO" ] || {
350 sng 62 [ -z "$cdWritter" ] && {
351     WHAT_CD=$(which what-cd)
352     [ -z "$WHAT_CD" ] && {
353     [ -e /root/.clonezilla-sysresccd/files/what-cd ] && {
354     WHAT_CD=/root/.clonezilla-sysresccd/files/what-cd
355 sng 63 chmod +x "$WHAT_CD"
356     cdWritter=$("$WHAT_CD" -bw)
357     [ -w "$cdWritter" ] || {
358 sng 62 echo " Error: Cannot determine your writter device name!!!"
359     exit 1
360     }
361     } || {
362     echo " Error: Parameter -w (writter device) not specified!!!"
363     exit 1
364     }
365     }
366     }
367     }
368    
369     printVersion
370    
371     echo -n "Mounting files... "
372     isClonezillaSysRescCDRunning
373    
374 sng 63 ##############################################################################
375     # #
376     # Mount inputFile (ISO file or actual CD) #
377     # #
378     ##############################################################################
379 sng 62 if [ -z $(mount | grep "$inputFile" | sed "s|\(^[^ ]*\).*|\1|" | uniq) ];then
380     # mount the inputFile
381     if [ -z "$ClonezillaSysRescCDRunning" ];then
382     # working on host system
383     mountPoint=/root/tmp/mountPoint.$$
384     else
385     # working with ClonezillaSysRescCD
386     mountPoint=/mountPoint.$$
387     fi
388     if [ -z "$workingFromCD" ];then
389     # working with ClonezillaSysRescCD image
390     mountOptions="-oloop"
391     fi
392     mkdir -p "$mountPoint" && mountPointCreated='y' || {
393     echo "failed"
394     echo
395     echo " Error: Temp folder \"$mountPoint\" cannot be created!!!"
396     exit 1
397     }
398    
399     mount "$inputFile" "$mountPoint" "$mountOptions" 2>/dev/null && inputFileMounted='y'
400     if [ -z "$inputFileMounted" ];then
401     echo "failed"
402     echo
403     echo " Error: \"$inputFile\" cannot be mounted!!!"
404     cleanUp
405     exit 1
406     fi
407     else
408     # our inputFile is mounted!!!
409     mountPoint=$(mount | grep "$inputFile" | grep 's|.* on \(.*\) type .*)|\1|')
410     fi
411 sng 63 ##############################################################################
412 sng 62
413    
414    
415    
416 sng 63 ##############################################################################
417     # #
418     # Check if savePartition is already mounted #
419     # #
420     ##############################################################################
421     if [ -n "$(mount | grep "$savePartition")" ];then
422     # it is mounted!!!
423     # can i write to it?
424     savePartitionMountPoint=$(mount | grep "$savePartition" | sed "s|"$savePartition" on \(.*\) type .*)|\1|")
425     rm -rf "$savePartitionMountPoint"/new-iso 2>/dev/null
426     mkdir "$savePartitionMountPoint"/new-iso 2>/dev/null || {
427 sng 62 echo
428 sng 63 echo " Error: Partition $savePartition is already mounted read-only"
429     exit 1
430     }
431     echo 'done'
432     else
433     doMountPartition
434 sng 62 fi
435 sng 63 ##############################################################################
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 sng 62
444     echo -n "Copying files... "
445    
446 sng 64
447     if [ -z "$workingFromCD" ];then
448    
449 sng 62 cp -r "$mountPoint"/* "$savePartitionMountPoint"/new-iso 2>/dev/null && {
450     echo "done"
451     } || {
452     echo "failed"
453     echo
454     cleanUp
455     exit 1
456     }
457    
458    
459 sng 64 else
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 sng 62 echo -n "Installing new files... "
474     if [ ! -z "$mainTitle" ];then
475     for n in $(find "$savePartitionMountPoint"/new-iso -iname "*.cfg");do
476 sng 64 sed "s/^MENU TITLE *Clonezilla-SysRescCD .*$/MENU TITLE $mainTitle/" "$n" > "$n".$$
477 sng 62 mv "$n".$$ "$n"
478     done
479     fi
480     if [ -e "$mainSplash" ];then
481     cp "$mainSplash" "$savePartitionMountPoint"/new-iso/isolinux/ocswp.png
482 sng 63 if [ -e "$restoreSplash" ];then
483     cp "$restoreSplash" "$savePartitionMountPoint"/new-iso/restorecd/default-restore-ocswp.png
484     cp "$restoreSplash" "$savePartitionMountPoint"/new-iso/restorecd/ocswp.png
485     fi
486 sng 62 fi
487    
488     cd "$savePartitionMountPoint"/new-iso
489    
490     if [ ! -z "$theLang" ];then
491     if [ "$theLang" = " " ];then theLang="";fi
492     if [ "$theLang" = "ASK" ];then theLang="";fi
493     for files in `find . -iname "*.cfg"`;do
494     sed "s|ocs_lang=[^ ]*|ocs_lang=\"$theLang\"|" "$files" > "$files".$$
495     mv "$files".$$ "$files"
496     done
497     fi
498    
499     if [ ! -z "$theKeymap" ];then
500     if [ "$theKeymap" = "ASK" ];then theKeymap="";fi
501     for files in `find . -iname "*.cfg"`;do
502     sed "s|ocs_live_keymap=[^ ]*|ocs_live_keymap=\"$theKeymap\"|" "$files" > "$files".$$
503     mv "$files".$$ "$files"
504     done
505     fi
506    
507     tar czf menu-iso.tar.gz $(find . -iname "*.cfg")
508     mv menu-iso.tar.gz restorecd
509     echo "done"
510    
511     [ -z "$keepFiles" ] || {
512     echo "The modified files can be found at: \"$savePartitionMountPoint/new-iso\""
513     cleanUp
514     exit
515     }
516    
517    
518     echo
519     echo
520     echo -n "Press ENTER to create the ISO file... "
521     read
522    
523     outputFile="$savePartitionMountPoint"/"$outputFile"
524    
525 sng 64 $MKISO -r -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat \
526 sng 62 -no-emul-boot -boot-load-size 4 -boot-info-table \
527     "$savePartitionMountPoint"/new-iso \
528     | \
529     (
530     case "$onTheFly" in
531     "y")
532     echo "Ready to burn your ISO file to CD"
533     echo "Place an empty disk in the writter and"
534     echo -n "press ENTER to continue... "
535     umount "$cdWritter" 2>/dev/null
536     eject "$cdWritter" 2>/dev/null
537     sleep 1
538     read
539     cdrecord dev="$cdWritter" -data -eject -v -
540     rc=$?
541     if [ "$rc" -gt 0 ]; then
542     echo " Error: CD burning failed!!!"
543     echo
544     cleanUp
545     exit 1
546     fi
547     echo
548     cleanUp
549     exit
550     ;;
551     *)
552     # use /dev/stdout as the bridge
553     cat - > "$outputFile"
554     rc=$?
555     if [ "$rc" -gt 0 ]; then
556     echo " Error: ISO file creation failed!!!"
557     cleanUp
558     exit 1
559     fi
560     [ -z "$deleteISO" ] && {
561     echo
562 sng 64 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 sng 62 echo "ISO file: \"$outputFile\""
573     };;
574     esac
575    
576     )
577    
578    
579     [ -z "$burnISO" ] || {
580     echo "Ready to burn your ISO file to CD"
581     echo "Place an empty disk in the writter and"
582     echo -n "press ENTER to continue... "
583     umount "$cdWritter" 2>/dev/null
584     eject "$cdWritter" 2>/dev/null
585     sleep 1
586     read
587     cdrecord dev="$cdWritter" -data -eject -v "$outputFile"
588     rc=$?
589     if [ "$rc" -gt 0 ]; then
590     echo " Error: CD burning failed!!!"
591     echo
592     cleanUp
593     exit 1
594     fi
595     }
596     [ -z "$deleteISO" ] || {
597     echo -n "Deleting ISO file... "
598     rm -rf "$outputFile" 2>/dev/null && echo "done" || echo "failed"
599     }
600 sng 63 # echo
601     # echo -n "Press ENTER to continue... "
602     # read
603 sng 62 cleanUp

Properties

Name Value
svn:executable *

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26