This file is indexed.

/usr/sbin/drbl-ocs is in clonezilla 3.21.13-1.

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
#!/bin/bash
#
# License: GPL 
# Original author: Blake, Kuo-Lien Huang
# Description:
#  2003/04/11 the first version, only work on /dev/hda1 & PXE
#  2003/06/01 disk to disk mode & etherboot support 
#             (the etherboot lzdsk images are located in
#              /tftpboot/etherboot-5.0.7 after DRBLCD installed)
#  2003/07/18 `checkInodeForDevice`
#
# Author: Steven Shiau <steven _at_ nchc org tw>
# 2003/07/21 the first version for Redhat, modified from Blake's version,
# only work on /dev/hda1 & PXE
# 2004/02/04 add the multicast function
# 2005/01/21 add code to save/restore some partitions (not entire disk).
# 2005/11/06 Many thanks to Christian Treczoks for providing "dd skip=1" method
# 2006/05/06 Remove save & restore hda1, since we can use save & restore partitions.
# 2006/12/07 Rewrite drbl-ocs to drbl-ocs + ocs-sr + ocs-functions.

# input parameters:
# startdisk/startparts IMAGE-NAME DEVICES

# Notes:
# task_restorexxx/savexxx function will always use $ocsroot (/home/partimag) as mount point to do the save/restore, so it might overwrite the /home/partimag by mounting $ocsroot from server:/home2 (for example).
# The mount action is done in function task_preprocessing

ocs_file="$0"
ocs=`basename $ocs_file`
ocs_myself_id="$$"
ocs_myself_ppid="$(LC_ALL=C ps --pid "$ocs_myself_id" -o ppid=)"
# log file for sfdisk when restoring
# RESTORE_SFDISK_LOG is loaded from drbl.conf

#
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

# Fedora Core 1 seems to use dumb for rc1, we have to force it use linux.
# otherwise setterm will complain.
[ -z "$TERM" -o "$TERM" = "dumb" ] && TERM="linux"
echo "Setting the TERM as $TERM"
export TERM="$TERM"

#
check_if_root

