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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 103 - (show annotations)
Wed Aug 25 11:40:55 2010 UTC (13 years, 7 months ago) by sng
File MIME type: application/x-sh
File size: 18690 byte(s)
adapting patch-clonezilla-sysresccd to latest CDs
1 ##############################################################################
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 (C) 2008-2010, Spiros Georgaras <sng@hellug.gr>
56
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/restorecd/what-cd ] || [ -e /restorecd/what-cd ];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 "$savePartitionMounted" ] || umount "$savePartition" 2>/dev/null
99 [ -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 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"
185 ##############################################################################
186 }
187
188
189
190 ####### 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 [ -e "$OPTARG" ] || {
206 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 outputFile="$(basename "$OPTARG")"
221 ;;
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 echo " Error: Parameter -p (storage partition) is not a valid partition"
245 exit 1
246 fi
247 if [ -z "$(fdisk -l "$OPTARG" 2>/dev/null)" ];then
248 echo " Error: Parameter -p (storage partition) is not a a valid partition"
249 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 echo " Error: Parameter -i (input file) not specified!!!"
308 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 if [ -n "$boot" ];then
328 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 echo " Error: Parameter -p (storage partition) not specified!!!"
344 exit 1
345 }
346
347 [ -n "$burnISO" ] && {
348 [ -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 chmod +x "$WHAT_CD"
354 cdWritter=$("$WHAT_CD" -bw)
355 [ -w "$cdWritter" ] || {
356 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
368 echo -n "Mounting files... "
369 isClonezillaSysRescCDRunning
370
371 ##############################################################################
372 # #
373 # Mount inputFile (ISO file or actual CD) #
374 # #
375 ##############################################################################
376 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 if [ -z "$workingFromCD" ];then
386 # working with ClonezillaSysRescCD image
387 mountOptions="-oloop"
388 fi
389 mkdir -p "$mountPoint" && mountPointCreated='y' || {
390 echo "failed"
391 echo
392 echo " Error: Temp folder \"$mountPoint\" cannot be created!!!"
393 exit 1
394 }
395
396 mount "$inputFile" "$mountPoint" "$mountOptions" 2>/dev/null && inputFileMounted='y'
397 if [ -z "$inputFileMounted" ];then
398 echo "failed"
399 echo
400 echo " Error: \"$inputFile\" cannot be mounted!!!"
401 cleanUp
402 exit 1
403 fi
404 else
405 # our inputFile is mounted!!!
406 mountPoint=$(mount | grep "$inputFile" | grep 's|.* on \(.*\) type .*)|\1|')
407 fi
408 ##############################################################################
409
410
411
412
413 ##############################################################################
414 # #
415 # Check if savePartition is already mounted #
416 # #
417 ##############################################################################
418 if [ -n "$(mount | grep "$savePartition")" ];then
419 # it is mounted!!!
420 # can i write to it?
421 savePartitionMountPoint=$(mount | grep "$savePartition" | sed "s|"$savePartition" on \(.*\) type .*)|\1|")
422 rm -rf "$savePartitionMountPoint"/new-iso 2>/dev/null
423 mkdir "$savePartitionMountPoint"/new-iso 2>/dev/null && newIsoCreated='y' || {
424 echo
425 echo " Error: Partition $savePartition is already mounted read-only"
426 exit 1
427 }
428 echo 'done'
429 else
430 doMountPartition
431 fi
432 ##############################################################################
433 # echo "mountPoint=$mountPoint"
434 # echo "workingFromCD=$workingFromCD"
435 # echo "ClonezillaSysRescCDRunning=$ClonezillaSysRescCDRunning"
436 # echo "savePartition=$savePartition"
437 # echo "savePartitionMountPoint=$savePartitionMountPoint"
438 # umount /dev/loop0
439 # exit
440
441 echo -n "Copying files... "
442
443
444 if [ -z "$workingFromCD" ];then
445
446 cp -r "$mountPoint"/* "$savePartitionMountPoint"/new-iso 2>/dev/null && {
447 echo "done"
448 } || {
449 echo "failed"
450 echo
451 cleanUp
452 exit 1
453 }
454
455
456 else
457
458 for n in "$mountPoint"/*;do
459 if [ "$n" != "$savePartitionMountPoint" ] && [ "$n" != "/proc" \ && [ "$n" != "/sys" ];then
460 cp -r "mountPoint"/"$n" "$savePartitionMountPoint"/new-iso 2>/dev/null || {
461 echo "failed"
462 echo
463 cleanUp
464 exit 1
465 }
466 fi
467 done
468 fi
469
470 echo -n "Installing new files... "
471 if [ ! -z "$mainTitle" ];then
472 for n in $(find "$savePartitionMountPoint"/new-iso -iname "*.cfg");do
473 sed "s/^MENU TITLE *Clonezilla-SysRescCD .*$/MENU TITLE $mainTitle/" "$n" > "$n".$$
474 mv "$n".$$ "$n"
475 done
476 fi
477 if [ -e "$mainSplash" ];then
478 cp "$mainSplash" "$savePartitionMountPoint"/new-iso/isolinux/ocswp.png
479 cp "$mainSplash" "$savePartitionMountPoint"/new-iso/syslinux/ocswp.png
480 if [ -e "$restoreSplash" ];then
481 cp "$restoreSplash" "$savePartitionMountPoint"/new-iso/restorecd/default-restore-ocswp.png
482 cp "$restoreSplash" "$savePartitionMountPoint"/new-iso/restorecd/ocswp.png
483 fi
484 fi
485
486 cd "$savePartitionMountPoint"/new-iso
487
488 if [ ! -z "$theLang" ];then
489 if [ "$theLang" = " " ];then theLang="";fi
490 if [ "$theLang" = "ASK" ];then theLang="";fi
491 for files in `find . -iname "*.cfg"`;do
492 sed "s|ocs_lang=[^ ]*|ocs_lang=\"$theLang\"|" "$files" > "$files".$$
493 mv "$files".$$ "$files"
494 done
495 fi
496
497 if [ ! -z "$theKeymap" ];then
498 if [ "$theKeymap" = "ASK" ];then theKeymap="";fi
499 for files in `find . -iname "*.cfg"`;do
500 sed "s|ocs_live_keymap=[^ ]*|ocs_live_keymap=\"$theKeymap\"|" "$files" > "$files".$$
501 mv "$files".$$ "$files"
502 done
503 fi
504
505 tar czf menu-for-iso.tar.gz $(find . -iname "*.cfg")
506 mv menu-for-iso.tar.gz restorecd
507 echo "done"
508
509 [ -z "$keepFiles" ] || {
510 echo "The modified files can be found at: \"$savePartitionMountPoint/new-iso\""
511 cleanUp
512 exit
513 }
514
515
516 echo
517 echo
518 echo -n "Press ENTER to create the ISO file... "
519 read
520
521 outputFile="$savePartitionMountPoint"/"$outputFile"
522 genisoimage --version >/dev/null 2>&1 && MKISO=genisoimage || MKISO=mkisofs
523 $MKISO -r -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat \
524 -no-emul-boot -boot-load-size 4 -boot-info-table \
525 "$savePartitionMountPoint"/new-iso \
526 | \
527 (
528 case "$onTheFly" in
529 "y")
530 echo "Ready to burn your ISO file to CD"
531 echo "Place an empty disk in the writter and"
532 echo -n "press ENTER to continue... "
533 umount "$cdWritter" 2>/dev/null
534 eject "$cdWritter" 2>/dev/null
535 sleep 1
536 read
537 cdrecord dev="$cdWritter" -data -eject -v -
538 rc=$?
539 if [ "$rc" -gt 0 ]; then
540 echo " Error: CD burning failed!!!"
541 echo
542 cleanUp
543 exit 1
544 fi
545 echo
546 cleanUp
547 exit
548 ;;
549 *)
550 # use /dev/stdout as the bridge
551 cat - > "$outputFile"
552 rc=$?
553 if [ "$rc" -gt 0 ]; then
554 echo " Error: ISO file creation failed!!!"
555 cleanUp
556 exit 1
557 fi
558 [ -z "$deleteISO" ] && {
559 echo
560 echo -n "Looking for iohybrid executable... "
561 chIsoHyb=`type isohybrid 2>/dev/null`
562 if [ -n "$chIsoHyb" ];then
563 echo found
564 echo -n "Isohybriding $outFile... "
565 isohybrid "$outputFile"
566 echo 'done'
567 else
568 echo not found
569 fi
570 echo "ISO file: \"$outputFile\""
571 };;
572 esac
573
574 )
575
576
577 [ -z "$burnISO" ] || {
578 echo "Ready to burn your ISO file to CD"
579 echo "Place an empty disk in the writter and"
580 echo -n "press ENTER to continue... "
581 umount "$cdWritter" 2>/dev/null
582 eject "$cdWritter" 2>/dev/null
583 sleep 1
584 read
585 cdrecord dev="$cdWritter" -data -eject -v "$outputFile"
586 rc=$?
587 if [ "$rc" -gt 0 ]; then
588 echo " Error: CD burning failed!!!"
589 echo
590 cleanUp
591 exit 1
592 fi
593 }
594 [ -z "$deleteISO" ] || {
595 echo -n "Deleting ISO file... "
596 rm -rf "$outputFile" 2>/dev/null && echo "done" || echo "failed"
597 }
598 # echo
599 # echo -n "Press ENTER to continue... "
600 # read
601 cleanUp

Properties

Name Value
svn:executable *

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26