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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 58 - (hide annotations)
Tue May 25 09:02:17 2010 UTC (11 years, 5 months ago) by sng
File size: 14697 byte(s)
Working on new SystemRescueCD CFG file and fixing misc stuff

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26