#
USAGE() {
    echo "Usage:"
    echo "To start clonezilla in server:"
    echo "$ocs [OPTION] {startdisk|startparts} {save|restore|multicast_restore}"
    echo " startdisk   operate on all partitions of the disk"
    echo " startparts  operate on the chosen partitions"
    echo
    echo " Options for saving:"
    USAGE_common_save
    echo " -i, --image-size SIZE    Set the split image file volume size SIZE (MB)."
    USAGE_reserved_word_for_save
    echo 
    echo " Options for restoring:"
    USAGE_common_restore
    echo " --time-to-wait TIME  Even when the necessary amount of clients do have connected, still wait until TIME seconds since first client connection have passed"
    echo " --clients-to-wait NUMBER  Automatically start as soon as a minimal number of clients NUMBER have connected"
    echo " -brdcst, --broadcast  Use Ethernet broadcast, rather than multicast in udpcast. Useful if you have Ethernet cards or switch which don't support multicast."
    echo " -sc0, --skip-check-restorable-on-srv  Skip checking image if restorable or not on Clonezilla server before restoring. By default it will be checked before restoring."
    USAGE_reserved_word_for_restore
    echo
    echo " General options:"
    USAGE_common_general
    dialog_like_prog_help_prompt
    echo " -h, --hosts     IP_LIST  Instead of all DRBL clients, assign the clients by IP address, like: -h \"192.168.0.1 192.168.0.2\" NOTE!!! You must put \" \" before and after the IP_LIST!"
    echo " -s, --skip-hw-detect     Skip the hardware detection (kudzu, harddrake or discover)"
    echo " -n, --no-nfs-restart     Do not to restart nfs when start or stop $ocs (This is default)"
    echo " -f, --nfs-restart        Restart nfs when start or stop $ocs (Default is to restart nfs)"
    echo " --mcast-iface  PORT      Specify the multicast seed ethernet port PORT (eth0, eth1, eth2...). Suppose clonezilla will try to find that for you, but in some case, you might want to specify that."
    echo " -x, --full-duplex         Use full-duplex network with udpcast in multicast mode (faster, but does not work with network hub, only works in switch.)."
    echo
    echo "Example:"
    echo "To start clonezilla in server (Both server and clients all will join):"
    echo "Prepare the clonezilla server, let client to save partitions hda1 and hda2 as image name 2006-12-05-22-img, with lzop compression, prompt language English. "
    echo "  $ocs" '-b -q -z3 -l en startparts save 2006-12-05-22-img "hda1 hda2"'
    echo
    echo "Prepare the clonezilla server, let client to restore hda1 and hda2 fromimage 2006-12-03-10-img to client local harddrive, with lzop compression, prompt language English, and grub-install will be run after cloning."
    echo "  $ocs -b -g auto -x -l en startparts restore 2006-12-03-10-img \"hda1 hda2\""
    echo

    echo "To stop clonezilla:"
    echo "  $ocs stop"
    echo
} # end of USAGE
#
prepare_pxecfg_for_pxe_ocs_live_if_required() {
  if [ "$diskless_client_os" = "clonezilla-live" ]; then
    # Check if Clonezilla live exists...
    if [ -z "$(ls $pxecfg_pd/Clonezilla-live-vmlinuz* 2>/dev/null)" -o \
         -z "$(ls $pxecfg_pd/Clonezilla-live-initrd*.img 2>/dev/null)" ] || \
       [ ! -e "$pxecfg_pd/Clonezilla-live-filesystem.squashfs" -a \
         ! -e "$drbl_common_root/clonezilla-live/live/filesystem.squashfs" ]; then
      [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
      echo "Clonezilla live related files (Clonezilla-live-vmlinuz*, Clonezilla-live-initrd*.img, and Clonezilla-live-filesystem.squashfs) NOT found in $pxecfg_pd!"
      [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
      echo "You have to download Clonezilla live iso file (1.2.5-2 or later is required), then run 'drbl-sl -i ISO_FILE'. E.g. '$DRBL_SCRIPT_PATH/sbin/drbl-sl -i clonezilla-live-1.2.5-2-486.iso'"
      echo "$msg_program_stop!"
      exit 1
    fi
    echo "Modifying keyboard-layouts, locales, ocs_daemonon, and ocs_prerun in $PXE_CONF if necessary..."
    # Keymap should be the same with server. If not found use that assigned in drbl-ocs.conf.
    if [ -e /etc/default/keyboard ]; then
      # Debian based system. The content of vconsole.conf is like:
      # ================
      # XKBMODEL="pc105"
      # XKBLAYOUT="us"
      # XKBVARIANT=""
      # XKBOPTIONS=""
      # ================
      . /etc/default/keyboard
      client_kb_layout="$XKBLAYOUT"
      client_kb_model="$XKBMODEL"
      client_kb_variant="$XKBVARIANT"
      client_kb_options="$XKBOPTIONS"
    fi
    if [ -z "$client_kb_layout" ]; then
      # If no keybouard layout is found, set it as that
      # is assigned in drbl-ocs.conf, force to update it.
      client_kb_layout="$ocs_live_keymap_for_pxe_ocs_live"
      # For the rest (model, variant or options they might be nothing.
    fi
    if [ -n "$client_kb_layout" ]; then
      add_opt_in_pxelinux_cfg_block -n Clonezilla-live keyboard-layouts "$client_kb_layout"
      add_opt_in_grub_efi_cfg_block -n "clonezilla-live-client" keyboard-layouts "$client_kb_layout"
    fi
    # locales should be forced to use that assigned from drbl-ocs.conf. Normally it should be "en_US.UTF-8". Check drbl-ocs.conf for more details.
    if [ -n "$ocs_lang_for_pxe_ocs_live" ]; then
      add_opt_in_pxelinux_cfg_block -n Clonezilla-live locales "$ocs_lang_for_pxe_ocs_live"
      add_opt_in_grub_efi_cfg_block -n "clonezilla-live-client" locales "$ocs_lang_for_pxe_ocs_live"
    fi
    if [ -n "$ocs_daemonon_for_pxe_ocs_live" ]; then
      add_opt_in_pxelinux_cfg_block Clonezilla-live ocs_daemonon "$ocs_daemonon_for_pxe_ocs_live"
      add_opt_in_grub_efi_cfg_block "clonezilla-live-client" ocs_daemonon "$ocs_daemonon_for_pxe_ocs_live"
    fi
    server_IP="$(LC_ALL=C get-all-nic-ip -i | awk -F" " '{print $1}')"
    # For Clonezilla live, the mount point is always /home/partimag/
    if [ -n "$ocs_prerun_for_pxe_ocs_live" ]; then
      add_opt_in_pxelinux_cfg_block Clonezilla-live ocs_prerun "$ocs_prerun_for_pxe_ocs_live"
      add_opt_in_grub_efi_cfg_block "clonezilla-live-client" ocs_prerun "$ocs_prerun_for_pxe_ocs_live"
    else
      if [ -z "$(grep -E "ocs_prerun=\"[^\"]+\"" $PXE_CONF)" ]; then
        add_opt_in_pxelinux_cfg_block Clonezilla-live ocs_prerun "mount -t nfs $server_IP:$ocsroot /home/partimag/" 
      fi
      if [ -z "$(grep -E "ocs_prerun=\"[^\"]+\"" $GRUB_CONF)" ]; then
        add_opt_in_grub_efi_cfg_block "clonezilla-live-client" ocs_prerun "mount -t nfs $server_IP:$ocsroot /home/partimag/"
      fi
    fi
    if [ "$remove_some_boot_param_for_pxe_ocs_live" = "yes" ]; then
      # We prefer verbose messages
      for i in $boot_param_2_be_removed_in_pxe_ocs_live; do
        remove_opt_in_pxelinux_cfg_block Clonezilla-live $i
        remove_opt_in_grub_efi_cfg_block "clonezilla-live-client" $i
      done
    fi
  fi
} # end of prepare_pxecfg_for_pxe_ocs_live_if_required

# OCS_OPT is for ocs-sr
OCS_OPT=
# Set some default values, 
nfs_restart="no"
always_restore="no"
pxe_menu_default_mode=""
# If always restore, i.e. multicast loop, we will show the loop number, starting from 1.
mcast_loop="1"
udp_sender_extra_opt="$udp_sender_extra_opt_default"
USE_NTFSCLONE="no"
FORCE_TO_USE_DD="no"
create_part="yes"
restore_mbr="yes"
restore_prebuild_mbr="no"
rm_win_swap_hib="no"
select_img_in_client="no"
# default output for udpcast stderr is surpressed.
# NOTE! Do not redirect it to standard output (stdin), otherwise partimage/ntfsclone pipe will get wrong image!
udpcast_stderr="/dev/null"
# default not to run those scripts in $OCS_PRERUN_DIR $OCS_POSTRUN_DIR
run_prerun_dir="no"
run_postrun_dir="no"
gen_md5sum="no"
gen_sha1sum="no"
check_md5sum="no"
check_sha1sum="no"
gen_chksum_for_files_in_dev="no"
chk_chksum_for_files_in_dev="no"
chk_img_restoreable_mod_save="yes"
chk_img_restoreable_mod_restore="yes"
chk_img_restoreable_on_srv="yes"

# 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
	    ;;
    -p|--postaction)  
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
	      postrun="$1"
              shift
            fi
	    OCS_OPT="$OCS_OPT -p $postrun"
            ;;
    -g|--grub-install)  
            install_grub="on"
            shift
            # skip the -xx option, in case 
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              grub_partition=$1
              shift
            fi
            [ -z "$grub_partition" ] && USAGE && exit 1
	    OCS_OPT="$OCS_OPT -g $grub_partition"
            ;;
    -a|--no-force-dma-on)  
	    OCS_OPT="$OCS_OPT --no-force-dma-on"
            shift;;
    -k|--no-fdisk|--no-create-partition)  
	    create_part="no"
	    OCS_OPT="$OCS_OPT -k"
            shift;;
    -k1|--fdisk-proportion)  
	    create_part="yes"
	    create_part_type="proportion"
	    OCS_OPT="$OCS_OPT -k1"
            shift;;
    -k2|--fdisk-manual)  
	    create_part="yes"
	    create_part_type="manual"
	    OCS_OPT="$OCS_OPT -k2"
            shift;;
    -t|--no-restore-mbr)  
	    restore_mbr="no"
	    OCS_OPT="$OCS_OPT -t"
            shift;;
    -t1|--restore-raw-mbr)  
            # The flag to restore syslinux mbr.bin to M$ windows system.
	    restore_prebuild_mbr="yes"
	    OCS_OPT="$OCS_OPT -t1"
            shift;;
    -u|--select-img-in-client)
	    select_img_in_client="yes"
	    OCS_OPT="$OCS_OPT -u"
            shift;;
    -e|--load-geometry)
	    OCS_OPT="$OCS_OPT -e"
            shift;;
    -e1|--change-geometry)  
            change_ntfs_boot_chs="on"
            shift
            # skip the -xx option, in case 
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              ntfs_boot_partition=$1
              shift
            fi
            [ -z "$ntfs_boot_partition" ] && USAGE && exit 1
	    OCS_OPT="$OCS_OPT -e1 $ntfs_boot_partition"
            ;;
    -e2|--load-geometry-from-edd)
	    OCS_OPT="$OCS_OPT -e2"
            shift;;
    -y|-y0|--always-restore|--always-restore-default-local)
	    always_restore="yes"
            pxe_menu_default_mode="local"
	    OCS_OPT="$OCS_OPT -y0"
            shift;;
    -y1|--always-restore-default-clone)
	    always_restore="yes"
            pxe_menu_default_mode="clone"
	    OCS_OPT="$OCS_OPT -y1"
            shift;;
    -y2|--always-restore-default-drbl)
	    always_restore="yes"
            pxe_menu_default_mode="drbl"
	    OCS_OPT="$OCS_OPT -y2"
            shift;;
    -c|--confirm)
	    OCS_OPT="$OCS_OPT -c"
	    shift;;
    -w|--wait-time)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
	      TIME_to_wait="$1"
	      OCS_OPT="$OCS_OPT -w $TIME_to_wait"
              shift
            fi
	    ;;
    -s|--skip-hw-detect)
            hw_detect="off"
	    shift;;
    --debug=?*)
            debug_level=${1#--debug=}
	    OCS_OPT="$OCS_OPT --debug=$debug_level"
	    shift;;
    -b|--batch)
            # Here we append --batch to OCS_OPT instead of -b, (it will confuse init, sinice -b for init is emergency mode)
            ocs_batch_mode="on"
	    OCS_OPT="$OCS_OPT --batch"
	    shift;;
    -d|--debug-mode)
            debug_mode="on"
	    OCS_OPT="$OCS_OPT -d"
	    shift;;
    -d0|--dialog)  
	    DIA="dialog" 
	    shift;;
    -d1|--Xdialog)  
	    DIA="Xdialog" 
	    shift;;
    -d2|--whiptail)  
	    DIA="whiptail" 
	    shift;;
    -d3|--gdialog)  
	    DIA="gdialog" 
	    shift;;
    -d4|--kdialog)  
	    DIA="kdialog" 
	    shift;;
    -h|--hosts)
	    LIST_HOST="on"
	    shift
            # skip the -xx option, in case 
            if [ -z "$(echo $1 |grep ^-.)" ]; then
	      # parse if the arg is IP, skip those not IP
              if [ -n "$(echo $1 | grep -E "^[[:space:]]*([[:digit:]]+\.){3}[[:digit:]]+([[:space:]]|$)+")" ] ; then
                IP_LIST=$1
                shift
	      else
		echo "\"$1\" is not a suitable IP_LIST!!! Program terminated!!!"
		exit 1
              fi
            fi
	    ;;
    -m|--module)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              module_to_load=$1
              shift
            fi
            [ -z "$module_to_load" ] && USAGE && exit 1
	    OCS_OPT="$OCS_OPT -m \"$module_to_load\""
            ;;
    -n|--no-nfs-restart)
            # This function is deprecated, and it's not necesssary (since we already set nfs_restart="no"), but we have to be compatable with the old version. We will remove this in the future.
	    nfs_restart="no"
	    shift;;
    -f|--nfs-restart)
	    nfs_restart="yes"
	    shift;;
    -r|--resize-partition)
	    OCS_OPT="$OCS_OPT -r"
	    shift;;
    -v|--verbose)
	    verbose="on"
	    OCS_OPT="$OCS_OPT -v"
	    shift;;
    -z0|--no-compress)
            OCS_OPT="$OCS_OPT -z0"
	    shift;;
    -z1|--gzip-compress)
            OCS_OPT="$OCS_OPT -z1"
	    shift;;
    -z1p|--smp-gzip-compress)
            OCS_OPT="$OCS_OPT -z1p"
	    shift;;
    -z2|--bz2-compress)
            OCS_OPT="$OCS_OPT -z2"
	    shift;;
    -z2p|--smp-bzip2-compress)
            OCS_OPT="$OCS_OPT -z2p"
	    shift;;
    -z3|--lzo-compress)
            OCS_OPT="$OCS_OPT -z3"
	    shift;;
    -z4|--lzma-compress)
            OCS_OPT="$OCS_OPT -z4"
	    shift;;
    -z5|--xz-compress)
            OCS_OPT="$OCS_OPT -z5"
	    shift;;
    -z5p|--smp-xz-compress)
            OCS_OPT="$OCS_OPT -z5p"
	    shift;;
    -z6|--lzip-compress)
            OCS_OPT="$OCS_OPT -z6"
	    shift;;
    -z6p|--smp-lzip-compress)
            OCS_OPT="$OCS_OPT -z6p"
	    shift;;
    -nogui|--nogui)
            # -nogui is for backward compatable, better to use --nogui
            OCS_OPT="$OCS_OPT --nogui"
	    shift;;
    -ntfs-ok|--ntfs-ok)
            # if ntfs integrity is assumed OK, do not check
            OCS_OPT="$OCS_OPT --ntfs-ok"
	    shift;;
    -rm-win-swap-hib|--rm-win-swap-hib)
            # Remove page and hibernation files in M$ windows
            OCS_OPT="$OCS_OPT --rm-win-swap-hib"
	    shift;;
    -rescue|--rescue)
            OCS_OPT="$OCS_OPT --rescue"
	    shift;;
    -fsck-src-part|--fsck-src-part)
            OCS_OPT="$OCS_OPT --fsck-src-part"
	    shift;;
    -fsck-src-part-y|--fsck-src-part-y)
            OCS_OPT="$OCS_OPT --fsck-src-part-y"
	    shift;;
    -mp|--mount-point)
            shift; 
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              mount_point=$1
	      shift
            fi
            [ -z "$mount_point" ] && USAGE && exit 1
	    OCS_OPT="$OCS_OPT --mount-point $mount_point" ; 
	    ;;
    -i|--image-size)
	    shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
              VOL_LIMIT=$1
	      shift
            fi
            [ -z "$VOL_LIMIT" ] && USAGE && exit 1
            OCS_OPT="$OCS_OPT -i $VOL_LIMIT"
	    ;;
    --time-to-wait)
	    shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
	      mcast_wait_time="$1"
	      shift
            fi
	    ;;
    --clients-to-wait)
	    shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
	      n_clients="$1"
	      shift
            fi
	    ;;
    --max-time-to-wait)
	    shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
	      mcast_max_wait_time="$1"
	      shift
            fi
            [ -z "$mcast_max_wait_time" ] && USAGE && exit 1
	    # Client need to know the --max-time-to-wait so that when sleeping
	    # between partitions restoring clone won't timeout.
            OCS_OPT="$OCS_OPT --max-time-to-wait $mcast_max_wait_time"
	    ;;
    -x|--full-duplex)
            udp_sender_extra_opt="$udp_sender_extra_opt --full-duplex"
	    shift;;
    -brdcst|--broadcast)
            udp_sender_extra_opt="$udp_sender_extra_opt --broadcast"
	    shift;;
    -q|--use-ntfsclone)
            USE_NTFSCLONE="yes"
            OCS_OPT="$OCS_OPT --use-ntfsclone"
	    shift;;
    -q1|--force-to-use-dd)
            FORCE_TO_USE_DD="yes"
            OCS_OPT="$OCS_OPT --force-to-use-dd"
	    shift;;
    -q2|--use-partclone)
            USE_PARTCLONE="yes"
            USE_NTFSCLONE="yes"
            OCS_OPT="$OCS_OPT --use-partclone"
	    shift;;
    -j|--create-part-by-sfdisk)
            # We leave this option for backward compatability.
	    OCS_OPT="$OCS_OPT --create-part-by-sfdisk"
	    shift;;
    -j0|--create-part-by-dd)
	    OCS_OPT="$OCS_OPT --create-part-by-dd"
	    shift;;
    -j1|--dump-mbr-in-the-end)
	    OCS_OPT="$OCS_OPT --dump-mbr-in-the-end"
	    shift;;
    -j2|--clone-hidden-data)
	    OCS_OPT="$OCS_OPT --clone-hidden-data"
	    shift;;
    -icrc|--icrc)
	    OCS_OPT="$OCS_OPT --icrc"
	    shift;;
    -irhr|--irhr)
	    OCS_OPT="$OCS_OPT --irhr"
	    shift;;
    -ius|--ius)
	    OCS_OPT="$OCS_OPT --ius"
	    shift;;
    -icds|--ignore-chk-dsk-size-pt)
	    OCS_OPT="$OCS_OPT --ignore-chk-dsk-size-pt"
	    shift;;
    -iefi|--ignore-update-efi-nvram)
	    OCS_OPT="$OCS_OPT --ignore-update-efi-nvram"
	    shift;;
    -srel|--save-restore-error-log)
	    OCS_OPT="$OCS_OPT --save-restore-error-log"
	    shift;;
    -hn0)
	    shift
            change_win_hostname="By_IP"
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
	      win_hostname_prefix="$1"
	      shift
            fi
            [ -z "$win_hostname_prefix" ] && USAGE && exit 1
            OCS_OPT="$OCS_OPT -hn0 $win_hostname_prefix"
	    ;;
    -hn1)
	    shift
            change_win_hostname="By_MAC"
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
	      win_hostname_prefix="$1"
	      shift
            fi
            [ -z "$win_hostname_prefix" ] && USAGE && exit 1
            OCS_OPT="$OCS_OPT -hn1 $win_hostname_prefix"
	    ;;
    -o|-o1|--run-postrun-dir) 
            # -o is for backward compatability
	    run_postrun_dir="yes"
	    OCS_OPT="$OCS_OPT --run-postrun-dir"
	    shift;;
    -o0|--run-prerun-dir) 
	    run_prerun_dir="yes"
	    OCS_OPT="$OCS_OPT --run-prerun-dir"
	    shift;;
    -ns|--ntfs-progress-in-image-dir)
	    OCS_OPT="$OCS_OPT --ntfs-progress-in-image-dir"
	    shift;;
    -gm|--gen-md5sum)
	    gen_md5sum="yes"
	    OCS_OPT="$OCS_OPT -gm"
	    shift;;
    -gs|--gen-sha1sum)
	    gen_sha1sum="yes"
	    OCS_OPT="$OCS_OPT -gs"
	    shift;;
    -gmf|--gen-chksum-for-files-in-dev)
	    gen_chksum_for_files_in_dev="yes"
	    OCS_OPT="$OCS_OPT -gmf"
	    shift;;
    -cm|--check-md5sum)
	    check_md5sum="yes"
	    OCS_OPT="$OCS_OPT -cm"
	    shift;;
    -cs|--check-sha1sum)
	    check_sha1sum="yes"
	    OCS_OPT="$OCS_OPT -cs"
	    shift;;
    -cmf|--chk-chksum-for-files-in-dev)
	    chk_chksum_for_files_in_dev="yes"
	    OCS_OPT="$OCS_OPT -cmf"
	    shift;;
    --mcast-iface)
	    shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
	      eth_for_multicast="$1"
	      shift
            fi
            [ -z "$eth_for_multicast" ] && USAGE && exit 1
	    ;;
    -um|--user-mode)
            shift
            # skip the -xx option, in case 
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              ocs_user_mode="$1"
              shift
            fi
            [ -z "$ocs_user_mode" ] && USAGE && exit 1
	    OCS_OPT="$OCS_OPT -um"
	    ;;
    -sc0|--skip-check-restorable-on-srv)
            # flag to check if the image is restorable on clonezilla server
	    chk_img_restoreable_on_srv="no"
	    shift
            ;;
    -sc|-scs|--skip-check-restorable|--skip-check-restorable-s)
            # flag to check if the image is restorable
	    chk_img_restoreable_mod_save="no"
	    OCS_OPT="$OCS_OPT -scs"
	    shift
            ;;
    -scr|--skip-check-restorable-r)
            # Flag to check if the image is restorable
	    chk_img_restoreable_mod_restore="no"
	    OCS_OPT="$OCS_OPT -scr"
	    shift
            ;;
    -*)     echo "${0}: ${1}: invalid option" >&2
            USAGE >& 2
            exit 2 ;;
    *)      break ;;
  esac
