This file is indexed.

/usr/sbin/create-gparted-live is in clonezilla 3.27.16-2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
#!/bin/bash
# Author: Steven Shiau <steven _at_ nchc org tw>
# License: GPL
# Description: This script will create a GParted live CD/USB flash drive iso/zip

#
set -e

#
DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
. /etc/drbl/drbl-ocs.conf
. $DRBL_SCRIPT_PATH/sbin/ocs-functions

# debian_mirror_url_def, debian_mirror_security_url_def, DRBL_REPOSITORY_URL_def and DRBL_GPG_KEY_URL are loaded from drbl-ocs.conf

# debian_type can be minimal (about 67 MB for Etch)/minimal-net (about 85 MB for Etch).
# Since from live-build 3.0~a55 "minimal" for debootstrap was removed. We use the option --variant of "debootstrap", i.e. "minbase" for minimal.
debian_type="minbase"
DEBIAN_DIST_DEF="sid"
# Do not assign any Xorg packges except xorg here. Let the Debian dependence decide that.
#Xorg_pkgs="xserver-xorg xfonts-base xserver-xorg-video-all xserver-xorg-input-mouse xserver-xorg-input-kbd xserver-xorg-input-evdev xserver-xorg-input-all-"
# Adding xserver-xorg-legacy to let non-root user can run startx since we use startx in GParted live. While not using it in DRBL live so this is different from that in DRBL live.
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=807015
Xorg_pkgs="xorg xserver-xorg-legacy"
# Some Asian fonts, like Chinese, Japan... (/NOTE/ Big size... about 5 - 10 MB)
#font_pkgs="x-ttcidfont-conf fonts-arphic-uming"
font_pkgs="fonts-arphic-uming fonts-hanazono"
# $debian_pkgs_for_gparted is from drbl.conf
# Use dhcp*-client$ for dhcp3-client, dhcp-client, and isc-dhcp-client (yes, debian will select 'dhcp-client' for regex 'dhcp*-client', then select 'isc-dhcp-client' for regex 'dhcp*-client'. With "$" in the end means we do not want "isc-dhcp-client-dbg"
# libpam-systemd and hence dbus are required, otherwise keyboard and mouse won't work in X after Sid >= Jan 2016. Thanks to Curtis for Gedak.
# Ref: https://lists.debian.org/debian-user/2015/10/msg01529.html
pkgs="console-data console-setup console-common kbd file eject user-setup \
grub-pc fluxbox idesk deborphan man testdisk mc less lxterminal zenity \
xbase-clients feh netpbm nano bogl-bterm mdetect lxrandr sdparm hdparm \
discover lsscsi pciutils ifupdown dhcp*-client$ cryptsetup gpart \
smartmontools vim-tiny gdisk fsarchiver mdadm dmraid sudo \
hicolor-icon-theme netbase ssh pppoeconf ethtool whiptail lshw \
cpufrequtils open-iscsi tree cifs-utils nilfs-tools netsurf ca-certificates \
gptsync net-tools iproute2 iw pcmanfm leafpad tcplay f2fs-tools \
partclone partimage screen rsync iputils-ping telnet traceroute bc lsof \
psmisc dnsutils wget ftp bzip2 xz-utils zip unzip w3m gsmartcontrol \
gddrescue ddrescueview zerofree efibootmgr libpam-systemd policykit-1 \
calcoo init udftools $debian_pkgs_for_gparted $Xorg_pkgs $font_pkgs"
categories_default="main"
cpu_flavor_default="686"
bootstrap_default="debootstrap"

# The files in dir in $ocs_live_include_dir will be included to the live-hook-dir/. Here we need some functions in ocs/live-hook so we include files in that dir.
ocs_live_include_dir="$DRBL_SCRIPT_PATH/setup/files/ocs/live-hook $DRBL_SCRIPT_PATH/setup/files/gparted/live-hook"
# The files in dir $ocs_live_script_dir will be copied to the /live-hook-dir/ in dir chroot, and $ocs_live_script_dir/$run_hook_script will be hooked and run
ocs_live_script_dir="$DRBL_SCRIPT_PATH/setup/files/gparted/live-hook"
# The script inside $ocs_live_script_dir will be run when chroot. Maybe there are many files in $ocs_live_script_dir, we will just run one here.
run_hook_script="gparted-live-hook"
# background image of syslinux/isolinux for gparted live
gparted_live_boot_bg_img="$DRBL_SCRIPT_PATH/setup/files/gparted/image/Gsplash.png"

#
vga_mode_gparted_live="normal"
# This hook is for binary_local-hooks, not for chroot hook
run_binary_hook_script="efi-binary-hook"
# The option to create a corresponding source image.
gen_source_tarball="no"
# Flag to put EFI booting image in iso
enabled_EFI=""

#
check_if_root
#
prog="$(basename $0)"
full_cmd="$prog $*"

