/[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 63 - (hide annotations)
Wed May 26 20:30:21 2010 UTC (13 years, 10 months ago) by sng
File MIME type: application/x-sh
File size: 17779 byte(s)
updating the ISO creation 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 "$inputFileMounted" ] || umount "$mountPoint" 2>/dev/null
98     [ -z "$mountPointCreated" ] || rmdir "$mountPoint" 2>/dev/null
99     [ -z "$savePartitionMounted" ] || umount "$savePartition" 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     savePartitionMountPoint=/root/tmp/savePartition.$$
147     else
148     savePartitionMountPoint=/savePartition.$$
149     fi
150     mkdir -p "$savePartitionMountPoint" 2>/dev/null && savePartitionMountPointCreated='y' || {
151     echo
152     echo " Error: Temp folder \"$savePartitionMountPoint\" cannot be created!!!"
153     cleanUp
154     exit 1
155     }
156    
157     ##############################################################################
158    
159    
160     ##############################################################################
161     # #
162     # Mount partition #
163     # #
164     ##############################################################################
165     unset savePartitionMounted
166     # mount partition
167     $mountCommand "$savePartition" "$savePartitionMountPoint" 2>/dev/null && savePartitionMounted='y'
168     # is it mounted?
169     if [ -z "$savePartitionMounted" ];then
170     echo
171     echo " Error: \"$savePartition\" cannot be mounted!!!"
172     cleanUp
173     exit 1
174     fi
175     # is it writeable?
176     rm -rf "$savePartitionMountPoint"/new-iso 2>/dev/null
177     mkdir "$savePartitionMountPoint"/new-iso 2>/dev/null || {
178     echo
179     echo " Error: Partition $savePartition is mounted read-only"
180     exit 1
181     }
182     echo "done"
183     ##############################################################################
184     }
185    
186    
187    
188 sng 62 ####### Script starts here #######
189    
190     # set -x
191     while getopts ":i:o:s:r:t:fp:bdwnvhl:k:" Option
192     do
193     case $Option in
194     h)
195     printHelp
196     exit
197     ;;
198     v)
199     printVersion
200     exit
201     ;;
202     i) # input file or cdrom device
203     test "$(whoami)" = "root" || noRoot
204     [ -s "$OPTARG" ] || {
205     echo " Error: The specified file \"$OPTARG\" cannot be found"
206     exit 1
207     }
208     inputFile="$OPTARG"
209     if [ ! -z $(echo "$inputFile" | grep '/dev/') ];then
210     workingFromCD=1
211     fi
212     ;;
213     o) # output file
214     test "$(whoami)" = "root" || noRoot
215     touch "$OPTARG" 2>/dev/null || {
216     echo " Error: The specified file \"$OPTARG\" cannot be created!!!"
217     exit 1
218     }
219 sng 63 outputFile="$(basename "$OPTARG")"
220 sng 62 ;;
221     s) # boot splash screen
222     test "$(whoami)" = "root" || noRoot
223     [ -s "$OPTARG" ] || {
224     echo " Error: The specified file \"$OPTARG\" cannot be found"
225     exit 1
226     }
227     mainSplash="$OPTARG"
228     ;;
229     r) # restore splash screen
230     test "$(whoami)" = "root" || noRoot
231     [ -s "$OPTARG" ] || {
232     echo " Error: The specified file \"$OPTARG\" cannot be found"
233     exit 1
234     }
235     restoreSplash="$OPTARG"
236     ;;
237     t) # boot screen title (boot screen)
238     test "$(whoami)" = "root" || noRoot
239     mainTitle="$OPTARG"
240     ;;
241     p) # storage partition
242     if [ -z $(echo "$OPTARG" | grep '/dev/') ];then
243 sng 63 echo " Error: Parameter -p (storage partition) is not a valid partition"
244 sng 62 exit 1
245     fi
246     if [ -z "$(fdisk -l "$OPTARG" 2>/dev/null)" ];then
247     echo " Error: Parameter -c (storage partition) is not a a valid partition"
248     exit 1
249     fi
250     savePartition="$OPTARG"
251     ;;
252     b) # burn image to CD
253     test "$(whoami)" = "root" || noRoot
254     burnISO='y'
255     ;;
256     f) # burn ISO to CD on the fly
257     test "$(whoami)" = "root" || noRoot
258     onTheFly='y'
259     ;;
260     d) # delete image after burning to CD
261     test "$(whoami)" = "root" || noRoot
262     deleteISO='y'
263     burnISO='y'
264     ;;
265     w) # CD writter device
266     test "$(whoami)" = "root" || noRoot
267     if [ -z $(echo "$OPTARG" | grep '/dev/') ];then
268     echo " Error: Parameter -w (writter device) is not valid"
269     exit 1
270     fi
271     tmpDev=$(echo "$OPTARG" | sed 's|^/dev/||')
272     if [ $(cat /proc/sys/dev/cdrom/info | grep "$tmpDev" | wc -l) -ne 0 ];then
273     # not found as dev name
274     # is it a link?
275     tmpDev=$(ls -la "$OPTARG" | sed 's|.*-> ||')
276     if [ $(cat /proc/sys/dev/cdrom/info | grep "$tmpDev" | wc -l) -eq 0 ];then
277     echo " Error: Parameter -w (writter device) is not valid"
278     exit 1
279     fi
280     fi
281     cdWritter="$OPTARG"
282     ;;
283     t) # boot screen title (boot screen)
284     test "$(whoami)" = "root" || noRoot
285     mainTitle="$OPTARG"
286     ;;
287     n) # boot screen title (boot screen)
288     test "$(whoami)" = "root" || noRoot
289     keepFiles='y'
290     ;;
291     l)
292     test "$(whoami)" = "root" || noRoot
293     theLang="$OPTARG"
294     ;;
295     k)
296     test "$(whoami)" = "root" || noRoot
297     theKeymap="$OPTARG"
298     ;;
299     esac
300     done
301     shift $(($OPTIND - 1))
302     test "$(whoami)" = "root" || noRoot
303    
304     # Check parameters
305     [ -z "$inputFile" ] && {
306     echo " Error: Parameter -i (input file) not specified!!!"
307     exit 1
308     }
309     [ -z "$mainSplash" ] || {
310     [ -z $(echo "$mainSplash" | grep -e '\.png$') ] && {
311     echo " Error: Boot splash screen (parameter -s) is not a png file!!!"
312     exit 1
313     }
314     boot=1
315     }
316     # } && {
317     # echo " Error: Parameter -s (boot splash screen) not specified!!!"
318     # exit 1
319     # }
320     [ -z "$restoreSplash" ] || {
321     [ -z $(echo "$restoreSplash" | grep -e '\.png$') ] && {
322     echo " Error: Restore splash screen (parameter -r) is not a png file!!!"
323     exit 1
324     }
325     } && {
326 sng 63 if [ -n "$boot" ];then
327 sng 62 echo " Error: Parameter -r (restore splash screen) not specified!!!"
328     exit 1
329     fi
330     }
331     # [ -z "$mainTitle" ] && {
332     # echo " Error: Parameter -t (boot screen title) not specified!!!"
333     # exit 1
334     # }
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 63 [ -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    
367     printVersion
368    
369     echo -n "Mounting files... "
370     isClonezillaSysRescCDRunning
371    
372 sng 63 ##############################################################################
373     # #
374     # Mount inputFile (ISO file or actual CD) #
375     # #
376     ##############################################################################
377 sng 62 if [ -z $(mount | grep "$inputFile" | sed "s|\(^[^ ]*\).*|\1|" | uniq) ];then
378     # mount the inputFile
379     if [ -z "$ClonezillaSysRescCDRunning" ];then
380     # working on host system
381     mountPoint=/root/tmp/mountPoint.$$
382     else
383     # working with ClonezillaSysRescCD
384     mountPoint=/mountPoint.$$
385     fi
386     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     mountPoint=$(mount | grep "$inputFile" | grep 's|.* on \(.*\) type .*)|\1|')
408     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     mkdir "$savePartitionMountPoint"/new-iso 2>/dev/null || {
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     cp -r "$mountPoint"/* "$savePartitionMountPoint"/new-iso 2>/dev/null && {
445     echo "done"
446     } || {
447     echo "failed"
448     echo
449     cleanUp
450     exit 1
451     }
452    
453    
454     echo -n "Installing new files... "
455     if [ ! -z "$mainTitle" ];then
456     for n in $(find "$savePartitionMountPoint"/new-iso -iname "*.cfg");do
457 sng 63 sed "0,/^MENU TITLE.*/s//MENU TITLE $mainTitle/" "$n" > "$n".$$
458 sng 62 mv "$n".$$ "$n"
459     done
460     fi
461     if [ -e "$mainSplash" ];then
462     cp "$mainSplash" "$savePartitionMountPoint"/new-iso/isolinux/ocswp.png
463 sng 63 if [ -e "$restoreSplash" ];then
464     cp "$restoreSplash" "$savePartitionMountPoint"/new-iso/restorecd/default-restore-ocswp.png
465     cp "$restoreSplash" "$savePartitionMountPoint"/new-iso/restorecd/ocswp.png
466     fi
467 sng 62 fi
468    
469     cd "$savePartitionMountPoint"/new-iso
470    
471     if [ ! -z "$theLang" ];then
472     if [ "$theLang" = " " ];then theLang="";fi
473     if [ "$theLang" = "ASK" ];then theLang="";fi
474     for files in `find . -iname "*.cfg"`;do
475     sed "s|ocs_lang=[^ ]*|ocs_lang=\"$theLang\"|" "$files" > "$files".$$
476     mv "$files".$$ "$files"
477     done
478     fi
479    
480     if [ ! -z "$theKeymap" ];then
481     if [ "$theKeymap" = "ASK" ];then theKeymap="";fi
482     for files in `find . -iname "*.cfg"`;do
483     sed "s|ocs_live_keymap=[^ ]*|ocs_live_keymap=\"$theKeymap\"|" "$files" > "$files".$$
484     mv "$files".$$ "$files"
485     done
486     fi
487    
488     tar czf menu-iso.tar.gz $(find . -iname "*.cfg")
489     mv menu-iso.tar.gz restorecd
490     echo "done"
491    
492     [ -z "$keepFiles" ] || {
493     echo "The modified files can be found at: \"$savePartitionMountPoint/new-iso\""
494     cleanUp
495     exit
496     }
497    
498    
499     echo
500     echo
501     echo -n "Press ENTER to create the ISO file... "
502     read
503    
504     outputFile="$savePartitionMountPoint"/"$outputFile"
505    
506     mkisofs -r -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat \
507     -no-emul-boot -boot-load-size 4 -boot-info-table \
508     "$savePartitionMountPoint"/new-iso \
509     | \
510     (
511     case "$onTheFly" in
512     "y")
513     echo "Ready to burn your ISO file to CD"
514     echo "Place an empty disk in the writter and"
515     echo -n "press ENTER to continue... "
516     umount "$cdWritter" 2>/dev/null
517     eject "$cdWritter" 2>/dev/null
518     sleep 1
519     read
520     cdrecord dev="$cdWritter" -data -eject -v -
521     rc=$?
522     if [ "$rc" -gt 0 ]; then
523     echo " Error: CD burning failed!!!"
524     echo
525     cleanUp
526     exit 1
527     fi
528     echo
529     cleanUp
530     exit
531     ;;
532     *)
533     # use /dev/stdout as the bridge
534     cat - > "$outputFile"
535     rc=$?
536     if [ "$rc" -gt 0 ]; then
537     echo " Error: ISO file creation failed!!!"
538     cleanUp
539     exit 1
540     fi
541     [ -z "$deleteISO" ] && {
542     echo
543     echo "ISO file: \"$outputFile\""
544     };;
545     esac
546    
547     )
548    
549    
550     [ -z "$burnISO" ] || {
551     echo "Ready to burn your ISO file to CD"
552     echo "Place an empty disk in the writter and"
553     echo -n "press ENTER to continue... "
554     umount "$cdWritter" 2>/dev/null
555     eject "$cdWritter" 2>/dev/null
556     sleep 1
557     read
558     cdrecord dev="$cdWritter" -data -eject -v "$outputFile"
559     rc=$?
560     if [ "$rc" -gt 0 ]; then
561     echo " Error: CD burning failed!!!"
562     echo
563     cleanUp
564     exit 1
565     fi
566     }
567     [ -z "$deleteISO" ] || {
568     echo -n "Deleting ISO file... "
569     rm -rf "$outputFile" 2>/dev/null && echo "done" || echo "failed"
570     }
571 sng 63 # echo
572     # echo -n "Press ENTER to continue... "
573     # read
574 sng 62 cleanUp

Properties

Name Value
svn:executable *

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26