done

# drbl_ocs_type, task, target_image are global variables.
# we use 3 times shift instead of "shift 3", it because the run command maybe like:
# drbl-ocs -b -q -p reboot -z3 -l en startdisk save
# so if we use "shift 3", it will fail, then target_dev will be "startdisk save"! It's wrong.
drbl_ocs_type="$1"
shift
task="$1"
shift
target_image="$1"
shift
target_dev="$*"
# If the inputted dev is: "hda hdb", convert it to hda hdb (so it won't be ""hda hdb"")
target_dev="$(echo $target_dev | tr -d \")"

#
ask_and_load_lang_set $specified_lang

# check DIA
check_DIA_set_ESC $DIA

[ -z "$VOL_LIMIT" ] && VOL_LIMIT=$VOL_LIMIT_DEFAULT
# ask_user is used for interactive dialog.
if [ "$target_image" = "ask_user" -a "$(echo $task | grep -E "save")" ]; then
  [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
  echo "$msg_ask_user_is_reserved_for_save_mode"
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  echo "Program terminated!!!"
  exit 1
fi

check_ocs_input_params

# ocs root
[ ! -d "$ocsroot" ] && mkdir -p $ocsroot

# change to other mount point for extra harddisk
# Note: functions get_existing_disk_image, get_existing_parts_image and get_existing_partitions_from_img will use $imagedir 
if [ -n "$mount_point" ]; then
   echo "Using the image root directory $mount_point instead of $ocsroot."
   imagedir="$mount_point" 
else
   imagedir="$ocsroot"
fi

echo $msg_delimiter_star_line
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
[ "$create_part" = "no" ] && echo "$msg_do_not_create_part"
[ "$restore_mbr" = "no" ] && echo "$msg_do_not_restore_mbr"
[ "$select_img_in_client" = "yes" ] && echo "$msg_you_have_to_input_image_names_in_client"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo $msg_delimiter_star_line

if [ "$verbose" = "on" ]; then
  # The default output for udpcast stderr is surpressed, now turn it on
  udpcast_stderr="/dev/stderr"
fi

# To avoid confusion about multicast or broadcast, we use different prompts.
if [ -n "$(echo "$udp_sender_extra_opt" | grep -E -- "--broadcast")" ]; then
  multi_broad_cast_prompt="broadcast"
else
  multi_broad_cast_prompt="multicast"
fi

##############
#### main ####
##############

# HOST_OPTION_MODIFY: add this part for specifying the hosts.
if [ "$LIST_HOST" = "on" ]; then
  # copy the skeleton file
  PXE_CONF="$PXELINUX_DIR/default_skeleton"
  cp -f $PXELINUX_DIR/default $PXE_CONF
  GRUB_CONF="$GRUB_EFINB_DIR/grub.cfg_skeleton"
  cp -f $GRUB_EFINB_DIR/grub.cfg $GRUB_CONF
else
  PXE_CONF="$PXELINUX_DIR/default"
  GRUB_CONF="$GRUB_EFINB_DIR/grub.cfg"
  # Clean all the previous saved config file.
  # These files maybe look like: 01-MAC address, something like C0A8XXXX (only for 192.168.x), default_skeleton
  echo -n "Clean all the previous saved config file if they exist..."
  clean_stale_node_pxe_cfg
  # Only for those non-stop case we will clean the GRUB UEFI NB config files
  # Otherwise if only /tftpboot/nbi_img/grub.cfg exist, the GRUB EFI NB clienet can not boot into local disk because the original "local-disk" menuentry is only a template. For the real working one, .e.g. grub.cfg-01-00-0c-29-7d-29-b7, it's the one created by ocsmgrd.
  if [ "$drbl_ocs_type" != "stop" ]; then
    clean_stale_node_grub_efi_cfg
  fi
fi

if [ ! -d "$ocsroot" ]; then
  echo "Please make sure your $ocsroot is a directory!!!"
  echo "We can NOT go on! Press \"c\" to enter command prompt or any other key to quit the program..." 
  read fail_answer
  case "$fail_answer" in
    [cC]) sulogin ;;
       *) exit 1 ;;
  esac