# functions
USAGE() {
    echo "Usage:"
    echo "To create a GParted live CD iso or USB flash drive zip:"
    echo "$prog [OPTION]"
    echo "OPTION:"
    language_help_prompt_by_idx_no
    echo "-b, --branch [s|stable|t|testing|u|unstable|e|experimental]  Sepcify the DRBL branch to be used in Live CD. Default is stable."
    echo "-bt, --bootstrap BOOTSTRAP  Specify the bootsrap type as BOOTSTRAP (cdebootstrap or debootstrap). If not specified, $bootstrap_default will be used."
    echo "-c, --categories CAT   Sepcify the category, e.g. 'main', 'main non-free', default is \'$categories_default\' if not specified."
    echo "-d, --debian-dist [stable|testing|unstable|jessie|strech|sid...]  Assign Debian dist, the default is $DEBIAN_DIST_DEF if not assigned."
    echo "-f, --arch-flavor ARCH  Assign the CPU architecture flavor as ARCH, e.g. 586, 686 or amd64. If it's not assigned, $cpu_flavor_default will be used."
    echo "-g, --drbl-repo-url URL  Assign the DRBL repository URL instead of default one $DRBL_REPOSITORY_URL_def."
    echo "-n, --live-kernel-pkg KERNEL_VER Assign kernel version as KERNEL_VER (KERNEL VER package must exist in repository. Ex. if KERNEL_VER is 2.6.20-1-486, then linux-image-2.6.20-1-486, squashfs-modules-2.6.20-1-486, and unionfs-modules-2.6.20-1-486 will be used."
    echo "-i, --assign-version-no NO  Assign the version no as NO instead of date."
    echo "-e, --drbl-live-branch [s|stable|t|testing|u|unstable|e|experimental]  specifies the DRBL live branch to be used in Live CD. Default is stable."
    echo "-k, --package FILE  Specifies FILE to be installed in Live CD."
    echo "-p, --packages-list FILE  specifies an external package list file (such as xfce, gnome, kde...), one package for each line"
    echo "-m, --mirror-url URL  Assign the Debian repository URL instead of default one $debian_mirror_url_def. "
    echo "-r, --rm-tmp-iso    Remove the first stage temp iso file"
    echo "-s, --mirror-security-url URL  Assign the Debian security repository URL instead of default one $debian_mirror_security_url_def."
    echo "-o, --create-source-tarball  Create a corresponding source image to the binary image.  By default such an source image will not be created since this would require to download quite a few source packages."
    echo "-t, --target-media-file  [cd|iso|usb|zip|b|both] Assign the target media file as CD (cd or iso), USB flash drive (usb or zip) or both of them (b or both). Default is both"
    echo "-u, --use-existing-tmp-iso  Use the existing first stage temp iso file"
    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. \"noeject\" can be use to not prompt to eject the CD on reboot."
    echo "-y, --syslinux-ver VER  Assign the syslinux version as VER. E.g. 6.02, 6.03-pre1"
    echo "-v, --verbose    Run live build in verbose mode"
    echo "Ex: $0 -l en -b u -e e -n 2.6.24-etchnhalf.1"
}
#
clean_tmp_dirs_files() {
  if [ -d "$stage1_iso_TMP" -a \
       -n "$(echo $stage1_iso_TMP | grep "ocs-iso-tmp")" ]; then
    rm -rf $stage1_iso_TMP
  fi
  if [ -d "$ISOSYSLNX_TMP" -a \
       -n "$(echo $ISOSYSLNX_TMP | grep "isolnx-tmp")" ]; then
    rm -rf $ISOSYSLNX_TMP
  fi
  if [ -d "$USB_TMP" -a \
       -n "$(echo $USB_TMP | grep "ocs-usb-dev")" ]; then
    rm -rf $USB_TMP
  fi
  # clean the tmp iso.
  if [ "$rm_tmp_iso" = "yes" -a -f "$stage1_target_iso" ]; then
    rm -f $stage1_target_iso
  fi
} # end of clean_tmp_dirs_files
#
create_version_tag_in_live() {
  local tag_file_in_abs_path="$1"
  local ver_tag_="$2"
  cat <<-TAG_END > $tag_file_in_abs_path
$ver_tag_
This GParted Live was created by:
$full_cmd
TAG_END
}
#
create_gparted_live_iso(){
  echo "$msg_delimiter_star_line"
  echo "Creating GParted Live iso file..."
  echo "$msg_delimiter_star_line"
  #
  # Possible kernel/initrd paths are /casper (created by casper) or /live (created by live-initramfs)
  # Find the kernel and initrd in $stage1_iso_TMP/casper or $stage1_iso_TMP/live
  # Ex: $stage1_iso_TMP/casper/vmlinuz1, /$stage1_iso_TMP/casper/initrd1.img
  # $live_sys_files_dir_list is from drbl-ocs.conf.
  # Possible kernel/initrd paths are /casper (created by casper) or /live (created by live-initramfs)
  sys_files_dir=""
  for i in $live_sys_files_dir_list; do
    krnfile="$(find $stage1_iso_TMP/$i/ -maxdepth 1 -name "vmlinuz*" -print 2>/dev/null)"
    if [ -n "$krnfile" ]; then
      krnfile="$(basename $krnfile)"
      sys_files_dir="$i"
      irdfile="$(find $stage1_iso_TMP/$i/ -maxdepth 1 -name "initrd*" -print)"
      irdfile="$(basename $irdfile)"
      break
    fi
  done
  BOOT_ITEM_DIR=$ISOSYSLNX_TMP/$sys_files_dir
  [ ! -d $BOOT_ITEM_DIR ] && mkdir $BOOT_ITEM_DIR

  if [ -z "$sys_files_dir" ]; then
    [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
    echo "No system files from template live iso are found!"
    [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
    echo "$msg_program_stop"
    exit 1
  fi
  
  if [ -z "$krnfile" -o -z "$irdfile" ]; then
     [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
     echo "Kernel and initrd files NOT found in path $stage1_iso_TMP/$sys_files_dir/!"
     echo "$msg_program_stop"
     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
     exit 1
  fi

  if [ "$output_mode" = "cdwriter" -a type wodim &>/dev/null ]; then
    [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
    echo "Program wodim is not aviailable! You have to install it."
    [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
    echo "$msg_program_stop"
    exit 1
  fi

  # now we can insert the boot menu of isolinux
  mkdir -p $ISOSYSLNX_TMP/syslinux $ISOSYSLNX_TMP/EFI/boot/
  # create isolinux menu
  # isolinux should be rw, so we have to copy it, and exclude the one in iso image.
  # we have to overwrite isolinux.bin since vesamenu.c32 should be same version with that.
  # Jan/19/2014 For both syslinux and isolinux (unified in one dir)
  # For syslinux
  cp -af $isolinux_file $pxelinux_simple_vesamenu $pxelinux_simple_menu $pxelinux_memdisk_file $gparted_live_boot_bg_img $pxelinux_chain_file $ISOSYSLNX_TMP/syslinux/
  # For Syslinux 5, new .c32 are required: ldlinux.c32, libcom32.c32, libutil.c32
  for i in $sys_pxelinux_v5p_required_c32; do
    if [ -e "$pxelinux_binsrc_dir/$i" ]; then
      # syslinux <= 5 
      cp -af $pxelinux_binsrc_dir/$i $ISOSYSLNX_TMP/syslinux/
    elif [ -e "$pxelinux_binsrc_dir/bios/$i" ]; then
      # syslinux >= 6, different path
      cp -af $pxelinux_binsrc_dir/bios/$i $ISOSYSLNX_TMP/syslinux/
    fi
  done
  # 2. For EFI machine
  # Copy the EFI boot files
  if [ "$live_efi_boot_loader" = "grub" ]; then
    if [ -e "$stage1_iso_TMP/EFI/boot/bootia32.efi" -a -e "$stage1_iso_TMP/EFI/boot/bootx64.efi" ]; then
      # The EFI/boot/{bootia32.efi,boox64.efi} are copied by the above rsync command from $stage1_iso_TMP
      cp -af $stage1_iso_TMP/EFI $ISOSYSLNX_TMP
      cp -af $gparted_live_boot_bg_img $ISOSYSLNX_TMP/EFI/boot/
    fi
  elif [ "$live_efi_boot_loader" = "syslinux" ]; then
    # Those files are prepared in /usr/share/drbl/pkg/syslinux/efi64/ by drbl-prepare-pxelinux
    cp -af $pxelinux_binsrc_dir/efi64/syslinux.efi $ISOSYSLNX_TMP/EFI/boot/bootx64.efi 
    cp -af $pxelinux_binsrc_dir/efi64/ldlinux.e64 $ISOSYSLNX_TMP/EFI/boot/
    cp -af $pxelinux_binsrc_dir/efi64/*.c32 $ISOSYSLNX_TMP/EFI/boot/
    cp -af $gparted_live_boot_bg_img $ISOSYSLNX_TMP/EFI/boot/
  fi

  #  etherboot_zlilo="$($query_pkglist_cmd drbl-etherboot | grep -E "eb-.*-etherboot-pci.zlilo$")"
  #  if [ -n "$etherboot_zlilo" ]; then
  #    # 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.
  #    # ref: http://syslinux.zytor.com/archives/2006-October/007440.html
  #    # "-" will be regards as "_" if you want to use "-" for isolinux.
  #    # In syslinux on vfat, etherboot.zlilo is too long, make it ever shorter as eb.zli
  #    cp -af $etherboot_zlilo $BOOT_ITEM_DIR/eb.zli
  #  fi
  #  # same reason, we have to use different name in isolinux
  #  [ -e "$fdos_img_src" ] && cp -af $fdos_img_src $BOOT_ITEM_DIR/freedos.img
  [ -e "$memtest86_file" ] && cp -af $memtest86_file $BOOT_ITEM_DIR/memtest

  # Put the tag
  # The VER_TAG is like drbl-live-xfce-20070315
  VER_TAG="$(echo $real_target_iso | sed -e "s/.iso$//g")"
  create_version_tag_in_live $ISOSYSLNX_TMP/GParted-Live-Version "$VER_TAG"
  # Copy another one in the live dir. It will be used for toram=live mode.
  cp -a $ISOSYSLNX_TMP/GParted-Live-Version $ISOSYSLNX_TMP/$sys_files_dir/

  # Excluding list for mkisofs
  # We will create it like this:
  # -x $stage1_iso_TMP/isolinux -x $stage1_iso_TMP/md5sum.txt -x $stage1_iso_TMP/casper/memtest 
  mkiso_exclude_list="isolinux syslinux EFI .disk md5sum.txt doc "
  for i in $live_sys_files_dir_list; do
    if [ -e "$stage1_iso_TMP/$i/memtest" ]; then
      mkiso_exclude_list="$mkiso_exclude_list $i/memtest"
      break
    fi
  done
  mkiso_exclude_opt=""
  for i in $mkiso_exclude_list; do
    mkiso_exclude_opt="$mkiso_exclude_opt -x $stage1_iso_TMP/$i"
  done

  # Find the boot param $boot_param
  if [ "$template_mode" = "from-booting-live-media" ]; then
    # From boot media (clonezilla live), DEBIAN_ISO_TMP is LIVE_MEDIA
    # Jan/19/2014 We have unified syslinux and isolinux to one dir "syslinux"
    get_live_boot_param $stage1_iso_TMP/syslinux
  else
    # From iso file (debian-live-for-ocs.iso)
    get_live_boot_param $stage1_iso_TMP/isolinux
  fi

  # generate the menu
  # For isolinux
  ocs-live-boot-menu -s -d -l $lang_answer --title "GParted Live" -f $vga_mode_gparted_live -n "$version_no" -k /$sys_files_dir/$krnfile -i /$sys_files_dir/$irdfile -m $gparted_live_boot_bg_img --boot-param "$boot_param $live_extra_boot_param noswap" -r "* Boot menu for BIOS machine" isolinux $ISOSYSLNX_TMP/syslinux/
  # For syslinux
  ocs-live-boot-menu -s -d -l $lang_answer --title "GParted Live" -f $vga_mode_gparted_live -n "$version_no" -k /$sys_files_dir/$krnfile -i /$sys_files_dir/$irdfile -m $gparted_live_boot_bg_img --boot-param "$boot_param $live_extra_boot_param noswap" -r "* Boot menu for BIOS machine" syslinux $ISOSYSLNX_TMP/syslinux/
  # For EFI, grub2 efi or syslinux efi
  if [ "$live_efi_boot_loader" = "grub" ]; then
    if [ -e "$ISOSYSLNX_TMP/EFI/boot/bootia32.efi" -a -e "$ISOSYSLNX_TMP/EFI/boot/bootx64.efi" ]; then
      ocs-live-boot-menu -s -d -l $lang_answer --title "GParted Live" -f $vga_mode_gparted_live -n "$version_no" -k /$sys_files_dir/$krnfile -i /$sys_files_dir/$irdfile -m $gparted_live_boot_bg_img --boot-param "$boot_param $live_extra_boot_param noswap" -r "* Boot menu for EFI machine" grub2-efi $ISOSYSLNX_TMP/EFI/boot/
    fi
  elif [ "$live_efi_boot_loader" = "syslinux" ]; then
    ocs-live-boot-menu -s -d -l $lang_answer --title "GParted Live" -f $vga_mode_gparted_live -n "$version_no" -k /$sys_files_dir/$krnfile -i /$sys_files_dir/$irdfile -m $gparted_live_boot_bg_img --boot-param "$boot_param $live_extra_boot_param noswap" -r "* Boot menu for EFI machine" syslinux $ISOSYSLNX_TMP/EFI/boot/
  fi
  
  # With syslinux-related files, we can put the iso file on USB stick and make ti bootable, too.
  echo "Preparing syslinux.exe, syslinux, makeboot.bat and makeboot.sh... "
  if [ -z "$isolinux_ver" ]; then
    isolinux_ver="$(LC_ALL=C strings $ISOSYSLNX_TMP/syslinux/isolinux.bin | grep "^ISOLINUX" | awk -F" " '{print $2}')"
  fi
  put_syslinux_makeboot_for_usb_flash $ISOSYSLNX_TMP/ $isolinux_ver

  utils_files_dir_graft_point=""
  if [ -d "$ISOSYSLNX_TMP/utils" ]; then
    utils_files_dir_graft_point="/utils/=$ISOSYSLNX_TMP/utils/"
  fi

  # $sys_files_dir maybe /casper, /live or /isolinux. If it is isolinux, we can not list them twice otherwise mkisofs will go wrong.
  if [ "$sys_files_dir" != "isolinux" ]; then
    sys_files_dir_graft_point="/syslinux/=$ISOSYSLNX_TMP/syslinux/ /$sys_files_dir/=$ISOSYSLNX_TMP/$sys_files_dir/"
  else
    sys_files_dir_graft_point="/syslinux/=$ISOSYSLNX_TMP/syslinux/" 
  fi

  # Remove the existing iso
  [ -e "$target_iso" ] && rm -f $target_iso

  #
  if [ -d "$ISOSYSLNX_TMP/EFI" ]; then
    sys_files_dir_graft_point="$sys_files_dir_graft_point /EFI/=$ISOSYSLNX_TMP/EFI"
  fi
  # Build the EFI boot image. This is especially for iso file. Not for USB stick.
  efi_img_opt=""
  if [ "$enabled_EFI" = "true" ]; then
    # The following codes are referred from Fedora 
    EFI_BOOTIMG_TMP="$(mktemp -d /tmp/efi-boot.XXXXXX)"
    EFI_BOOTTREE="$stage1_iso_TMP/EFI"
    EFI_IMGTREE="$ISOSYSLNX_TMP/EFI/images"
    EFI_IMG="$EFI_IMGTREE/efiboot.img"
    mkdir -p $EFI_IMGTREE
    rm -rf $ISOSYSLNX_TMP/.disk
    rm -f $EFI_IMG
    
    BOOTDISKSIZE="$(LC_ALL=C du -kcs $EFI_BOOTTREE | tail -n1 | awk '{print $1}')"
    BOOTDISKSIZE="$(LC_ALL=C echo "scale=0; $BOOTDISKSIZE * 1.03 / 1" | bc -l)"
    echo "The size of the $EFI_IMG is $BOOTDISKSIZE"
    mkdosfs -n GParted-EFI -C $EFI_IMG $BOOTDISKSIZE >/dev/null
    mount -o loop,shortname=winnt,umask=0077 -t vfat $EFI_IMG $EFI_BOOTIMG_TMP
    mkdir -p $EFI_BOOTIMG_TMP/EFI/
    if [ "$live_efi_boot_loader" = "grub" ]; then
      # In this case, bootx64.efi is in $EFI_BOOTTREE/, but we should exclude the existing $EFI_BOOTTREE/images/efiboot.img
      # However, when mkdosfs we do not exclude $EFI_BOOTTREE/images/efiboot.img, so the size might be counted. It's better to put efiboot.img not in /EFI/ in the future.
      rsync -a --exclude images/ $EFI_BOOTTREE/* $EFI_BOOTIMG_TMP/EFI/
    elif [ "$live_efi_boot_loader" = "syslinux" ]; then
      # In this case, bootx64.efi is copied in $ISOSYSLNX_TMP/EFI/, we should do something similar with ocs-gen-grub2-efi-bldr
      rsync -a --exclude images/ $ISOSYSLNX_TMP/EFI/* $EFI_BOOTIMG_TMP/EFI/
      # TODO similar to ocs-gen-grub2-efi-bldr, create a syslinux.cfg to include /syslinux/syslinux.cfg.
    fi
    umount $EFI_BOOTIMG_TMP
    if [ -d "$EFI_BOOTIMG_TMP" -a -n \
    	"$(echo $EFI_BOOTIMG_TMP | grep -e "efi-boot")" ]; then
      rm -rf $EFI_BOOTIMG_TMP
    fi
    
    # Create an info file for grub2 to autodetect the cd root
    # Ref: http://www.sysresccd.org/forums/viewtopic.php?f=5&t=4410
    mkdir $ISOSYSLNX_TMP/.disk
    echo -n "[GParted]" > $ISOSYSLNX_TMP/.disk/info
    
    efi_img_opt="-eltorito-alt-boot -efi-boot EFI/images/efiboot.img -no-emul-boot"
    # For Ubuntu uEFI secure boot signed grubx64.efi, it will search /boot/grub/grub.cfg instead of what we have (/EFI/boot/grub.cfg). Although we do not use Ubuntu as the underlaying OS, we still keep this for the future just in case.
    mkdir -p $ISOSYSLNX_TMP/boot/grub/
    cat <<-EFI_END > $ISOSYSLNX_TMP/boot/grub/grub.cfg
# This file is for compatibility to Ubuntu Linux's uEFI secure boot. 
# The real config file for grub is /EFI/boot/grub.cfg.
configfile /EFI/boot/grub.cfg
EFI_END
    efi_img_graft_opt="/.disk/=$ISOSYSLNX_TMP/.disk"
  fi

  # Prepare the sort file for genisoimage.
  gen_iso_sort_file $ISOSYSLNX_TMP/syslinux/iso_sort.txt

  # Create the iso file
  genisoimage \
   -A "GParted Live CD" \
   -V "GParted-live" \
   -publisher "GParted http://gparted.org" \
   -f -r -hide-rr-moved -hide-joliet-trans-tbl -J -l -allow-limited-size\
   -b syslinux/isolinux.bin -c syslinux/boot.cat \
   -no-emul-boot -boot-load-size 4 -boot-info-table \
   -sort $ISOSYSLNX_TMP/syslinux/iso_sort.txt \
   $efi_img_opt \
   $mkiso_exclude_opt \
   -graft-points \
   $sys_files_dir_graft_point \
   $utils_files_dir_graft_point \
   $efi_img_graft_opt \
   /GPL=$DRBL_SCRIPT_PATH/doc/GPL \
   /GParted-Live-Version=$ISOSYSLNX_TMP/GParted-Live-Version \
   $stage1_iso_TMP \
   > $real_target_iso
  RC_ISO=$?
  if [ "$RC_ISO" -eq 0 ]; then
    [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
    echo "The $real_target_iso is created successfully!"
    [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  else
    [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
    echo "The $real_target_iso is NOT created!"
    [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  fi
} # end of create_gparted_live_iso
#
create_gparted_live_zip() {
  # create temp dir for usb flash drive
  echo "$msg_delimiter_star_line"
  echo "Creating GParted Live zip file..."
  echo "$msg_delimiter_star_line"
  #
  # Possible kernel/initrd paths are /casper (created by casper) or /live (created by live-initramfs)
  # Find the kernel and initrd in $stage1_iso_TMP/casper or $stage1_iso_TMP/live
  # Ex: $stage1_iso_TMP/casper/vmlinuz1, /$stage1_iso_TMP/casper/initrd1.img
  # $live_sys_files_dir_list is from drbl-ocs.conf.
  # Possible kernel/initrd paths are /casper (created by casper) or /live (created by live-initramfs)
  sys_files_dir=""
  for i in $live_sys_files_dir_list; do
    krnfile="$(find $stage1_iso_TMP/$i/ -maxdepth 1 -name "vmlinuz*" -print 2>/dev/null)"
    if [ -n "$krnfile" ]; then
      krnfile="$(basename $krnfile)"
      sys_files_dir="$i"
      irdfile="$(find $stage1_iso_TMP/$i/ -maxdepth 1 -name "initrd*" -print)"
      irdfile="$(basename $irdfile)"
      break
    fi
  done

  if [ -z "$sys_files_dir" ]; then
    [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
    echo "No system files from template live iso are found!"
    [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
    echo "$msg_program_stop"
    exit 1
  fi
  
  if [ -z "$krnfile" -o -z "$irdfile" ]; then
     [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
     echo "Kernel and initrd files NOT found in path $stage1_iso_TMP/$sys_files_dir/!"
     echo "$msg_program_stop"
     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
     exit 1
  fi

  WD="$(pwd)"
  # Since we need more space for zip working dir, therefore if it's possible, we use the working dir instead of /tmp (which might be RAM in live CD case).
  if [ -w "$WD" ]; then
    USB_TMP="$(mktemp -d ./ocs-usb-dev.XXXXXX)"
  else
    USB_TMP="$(mktemp -d /tmp/ocs-usb-dev.XXXXXX)"
  fi
  mkdir -p $USB_TMP/$sys_files_dir
  mkdir -p $USB_TMP/syslinux/ $USB_TMP/EFI/boot/
  echo "Copying files to temp working directory... This might take some time..."
  rsync -av --exclude isolinux --exclude md5sum.txt --exclude doc $stage1_iso_TMP/.  $USB_TMP/
  cp -af $DRBL_SCRIPT_PATH/doc/GPL $USB_TMP/
  # Jan/19/2014 For both syslinux and isolinux (unified in one dir)
  # For syslinux
  cp -af $isolinux_file $pxelinux_simple_vesamenu $pxelinux_simple_menu $pxelinux_memdisk_file $gparted_live_boot_bg_img $pxelinux_chain_file $USB_TMP/syslinux/
  # For Syslinux 5, new .c32 are required: ldlinux.c32, libcom32.c32, libutil.c32
  for i in $sys_pxelinux_v5p_required_c32; do
    if [ -e "$pxelinux_binsrc_dir/$i" ]; then
      # syslinux <= 5 
      cp -af $pxelinux_binsrc_dir/$i $USB_TMP/syslinux/
    elif [ -e "$pxelinux_binsrc_dir/bios/$i" ]; then
      # syslinux >= 6, different path
      cp -af $pxelinux_binsrc_dir/bios/$i $USB_TMP/syslinux/
    fi
  done
  # 2. For EFI machine
  # Copy the EFI boot files
  if [ "$live_efi_boot_loader" = "grub" ]; then
    # The EFI/boot/{bootia32.efi,boox64.efi} are copied by the above rsync command from $$stage1_iso_TMP
    if [ -d "$USB_TMP/EFI/boot/" ]; then
      cp -af $gparted_live_boot_bg_img $USB_TMP/EFI/boot/
    fi
  elif [ "$live_efi_boot_loader" = "syslinux" ]; then
    # Those files are prepared in /usr/share/drbl/pkg/syslinux/efi64/ by drbl-prepare-pxelinux
    cp -af $pxelinux_binsrc_dir/efi64/syslinux.efi $USB_TMP/EFI/boot/bootx64.efi 
    cp -af $pxelinux_binsrc_dir/efi64/ldlinux.e64 $USB_TMP/EFI/boot/
    cp -af $pxelinux_binsrc_dir/efi64/*.c32 $USB_TMP/EFI/boot/
    cp -af $gparted_live_boot_bg_img $USB_TMP/EFI/boot/
  fi
  # $USB_TMP/EFI and its sub dirs might be not in the mode of 755 since they are copied from the files from iso. We chmod to 755 so that it's easier to remove them by "rm -rf" when it's not used anymore.
  # This especially for zip file, not iso file, because iso file won't only mount it, not unzip it.
  chmod 755 $USB_TMP/EFI
  find $USB_TMP/EFI -type d -exec chmod 755 {} \;

  if [ "$enabled_EFI" = "true" ]; then
    # Build the EFI boot image. This is especially for iso file. Not for USB stick. However, here we still prepare the file so that later it's easier to use genisoimage to create the EFI-enabled iso.
    # The following codes are referred from Fedora 
    EFI_BOOTIMG_TMP="$(mktemp -d /tmp/efi-boot.XXXXXX)"
    EFI_BOOTTREE="$stage1_iso_TMP/EFI"
    EFI_IMGTREE="$USB_TMP/EFI/images"
    EFI_IMG="$EFI_IMGTREE/efiboot.img"
    mkdir -p $EFI_IMGTREE
    rm -rf $USB_TMP/.disk
    rm -f $EFI_IMG
    
    BOOTDISKSIZE="$(LC_ALL=C du -kcs $EFI_BOOTTREE | tail -n1 | awk '{print $1}')"
    BOOTDISKSIZE="$(LC_ALL=C expr $BOOTDISKSIZE + 100)"
    echo "The size of the $EFI_IMG is $BOOTDISKSIZE"
    mkdosfs -n GParted-EFI -C $EFI_IMG $BOOTDISKSIZE >/dev/null
    mount -o loop,shortname=winnt,umask=0077 -t vfat $EFI_IMG $EFI_BOOTIMG_TMP
    mkdir -p $EFI_BOOTIMG_TMP/EFI/
    if [ "$live_efi_boot_loader" = "grub" ]; then
      # In this case, bootx64.efi is in $EFI_BOOTTREE/, but we should exclude the existing $EFI_BOOTTREE/images/efiboot.img
      # However, when mkdosfs we do not exclude $EFI_BOOTTREE/images/efiboot.img, so the size might be counted. It's better to put efiboot.img not in /EFI/ in the future.
      rsync -a --exclude images/ $EFI_BOOTTREE/* $EFI_BOOTIMG_TMP/EFI/
    elif [ "$live_efi_boot_loader" = "syslinux" ]; then
      # In this case, bootx64.efi is copied in $USB_TMP/EFI/, we should do something similar with ocs-gen-grub2-efi-bldr
      rsync -a --exclude images/ $USB_TMP/EFI/* $EFI_BOOTIMG_TMP/EFI/
      # TODO similar to ocs-gen-grub2-efi-bldr, create a syslinux.cfg to include /syslinux/syslinux.cfg.
    fi
    umount $EFI_BOOTIMG_TMP
    if [ -d "$EFI_BOOTIMG_TMP" -a -n \
    	"$(echo $EFI_BOOTIMG_TMP | grep -e "efi-boot")" ]; then
      rm -rf $EFI_BOOTIMG_TMP
    fi
    
    # Create an info file for grub2 to autodetect the cd root
    # Ref: http://www.sysresccd.org/forums/viewtopic.php?f=5&t=4410
    mkdir $USB_TMP/.disk
    echo -n "[GParted]" > $USB_TMP/.disk/info
  
    # For Ubuntu uEFI secure boot signed grubx64.efi, it will search /boot/grub/grub.cfg instead of what we have (/EFI/boot/grub.cfg). Although we do not use Ubuntu as the underlaying OS, we still keep this for the future just in case.
    mkdir -p $USB_TMP/boot/grub/
    cat <<-EFI_END > $USB_TMP/boot/grub/grub.cfg
# This file is for compatibility to Ubuntu Linux's uEFI secure boot. 
# The real config file for grub is /EFI/boot/grub.cfg.
configfile /EFI/boot/grub.cfg
EFI_END
  fi

  # Prepare the sort file for genisoimage. Although we do not use genisoimage here, however, we'd like the file created by ocs-live-dev is the same with that of ocs-iso. So it's easier to convert zip file to iso file.
  # Therefore we still put the file iso_sort.txt here.
  gen_iso_sort_file $USB_TMP/syslinux/iso_sort.txt

  # ref: http://syslinux.zytor.com/archives/2006-October/007440.html
  # "-" will be regards as "_" if you want to use "-" for isolinux.
  # In syslinux on vfat, etherboot.zlilo is too long, make it ever shorter as eb.zli
  #  etherboot_zlilo="$($query_pkglist_cmd drbl-etherboot | grep -E "eb-.*-etherboot-pci.zlilo$")"
  #  if [ -n "$etherboot_zlilo" ]; then
  #    # 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.
  #    # ref: http://syslinux.zytor.com/archives/2006-October/007440.html
  #    # "-" will be regards as "_" if you want to use "-" for isolinux.
  #    # In syslinux on vfat, etherboot.zlilo is too long, make it ever shorter as eb.zli
  #    cp -af $etherboot_zlilo $USB_TMP/$sys_files_dir/eb.zli
  #  fi
  #  [ -e "$fdos_img_src" ] && cp -af $fdos_img_src $USB_TMP/$sys_files_dir/freedos.img
  [ -e "$memtest86_file" ] && cp -af $memtest86_file $USB_TMP/$sys_files_dir/memtest
  cp -af $stage1_iso_TMP/$sys_files_dir/{$krnfile,$irdfile} $USB_TMP/$sys_files_dir/
  # Put the tag
  # The VER_TAG is like drbl-live-xfce-20070315
  VER_TAG="$(echo $real_target_zip | sed -e "s/.zip$//g")"
  create_version_tag_in_live $USB_TMP/GParted-Live-Version "$VER_TAG" 
  # Copy another one in the live dir. It will be used for toram=live mode.
  cp -a $USB_TMP/GParted-Live-Version $USB_TMP/$sys_files_dir/

  # Find the boot param $boot_param
  if [ "$template_mode" = "from-booting-live-media" ]; then
    # From boot media (clonezilla live), DEBIAN_ISO_TMP is LIVE_MEDIA
    # Jan/19/2014 We have unified syslinux and isolinux to one dir "syslinux"
    get_live_boot_param $stage1_iso_TMP/syslinux
  else
    # From iso file (debian-live-for-ocs.iso)
    get_live_boot_param $stage1_iso_TMP/isolinux
  fi
  # generate the menu
  # For syslinux
  ocs-live-boot-menu -s -d -l $lang_answer --title "GParted Live" -f $vga_mode_gparted_live -n "$version_no" -k /$sys_files_dir/$krnfile -i /$sys_files_dir/$irdfile -m $gparted_live_boot_bg_img --boot-param "$boot_param $live_extra_boot_param noswap" -r "* Boot menu for BIOS machine" syslinux $USB_TMP/syslinux/
  # For isolinux
  ocs-live-boot-menu -s -d -l $lang_answer --title "GParted Live" -f $vga_mode_gparted_live -n "$version_no" -k /$sys_files_dir/$krnfile -i /$sys_files_dir/$irdfile -m $gparted_live_boot_bg_img --boot-param "$boot_param $live_extra_boot_param noswap" -r "* Boot menu for BIOS machine" isolinux $USB_TMP/syslinux/
  # For EFI, grub2 efi or syslinux efi
  if [ "$live_efi_boot_loader" = "grub" ]; then
    if [ -e "$USB_TMP/EFI/boot/bootia32.efi" -a -e "$USB_TMP/EFI/boot/bootx64.efi" ]; then
      ocs-live-boot-menu -s -d -l $lang_answer --title "GParted Live" -f $vga_mode_gparted_live -n "$version_no" -k /$sys_files_dir/$krnfile -i /$sys_files_dir/$irdfile -m $gparted_live_boot_bg_img --boot-param "$boot_param $live_extra_boot_param noswap" -r "* Boot menu for EFI machine" grub2-efi $USB_TMP/EFI/boot/
    fi
  elif [ "$live_efi_boot_loader" = "syslinux" ]; then
    ocs-live-boot-menu -s -d -l $lang_answer --title "GParted Live" -f $vga_mode_gparted_live -n "$version_no" -k /$sys_files_dir/$krnfile -i /$sys_files_dir/$irdfile -m $gparted_live_boot_bg_img --boot-param "$boot_param $live_extra_boot_param noswap" -r "* Boot menu for EFI machine" syslinux $USB_TMP/EFI/boot/
  fi

  echo "Preparing syslinux.exe, syslinux, makeboot.bat and makeboot.sh... "
  # Since we can not judge the version from any files in $USB_TMP/syslinux, we use $USB_TMP/syslinux/isolinux.bin.
  if [ -z "$isolinux_ver" ]; then
    isolinux_ver="$(LC_ALL=C strings $USB_TMP/syslinux/isolinux.bin | grep "^ISOLINUX" | awk -F" " '{print $2}')"
  fi
  put_syslinux_makeboot_for_usb_flash $USB_TMP $isolinux_ver
  # just store it. since big files, like squash flie and opt_drbl.tgz are compressed, it's not necessary to compress it again.
  [ -e "$WD/$real_target_zip" ] && rm -f $WD/$real_target_zip
  # Before packing it, make sure all the mode is writable
  chmod -R u+w $USB_TMP
  (cd $USB_TMP; zip -0 -r $WD/$real_target_zip .)
  echo "The created release file is $real_target_zip. You can extract all the files into your pendrive, and run makeboot.bat from pendrive in M$ windows."
  [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
  echo "Warning: DO NOT RUN makeboot.bat from your local hard drive!! It is intended to be run from your USB device."
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  
} # end of create_gparted_live_zip

# default settings
pkg_list=""
pkg_list_opt=""
rm_tmp_iso="no"
use_existing_stage1_iso="no"
TARGET_MEDIA_FILE_DEF="both"
# Parse command-line options
while [ $# -gt 0 ]; do
  case "$1" in
    -l|--language)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              specified_lang="$1"
              shift
            fi
	    [ -z "$specified_lang" ] && USAGE && exit 1
            ;;
    -b|--branch)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              drbl_branch="$1"
              shift
            fi
	    [ -z "$drbl_branch" ] && USAGE && exit 1
            ;;
    -bt|--bootstrap)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              bootstrap="$1"
              shift
            fi
	    [ -z "$bootstrap" ] && USAGE && exit 1
            ;;
    -c|--categories)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              categories="$1"
              shift
            fi
	    [ -z "$categories" ] && USAGE && exit 1
            ;;
    -d|--debian-dist)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              debian_dist="$1"
              shift
            fi
	    [ -z "$debian_dist" ] && USAGE && exit 1
            ;;
    -i|--assign-version-no)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              version_no="$1"
              shift
            fi
	    [ -z "$version_no" ] && USAGE && exit 1
            ;;
    -k|--package)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              extra_pkgs="$1"
              shift
            fi
	    [ -z "$extra_pkgs" ] && USAGE && exit 1
            ;;
    -n|--live-kernel-pkg)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              live_kernel_ver="$1"
              shift
            fi
	    [ -z "$live_kernel_ver" ] && USAGE && exit 1
            ;;
    -e|--drbl-live-branch)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              drbl_live_branch="$1"
              shift
            fi
	    [ -z "$drbl_live_branch" ] && USAGE && exit 1
            ;;
    -p|--packages-list)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              pkg_list="$pkg_list $1"
              shift
            fi
	    [ -z "$pkg_list" ] && USAGE && exit 1
            ;;
    -f|--arch-flavor)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              cpu_flavor="$1"
              shift
            fi
	    [ -z "$cpu_flavor" ] && USAGE && exit 1
            ;;
    -g|--drbl-repo-url)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              DRBL_REPOSITORY_URL="$1"
              shift
            fi
	    [ -z "$DRBL_REPOSITORY_URL" ] && USAGE && exit 1
            ;;
    -m|--mirror-url)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              mirror_url="$1"
              shift
            fi
	    [ -z "$mirror_url" ] && USAGE && exit 1
            ;;
    -o|--create-source-tarball)
	    gen_source_tarball="yes"
            shift ;;
    -s|--mirror-security-url)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              mirror_security_url="$1"
              shift
            fi
	    [ -z "$mirror_security_url" ] && USAGE && exit 1
            ;;
    -t|--target-media-file)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              target_media_file="$1"
              shift
            fi
	    [ -z "$target_media_file" ] && USAGE && exit 1
            ;;
    -r|--rm-tmp-iso)
	    rm_tmp_iso="yes"
            shift ;;
    -u|--use-existing-tmp-iso)
            use_existing_stage1_iso="yes"
            shift ;;
    -v|--verbose)
	    verbose="on"
            shift ;;
    -x|--extra-boot-param)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              live_extra_boot_param="$1"
              shift
            fi
	    [ -z "$live_extra_boot_param" ] && USAGE && exit 1
            ;;
    -y|--syslinux-ver)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              isolinux_ver="$1"
              shift
            fi
	    [ -z "$isolinux_ver" ] && USAGE && exit 1
            ;;
    -*)     echo "${0}: ${1}: invalid option" >&2
            USAGE >& 2
            exit 2 ;;
    *)      break ;;
  esac
done

#
if [ "$use_existing_stage1_iso" = "no" ]; then
  # if we use existing stage 1 iso file, then we do not have to check if make-live/lb build exists. Otherwise we need make-live to create the stage 1 iso file
  if ! type lb &>/dev/null; then
    [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
    echo "This script only works in Debian Etch or later!"
    echo "If you are running Debian Etch or later, use 'apt-get install live-build' to install the live-build (version $lh_ver_required or later), then run $0 again."
    [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
    exit 1
  fi
  create_live_required_debian_based_prompt
fi

# we need zip to create the release file when target_mode is release_file
if ! type zip &>/dev/null; then
  [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
  echo "Command zip not found!"
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  echo "$msg_program_stop"
  exit 1
fi

ask_and_load_lang_set $specified_lang

[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "Creating GParted Live..." 
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL

rm -rf debian-live/.stage/

# Apply default settings if not assigned
[ -z "$debian_dist" ] && debian_dist="$DEBIAN_DIST_DEF"
[ -z "$categories" ] && categories="$categories_default"
[ -z "$DRBL_REPOSITORY_URL" ] && DRBL_REPOSITORY_URL="$DRBL_REPOSITORY_URL_def"
[ -z "$mirror_url" ] && mirror_url="$debian_mirror_url_def"
[ -z "$mirror_security_url" ] && mirror_security_url="$debian_mirror_security_url_def"
[ -z "$cpu_flavor" ] && cpu_flavor="$cpu_flavor_default"
[ -z "$bootstrap" ] && bootstrap=$bootstrap_default

# Append the extra packages
[ -n "$extra_pkgs" ] && pkgs="$pkgs $extra_pkgs"

echo "The packages to be included in this live CD:"
echo "$msg_delimiter_star_line"
echo "$pkgs"
echo "$msg_delimiter_star_line"
if [ -n "$pkg_list" ]; then
  pkg_list_opt="$pkg_list_opt --packages-list $pkg_list"
  echo "The packages list to be included in this live CD:"
  echo "$msg_delimiter_star_line"
  echo "$pkg_list"
  echo "$msg_delimiter_star_line"
fi
#
echo "Using Debian repository from: $mirror_url"
echo "Using Debian security repository from: $mirror_security_url"
echo "Using DRBL repository from: $DRBL_REPOSITORY_URL"

#
case "$drbl_branch" in
  t|testing)
     echo "Using DRBL testing branch..."
     LIVE_REPOSITORY_SECTIONS_drbl="testing"
     ;;
  u|unstable)
     echo "Using DRBL unstable branch..."
     LIVE_REPOSITORY_SECTIONS_drbl="unstable"
     ;;
  e|experimental)
     echo "Using DRBL experimental branch..."
     LIVE_REPOSITORY_SECTIONS_drbl="experimental"
     ;;
  *)
     echo "Using DRBL stable branch..."
     LIVE_REPOSITORY_SECTIONS_drbl="stable"
     ;;
esac
case "$drbl_live_branch" in
  t|testing)
     echo "Using DRBL Live testing branch..."
     LIVE_REPOSITORY_SECTIONS_drbl="$LIVE_REPOSITORY_SECTIONS_drbl live-testing"
     ;;
  u|unstable)
     echo "Using DRBL Live unstable branch..."
     LIVE_REPOSITORY_SECTIONS_drbl="$LIVE_REPOSITORY_SECTIONS_drbl live-unstable"
     ;;
  e|experimental)
     echo "Using DRBL Live experimental branch..."
     LIVE_REPOSITORY_SECTIONS_drbl="$LIVE_REPOSITORY_SECTIONS_drbl live-experimental"
     ;;
  *)
     echo "Using DRBL Live stable branch..."
     LIVE_REPOSITORY_SECTIONS_drbl="$LIVE_REPOSITORY_SECTIONS_drbl live-stable"
     ;;
esac

if [ -z "$pkg_list" ]; then
  nametag="live"
else
  # choose the first one, and strip space.
  #nametag="$(echo $pkg_list | awk -F" " '{print $1}' | sed -e "s/ //g")"
  # strip the spaces in the beginning and end, replace other space with -
  nametag="$(echo $pkg_list | sed -e "s/^ *//g" -e "s/ *$//g" -e "s/ /-/g")"
fi
  
if [ "$debian_dist" = "etch" ]; then
  # grandr and hfsprogs exist in Lenny or later dist. Remove them.
  pkgs="$(echo $pkgs | sed -e "s/grandr//g" -e "s/hfsprogs//g")"  
fi

if [ "$debian_dist" = "squeeze" -o \
     "$debian_dist" = "wheezy" -o \
     "$debian_dist" = "sid" ]; then
  # From around Oct/2009, the dummy package name "grub" is actually grub-pc, therefore we force to use grub-legacy and assume that if grub2 boot loader is used in the restored GNU/Linux, grub2 is available in the restored GNU/Linux so therefore we can use chroot to run it.
  # 2011/Dec/03 Since most of GNU/Linux distributions now use grub2, no more force to use grub-legacy, and we have backup plan by putting grub1 deb package in the live system. 
  # pkgs="$(LC_ALL=C echo $pkgs | sed -r -e "s/grub[[:space:]]+/grub-legacy /")"
  # Since with squeeze or sid, we can use uvesafb to replace vesafb, we need v86d. Check https://bugs.launchpad.net/ubuntu/+source/v86d/+bug/189621 for more details.
  pkgs="$pkgs v86d"
fi
# Adding libc6-i386 for AMD64 arch. This will allow 32-bit program to run on AMD64 arch.
if [ "$cpu_flavor" = "amd64" ]; then
  pkgs="$pkgs libc6-i386"
fi

# if version_no is not assigned, use date (Ex. 20070409)
[ -z "$version_no" ] && version_no="$(date +%Y%m%d)"
stage1_target_iso="gparted-${nametag}-stage1-${version_no}.iso"
real_target_iso="gparted-${nametag}-${version_no}.iso"
real_target_zip="gparted-${nametag}-${version_no}.zip"
target_src_tarball="gparted-live-src-${version_no}.debian.tar"
target_src_tarball_list="gparted-live-src-${version_no}.debian.contents"
target_src_debian_live_tarball="gparted-live-src-${version_no}.debian-live.tar"
target_src_debian_live_tarball_list="gparted-live-src-${version_no}.debian-live.contents"
[ -z "$target_media_file" ] && target_media_file="$TARGET_MEDIA_FILE_DEF"
echo "$msg_delimiter_star_line"

if [ "$verbose" = "on" ]; then
  pref="bash -x"
  export DEBOOTSTRAP_OPTIONS="$DEBOOTSTRAP_OPTIONS --verbose"
fi

if [ "$use_existing_stage1_iso" = "no" ]; then
  if [ -d "debian-live" ]; then
    echo "Found dir debian-live, clean stale debian-live files..."
    chroot debian-live/chroot umount /dev/pts &>/dev/null || true
    chroot debian-live/chroot umount /proc &>/dev/null || true
    chroot debian-live/chroot umount /sys &>/dev/null || true
    (
      cd debian-live/
      lb clean
    )
  fi
  rm -rf debian-live
  mkdir debian-live
  (
  cd debian-live
  $pref lb config --archive-areas "$categories"
  # It's important to make the url for --parent-mirror-binary is different from that of --parent-mirror-chroot so that in /usr/lib/live/build/chroot_archives the "lb config --cache-packages false" and "lb config --apt-indices false" can work and those /var/cache/apt/{pkgcache.bin,srcpkgcache.bin} and those /var/lib/apt/lists/{*_Packages,*Release*,*_Sources} won't be cached.
  $pref lb config --parent-mirror-bootstrap $mirror_url --parent-mirror-binary $debian_mirror_url_def --parent-mirror-chroot $mirror_url --parent-mirror-chroot-security $mirror_security_url --parent-mirror-binary-security $debian_mirror_security_url_def --parent-mirror-debian-installer $debian_mirror_url_def
  # Since we use Debian Sid normally, disable updates.
  $pref lb config --updates false
  $pref lb config --mirror-debian-installer $mirror_url
  $pref lb config --mirror-bootstrap $mirror_url
  $pref lb config --mirror-chroot $mirror_url --mirror-chroot-security $mirror_security_url
  # From live-build 3.0~a58-1, no --bootstrap-flavour option.
  #$pref lb config --bootstrap-flavour $debian_type 

  # Due to this issue: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=830696
  # We have to add gnupg in the base environment
  export DEBOOTSTRAP_OPTIONS="$DEBOOTSTRAP_OPTIONS --include=gnupg"
  $pref lb config --debootstrap-options="${DEBOOTSTRAP_OPTIONS} --variant=$debian_type"
  # Since we might assign the package version, e.g. live-boot=3.0.1-1.drbl4.
  # If we do not adding "--no-upgrade", then 
  # in /usr/lib/live/build/chroot_live-packages it will run
  # "apt-get install live-boot" then it will be upgraded.
  $pref lb config --apt apt --apt-options "--yes --no-upgrade --allow-downgrades" --apt-recommends false --bootstrap $bootstrap
  # From live-build 3.0~a59-1, no --volatile option.
  #$pref lb config --volatile false
  # We want "noswap", which only exists in live-initramfs
  # Disable the firmware packages automatically inclusion
  $pref lb config --firmware-binary false --firmware-chroot false
  $pref lb config --security false
  $pref lb config --initramfs live-boot
  # Refer to /usr/share/live/build/functions/defaults.sh for the original boot append parameters.
  # Don't be confused. It won't be appended. Therefore we have to put all required ones.
  $pref lb config --bootappend-live "boot=live union=overlay config username=user"
  # Enable cache-indices, by doing this, "apt-get upgrade" won't be run in lb chroot_sources after hook since we might assign older package version when building.
  # This is important especially when there is newer live-boot in Sid. E.g. on 2014/Apr/1 live-boot 4.0 alpha is aviailable, but we still want to keep using 3.0.1-1.drbl4. If --cache-indices is set true, live-boot is upgraded, and 4.0 is installed on the system after filesystem.squashfs is created. Then the initrd.img is re-created again, with live-boot 4.x in initrd.img. It will be inconsistent with what we want.
  $pref lb config --cache-indices true
  $pref lb config --cache-packages false
  $pref lb config --apt-indices false
  $pref lb config --apt-source-archives true
  $pref lb config --tasksel none

  if [ "$debian_dist" = "lenny" ]; then
    # Force to use iso instead of iso-hybrid. Since the syslinux in lenny comes without isohybrid program.
    $pref lb config --binary-images iso
  else
    # Enable iso-hybrid for version >= squeeze
    # //NOTE// This is for template iso only, not for GParted live iso.
    $pref lb config --binary-images iso-hybrid
  fi

  # This decide_live_kernel_related_pkgs_from_debian function will output "kernel_related_pkgs" and "export MKSQUASHFS_OPTIONS"
  decide_live_kernel_related_pkgs_from_debian
  $pref lb config --distribution $debian_dist --parent-distribution $debian_dist
  $pref lb config --linux-packages "$kernel_related_pkgs"

  # We force to use the specific CPU kernel.
  $pref lb config --linux-flavours $cpu_flavor

  # For OS arch, we can build amd64 Debian on i386 Debian or vice versus.
  case "$cpu_flavor" in
    686*|586*|486*) os_arch="i386";;
    amd64) os_arch="amd64";;
  esac
  $pref lb config --architectures $os_arch
  $pref lb config --initsystem systemd

  # No memtest from debian, we will use the one from drbl since it's newer.
  $pref lb config --memtest none

  $pref lb config --debian-installer false
  $pref lb config --win32-loader false

  # Disable zsync, it might fail due to download files after /etc/resolv.conf is deconfigured.
  $pref lb config --zsync false

  # Create a source tarball or not.
  if [ "$gen_source_tarball" = "yes" ]; then
    $pref lb config --source true
    $pref lb config --source-images tar
    # Since most of the debian packages are compressed (xz or gzip), we just use none, not the default one gzip.
    $pref lb config --compression none
  else
    $pref lb config --source false
  fi

  # Put files to be included in the chroot hook
  mkdir -p config/includes.chroot/live-hook-dir
  for i in $ocs_live_include_dir; do
    cp -pr $i/* config/includes.chroot/live-hook-dir/
  done
  cp -a /etc/drbl/{drbl.conf,drbl-ocs.conf} config/includes.chroot/live-hook-dir
  cp -ar $DRBL_SCRIPT_PATH/setup/files/gparted config/includes.chroot/live-hook-dir/

  # Put packages list in config/package-lists/. //NOTE// Do not use file name like gparted-packages.list. Make it like gparted-packages.list.binary (for lb_binary) or gparted-packages.list.chroot (for lb_chroot). Otherwise lb_binary_package-lists will generate deb repository (/pool). 
  # Ref: http://lists.debian.org/debian-live/2012/07/msg00119.html
  echo "$pkgs" > config/package-lists/gparted-packages.list.chroot

  # Put hook file to be run
  cp $ocs_live_script_dir/${run_hook_script} config/hooks/${run_hook_script}.chroot

  # Put hook file to be run in the binary_local-hooks
  cp $ocs_live_script_dir/$run_binary_hook_script config/hooks/${run_binary_hook_script}.binary
  
  # prepare drbl source list
  # //NOTE// Use drbl-repository.list instead of drbl-repository.list.chroot because 
  # with ".chroot" it means only for chroot and it will be removed from the squashfs.
  cat << AddDRBLRepository > config/archives/drbl-repository.list
deb $DRBL_REPOSITORY_URL drbl $LIVE_REPOSITORY_SECTIONS_drbl
deb-src $DRBL_REPOSITORY_URL drbl $LIVE_REPOSITORY_SECTIONS_drbl
AddDRBLRepository
  
  # Prepare drbl key
  LC_ALL=C wget -O config/archives/drbl-gpg.key $DRBL_GPG_KEY_URL

  # Disable apt languages and translations when creating DRBL live. This could reduce apt repository issue.
  disable_apt_lang_translation chroot/etc/apt/apt.conf.d/99lang
  
  # Build it.
  $pref lb build
  )
  lb_ver="$(LC_ALL=C lb --version)"  # e.g. 3.0.5-1
  if [ "$lb_ver" \> 3 ] && [ "$lb_ver" \< 4 ]; then
    # Live build version 3 
    mv -f debian-live/binary*.iso $stage1_target_iso
    if [ "$gen_source_tarball" = "yes" ]; then
      mv -f debian-live/source.debian.tar $target_src_tarball
      mv -f debian-live/source.debian.contents $target_src_tarball_list
      mv -f debian-live/source.debian-live.tar $target_src_debian_live_tarball
      mv -f debian-live/source.debian-live.contents $target_src_debian_live_tarball_list
    fi
  else
    # Live build version 4
    mv -f debian-live/live-image*.iso $stage1_target_iso
    if [ "$gen_source_tarball" = "yes" ]; then
      mv -f debian-live/live-image-source.debian.contents $target_src_tarball_list
      mv -f debian-live/live-image-source.debian.tar $target_src_tarball
      mv -f debian-live/live-image-source.live.contents $target_src_debian_live_tarball_list
      mv -f debian-live/live-image-source.live.tar $target_src_debian_live_tarball
    fi
  fi
else
  echo "Use existing temp iso file: $stage1_target_iso"
fi

# clean the dir debian-live if $stage1_target_iso is already created
if [ -f "$stage1_target_iso" -a -d "debian-live" ]; then
  echo "Removing working dir debian-live in background..."
  # If live cd is not created, we have to force umount these before rm files.
  umount -l debian-live/chroot/dev/pts &>/dev/null || true
  umount -l debian-live/chroot/proc &>/dev/null || true
  umount -l debian-live/chroot/sys &>/dev/null || true
  rm -rf debian-live &
fi
# 
if [ ! -e "$stage1_target_iso" ]; then
  [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
  echo "$stage1_target_iso does NOT exist!"
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  echo "$msg_program_stop!"
  exit 1
fi

# mount the stage 1 iso file
stage1_iso_TMP="$(mktemp -d /tmp/ocs-iso-tmp.XXXXXX)"
trap "[ -d "$stage1_iso_TMP" ] && umount $stage1_iso_TMP &>/dev/null && clean_tmp_dirs_files" HUP INT QUIT TERM EXIT
ISOSYSLNX_TMP="$(mktemp -d /tmp/isolnx-tmp.XXXXXX)"
mount -o loop $stage1_target_iso $stage1_iso_TMP

# Check if EFI boot could be supported.
if [ ! -e "$stage1_iso_TMP/EFI/boot/bootx64.efi" ]; then
  # We only check bootx64.efi since bootx86.efi is optional.
  [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
  echo "Warning! /EFI/boot/bootx64.efi was not found in stage1 GParted live!"
  echo "The generated $target_iso will not support EFI boot!"
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  sleep 5
  enabled_EFI="false"
elif [ -n "$(LC_ALL=C genisoimage --help 2>&1 | grep -E -- "-efi-boot")" ]; then
  # Check if genisoimage support -efi-boot option
  enabled_EFI="true"
else
  [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
  echo "Warning! Setting EFI boot image name is not supported in genisoimage!"
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  sleep 5
  enabled_EFI="false"
fi
  
#
case "$target_media_file" in
  cd|CD|iso|ISO)
     create_gparted_live_iso ;;
  usb|zip)
     create_gparted_live_zip ;;
  b|both|BOTH)
     create_gparted_live_iso
     create_gparted_live_zip
     ;;
esac

# unmount all iso file
umount $stage1_iso_TMP &>/dev/null

# Isohybrid the generated iso file.
# //NOTE// This is for GParted live iso. It's different from that for template iso.

if [ -e "$real_target_iso" ]; then
  if type isohybrid &>/dev/null; then
    echo -n "Isohybriding $real_target_iso... "
    isohybrid --uefi $real_target_iso
    echo "done!"
  fi
fi

case "$target_media_file" in
  cd|CD|iso|ISO)
     [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
     echo "$msg_burn_drbl_live_img_iso: $real_target_iso"
     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
     ;;
  usb|zip)
     [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
     echo "$msg_burn_drbl_live_img_zip: $real_target_zip"
     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
     ;;
  b|both|BOTH)
     [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
     echo "$msg_burn_drbl_live_img_iso: $real_target_iso"
     echo "$msg_burn_drbl_live_img_zip: $real_target_zip"
     [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
     ;;
esac

# ///NOTE/// This should be the last command otherwise the rest of commands might be skipped due to trap.
# Clean the tmp working directory
echo "Cleaning tmp dirs..."
clean_tmp_dirs_files