/[clonezilla-sysresccd]/trunk/create-clonezilla-sysresccd/files/ocs-iso
ViewVC logotype

Annotation of /trunk/create-clonezilla-sysresccd/files/ocs-iso

Parent Directory Parent Directory | Revision Log Revision Log


Revision 47 - (hide annotations)
Thu May 20 12:12:53 2010 UTC (13 years, 10 months ago) by sng
File size: 36050 byte(s)
adding release scripts

1 sng 47 #!/bin/bash
2     # Author: Steven Shiau <steven _at_ nchc org tw>
3     # License: GPL
4     # Description: This program will put Debian Live minimal + DRBL/Clonezilla program into a bootable iso file.
5    
6     #
7     DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/opt/drbl/}"
8    
9     . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
10     . $DRBL_SCRIPT_PATH/conf/drbl-ocs.conf
11     . $DRBL_SCRIPT_PATH/sbin/ocs-functions
12    
13     # other default settings
14     # If insert_mode=prog_only, only copy DRBL/Clonezilla programs only, no ocs images.
15     insert_mode="prog_and_img"
16     img_size_sum=0
17     # Default to output the result to iso file, another vaule is cdwriter.
18     output_mode="file"
19     # If there is any file larger then 2GB, we need to turn on -allow-limited-size option for genisoimage. Actually it can be 4GB. Anyway, here we use 2GB. (man genisoimage for more details)
20     iso9660_file_size_limit="2000M" # For command "find" to find the file size (unit: Bytes)
21    
22     # Excluding list for mkisofs
23     # We will create it like this:
24     # -x $DEBIAN_ISO_TMP/isolinux -x $DEBIAN_ISO_TMP/md5sum.txt -x $DEBIAN_ISO_TMP/casper/memtest
25     # "home" should also be excluded since if it exists, it will conflict with the real home later we will merge. Ref: https://sourceforge.net/forum/message.php?msg_id=7599463 Thanks to Andrew Bloxom for this idea.
26     mkiso_exclude_list_1="isolinux md5sum.txt doc live etc pkg ocs-live.d utils"
27     mkiso_exclude_list_2="home" # This should not be a duplicated count.
28     mkiso_exclude_list="$mkiso_exclude_list_1 $mkiso_exclude_list_2"
29    
30     #
31     prog="$(basename $0)"
32     prog_option="$*"
33    
34     # functions
35     USAGE() {
36     echo "Usage:"
37     echo "To put clonezilla image into live CD:"
38     echo "$prog [OPTION] CLONEZILLA_IMAGE_NAME"
39     echo "OPTION:"
40     language_help_prompt_by_idx_no
41     echo "-a, --file-name-prefix NAME Assign the output file name as NAME.iso. $0 will auto append '.iso' in the end of filename."
42     echo "-b, --bg-mode [text|graphic] Assign the background of boot menu. Default is graphic"
43     echo "-m, --custom-ocs PATH/custom-ocs Use the customized ocs program 'custom-ocs' instead of the default one. Note! PATH should be assigned so that it can be found. This is advanced mode."
44     echo "-e, --extra-param PARAM Assign extra parameter PARAM for clonezilla live to run, PARAM will be appended when run in ocs-live-restore or ocs."
45     echo "-g, --ocs-live-language LANGUAGE Assign the language when using clonezilla live, available languages are en_US.UTF-8, zh_TW.UTF-8 "
46     echo "-k, --ocs-live-keymap KEYMAP Assign the keyboard when using clonezilla live. Use full path for KEYMAP, for example: /usr/share/keymaps/i386/azerty/fr.kmap.gz. If 'NONE' is used, the default one (US keyboard) will be use."
47     echo "-t, --ocs-live-batch Set clonezilla live to run in batch mode, usually it's for restoring. If this mode is set, some dialog question will be ignored."
48     echo "-i, --assign-version-no NO Assign the version no as NO instead of date. This only works when using with option -s."
49     echo "-j, --debian-iso ISO_FILE Assign Debian live template iso file name as ISO_FILE to be used to create Clonezilla live."
50     echo "-n, --debian-iso-etc-url-path ISO_ETC_FILE_URL Assign the url (Ex. http://localhost/clonezilla-live/template-iso) for Debian live template iso file as ISO_FILE_URL to be used to create Clonezilla live."
51     echo "-p, --image-path Assign the clonezilla image path where CLONEZILLA_IMAGE_NAME exists. Default = $ocsroot"
52     echo "-s, --skip-image Do not include any clonezilla image. The is used to created a live CD with DRBL/Clonezilla programs only."
53     echo "-f, --on-the-fly DEV Write the output to CD/DVD writer DEV (such as /dev/hdc) instead of creating an ISO file."
54     echo "-o, --normal-menu When a clonezilla image is inserted, by default only restore menu will be shown in the created ISO file. If you want to show normal menu, i.e. with save and restore menu, use this one."
55     echo "-x, --extra-boot-param EXTRA_PARAM Assign extra boot parameter EXTRA_PARAM for clonezilla live kernel to read. These parameters are the same with that from live-initramfs. Ex. \"noprompt\" can be use to not prompt to eject the CD on reboot."
56     echo "-u, --include-dir DIR Include a dir in the target iso file."
57     echo "--ocs-live-boot-menu-option EXTRA_OPTION Assign an extra option for ocs-live-boot-menu. //NOTE// Do not put '-' in this EXTRA_OPTION, $0 will add that automatically. e.g. if you want to add -s1 for ocs-live-boot-menu to run, use 's1' only."
58     echo "$prog will download a template Debian live CD for clonezilla iso file if ncecessary. You can also download it by yourself, and put it in the working directory when you run $prog. If you want to create that template iso file in Debian Etch, run create-debian-live."
59     echo "NOTE! Due to the limitation in mkisofs, this program does not work in clonezilla image file larger than $FILE_LIMIT MB."
60     echo "Ex:"
61     echo "To put clonezilla image sarge-ocs (located in /home/partimag in clonezilla server) to Live CD, you can run:"
62     echo " $prog sarge-ocs"
63     echo "To put more images, just append them, such as:"
64     echo " $prog sarge-ocs etch-ocs"
65     echo "To create a Live CD with DRBL/Clonezilla programs:"
66     echo " $prog -s"
67     echo "To specify the Debian live template iso, run like this:"
68     echo " $prog -j debian-live-for-ocs-1.0.1-3.iso -n http://localhost/clonezilla-live/template-iso/testing -s"
69     echo "To put clonezilla image sarge-ocs, etch-ocs to to Live CD, and write it to cd writer /dev/hdc, you can run:"
70     echo " $prog -f /dev/hdc sarge-ocs etch-ocs"
71     echo "To create an iso file for restoring with clonezilla image sarge-r5 builtin, and make it boot then restore the image sarge-r5 to hda in unattended mode (Only confirmation in the beginning), you can run:"
72     echo " $prog -g en_US.UTF-8 -t -k NONE -e \"-b -c restoredisk sarge-r5 hda\" sarge-r5"
73     echo "To create an iso file to run your own custom-ocs program:"
74     echo " $prog -g en_US.UTF-8 -k NONE -s -m ./custom-ocs"
75     }
76     #
77     check_file_size_in_ocs_image() {
78     local img_path="$1"
79     local size_t
80     for ifile in $img_path $img_path/*; do
81     size_t="$(du -Lms $ifile | awk -F" " '{print $1}')"
82     if [ "$size_t" -gt "$FILE_LIMIT" ]; then
83     ################################################################################
84     # Section edited by S. Georgaras <sng@hellug.gr>
85    
86     # [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
87     # echo "$ifile size ($size_t MB) is too large! $msg_mkisofs_unable_process_that"
88     # echo "$msg_unable_to_create_clonezilla_img_iso"
89     # [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
90     # exit 1
91     whiptail --backtitle Clonezilla-SysRescCD --title ' Excessive Image Size ' --yesno "The image file \"$(basename ${ifile%/})\" is too large ($size_t MB) and cannot be processed!!!
92    
93     Do you want to create a 8GB DVD instead?" 0 60
94     if [ $? -eq 1 ];then
95     exit 1
96     fi
97     going2RAM="prog_only"
98     break
99     ################################################################################
100     fi
101     done
102     }
103    
104     #
105     clean_tmp_dir() {
106     [ -d "$ISOLNX_TMP" -a -n "$ISOLNX_TMP" ] && rm -rf $ISOLNX_TMP
107     [ -d "$WD_TMP" -a -n "$WD_TMP" ] && rm -rf $WD_TMP
108     [ -d "$DEBIAN_ISO_TMP" ] && umount $DEBIAN_ISO_TMP &>/dev/null && rm -rf $DEBIAN_ISO_TMP
109     } # End of clean_tmp_dir
110    
111     #
112     check_if_root
113    
114     # default settings:
115     ocs_live_batch="no"
116     custom_ocs=""
117     normal_menu_with_insert_image="no"
118     template_mode=""
119    
120     # Parse command-line options
121     while [ $# -gt 0 ]; do
122     case "$1" in
123     -a|--file-name-prefix)
124     shift
125     if [ -z "$(echo $1 |grep ^-.)" ]; then
126     # skip the -xx option, in case
127     target_iso_prefix="$1"
128     shift
129     fi
130     [ -z "$target_iso_prefix" ] && USAGE && exit 1
131     ;;
132     -l|--language)
133     shift
134     if [ -z "$(echo $1 |grep ^-.)" ]; then
135     # skip the -xx option, in case
136     specified_lang="$1"
137     shift
138     fi
139     [ -z "$specified_lang" ] && USAGE && exit 1
140     ;;
141     -b|--bg-mode)
142     shift
143     if [ -z "$(echo $1 |grep ^-.)" ]; then
144     # skip the -xx option, in case
145     bg_mode="$1"
146     shift
147     fi
148     [ -z "$bg_mode" ] && USAGE && exit 1
149     ;;
150     -m|--custom-ocs)
151     shift
152     if [ -z "$(echo $1 |grep ^-.)" ]; then
153     # skip the -xx option, in case
154     custom_ocs="$1"
155     shift
156     fi
157     [ -z "$custom_ocs" ] && USAGE && exit 1
158     ;;
159     -e|--extra-param)
160     shift
161     # extra param might begin with -, i.e. Ex. -b -p true. Therefore we should not skip this.
162     ocs_live_extra_param="$1"
163     shift
164     [ -z "$ocs_live_extra_param" ] && USAGE && exit 1
165     ;;
166     -i|--assign-version-no)
167     shift
168     if [ -z "$(echo $1 |grep ^-.)" ]; then
169     # skip the -xx option, in case
170     version_no="$1"
171     shift
172     fi
173     [ -z "$version_no" ] && USAGE && exit 1
174     ;;
175     -g|--ocs-live-language)
176     shift
177     if [ -z "$(echo $1 |grep ^-.)" ]; then
178     # skip the -xx option, in case
179     ocs_lang="$1"
180     shift
181     fi
182     [ -z "$ocs_lang" ] && USAGE && exit 1
183     ;;
184     -k|--ocs-live-keymap)
185     shift
186     if [ -z "$(echo $1 |grep ^-.)" ]; then
187     # skip the -xx option, in case
188     ocs_live_keymap="$1"
189     shift
190     fi
191     [ -z "$ocs_live_keymap" ] && USAGE && exit 1
192     ;;
193     -p|--image-path)
194     shift
195     if [ -z "$(echo $1 |grep ^-.)" ]; then
196     # skip the -xx option, in case
197     image_path="$1"
198     shift
199     fi
200     [ -z "$image_path" ] && USAGE && exit 1
201     ;;
202     -s|--skip-image)
203     insert_mode="prog_only"
204     shift ;;
205     -t|--ocs-live-batch)
206     ocs_live_batch="yes"
207     shift ;;
208     -o|--normal-menu)
209     normal_menu_with_insert_image="yes"
210     shift ;;
211     -f|--on-the-fly)
212     shift
213     output_mode="cdwriter"
214     if [ -z "$(echo $1 |grep ^-.)" ]; then
215     # skip the -xx option, in case
216     output_dev="$1"
217     shift
218     fi
219     [ -z "$output_dev" ] && USAGE && exit 1
220     ;;
221     -j|--debian-iso)
222     shift
223     if [ -z "$(echo $1 |grep ^-.)" ]; then
224     # skip the -xx option, in case
225     DEBIAN_ISO="$1"
226     template_mode="from-download-live-media"
227     shift
228     fi
229     [ -z "$DEBIAN_ISO" ] && USAGE && exit 1
230     ;;
231     -n|--debian-iso-etc-url-path)
232     shift
233     if [ -z "$(echo $1 |grep ^-.)" ]; then
234     # skip the -xx option, in case
235     DEBIAN_ISO_ETC_PATH="$1"
236     shift
237     fi
238     [ -z "$DEBIAN_ISO_ETC_PATH" ] && USAGE && exit 1
239     ;;
240     -x|--extra-boot-param)
241     shift
242     if [ -z "$(echo $1 |grep ^-.)" ]; then
243     # skip the -xx option, in case
244     live_extra_boot_param="$1"
245     shift
246     fi
247     [ -z "$live_extra_boot_param" ] && USAGE && exit 1
248     ;;
249     --ocs-live-boot-menu-option)
250     shift
251     if [ -z "$(echo $1 |grep ^-.)" ]; then
252     # skip the -xx option, in case
253     ocs_live_boot_menu_option="$1"
254     shift
255     fi
256     [ -z "$ocs_live_boot_menu_option" ] && USAGE && exit 1
257     ;;
258     -u|--include-dir)
259     shift
260     if [ -z "$(echo $1 |grep ^-.)" ]; then
261     # skip the -xx option, in case
262     include_dir="$1"
263     include_dir_graft_point="$include_dir=$include_dir"
264     shift
265     fi
266     [ -z "$include_dir" ] && USAGE && exit 1
267     ;;
268     -*) echo "${0}: ${1}: invalid option" >&2
269     USAGE >& 2
270     exit 2 ;;
271     *) break ;;
272     esac
273     done
274     ocs_image="$*"
275     # strip the / to avoid problem
276     ocs_image="$(echo $ocs_image | sed -e "s|/||g")"
277    
278     [ -z "$ocs_image" -a "$insert_mode" = "prog_and_img" ] && USAGE && exit 1
279     [ -z "$image_path" ] && image_path=$ocsroot
280     [ -z "$bg_mode" ] && bg_mode="$BG_MODE_DEF"
281     [ -z "$DEBIAN_ISO_ETC_PATH" ] && DEBIAN_ISO_ETC_PATH="$DEBIAN_ISO_ETC_PATH_DEF"
282     [ -z "$DEBIAN_ISO" ] && DEBIAN_ISO="$DEBIAN_ISO_DEF"
283     [ -n "$ocs_live_boot_menu_option" ] && ocs_live_boot_menu_option="-$ocs_live_boot_menu_option"
284     DEBIAN_ISO_URL="$DEBIAN_ISO_ETC_PATH/$DEBIAN_ISO"
285     md5_file_url="$DEBIAN_ISO_ETC_PATH/$md5_file"
286    
287     #
288     ask_and_load_lang_set $specified_lang
289    
290     #
291     if ! type genisoimage &>/dev/null; then
292     [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
293     echo "Program genisoimage not found!"
294     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
295     echo "$msg_program_stop"
296     exit 1
297     fi
298    
299     if [ "$output_mode" = "cdwriter" -a type wodim &>/dev/null ]; then
300     [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
301     echo "Program wodim is not aviailable! You have to install it."
302     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
303     echo "$msg_program_stop"
304     exit 1
305     fi
306    
307     if [ -n "$custom_ocs" -a ! -e "$custom_ocs" ]; then
308     [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
309     echo "File $custom_ocs not found!"
310     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
311     echo "$msg_program_stop"
312     exit 1
313     fi
314    
315     # Format the lang variable. This is for clonezilla live running, not for ocs-iso.
316     case "$ocs_lang" in
317     zh_TW.BIG5|zh_TW.big5|tw.BIG5)
318     [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
319     echo "For Traditional Chinese locale, Clonezilla live only supports unicode (zh_TW.UTF-8), not Big5 encoding (zh_TW.BIG5). Force to use UTF-8 for Traditional Chinese in Clonezilla live."
320     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
321     ocs_lang="zh_TW.UTF-8" ;;
322     zh_TW.UTF-8|zh_TW.utf8|tw.UTF-8|tw.utf8)
323     ocs_lang="zh_TW.UTF-8" ;;
324     esac
325    
326     # Decide where is the $LIVE_MEDIA
327     get_live_media_mnt_point &>/dev/null
328    
329     # Some temp dirs
330     # Thanks to Orgad Shaneh. Since the temp files from Clonezilla live won't take too much space, we just use /tmp/ to store these temp files.
331     #if [ -w ./ ]; then
332     # ISOLNX_TMP="$(mktemp -d ./isolnx.XXXXXX)"
333     # WD_TMP="$(mktemp -d ./iso_wd.XXXXXX)"
334     #else
335     # ISOLNX_TMP="$(mktemp -d /tmp/isolnx.XXXXXX)"
336     # WD_TMP="$(mktemp -d /tmp/iso_wd.XXXXXX)"
337     #fi
338     ISOLNX_TMP="$(mktemp -d /tmp/isolnx.XXXXXX)"
339     WD_TMP="$(mktemp -d /tmp/iso_wd.XXXXXX)"
340    
341     #
342     trap clean_tmp_dir HUP INT QUIT TERM EXIT
343    
344     # Try to find if it is running on live cd/usb already
345     if [ -z "$template_mode" ]; then
346     if [ -n "$LIVE_MEDIA" ]; then
347     # It's running from Clonezilla live media, use the existing resource
348     template_mode="from-booting-live-media"
349     [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
350     echo "Found a Clonezilla live media... Will use that as a template..."
351     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
352     else
353     template_mode="from-downloaded-live-media"
354     [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
355     echo "No Clonezilla live media was found... Will use the downloaded template from Clonezilla repository..."
356     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
357     fi
358     fi
359    
360     if [ "$template_mode" = "from-downloaded-live-media" ]; then
361     if [ ! -f "$DEBIAN_ISO" ]; then
362     echo "We need Debian live CD for Clonnezilla to create clonezilla cd."
363     echo "Downloadling the iso file from $DEBIAN_ISO_URL..."
364     wget $DEBIAN_ISO_URL
365     get_iso_rc=$?
366     # validate it
367     if [ "$get_iso_rc" -eq 0 ]; then
368     echo -n "Validating $DEBIAN_ISO... "
369     md5_tmp="$(mktemp -d /tmp/isomd5.XXXXX)"
370     # wget http://opensource.nchc.org.tw/drbl-core/iso/MD5SUMS
371     echo -n "Downloading $md5_file_url... "
372     wget $wget_opt -P "$md5_tmp" $md5_file_url
373     if ! grep -w "$DEBIAN_ISO" $md5_tmp/MD5SUMS | md5sum -c; then
374     [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
375     echo "$DEBIAN_ISO is broken! Something went wrong! Try to remove $DEBIAN_ISO and run this program again."
376     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
377     echo "$msg_program_stop"
378     exit 1
379     fi
380     else
381     [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
382     echo "Unable to download $DEBIAN_ISO_URL!"
383     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
384     echo "$msg_program_stop"
385     exit 1
386     fi
387     else
388     echo "A template iso ($DEBIAN_ISO) was found!"
389     fi
390     fi
391    
392     allow_limited_size_flag=""
393     if [ "$insert_mode" = "prog_and_img" ]; then
394     # 2 cases:
395     # (1) normal_menu_with_insert_image=no, i.e. only restore menu. ocs-live-restore is the main program.
396     # If it's not batch mode for clonezilla live (especially for restoring), by default we have to append "-x --restore-only", and especially before any other parameters, so that ocs-sr will run like:
397     # ocs-sr -l $ocs_lang -p true -x --restore-only -b restoredisk sarge_image
398     # (2) normal_menu_with_insert_image=yes, i.e. normal menu. ocs-live-general is the main program. Threfore no extra param.
399     if [ "$ocs_live_batch" = "no" ]; then
400     case "$normal_menu_with_insert_image" in
401     no) ocs_live_extra_param="-x --restore-only $ocs_live_extra_param" ;;
402     yes) ocs_live_extra_param="" ;;
403     esac
404     fi
405    
406     echo "Creating clonezilla ISO with image(s) $ocs_image from $image_path..."
407     # here we put ocs-live-restore as ocs-live inside live cd, and it will be shown as /$LIVE_MEDIA/ocs-live when using in running live CD.
408     # use the 1st image name as iso filename
409     iso_label_tag="$(echo $ocs_image | awk -F" " '{print $1}')"
410     # mkisofs only allow 32 characters for volume ID
411     iso_label_tag="${iso_label_tag:0:31}"
412     ocs_imgs_with_abs_path=""
413     for im in $ocs_image; do
414     if [ ! -d "$image_path/$im" ]; then
415     [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
416     echo "$image_path/$im $msg_NOT_found!"
417     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
418     echo "$msg_program_stop"
419     exit 1
420     fi
421     if [ -z "$allow_limited_size_flag" ]; then
422     if [ -n "$(find $image_path/$im -size +${iso9660_file_size_limit} -print)" ]; then
423     allow_limited_size_flag="yes"
424     fi
425     fi
426     # we will put all the images in $ocsroot/ inside ISO file.
427     # Since we will always use /home/partimag as the image root in Clonezilla live, here the path in the created iso is /home/partimag/
428     ocs_imgs_with_abs_path="$ocs_imgs_with_abs_path /home/partimag/$im/=$image_path/$im/"
429     convert_ocs_format_from_1.5_to_2.0_or_newer $image_path/$im/
430     check_file_size_in_ocs_image $image_path/$im/
431     img_size="$(du -ms $image_path/$im/ | awk -F" " '{print $1}')" # unit: MB
432     img_size_sum="$((img_size_sum+img_size))"
433     done
434     else
435     echo "Creating clonezilla Live CD ISO file..."
436     # if version_no is not set, use date (Ex. 20070409)
437     [ -z "$version_no" ] && version_no="$(date +%Y%m%d)"
438     iso_label_tag="${version_no}"
439     fi
440     boot_menu_opt="--version-no $iso_label_tag"
441    
442     if [ -n "$target_iso_prefix" ]; then
443     target_iso="${target_iso_prefix}.iso"
444     else
445     target_iso="clonezilla-live-${iso_label_tag}.iso"
446     fi
447     echo "The output file name is: $target_iso."
448    
449     if [ "$template_mode" = "from-booting-live-media" ]; then
450     DEBIAN_ISO_TMP="$LIVE_MEDIA"
451     else
452     DEBIAN_ISO_TMP="$(mktemp -d /tmp/ocs-iso.XXXXXX)"
453     mount -o loop,ro $DEBIAN_ISO $DEBIAN_ISO_TMP
454     fi
455    
456     #
457     if [ "$template_mode" = "from-booting-live-media" ]; then
458     # From boot media, DEBIAN_ISO_TMP is LIVE_MEDIA
459     # Here we use -Lks to make it more accurate.
460     template_iso_size="$(LC_ALL=C du -Lks $LIVE_MEDIA | awk -F" " '{print $1}')"
461     # Exclude those dirs
462     exclude_dir_size="0"
463     for i in $mkiso_exclude_list_2; do
464     [ ! -d "$LIVE_MEDIA/$i" ] && continue
465     exclude_dir_size="$(($exclude_dir_size + $(LC_ALL=C du -Lks "$LIVE_MEDIA/$i" | awk -F" " '{print $1}')))"
466     done
467     template_iso_size="$(LC_ALL=C echo "scale=0; ($template_iso_size - $exclude_dir_size)/1024" | bc -l)" # converted as MB.
468     else
469     # From iso file
470     # Here we use -Lks to make it more accurate.
471     template_iso_size="$(LC_ALL=C du -Lks $DEBIAN_ISO | awk -F" " '{print $1}')"
472     # Exclude those dirs
473     exclude_dir_size="0"
474     for i in $mkiso_exclude_list_2; do
475     [ ! -d "$DEBIAN_ISO/$i" ] && continue
476     exclude_dir_size="$(($exclude_dir_size + $(LC_ALL=C du -Lks "$DEBIAN_ISO/$i" | awk -F" " '{print $1}')))"
477     done
478     template_iso_size="$(LC_ALL=C echo "scale=0; ($template_iso_size - $exclude_dir_size)/1024" | bc -l)" # converted as MB.
479     fi
480     target_iso_size="$(($template_iso_size + $img_size_sum))"
481    
482     #
483     # Possible kernel/initrd paths are /casper (created by casper) or /live (created by live-initramfs)
484     # Find the kernel and initrd in $DEBIAN_ISO_TMP/casper or $DEBIAN_ISO_TMP/live
485     # Ex: $DEBIAN_ISO_TMP/casper/vmlinuz1, /$DEBIAN_ISO_TMP/casper/initrd1.img
486     # $live_sys_files_dir_list is from drbl-ocs.conf.
487     # Possible kernel/initrd paths are /casper (created by casper) or /live (created by live-initramfs)
488     sys_files_dir=""
489     for i in $live_sys_files_dir_list; do
490     krnfile_full_path="$(find $DEBIAN_ISO_TMP/$i/ -maxdepth 1 -name "vmlinuz*" -print 2>/dev/null)"
491     if [ -n "$krnfile_full_path" ]; then
492     krnfile="$(basename $krnfile_full_path)"
493     sys_files_dir="$i"
494     irdfile_full_path="$(find $DEBIAN_ISO_TMP/$i/ -maxdepth 1 -name "initrd*" -print)"
495     irdfile="$(basename $irdfile_full_path)"
496     break
497     fi
498     done
499    
500     #
501     if [ -z "$sys_files_dir" ]; then
502     [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
503     echo "No system files from template live iso are found! Something went wrong!"
504     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
505     echo "$msg_program_stop"
506     exit 1
507     fi
508    
509     if [ -z "$krnfile" -o -z "$irdfile" ]; then
510     [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
511     echo "Kernel and initrd files NOT found in path $DEBIAN_ISO_TMP/$sys_files_dir/!"
512     echo "$msg_program_stop"
513     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
514     exit 1
515     fi
516    
517     #
518     BOOT_ITEM_DIR=$ISOLNX_TMP/$sys_files_dir
519     [ ! -d $BOOT_ITEM_DIR ] && mkdir $BOOT_ITEM_DIR
520     echo -n "Copying the system files to working dir... This might take a few minutes... "
521     cp -af $DEBIAN_ISO_TMP/$sys_files_dir $ISOLNX_TMP/
522     RC=$?
523     if [ "$RC" -ne 0 ]; then
524     [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
525     echo "Failed to copy system files to working dir..."
526     echo "$msg_program_stop"
527     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
528     exit 1
529     fi
530     echo "done!"
531    
532     ################################################################################
533     # Section edited by S. Georgaras <sng@hellug.gr>
534     #
535     # echo "Estimated target ISO file \"$target_iso\" size: $target_iso_size MB"
536     # if [ "$target_iso_size" -gt "$FILE_LIMIT" ]; then
537     # [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
538     # echo "$msg_ocs_iso_too_big_for_DVD"
539     # [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
540     # echo "$msg_are_u_sure_u_want_to_continue"
541     # echo -n "[y/N] "
542     # read cont_ans
543     # case "$cont_ans" in
544     # y|Y|[yY][eE][sS])
545     # echo $msg_ok_let_do_it
546     # ;;
547     # *)
548     # echo "Abort!"
549     # exit 2
550     # esac
551     # elif [ "$target_iso_size" -gt "$CD_FILE_LIMIT" ]; then
552     # [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
553     # echo "$msg_ocs_iso_too_big_for_CD"
554     # [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
555     # echo "$msg_are_u_sure_u_want_to_continue"
556     # echo -n "[y/N] "
557     # read cont_ans
558     # case "$cont_ans" in
559     # y|Y|[yY][eE][sS])
560     # echo $msg_ok_let_do_it
561     # ;;
562     # *)
563     # echo "Abort!"
564     # exit 2
565     # esac
566     # fi
567    
568     ################################################################################
569    
570     # output setting for clonezilla live
571     mkdir -p $WD_TMP/etc/ocs
572    
573     # Decide ocs_live_run
574     # $DRBL_SCRIPT_PATH/sbin/custom-ocs is copied from $LIVE_MEDIA/pkg/custom-ocs by /etc/ocs/ocs-live.d/S03prep-drbl-clonezilla when booting
575     if [ -n "$custom_ocs" ]; then
576     custom_ocs_opt="/pkg/custom-ocs=$custom_ocs"
577     ocs_live_run="custom-ocs"
578     else
579     if [ "$insert_mode" = "prog_and_img" ]; then
580     case "$normal_menu_with_insert_image" in
581     no) ocs_live_run="ocs-live-restore" ;;
582     yes) ocs_live_run="ocs-live-general" ;;
583     esac
584     else # prog_only mode
585     ocs_live_run="ocs-live-general"
586     fi
587     fi
588    
589     # Create the iso image file
590     # isolinux should be rw, so we have to copy it, and exclude the one in iso image.
591     mkdir -p $ISOLNX_TMP/isolinux/
592     # rsync -a --exclude f*.txt --exclude boot.cat --exclude isolinux.txt --exclude isolinux.bin --exclude splash.rle --exclude doc $DRBL_SCRIPT_PATH/pkg/syslinux/* $ISOLNX_TMP/isolinux/
593     # we have to overwrite isolinux.bin since vesamenu.c32 should be same version with that.
594     cp -af $isolinux_file $pxelinux_simple_vesamenu $pxelinux_simple_menu $pxelinux_memdisk_file $pxelinux_bg_img $ocs_logo_img_syslinux $pxelinux_chain_file $ISOLNX_TMP/isolinux/
595    
596     etherboot_zlilo="$($query_pkglist_cmd drbl-etherboot 2>/dev/null | grep -E "eb-.*-etherboot-pci.zlilo$")"
597     # we have to force it name as etherboot.zdsk, since isolinux only uses the "plain" ISO 9660 filenames, i.e. it does not support Rock Ridge or Joliet filenames.
598     # ref: http://syslinux.zytor.com/archives/2006-October/007440.html
599     # "-" will be regards as "_" if you want to use "-" for isolinux.
600     # In syslinux on vfat, etherboot.zlilo is too long, make it ever shorter as eb.zli
601     if [ -n "$etherboot_zlilo" ]; then
602     # This is run in DRBL server
603     cp -af $etherboot_zlilo $BOOT_ITEM_DIR/eb.zli
604     else
605     # This is run in Clonezilla live with casper or live mechanism
606     for i in $live_sys_files_dir_list; do
607     if [ -e "$LIVE_MEDIA/$i/eb.zli" ]; then
608     cp -af $LIVE_MEDIA/$i/eb.zli $BOOT_ITEM_DIR/eb.zli
609     break
610     fi
611     done
612     fi
613     # same reason, we have to use different name in isolinux
614     gpxe_lkn="$($query_pkglist_cmd gpxe 2>/dev/null | grep -E "gpxe.lkrn$")"
615     if [ -n "$gpxe_lkn" ]; then
616     # This is run in DRBL server
617     cp -af $gpxe_lkn $BOOT_ITEM_DIR/gpxe.lkn
618     else
619     # This is run in Clonezilla live with casper or live mechanism
620     for i in $live_sys_files_dir_list; do
621     if [ -e "$LIVE_MEDIA/$i/gpxe.lkn" ]; then
622     cp -af $LIVE_MEDIA/$i/gpxe.lkn $BOOT_ITEM_DIR/gpxe.lkn
623     break
624     fi
625     done
626     fi
627     # same reason, we have to use different name in isolinux
628     if [ -e "$fdos_img_src" ] ; then
629     cp -af $fdos_img_src $BOOT_ITEM_DIR/freedos.img
630     else
631     # This is run in Clonezilla live with casper or live mechanism
632     for i in $live_sys_files_dir_list; do
633     if [ -e "$LIVE_MEDIA/$i/freedos.img" ]; then
634     cp -af $LIVE_MEDIA/$i/freedos.img $BOOT_ITEM_DIR/freedos.img
635     break
636     fi
637     done
638     fi
639     # $memtest86_file (memtest86) is 9 characters, will go wrong when it's FAT (usb flash drive). We use memtest to overwrite the one comes from Debian live.
640     # Since live helper will put memtest in casper, we can choose to copy it or not.
641     # If we really want to use the memtest from drbl, we have to remove $DEBIAN_ISO_TMP/casper/memtest before doing mkisofs, otherwise it will complain like:
642     # Using MEMTEST000.;1 for /tmp/ocs-iso.E15902/casper/memtest (memtest)
643     # genisoimage: Error: '/tmp/isolnx.V15903/casper/memtest' and '/tmp/ocs-iso.E15902/casper/memtest' have the same Rock Ridge name 'memtest'.
644     # Unable to sort directory /tmp/ocs-iso.E15902/casper
645     # since $DEBIAN_ISO_TMP/casper/memtest is read-only, we can not remove it. Later we will exclude that later by mkisofs.
646     if [ -e "$memtest86_file" ]; then
647     cp -af $memtest86_file $BOOT_ITEM_DIR/memtest
648     else
649     # This is run in Clonezilla live with casper or live mechanism
650     for i in $live_sys_files_dir_list; do
651     if [ -e "$LIVE_MEDIA/$i/memtest" ]; then
652     cp -af $LIVE_MEDIA/$i/memtest $BOOT_ITEM_DIR/memtest
653     break
654     fi
655     done
656     fi
657    
658     # Excluding list for mkisofs
659     for i in $live_sys_files_dir_list; do
660     if [ -e "$DEBIAN_ISO_TMP/$i/memtest" ]; then
661     mkiso_exclude_list="$mkiso_exclude_list $i/memtest"
662     break
663     fi
664     done
665     mkiso_exclude_opt=""
666     for i in $mkiso_exclude_list; do
667     mkiso_exclude_opt="$mkiso_exclude_opt -x $DEBIAN_ISO_TMP/$i"
668     done
669    
670     # Find the boot param $boot_param
671     get_live_boot_param $DEBIAN_ISO_TMP/isolinux
672    
673     #
674     if [ -n "$ocs_image" ]; then
675     ocs-live-boot-menu $ocs_live_boot_menu_option -l $lang_answer -f $VGA_MODE_DEF -b $bg_mode -k /$sys_files_dir/$krnfile -i /$sys_files_dir/$irdfile -m $ocs_logo_img_syslinux $boot_menu_opt --boot-param "$boot_param $live_extra_boot_param noswap nolocales ocs_live_run=\"$ocs_live_run\" ocs_live_extra_param=\"$ocs_live_extra_param\" ocs_live_keymap=\"$ocs_live_keymap\" ocs_live_batch=\"$ocs_live_batch\" ocs_lang=\"$ocs_lang\"" --title "clonezilla live with img $ocs_image" isolinux $ISOLNX_TMP/isolinux/
676     else
677     ocs-live-boot-menu $ocs_live_boot_menu_option -l $lang_answer -f $VGA_MODE_DEF -b $bg_mode -k /$sys_files_dir/$krnfile -i /$sys_files_dir/$irdfile -m $ocs_logo_img_syslinux $boot_menu_opt --boot-param "$boot_param $live_extra_boot_param noswap nolocales ocs_live_run=\"$ocs_live_run\" ocs_live_extra_param=\"$ocs_live_extra_param\" ocs_live_keymap=\"$ocs_live_keymap\" ocs_live_batch=\"$ocs_live_batch\" ocs_lang=\"$ocs_lang\"" isolinux $ISOLNX_TMP/isolinux/
678     fi
679    
680     #
681     echo "Preparing syslinux.exe, syslinux, makeboot.bat and makeboot.sh in dir utils... "
682     # If it's in Clonezilla live environment, we have those files
683     if [ -e "$LIVE_MEDIA/utils/linux/syslinux" -a \
684     -e "$LIVE_MEDIA/utils/mbr/mbr.bin" -a \
685     -e "$LIVE_MEDIA/utils/win32/syslinux.exe" ]; then
686     cp -rf $LIVE_MEDIA/utils $ISOLNX_TMP
687     else
688     put_syslinux_makeboot_for_usb_flash $ISOLNX_TMP
689     fi
690     if [ -d "$ISOLNX_TMP/utils" ]; then
691     utils_files_dir_graft_point="/utils/=$ISOLNX_TMP/utils/"
692     fi
693    
694     # put version tag
695     # The content is like clonezilla-live-20070308
696     echo "clonezilla-live-${iso_label_tag}" > $ISOLNX_TMP/Clonezilla-Live-Version
697     echo "This Clonezilla live iso file was created by this command:" >> $ISOLNX_TMP/Clonezilla-Live-Version
698     echo "$prog $prog_option" >> $ISOLNX_TMP/Clonezilla-Live-Version
699    
700     # $sys_files_dir maybe /casper, /live or /isolinux. If it is isolinux, we can not list them twice otherwise mkisofs will go wrong.
701     if [ "$sys_files_dir" != "isolinux" ]; then
702     sys_files_dir_graft_point="/isolinux/=$ISOLNX_TMP/isolinux/ /$sys_files_dir/=$ISOLNX_TMP/$sys_files_dir/"
703     else
704     sys_files_dir_graft_point="/isolinux/=$ISOLNX_TMP/isolinux/"
705     fi
706    
707     # If template_mode="from-booting-live-media", then there is /COPYING and /Clonezilla-Live-Version, then we should not assign that.
708     doc_insert_in_root=""
709     if [ ! -e "$DEBIAN_ISO_TMP/COPYING" ]; then
710     doc_insert_in_root="/COPYING=$DRBL_SCRIPT_PATH/doc/COPYING"
711     fi
712     if [ ! -e "$DEBIAN_ISO_TMP/Clonezilla-Live-Version" ]; then
713     doc_insert_in_root="$doc_insert_in_root /Clonezilla-Live-Version=$ISOLNX_TMP/Clonezilla-Live-Version"
714     fi
715    
716     #
717     allow_limited_size_opt=""
718     if [ "$allow_limited_size_flag" = "yes" ]; then
719     [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
720     echo "Since there is at least one file larger than ${iso9660_file_size_limit}B in the image file, we turn on the option -allow-limited-size for genisoimage. This also implies enabling UDF format instead of iso9660."
721     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
722     allow_limited_size_opt="-allow-limited-size"
723     fi
724    
725     echo "genisoimage \
726     -A "Clonezilla live CD" \
727     -V "$iso_label_tag" \
728     -publisher "DRBL/Clonezilla http://drbl.name http://clonezilla.org" \
729     -f -r -J -l $allow_limited_size_opt \
730     -b isolinux/isolinux.bin -c isolinux/boot.cat \
731     -no-emul-boot -boot-load-size 4 -boot-info-table \
732     $mkiso_exclude_opt \
733     -graft-points $DEBIAN_ISO_TMP \
734     $sys_files_dir_graft_point \
735     $utils_files_dir_graft_point \
736     $doc_insert_in_root \
737     $ocs_imgs_with_abs_path \
738     $custom_ocs_opt \
739     $include_dir_graft_point
740     "
741    
742     echo "DEBIAN_ISO_TMP=$DEBIAN_ISO_TMP"
743     echo "sys_files_dir_graft_point=$sys_files_dir_graft_point"
744     echo "utils_files_dir_graft_point=$utils_files_dir_graft_point"
745     echo "doc_insert_in_root=$doc_insert_in_root"
746     echo "ocs_imgs_with_abs_path=$ocs_imgs_with_abs_path"
747     echo "custom_ocs_opt=$custom_ocs_opt"
748     echo "include_dir_graft_point=$include_dir_graft_point"
749     echo
750     echo "ocs_image=$ocs_image"
751     echo "image_path=$image_path"
752    
753     #read
754    
755     cust-menu -publisher "DRBL/Clonezilla http://drbl.name http://clonezilla.org" -V "$iso_label_tag" "$going2RAM"
756    
757    
758     if [ -n "$going2RAM" ];then
759     ocs_imgs_with_abs_path=''
760     fi
761    
762     if [ -e /tmp/isodata ];then
763     iso_label_tag=`sed '2d' /tmp/isodata`
764     isoPublisher=`sed '1d' /tmp/isodata`
765     rm /tmp/isodata 2>/dev/null
766     fi
767    
768     # make iso file
769     genisoimage \
770     -A "Clonezilla live CD" \
771     -V "$iso_label_tag" \
772     -publisher "$isoPublisher" \
773     -f -r -J -l $allow_limited_size_opt \
774     -b isolinux/isolinux.bin -c isolinux/boot.cat \
775     -no-emul-boot -boot-load-size 4 -boot-info-table \
776     $mkiso_exclude_opt \
777     -graft-points $DEBIAN_ISO_TMP \
778     $sys_files_dir_graft_point \
779     $utils_files_dir_graft_point \
780     $doc_insert_in_root \
781     $ocs_imgs_with_abs_path \
782     $custom_ocs_opt \
783     $include_dir_graft_point \
784     | \
785     (
786     case "$output_mode" in
787     "cdwriter")
788     wodim dev=$output_dev -data -eject -v -
789     ;;
790     *)
791     # use /dev/stdout as the bridge
792     cat - > $target_iso
793     ;;
794     esac
795     )
796    
797     rc=$?
798     if [ "$rc" -gt 0 ]; then
799     [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
800     echo "Something went wrong!"
801     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
802     umount $DEBIAN_ISO_TMP &>/dev/null
803     if [ ! -z "$DEBIAN_ISO_TMP" -a \
804     "$template_mode" = "from-downloaded-live-media" ]; then
805     # We put some tmp file when template_mode is from-downloaded-live-media
806     rm -rf $DEBIAN_ISO_TMP
807     fi
808     [ -n "$target_iso" -a -f "$target_iso" ] && rm -fv $target_iso
809     [ -n "$ISOLNX_TMP" -a -d "$ISOLNX_TMP" ] && rm -rf $ISOLNX_TMP
810     [ -n "$WD_TMP" -a -d "$WD_TMP" ] && rm -rf $WD_TMP
811     echo "$msg_program_stop"
812     exit 1
813     fi
814    
815     # unmount all iso file
816     umount $DEBIAN_ISO_TMP &>/dev/null
817    
818     # Clean the tmp working directory
819     echo "Cleaning tmp dirs..."
820     if [ ! -z "$DEBIAN_ISO_TMP" -a \
821     "$template_mode" = "from-downloaded-live-media" ]; then
822     # We put some tmp file when template_mode is from-downloaded-live-media
823     rm -rf $DEBIAN_ISO_TMP
824     fi
825     [ -n "$ISOLNX_TMP" -a -d "$ISOLNX_TMP" ] && rm -rf $ISOLNX_TMP
826     [ -n "$WD_TMP" -a -d "$WD_TMP" ] && rm -rf $WD_TMP
827    
828     #
829     if [ -e "$target_iso" ]; then
830     if type isohybrid &>/dev/null; then
831     echo -n "Isohybriding $target_iso... "
832     isohybrid $target_iso
833     echo "done!"
834     fi
835     [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
836     echo "$msg_burn_clonezilla_img_iso: $target_iso"
837     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
838     fi
839    
840    
841     ################################################################################
842     # Section edited by S. Georgaras <sng@hellug.gr>
843     ifile1=`dirname "$ifile"`
844     if [ "$going2RAM" = "prog_only" ];then
845     whiptail --backtitle Clonezilla-SysRescCD --title ' Info ' --msgbox "The ISO file has been saved as $target_iso
846    
847     This ISO file contains the program and settings to restore your image
848     ($(basename ${ifile%/})), but not the image itself. Now you have to burn
849     the ISO file to a 8GB DVD and then add the image file to it.
850    
851     These are the commands to execute:
852     cd /home/partimag
853     growisofs -Z \$(what-cd -dwb)=$target_iso
854     eject \$(what-cd -dwb)
855     growisofs -M \$(what-cd -dwb) -R -J \\
856     -V \"$iso_label_tag\" --publisher \"$isoPublisher\" \\
857     -graft-points /$(basename ${ifile%/})/=${ifile%/}
858    
859     Alternatively, you can excute the file /tmp/burnISO
860    
861     NOTE: \$(what-cd -dwb) will use your first DVD-writer. In case you want
862     to use another device, you have to replace \$(what-cd -dwb) with
863     that device name e.g. /dev/hdd
864     " 0 0
865     fi
866    
867     echo "#!/bin/bash" > /tmp/burnISO
868     echo "eject \$(what-cd -dwb)" >> /tmp/burnISO
869     echo "echo -n \"Place an empty DVD in the DVD-writer and press ENTER \"" >> /tmp/burnISO
870     echo "read" >> /tmp/burnISO
871     echo "cd /home/partimag" >> /tmp/burnISO
872     echo "growisofs -Z \$(what-cd -dwb)=$target_iso" >> /tmp/burnISO
873     echo "eject \$(what-cd -dwb)" >> /tmp/burnISO
874     echo "echo \"The medium must now be ejected and reinserted into\"" >> /tmp/burnISO
875     echo "echo \"the DVD-writer for the burning process to continue\"" >> /tmp/burnISO
876     echo "echo -n \"Place reload the DVD in the DVD-writer and press ENTER \"" >> /tmp/burnISO
877     echo "read" >> /tmp/burnISO
878     echo "growisofs -M \$(what-cd -dwb) -R -J \\" >> /tmp/burnISO
879     echo "-V \"$iso_label_tag\" --publisher \"$isoPublisher\" \\" >> /tmp/burnISO
880     echo "-graft-points /$(basename ${ifile%/})/=${ifile%/}" >> /tmp/burnISO
881     chmod +x /tmp/burnISO
882    
883     ################################################################################

Properties

Name Value
svn:executable *

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26