fi
#
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "Client OS type when doing Clonezilla job is: $diskless_client_os"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL

#
prepare_pxecfg_for_pxe_ocs_live_if_required

# Create the dir for clonezilla pre/post run when clone starts/finishes. Therefore we can put some scripts in that directory.
[ ! -d $OCS_PRERUN_DIR ] && mkdir -p $OCS_PRERUN_DIR
[ ! -d $OCS_POSTRUN_DIR ] && mkdir -p $OCS_POSTRUN_DIR

# put default postrun if empty
[ -z "$postrun" ] && postrun="$POSTRUN_DEF"

# If the image is checked on the server, then we force to skip image checking on the clients when restoring.
if [ "$chk_img_restoreable_on_srv" = "yes" ]; then
  chk_img_restoreable_mod_restore="no"
  OCS_OPT="$OCS_OPT -scr"
else
  # When image is not checked on the server, how about the client? Only select_in_client mode we will make it to be check on the clients.
  if [ ! "$drbl_ocs_type" = "select_in_client" ]; then
    if [ -n "$(echo $task | grep -i "restore")" ]; then
      # Not in select_in_client mode, skip checking in the clients.
      chk_img_restoreable_mod_restore="no"
      OCS_OPT="$OCS_OPT -scr"
    fi
  fi
