/[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 104 - (show annotations)
Mon Sep 6 14:09:54 2010 UTC (13 years, 6 months ago) by sng
File MIME type: application/x-sh
File size: 18717 byte(s)
fixing scripts...
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 set -x
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 mountOptions="-oro"
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" | sed 's|.* on \(.*\) type .*)|\1|')
408 fi
409 ##############################################################################
410
411
412
413
414 ##############################################################################
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 && newIsoCreated='y' || {
425 echo
426 echo " Error: Partition $savePartition is already mounted read-only"
427 exit 1
428 }
429 echo 'done'
430 else
431 doMountPartition
432 fi
433 ##############################################################################
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
442 echo -n "Copying files... "
443
444
445 if [ -z "$workingFromCD" ];then
446
447 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 else
458
459 for n in "$mountPoint"/*;do
460 if [ "$n" != "$savePartitionMountPoint" ] && [ "$n" != "/proc" \ && [ "$n" != "/sys" ];then
461 cp -r "mountPoint"/"$n" "$savePartitionMountPoint"/new-iso 2>/dev/null || {
462 echo "failed"
463 echo
464 cleanUp
465 exit 1
466 }
467 fi
468 done
469 fi
470
471 echo -n "Installing new files... "
472 if [ ! -z "$mainTitle" ];then
473 for n in $(find "$savePartitionMountPoint"/new-iso -iname "*.cfg");do
474 sed "s/^MENU TITLE *Clonezilla-SysRescCD .*$/MENU TITLE $mainTitle/" "$n" > "$n".$$
475 mv "$n".$$ "$n"
476 done
477 fi
478 if [ -e "$mainSplash" ];then
479 cp "$mainSplash" "$savePartitionMountPoint"/new-iso/isolinux/ocswp.png
480 cp "$mainSplash" "$savePartitionMountPoint"/new-iso/syslinux/ocswp.png
481 if [ -e "$restoreSplash" ];then
482 cp "$restoreSplash" "$savePartitionMountPoint"/new-iso/restorecd/default-restore-ocswp.png
483 cp "$restoreSplash" "$savePartitionMountPoint"/new-iso/restorecd/ocswp.png
484 fi
485 fi
486
487 cd "$savePartitionMountPoint"/new-iso
488
489 if [ ! -z "$theLang" ];then
490 if [ "$theLang" = " " ];then theLang="";fi
491 if [ "$theLang" = "ASK" ];then theLang="";fi
492 for files in `find . -iname "*.cfg"`;do
493 sed "s|ocs_lang=[^ ]*|ocs_lang=\"$theLang\"|" "$files" > "$files".$$
494 mv "$files".$$ "$files"
495 done
496 fi
497
498 if [ ! -z "$theKeymap" ];then
499 if [ "$theKeymap" = "ASK" ];then theKeymap="";fi
500 for files in `find . -iname "*.cfg"`;do
501 sed "s|ocs_live_keymap=[^ ]*|ocs_live_keymap=\"$theKeymap\"|" "$files" > "$files".$$
502 mv "$files".$$ "$files"
503 done
504 fi
505
506 tar czf menu-for-iso.tar.gz $(find . -iname "*.cfg")
507 mv menu-for-iso.tar.gz restorecd
508 echo "done"
509
510 [ -z "$keepFiles" ] || {
511 echo "The modified files can be found at: \"$savePartitionMountPoint/new-iso\""
512 cleanUp
513 exit
514 }
515
516
517 echo
518 echo
519 echo -n "Press ENTER to create the ISO file... "
520 read
521
522 outputFile="$savePartitionMountPoint"/"$outputFile"
523 genisoimage --version >/dev/null 2>&1 && MKISO=genisoimage || MKISO=mkisofs
524 $MKISO -r -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat \
525 -no-emul-boot -boot-load-size 4 -boot-info-table \
526 "$savePartitionMountPoint"/new-iso \
527 | \
528 (
529 case "$onTheFly" in
530 "y")
531 echo "Ready to burn your ISO file to CD"
532 echo "Place an empty disk in the writter and"
533 echo -n "press ENTER to continue... "
534 umount "$cdWritter" 2>/dev/null
535 eject "$cdWritter" 2>/dev/null
536 sleep 1
537 read
538 cdrecord dev="$cdWritter" -data -eject -v -
539 rc=$?
540 if [ "$rc" -gt 0 ]; then
541 echo " Error: CD burning failed!!!"
542 echo
543 cleanUp
544 exit 1
545 fi
546 echo
547 cleanUp
548 exit
549 ;;
550 *)
551 # use /dev/stdout as the bridge
552 cat - > "$outputFile"
553 rc=$?
554 if [ "$rc" -gt 0 ]; then
555 echo " Error: ISO file creation failed!!!"
556 cleanUp
557 exit 1
558 fi
559 [ -z "$deleteISO" ] && {
560 echo
561 echo -n "Looking for iohybrid executable... "
562 chIsoHyb=`type isohybrid 2>/dev/null`
563 if [ -n "$chIsoHyb" ];then
564 echo found
565 echo -n "Isohybriding $outFile... "
566 isohybrid "$outputFile"
567 echo 'done'
568 else
569 echo not found
570 fi
571 echo "ISO file: \"$outputFile\""
572 };;
573 esac
574
575 )
576
577
578 [ -z "$burnISO" ] || {
579 echo "Ready to burn your ISO file to CD"
580 echo "Place an empty disk in the writter and"
581 echo -n "press ENTER to continue... "
582 umount "$cdWritter" 2>/dev/null
583 eject "$cdWritter" 2>/dev/null
584 sleep 1
585 read
586 cdrecord dev="$cdWritter" -data -eject -v "$outputFile"
587 rc=$?
588 if [ "$rc" -gt 0 ]; then
589 echo " Error: CD burning failed!!!"
590 echo
591 cleanUp
592 exit 1
593 fi
594 }
595 [ -z "$deleteISO" ] || {
596 echo -n "Deleting ISO file... "
597 rm -rf "$outputFile" 2>/dev/null && echo "done" || echo "failed"
598 }
599 # echo
600 # echo -n "Press ENTER to continue... "
601 # read
602 cleanUp

Properties

Name Value
svn:executable *

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26