/[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 105 - (hide annotations)
Fri Sep 10 18:39:43 2010 UTC (10 years, 7 months ago) by sng
File MIME type: application/x-sh
File size: 18739 byte(s)
keep working on the 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 sng 103 if [ -e /live/image/restorecd/what-cd ] || [ -e /restorecd/what-cd ];then
89 sng 62 ClonezillaSysRescCDRunning='y'
90     fi
91     }
92    
93    
94     function cleanUp(){
95     cd
96     echo -n "Cleanning up... "
97 sng 103 [ -z "$inputFileMounted" ] || umount "$mountPoint" 2>/dev/null
98     [ -z "$savePartitionMounted" ] || umount "$savePartition" 2>/dev/null
99 sng 62 [ -z "$mountPointCreated" ] || rmdir "$mountPoint" 2>/dev/null
100     [ -z "$newIsoCreated" ] || {
101     [ -z "$keepFiles" ] && rm -rf "$savePartitionMountPoint"/new-iso 2>/dev/null
102     }
103     [ -z "$savePartitionMountPointCreated" ] || {
104     rmdir "$savePartitionMountPoint"/new-iso 2>/dev/null
105     rmdir "$savePartitionMountPoint" 2>/dev/null
106     }
107     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 103 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     while getopts ":i:o:s:r:t:fp:bdwnvhl:k:" Option
193     do
194     case $Option in
195     h)
196     printHelp
197     exit
198     ;;
199     v)
200     printVersion
201     exit
202     ;;
203     i) # input file or cdrom device
204     test "$(whoami)" = "root" || noRoot
205 sng 64 [ -e "$OPTARG" ] || {
206 sng 62 echo " Error: The specified file \"$OPTARG\" cannot be found"
207     exit 1
208     }
209     inputFile="$OPTARG"
210     if [ ! -z $(echo "$inputFile" | grep '/dev/') ];then
211     workingFromCD=1
212     fi
213     ;;
214     o) # output file
215     test "$(whoami)" = "root" || noRoot
216     touch "$OPTARG" 2>/dev/null || {
217     echo " Error: The specified file \"$OPTARG\" cannot be created!!!"
218     exit 1
219     }
220 sng 63 outputFile="$(basename "$OPTARG")"
221 sng 62 ;;
222     s) # boot splash screen
223     test "$(whoami)" = "root" || noRoot
224     [ -s "$OPTARG" ] || {
225     echo " Error: The specified file \"$OPTARG\" cannot be found"
226     exit 1
227     }
228     mainSplash="$OPTARG"
229     ;;
230     r) # restore splash screen
231     test "$(whoami)" = "root" || noRoot
232     [ -s "$OPTARG" ] || {
233     echo " Error: The specified file \"$OPTARG\" cannot be found"
234     exit 1
235     }
236     restoreSplash="$OPTARG"
237     ;;
238     t) # boot screen title (boot screen)
239     test "$(whoami)" = "root" || noRoot
240     mainTitle="$OPTARG"
241     ;;
242     p) # storage partition
243     if [ -z $(echo "$OPTARG" | grep '/dev/') ];then
244 sng 63 echo " Error: Parameter -p (storage partition) is not a valid partition"
245 sng 62 exit 1
246     fi
247     if [ -z "$(fdisk -l "$OPTARG" 2>/dev/null)" ];then
248 sng 64 echo " Error: Parameter -p (storage partition) is not a a valid partition"
249 sng 62 exit 1
250     fi
251     savePartition="$OPTARG"
252     ;;
253     b) # burn image to CD
254     test "$(whoami)" = "root" || noRoot
255     burnISO='y'
256     ;;
257     f) # burn ISO to CD on the fly
258     test "$(whoami)" = "root" || noRoot
259     onTheFly='y'
260     ;;
261     d) # delete image after burning to CD
262     test "$(whoami)" = "root" || noRoot
263     deleteISO='y'
264     burnISO='y'
265     ;;
266     w) # CD writter device
267     test "$(whoami)" = "root" || noRoot
268     if [ -z $(echo "$OPTARG" | grep '/dev/') ];then
269     echo " Error: Parameter -w (writter device) is not valid"
270     exit 1
271     fi
272     tmpDev=$(echo "$OPTARG" | sed 's|^/dev/||')
273     if [ $(cat /proc/sys/dev/cdrom/info | grep "$tmpDev" | wc -l) -ne 0 ];then
274     # not found as dev name
275     # is it a link?
276     tmpDev=$(ls -la "$OPTARG" | sed 's|.*-> ||')
277     if [ $(cat /proc/sys/dev/cdrom/info | grep "$tmpDev" | wc -l) -eq 0 ];then
278     echo " Error: Parameter -w (writter device) is not valid"
279     exit 1
280     fi
281     fi
282     cdWritter="$OPTARG"
283     ;;
284     t) # boot screen title (boot screen)
285     test "$(whoami)" = "root" || noRoot
286     mainTitle="$OPTARG"
287     ;;
288     n) # boot screen title (boot screen)
289     test "$(whoami)" = "root" || noRoot
290     keepFiles='y'
291     ;;
292     l)
293     test "$(whoami)" = "root" || noRoot
294     theLang="$OPTARG"
295     ;;
296     k)
297     test "$(whoami)" = "root" || noRoot
298     theKeymap="$OPTARG"
299     ;;
300     esac
301     done
302     shift $(($OPTIND - 1))
303     test "$(whoami)" = "root" || noRoot
304    
305     # Check parameters
306     [ -z "$inputFile" ] && {
307 sng 105 printHelp
308 sng 62 exit 1
309     }
310     [ -z "$mainSplash" ] || {
311     [ -z $(echo "$mainSplash" | grep -e '\.png$') ] && {
312     echo " Error: Boot splash screen (parameter -s) is not a png file!!!"
313     exit 1
314     }
315     boot=1
316     }
317     # } && {
318     # echo " Error: Parameter -s (boot splash screen) not specified!!!"
319     # exit 1
320     # }
321     [ -z "$restoreSplash" ] || {
322     [ -z $(echo "$restoreSplash" | grep -e '\.png$') ] && {
323     echo " Error: Restore splash screen (parameter -r) is not a png file!!!"
324     exit 1
325     }
326     } && {
327 sng 63 if [ -n "$boot" ];then
328 sng 62 echo " Error: Parameter -r (restore splash screen) not specified!!!"
329     exit 1
330     fi
331     }
332     # [ -z "$mainTitle" ] && {
333     # echo " Error: Parameter -t (boot screen title) not specified!!!"
334     # exit 1
335     # }
336     [ -z "$outputFile" ] && {
337     outputFile=$(basename "$0").$$.iso
338     burnISO='y'
339     deleteISO='y'
340     }
341    
342     [ -z "$savePartition" ] && {
343 sng 63 echo " Error: Parameter -p (storage partition) not specified!!!"
344 sng 62 exit 1
345     }
346    
347 sng 103 [ -n "$burnISO" ] && {
348 sng 62 [ -z "$cdWritter" ] && {
349     WHAT_CD=$(which what-cd)
350     [ -z "$WHAT_CD" ] && {
351     [ -e /root/.clonezilla-sysresccd/files/what-cd ] && {
352     WHAT_CD=/root/.clonezilla-sysresccd/files/what-cd
353 sng 63 chmod +x "$WHAT_CD"
354     cdWritter=$("$WHAT_CD" -bw)
355     [ -w "$cdWritter" ] || {
356 sng 62 echo " Error: Cannot determine your writter device name!!!"
357     exit 1
358     }
359     } || {
360     echo " Error: Parameter -w (writter device) not specified!!!"
361     exit 1
362     }
363     }
364     }
365     }
366     printVersion
367 sng 105 # set -x
368 sng 62 echo -n "Mounting files... "
369     isClonezillaSysRescCDRunning
370    
371 sng 63 ##############################################################################
372     # #
373     # Mount inputFile (ISO file or actual CD) #
374     # #
375     ##############################################################################
376 sng 62 if [ -z $(mount | grep "$inputFile" | sed "s|\(^[^ ]*\).*|\1|" | uniq) ];then
377     # mount the inputFile
378     if [ -z "$ClonezillaSysRescCDRunning" ];then
379     # working on host system
380     mountPoint=/root/tmp/mountPoint.$$
381     else
382     # working with ClonezillaSysRescCD
383     mountPoint=/mountPoint.$$
384     fi
385 sng 104 mountOptions="-oro"
386 sng 62 if [ -z "$workingFromCD" ];then
387     # working with ClonezillaSysRescCD image
388     mountOptions="-oloop"
389     fi
390     mkdir -p "$mountPoint" && mountPointCreated='y' || {
391     echo "failed"
392     echo
393     echo " Error: Temp folder \"$mountPoint\" cannot be created!!!"
394     exit 1
395     }
396    
397     mount "$inputFile" "$mountPoint" "$mountOptions" 2>/dev/null && inputFileMounted='y'
398     if [ -z "$inputFileMounted" ];then
399     echo "failed"
400     echo
401     echo " Error: \"$inputFile\" cannot be mounted!!!"
402     cleanUp
403     exit 1
404     fi
405     else
406     # our inputFile is mounted!!!
407 sng 104 mountPoint=$(mount | grep "$inputFile" | sed 's|.* on \(.*\) type .*)|\1|')
408 sng 62 fi
409 sng 63 ##############################################################################
410 sng 62
411    
412    
413    
414 sng 63 ##############################################################################
415     # #
416     # Check if savePartition is already mounted #
417     # #
418     ##############################################################################
419     if [ -n "$(mount | grep "$savePartition")" ];then
420     # it is mounted!!!
421     # can i write to it?
422     savePartitionMountPoint=$(mount | grep "$savePartition" | sed "s|"$savePartition" on \(.*\) type .*)|\1|")
423     rm -rf "$savePartitionMountPoint"/new-iso 2>/dev/null
424 sng 103 mkdir "$savePartitionMountPoint"/new-iso 2>/dev/null && newIsoCreated='y' || {
425 sng 62 echo
426 sng 63 echo " Error: Partition $savePartition is already mounted read-only"
427     exit 1
428     }
429     echo 'done'
430     else
431     doMountPartition
432 sng 62 fi
433 sng 63 ##############################################################################
434     # echo "mountPoint=$mountPoint"
435     # echo "workingFromCD=$workingFromCD"
436     # echo "ClonezillaSysRescCDRunning=$ClonezillaSysRescCDRunning"
437     # echo "savePartition=$savePartition"
438     # echo "savePartitionMountPoint=$savePartitionMountPoint"
439     # umount /dev/loop0
440     # exit
441 sng 62
442     echo -n "Copying files... "
443    
444 sng 64
445     if [ -z "$workingFromCD" ];then
446    
447 sng 62 cp -r "$mountPoint"/* "$savePartitionMountPoint"/new-iso 2>/dev/null && {
448     echo "done"
449     } || {
450     echo "failed"
451     echo
452     cleanUp
453     exit 1
454     }
455    
456    
457 sng 64 else
458    
459 sng 105 # if [ -z "$mountPoint" ];then
460     # echo "mountPoint is empty!!!"
461     # exit
462     # fi
463    
464 sng 64 for n in "$mountPoint"/*;do
465 sng 105 if [ "$n" != "$savePartitionMountPoint" ] && [ "$n" != "/proc" ] && [ "$n" != "/sys" ];then
466     cp -r "$n" "$savePartitionMountPoint"/new-iso 2>/dev/null || {
467 sng 64 echo "failed"
468     echo
469     cleanUp
470     exit 1
471     }
472     fi
473     done
474     fi
475    
476 sng 62 echo -n "Installing new files... "
477     if [ ! -z "$mainTitle" ];then
478     for n in $(find "$savePartitionMountPoint"/new-iso -iname "*.cfg");do
479 sng 64 sed "s/^MENU TITLE *Clonezilla-SysRescCD .*$/MENU TITLE $mainTitle/" "$n" > "$n".$$
480 sng 62 mv "$n".$$ "$n"
481     done
482     fi
483     if [ -e "$mainSplash" ];then
484     cp "$mainSplash" "$savePartitionMountPoint"/new-iso/isolinux/ocswp.png
485 sng 103 cp "$mainSplash" "$savePartitionMountPoint"/new-iso/syslinux/ocswp.png
486 sng 63 if [ -e "$restoreSplash" ];then
487     cp "$restoreSplash" "$savePartitionMountPoint"/new-iso/restorecd/default-restore-ocswp.png
488     cp "$restoreSplash" "$savePartitionMountPoint"/new-iso/restorecd/ocswp.png
489     fi
490 sng 62 fi
491    
492     cd "$savePartitionMountPoint"/new-iso
493    
494     if [ ! -z "$theLang" ];then
495     if [ "$theLang" = " " ];then theLang="";fi
496     if [ "$theLang" = "ASK" ];then theLang="";fi
497     for files in `find . -iname "*.cfg"`;do
498     sed "s|ocs_lang=[^ ]*|ocs_lang=\"$theLang\"|" "$files" > "$files".$$
499     mv "$files".$$ "$files"
500     done
501     fi
502    
503     if [ ! -z "$theKeymap" ];then
504     if [ "$theKeymap" = "ASK" ];then theKeymap="";fi
505     for files in `find . -iname "*.cfg"`;do
506     sed "s|ocs_live_keymap=[^ ]*|ocs_live_keymap=\"$theKeymap\"|" "$files" > "$files".$$
507     mv "$files".$$ "$files"
508     done
509     fi
510    
511 sng 93 tar czf menu-for-iso.tar.gz $(find . -iname "*.cfg")
512     mv menu-for-iso.tar.gz restorecd
513 sng 62 echo "done"
514    
515     [ -z "$keepFiles" ] || {
516     echo "The modified files can be found at: \"$savePartitionMountPoint/new-iso\""
517     cleanUp
518     exit
519     }
520    
521    
522     echo
523     echo
524     echo -n "Press ENTER to create the ISO file... "
525     read
526    
527     outputFile="$savePartitionMountPoint"/"$outputFile"
528 sng 103 genisoimage --version >/dev/null 2>&1 && MKISO=genisoimage || MKISO=mkisofs
529 sng 64 $MKISO -r -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat \
530 sng 62 -no-emul-boot -boot-load-size 4 -boot-info-table \
531     "$savePartitionMountPoint"/new-iso \
532     | \
533     (
534     case "$onTheFly" in
535     "y")
536     echo "Ready to burn your ISO file to CD"
537     echo "Place an empty disk in the writter and"
538     echo -n "press ENTER to continue... "
539     umount "$cdWritter" 2>/dev/null
540     eject "$cdWritter" 2>/dev/null
541     sleep 1
542     read
543     cdrecord dev="$cdWritter" -data -eject -v -
544     rc=$?
545     if [ "$rc" -gt 0 ]; then
546     echo " Error: CD burning failed!!!"
547     echo
548     cleanUp
549     exit 1
550     fi
551     echo
552     cleanUp
553     exit
554     ;;
555     *)
556     # use /dev/stdout as the bridge
557     cat - > "$outputFile"
558     rc=$?
559     if [ "$rc" -gt 0 ]; then
560     echo " Error: ISO file creation failed!!!"
561     cleanUp
562     exit 1
563     fi
564     [ -z "$deleteISO" ] && {
565     echo
566 sng 64 echo -n "Looking for iohybrid executable... "
567     chIsoHyb=`type isohybrid 2>/dev/null`
568     if [ -n "$chIsoHyb" ];then
569     echo found
570     echo -n "Isohybriding $outFile... "
571 sng 103 isohybrid "$outputFile"
572 sng 64 echo 'done'
573     else
574     echo not found
575     fi
576 sng 62 echo "ISO file: \"$outputFile\""
577     };;
578     esac
579    
580     )
581    
582    
583     [ -z "$burnISO" ] || {
584     echo "Ready to burn your ISO file to CD"
585     echo "Place an empty disk in the writter and"
586     echo -n "press ENTER to continue... "
587     umount "$cdWritter" 2>/dev/null
588     eject "$cdWritter" 2>/dev/null
589     sleep 1
590     read
591     cdrecord dev="$cdWritter" -data -eject -v "$outputFile"
592     rc=$?
593     if [ "$rc" -gt 0 ]; then
594     echo " Error: CD burning failed!!!"
595     echo
596     cleanUp
597     exit 1
598     fi
599     }
600     [ -z "$deleteISO" ] || {
601     echo -n "Deleting ISO file... "
602     rm -rf "$outputFile" 2>/dev/null && echo "done" || echo "failed"
603     }
604 sng 63 # echo
605     # echo -n "Press ENTER to continue... "
606     # read
607 sng 62 cleanUp

Properties

Name Value
svn:executable *

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26