fi

#
case "$drbl_ocs_type" in
  "startdisk")
    target_hd="$target_dev"
    # task, target_image & target_hd are global variables
    do_startdisk
    if [ "$diskless_client_os" = "clonezilla-live" ]; then
      hide_reveal_pxe_img Clonezilla-live reveal $PXE_CONF
      hide_reveal_grub_efi_ent clonezilla-live-client reveal $GRUB_CONF
    else
      hide_reveal_pxe_img clonezilla reveal $PXE_CONF
      hide_reveal_grub_efi_ent clonezilla-se-client reveal $GRUB_CONF
    fi
    [ "$copy_rc1d_for_drbl_ssi_clone_box" = "yes" ] && copy_rc1d_for_drbl_ssi
    prompt_to_turn_on_client $task
    ;;
  "startparts")
    target_parts="$target_dev"
    # task, target_image & target_parts are global variables
    do_startparts
    if [ "$diskless_client_os" = "clonezilla-live" ]; then
      hide_reveal_pxe_img Clonezilla-live reveal $PXE_CONF
      hide_reveal_grub_efi_ent clonezilla-live-client reveal $GRUB_CONF
    else
      hide_reveal_pxe_img clonezilla reveal $PXE_CONF
      hide_reveal_grub_efi_ent clonezilla-se-client reveal $GRUB_CONF
    fi
    [ "$copy_rc1d_for_drbl_ssi_clone_box" = "yes" ] && copy_rc1d_for_drbl_ssi
    prompt_to_turn_on_client $task
    ;;
  "select_in_client")
    do_select_in_client
    if [ "$diskless_client_os" = "clonezilla-live" ]; then
      hide_reveal_pxe_img Clonezilla-live reveal $PXE_CONF
      hide_reveal_grub_efi_ent clonezilla-live-client reveal $GRUB_CONF
    else
      hide_reveal_pxe_img clonezilla reveal $PXE_CONF
      hide_reveal_grub_efi_ent clonezilla-se-client reveal $GRUB_CONF
    fi
    [ "$copy_rc1d_for_drbl_ssi_clone_box" = "yes" ] && copy_rc1d_for_drbl_ssi
    prompt_to_turn_on_client "select_in_client"
    ;;
  "stop")
    [ "$copy_rc1d_for_drbl_ssi_clone_box" = "yes" ] && remove_rc1d_for_drbl_ssi
    # since now drbl and clonezilla separates in PXELinux menu, no more regen the drbl ssi template tarball.
    stop_ocs_service no
    # Make client to boot in drbl mode with menu label specified.
    # get the distribution name and type: OS_Version and OS_type
    check_distribution_name
    # Check if drbl_mode is none or not. If none, we have to set the default menu as local
    # Here we use subshell to avoid variables are introduced.
    (
      if [ -e /etc/drbl/drbl_deploy.conf ]; then
        . /etc/drbl/drbl_deploy.conf
      fi
      case "$drbl_mode" in
        none) force_pxe_clients_boot_label local 
              force_grub_efi_clients_boot_label local-disk "Local"
              ;;
           *) force_pxe_clients_boot_label drbl
              force_grub_efi_clients_boot_label drbl-client
              ;;
      esac
    )
    # When stopping the service, we disable all, no matter it's NFSroot-based or Clonezilla-live based.
    # (1) for NFSroot-based
    # For GRUB EFI NB config, it's important we have to remove the option first, then hide it.
    remove_opt_in_pxelinux_cfg_block clonezilla ocs_opt
    remove_opt_in_grub_efi_cfg_block "clonezilla-se-client" ocs_opt
    hide_reveal_pxe_img clonezilla hide $PXE_CONF
    hide_reveal_grub_efi_ent clonezilla-se-client hide $GRUB_CONF
    # (2) for Clonezila-live-based
    if [ -n "$(LC_ALL=C grep -E '^label Clonezilla-live' $PXE_CONF)" ]; then
      remove_opt_in_pxelinux_cfg_block Clonezilla-live ocs_live_run
      hide_reveal_pxe_img Clonezilla-live hide $PXE_CONF
    fi
    if [ -e "$GRUB_CONF" ]; then
      if [ -n "$(LC_ALL=C grep -E '^menuentry.*--id clonezilla-live-client' $GRUB_CONF)" ]; then
        remove_opt_in_grub_efi_cfg_block "clonezilla-live-client" ocs_live_run
        hide_reveal_grub_efi_ent clonezilla-live-client hide $GRUB_CONF
      fi
    fi
    # Since now we separate Clonezilla and DRBL label block in PXE menu, 
    # Clonezilla will always with runlevel 1. Skip this.
    # remove runlevel 1 to kernel parameter in pxelinux config
    # remove_runlevel_1_in_pxelinux_cfg_block clonezilla

    # If the mode is in always_restore, we will set local boot as default. Since
    # the always_restore mode is only useful with local OS exists.
    if [ "$always_restore" = "yes" ]; then
      force_pxe_clients_boot_label local "$local_os_menu_label"
      force_grub_efi_clients_boot_label local-disk "Local" >/dev/null 
    fi
    ;;
  *)
    USAGE
    ;;
esac

exit 0