#!/bin/bash
# Author: Steven Shiau <steven _at_ nchc org tw> and Blake, Kuo-Lien Huang <klhaung _at_ gmail.com>. 
# License: GPL 
# Description: DRBL utitilty to switch the mode for clients.

# To use reboot, shutdown, wake-on-lan for Cygwin clients, you must put the
# ssh key to those Cygwin clients.

# Load DRBL setting and functions
if [ ! -f "/opt/drbl/sbin/drbl-conf-functions" ]; then
  echo "Unable to find /opt/drbl/sbin/drbl-conf-functions! Program terminated!" 
  exit 1
fi
. /opt/drbl/sbin/drbl-conf-functions

#
# DIA (="dialog") is loaded from drbl.conf
MAX_DIALOG_HEIGHT="12"

#
check_if_root

# get the OS_Version and OS_type
check_distribution_name

# function
USAGE() {
   echo "Usage: $0 [OPTION] MODE [MODE2]"
   echo "OPTION"
   language_help_prompt_by_idx_no
   echo "-h, --host [IP_LIST|MAC_LIST] Instead of all DRBL clients, assign some DRBL clients (IP_LIST or MAC_LIST) to be processed, if IP_LIST or MAC_LIST is not set, a dialog menu will be shown so that the target DRBL client(s) can be selected. The IP_LIST is like: \"192.168.0.1 192.168.0.2\", and the MAC_LIST is like \"00:50:56:01:02:01 00:50:56:01:02:02\". NOTE!!! You must put \" \" before and after the IP_LIST or MAC_LIST!"
   echo "-nl, --no-list-host   Set all clients' mode (This is default)"
   echo "MODE:"
   echo "remote-linux-gra      Client machine will boot from DRBL server,"
   echo "                      and enter graphic mode, for powerful client."
   echo "remote-linux-txt      Client machine will boot from DRBL server,"
   echo "                      and enter text mode, for powerful client."
   echo "terminal              Remote display Linux, terminal mode."
   echo "remote-memtest        Remote boot to run memtest86"
   echo "remote-fdos           Remote boot to run FreeDOS"
   echo "clonezilla-start      Start Clonezilla mode"
   echo "clonezilla-stop       Stop the clonezilla mode"
   echo "local                 Client machine will boot from local (now PXE only)"
   echo "reboot                Reboot DRBL clients now"
   echo "shutdown              Shutdown DRBL clients now"
   echo "Wake-on-LAN           Turn on DRBL clients by Wake-on-LAN now"
   echo "netinstall            Let clients to install Linux distribution via network (PXE/etherboot)"
   echo "switch-pxe-menu       Switch DRBL client menus"
   echo "drbl-ssi              Switch the DRBL Single System Image mode" 
   echo "login-switch          Switch DRBL client login mode"
   echo 
   echo "MODE2:"
   echo "Based on MODE, assign the 2nd level mode:"
   echo "For MODE=clonezilla-start, available MODE2:"
   echo "clonezilla-save-disk: Clonezilla save disk mode"
   echo "clonezilla-restore-disk: Clonezilla restore disk Mode"
   echo "clonezilla-save-parts: Clonezilla save partitions mode"
   echo "clonezilla-restore-parts: Clonezilla restore partitions mode"
   echo "clonezilla-save-hda1: Clonezilla save 1st partition (hda1) mode"
   echo "clonezilla-restore-hda1: Clonezilla restore 1st partition (hda1) mode"
   echo "For MODE=others, available MODE2:"
   echo "switch-drbl-serv      Start, stop or restart DRBL related services in DRBL server"
   echo "client-reautologin    Force to restart client autologin" 
   echo "clean-autologin-account Delete all autologin accounts" 
   echo "re-deploy             Re-deploy files to clients, i.e. update the files of server to clients."
   echo "clean-dhcpd-lease     Force to reset DHCP IP address leases" 
   echo 
   echo "If no argument is specified, a dialog will appear to let you choose the mode!"
}

# function : stop_ocs
stop_ocs_if_necessary() {
  # $IP_LIST and $OCS_OPTS are global variables
  # if "LIST_HOST" is NOT nothing, we will process those clients... use the
  # -h parameter of drbl-ocs.
  if [ -f "$ocsroot/clonezilla.lock" ]; then
    echo "Your system is already in clonezilla mode... we will stop it first, then change to other mode..."
    if [ -n "$IP_LIST" ]; then 
      $DRBL_SCRIPT_PATH/sbin/drbl-ocs -n $OCS_OPTS -h "$IP_LIST" -l $lang stop
    else
      $DRBL_SCRIPT_PATH/sbin/drbl-ocs -n $OCS_OPTS -l $lang stop
    fi
  fi
}

#
multicast_clonezilla_restore_warning() {
  $DIA --title "$msg_multicast_clonezilla_warning" --clear \
       --msgbox "$msg_multicast_clonezilla_warning_des" 0 0
}

#
ask_if_want_list_host() {
$DIA --title "$msg_title_set_all_clients" \
     --yesno "$msg_set_all_clients \n\
$msg_set_all_clients_des" 0 0 

case $? in
  0)
    LIST_HOST="off";;
  1)
    LIST_HOST="on";;
  255)
    echo "Box closed.";;
esac

}
#
ask_if_skip_set_ocs_extra_param() {
#TODO: not all drbl-ocs parameters are set here... add more in the future.
local mode=$1
OCS_PARAM_TMP=$2
local OCS_OPTS

if [ "$mode" = "restore" ]; then
  restore_prompt1="-g auto, $msg_ocs_param_g_auto \n-c,      $msg_ocs_param_c \n-u,      $msg_ocs_param_u \n-y,      $msg_ocs_param_y \n-t,      $msg_ocs_param_t \n-k,      $msg_ocs_param_k \n-e,      $msg_ocs_param_e"
fi

$DIA --title "$msg_clonezilla_advanced_extra_param" \
     --yesno "$msg_skip_set_advanced_extra_param\
$restore_prompt1" 0 0 
case $? in
  0)
    # skip setting, so set_ocs_param=no
    set_ocs_param="no";;
  1)
    # NO skiping setting, so set_ocs_param=yes
    set_ocs_param="yes";;
  255)
    echo "Box closed.";;
esac

if [ "$set_ocs_param" = "yes" ]; then
  if [ "$mode" = "restore" ]; then
    $DIA --separate-output --backtitle "$msg_nchc_free_software_labs" --title  \
    "$msg_clonezilla_advanced_extra_param" --checklist "$msg_choose_param_to_set:" \
    0 0 0 \
    "-g auto"  "$msg_ocs_param_g_auto" off \
    "-f"       "$msg_ocs_param_f" off \
    "-c"       "$msg_ocs_param_c" off \
    "-u"       "$msg_ocs_param_u" off \
    "-y"       "$msg_ocs_param_y" off \
    "-s"       "$msg_ocs_param_s" off \
    "-k"       "$msg_ocs_param_k" off \
    "-t"       "$msg_ocs_param_t" off \
    "-e"       "$msg_ocs_param_e" off \
    2> $OCS_PARAM_TMP
  else
    # save
    $DIA --separate-output --backtitle "$msg_nchc_free_software_labs" --title  \
    "$msg_clonezilla_advanced_extra_param" --checklist "$msg_choose_param_to_set:" \
    0 0 0 \
    "-f"       "$msg_ocs_param_f" off \
    "-s"       "$msg_ocs_param_s" off \
    2> $OCS_PARAM_TMP
  fi
fi

if [ "$mode" = "save" ]; then
  save_prompt2="-z0,     $msg_ocs_param_z0 \n-z1,     $msg_ocs_param_z1 \n-z2,     $msg_ocs_param_z2"

  $DIA --title "$msg_clonezilla_advanced_extra_param" \
       --yesno "$msg_skip_set_save_compression_extra_param\
$save_prompt2"\
       0 0 
  case $? in
    0)
      # skip setting, so set_ocs_save_param=no
      set_ocs_save_param="no";;
    1)
      # NO skiping setting, so set_ocs_save_param=yes
      set_ocs_save_param="yes";;
    255)
      echo "Box closed.";;
  esac
fi

if [ "$set_ocs_save_param" = "yes" ]; then
  # save
  $DIA --backtitle "$msg_nchc_free_software_labs" --title  \
  "$msg_clonezilla_advanced_extra_param" --radiolist "$msg_choose_one_compression_param_to_save:" \
  0 0 0\
  "-z0"      "$msg_ocs_param_z0" off \
  "-z1"      "$msg_ocs_param_z1" off \
  "-z2"      "$msg_ocs_param_z2" off \
  2>> $OCS_PARAM_TMP
fi
}

#
ask_if_input_save_image_name_in_server() {
  local save_type=$1
$DIA --title "$msg_title_input_save_image_name_in_server" \
     --yesno "$msg_ask_if_input_save_image_name_in_server" 0 0 

case $? in
  0)
    input_save_image_name_in_server="yes";;
  1)
    input_save_image_name_in_server="no";;
  255)
    echo "Box closed.";;
esac

  if [ "$input_save_image_name_in_server" = "yes" ]; then
    local TMP=`mktemp /tmp/ocs_name.XXXXXX`
    local img_name_default="$(date +%F-%H-img)"
    trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
    $DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla" \
    --inputbox "$msg_input_image_name" 0 0 "$img_name_default" 2> $TMP
    input_save_img_name="$(cat $TMP)"
    [ -z "$input_save_img_name" ] && echo "You must input a name to save the image! Program terminated!" && exit 1
    [ -d "$ocsroot/$input_save_img_name" ] && echo "The name you inputted already existed! Program terminated!" && exit 1
    [ -f "$TMP" ] && rm -f $TMP

    # if it's savehda1, we won't ask the device, it's hda1 always.
    [ "$save_type" = "savehda1" ] && return

    local TMP=`mktemp /tmp/ocs_name.XXXXXX`
    local dev_example
    trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
    case "$save_type" in
     "savedisk")
           dev_example="hda"
           ;;
     "saveparts")
           dev_example="hda1 hda2"
           ;;
    esac
    $DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla" \
    --inputbox "$msg_input_device_name (Ex: $dev_example)" 0 0 "$dev_example" 2> $TMP
    input_device_name="$(cat $TMP)"
    [ -z "$input_device_name" ] && echo "You must input a device name to save the image! Program terminated!" && exit 1
    [ -f "$TMP" ] && rm -f $TMP
  fi
}

#
run_login_switch() {
  TMP=$(mktemp /tmp/menu.XXXXXX)
  trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
  echo "Switch DRBL client login mode"
  $DIA --backtitle "$msg_nchc_free_software_labs" --title  \
  "$msg_login_switch" --radiolist "$msg_choose_action:" \
  0 0 0 \
  "normal"  "$msg_normal_login" off \
  "auto"    "$msg_auto_login" off \
  "timed"   "$msg_timed_login" off \
  2> $TMP
  action="--""$(cat $TMP)"
  [ -f "$TMP" ] && rm -f $TMP
  [ -z "$action" ] && echo "You must specify the action! Program terminated!!!" && exit 1
  $DRBL_SCRIPT_PATH/sbin/drbl-login-switch $action -l $lang
} # end of run_login_switch
#
run_drbl_ssi_switch() {
  TMP=$(mktemp /tmp/menu.XXXXXX)
  trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
  echo "Switch DRBL client image mode"
  $DIA --backtitle "$msg_nchc_free_software_labs" --title  \
  "$msg_drbl_ssi_switch" --radiolist "$msg_drbl_ssi_switch_long" \
  0 0 0 \
  "on"  "$msg_drbl_ssi_on" off \
  "off" "$msg_drbl_ssi_off" off \
  2> $TMP
  action="$(cat $TMP)"
  [ -f "$TMP" ] && rm -f $TMP
  [ -z "$action" ] && echo "You must specify the action! Program terminated!!!" && exit 1
  # Ask if clonezilla box mode is used or not ?
  if [ "$action" = "on" ]; then
    TMP2=$(mktemp /tmp/menu2.XXXXXX)
    trap "[ -f "$TMP2" ] && rm -f $TMP2" HUP INT QUIT TERM EXIT
    echo "Turn on clonezilla box mode, too ?"
    $DIA --backtitle "$msg_nchc_free_software_labs" --title  \
    "$msg_clonezilla_box_mode_switch" --radiolist "$msg_clonezilla_box_mode_switch_long" \
    0 0 0 \
    "yes"  "$msg_clonezilla_box_mode_yes" off \
    "no" "$msg_clonezilla_box_mode_no" off \
    2> $TMP2
    clonezilla_box_mode_opt="$(cat $TMP2)"
    [ -f "$TMP2" ] && rm -f $TMP2
    [ -z "$clonezilla_box_mode_opt" ] && echo "You must specify the clonezilla_box_mode_opt! Program terminated!!!" && exit 1
    [ -n "$clonezilla_box_mode_opt" ] && clonezilla_box_mode_opt="-z $clonezilla_box_mode_opt"
  fi
  $DRBL_SCRIPT_PATH/sbin/turn-drbl-ssi-mode $clonezilla_box_mode_opt $action
} # end of run_drbl_ssi_switch

#
run_switch_drbl_service() {
  TMP=$(mktemp /tmp/menu.XXXXXX)
  trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
  echo "Switch DRBL related services in DRBL server"
  $DIA --backtitle "$msg_nchc_free_software_labs" --title  \
  "$msg_switch_drbl_service" --radiolist "$msg_choose_action:" \
  0 0 0 \
  "start"    "$msg_start_drbl_all_services" off \
  "stop"     "$msg_stop_drbl_all_services" off \
  "restart"  "$msg_restart_drbl_all_services" off \
  2> $TMP
  action="$(cat $TMP)"
  [ -f "$TMP" ] && rm -f $TMP
  [ -z "$action" ] && echo "You must specify the action! Program terminated!!!" && exit 1
  $DRBL_SCRIPT_PATH/sbin/drbl-all-service $action
} # end of run_switch_drbl_service

# 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
	;;
    -h|--host)  
	    LIST_HOST="on"
            shift
            # skip the -xx option, in case 
            if [ -z "$(echo $1 |grep ^-.)" ]; then
	      # parse if the arg is MAC or IP, skip those not MAC or IP
              if [ -n "$(echo $1 | grep -E "^[[:space:]]*([[:alnum:]]+:){5}[[:alnum:]]+([[:space:]]|$)+")" -o -n "$(echo $1 | grep -E "^[[:space:]]*([[:digit:]]+\.){3}[[:digit:]]+([[:space:]]|$)+")" -o -z "$1" ] ; then
                IP_LIST=$1
                shift
	      else
		echo "\"$1\" is not a suitable IP_LIST or MAC_LIST !!! Program terminated!!!"
		exit 1
              fi
            fi
	    ;;
    -nl|--no-list-host)  
	    LIST_HOST="off" 
	    shift;;
    -*)     echo "${0}: ${1}: invalid option" >&2
            USAGE >& 2
            exit 2 ;;
    *)      break ;;
  esac
done

######
## main script
######
MODE="$1"
# We havw two levels, like clonezilla-start clonezilla-save-disk
MODE2="$2"

ask_and_load_lang_set $specified_lang

[ -z "$LIST_HOST" ] && ask_if_want_list_host

# 
if [ "$LIST_HOST" = "on" ]; then
  # We need 1 file and 1 variable to sepcify hosts, 
  # (1) file "HOSTS_TMP", which contains IP list or MAC list.
  # (2) variable "IP_LIST", which contains IP list only (if user specify MAC list, we will convert them to IP list based on dhcpd.conf)

  # NOTES: after the modification of PXE_CONF, we must run
  #       [ "$LIST_HOST" = "on" ] && set_specific_host_pxe_conf `cat $HOSTS_TMP`
  # to update the pxeconf (both for 01-MAC and IP)

  HOSTS_TMP="$(mktemp /tmp/hosts_tmp.XXXXXXX)"
  trap "[ -f "$HOSTS_TMP" ] && rm -f $HOSTS_TMP" HUP INT QUIT TERM EXIT
  MAC_LIST=""
  # The content of $HOSTS_TMP can be IP list or MAC list (generated by select_hosts)
  if [ -z "$IP_LIST" ]; then
    $DRBL_SCRIPT_PATH/sbin/select_hosts -l $lang $HOSTS_TMP 
    retval=$?
  else
    # user already specified the hosts, so we just put them in $HOSTS_TMP
    echo $IP_LIST > $HOSTS_TMP
    retval=$?
  fi
  if [ $retval -eq 0 ]; then
    # copy the skeleton file
    PXE_CONF="$PXELINUX_DIR/default_skeleton"
    cp -f $PXELINUX_DIR/default $PXE_CONF
  
    if grep -Eq "^[[:space:]]*([[:alnum:]]+:){5}[[:alnum:]]+([[:space:]]|$)+" $HOSTS_TMP; then
      # HOSTS_TMP is MAC list.
      # prepare the IP list if the HOSTS_TMP is MAC list.
      MAC_LIST="$(cat $HOSTS_TMP)"
      for imac in $MAC_LIST; do
        #IP="$(awk -F" " '/$imac/ {print $2}' $HOST_MAC_TABLE)"
        IP="$(grep $imac $HOST_MAC_TABLE | awk -F" " '{print $2}')"
        IP_LIST="$IP_LIST $IP"
      done
    else
      # HOSTS_TMP is IP list.
      IP_LIST="$(cat $HOSTS_TMP)"
    fi
  else
    echo "No client is selected! Abort!"
    exit 0
  fi
else
  PXE_CONF="$PXELINUX_DIR/default"
  # Clean all the previous saved config file.
  # These files maybe look like: 01-MAC address (with ":" -> "-"), something like C0A8XXXX (only for 192.168.x), default_skeleton
  echo -n "Clean all the previous saved PXELINUX config file if they exist..."
  for ifile in $PXELINUX_DIR/*; do
    [ "$ifile" != "$PXE_CONF" -a -f "$ifile" ] && rm -f $ifile
  done
  echo "done!"
fi
# If clonezilla box mode, we have to suppress some functions
[ -f /etc/drbl/drbl_deploy.conf ] && . /etc/drbl/drbl_deploy.conf
if [ "$clonezilla_box_mode" != "yes" ]; then
   # "remote-linux-gra" "$msg_remote_linux_graphic" off \
   remote_linux_gra_1="remote-linux-gra"
   remote_linux_gra_2="$msg_remote_linux_graphic"
   remote_linux_gra_3="off"
   # "remote-linux-txt" "$msg_remote_linux_text" off \
   remote_linux_txt_1="remote-linux-txt"
   remote_linux_txt_2="$msg_remote_linux_text"
   remote_linux_txt_3="off"
   # "terminal" "$msg_terminal" off \
   terminal_1="terminal"
   terminal_2="$msg_thin_client"
   terminal_3="off"
   # "login-switch" "$msg_login_switch" off \
   login_switch_1="login-switch"
   login_switch_2="$msg_login_switch"
   login_switch_3="off"
   # "client-reautologin" "$msg_client_reautologin" off \
   client_reautologin_1="client-reautologin"
   client_reautologin_2="$msg_client_reautologin"
   client_reautologin_3="off"
   # "clean-autologin-account" "$msg_clean_autologin_account" off \
   clean_autologin_account_1="clean-autologin-account"
   clean_autologin_account_2="$msg_clean_autologin_account"
   clean_autologin_account_3="off"
   # "reset-autologin-account" "$msg_reset_autologin_account" off \
   reset_autologin_account_1="reset-autologin-account"
   reset_autologin_account_2="$msg_reset_autologin_account"
   reset_autologin_account_3="off"
fi

# Get the mode from use
if [ -z "$MODE" ]; then 
     TMP="$(mktemp /tmp/menu.XXXXXX)"
     trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
     $DIA \
     --backtitle "$msg_nchc_title" \
     --title "$msg_nchc_drbl" \
     --no-shadow \
     --radiolist "$msg_switch_client_mode:" 0 0 0 \
     $remote_linux_gra_1 $remote_linux_gra_2 $remote_linux_gra_3 \
     $remote_linux_txt_1 $remote_linux_txt_2 $remote_linux_txt_3 \
     $terminal_1 $terminal_2 $terminal_3 \
     "remote-memtest" "$msg_remote_memtest" off \
     "remote-fdos" "$msg_remote_fdos" off \
     "clonezilla-start" "$msg_clonezilla_start" off \
     "clonezilla-stop" "$msg_clonezilla_stop" off \
     "netinstall" "$msg_netinstall" off \
     "local" "$msg_local" off \
     "reboot" "$msg_reboot" off \
     "shutdown" "$msg_shutdown" off \
     "Wake-on-LAN" "$msg_Wake_on_LAN" off \
     "switch-pxe-menu" "$msg_switch_pxe_menu" off \
     "drbl-ssi" "$msg_drbl_ssi_switch" off \
     $login_switch_1 $login_switch_2 $login_switch_3 \
     "others" "$msg_dcs_others" off \
     2> $TMP
     MODE=$(cat $TMP)
     [ -f "$TMP" ] && rm -f $TMP
fi

# set the mode for PXE client
case "$MODE" in
  "remote-linux-gra") 
         echo "Settinig client as remote-linux graphic mode..."
         stop_ocs_if_necessary
         $DRBL_SCRIPT_PATH/sbin/set-default-pxe-img -i drbl -c $PXE_CONF -l "$FULL_OS_Version $powerful_client_menu_label"
         if [ "$LIST_HOST" = "on" ]; then
           # use --no-gen-ssi, we will run gen_ssi_files when finished
	   $DRBL_SCRIPT_PATH/sbin/drbl-powerful-thin-client --no-gen-ssi -p -h "$IP_LIST" -ln $lang
         else
           # use --no-gen-ssi, we will run gen_ssi_files when finished
	   $DRBL_SCRIPT_PATH/sbin/drbl-powerful-thin-client --no-gen-ssi -p -ln $lang
         fi

	 # specify the nodes if assigned by user
         [ "$LIST_HOST" = "on" ] && set_specific_host_pxe_conf `cat $HOSTS_TMP`

         for host in $drblroot/*; do
           # if the LIST_HOST is on, skip those IP not listed in the $IP_LIST
	   if [ "$LIST_HOST" = "on" ]; then
	     [ -z "$(echo $IP_LIST | grep ${host##/*/})" ] && continue
           fi

	   # 
           host_ip=$(basename $host)
           echo "Setting the remote-linux graphic mode for node IP = $host_ip"
	   if [ -e /etc/debian_version ]; then
             # Debian
             if [ -e /etc/b2d-release ]; then
	       # For B2D, it uses runlevel 5 for X 
               CLIENT_INIT="5"
             else
	       # For Debian, Ubuntu, it uses runlevel 2 for X 
               CLIENT_INIT="2"
             fi
             default_dm="$($DRBL_SCRIPT_PATH/bin/check_dm -h $host_ip)"
             prepare_update_rc_d_env $host
             LC_ALL=C chroot $host/ /usr/sbin/update-rc.d $default_dm start 99 2 3 4 5 . stop 05 0 1 6 . &> /dev/null
           else
             # RH-like or SUSE
             # set the init to 5, i.e. default is X
             CLIENT_INIT="5"
           fi
	   # Modify client's /etc/inittab
           perl -p -i -e "s/^id:[0-9]:initdefault:/id:$CLIENT_INIT:initdefault:/g" $host/etc/inittab
         done
	 echo "done!"
         #
         echo "-------------------------------------------------------"
         echo "Since some config files are modified in template client, creating template tarball for DRBL SSI..."
         $DRBL_SCRIPT_PATH/sbin/gen_ssi_files
         ;;
  "remote-linux-txt") 
         echo "Settinig client as remote-linux text mode..."
         stop_ocs_if_necessary
         $DRBL_SCRIPT_PATH/sbin/set-default-pxe-img -i drbl -c $PXE_CONF -l "$FULL_OS_Version $powerful_client_menu_label"
         if [ "$LIST_HOST" = "on" ]; then
           # use --no-gen-ssi, we will run gen_ssi_files when finished
	   $DRBL_SCRIPT_PATH/sbin/drbl-powerful-thin-client --no-gen-ssi -p -h "$IP_LIST" -ln $lang
         else
           # use --no-gen-ssi, we will run gen_ssi_files when finished
	   $DRBL_SCRIPT_PATH/sbin/drbl-powerful-thin-client --no-gen-ssi -p -ln $lang
	 fi

	 # specify the nodes if assigned by user
         [ "$LIST_HOST" = "on" ] && set_specific_host_pxe_conf `cat $HOSTS_TMP`

         for host in $drblroot/*; do
           # if the LIST_HOST is on, skip those IP not listed in the $IP_LIST
	   if [ "$LIST_HOST" = "on" ]; then
	     [ -z "$(echo $IP_LIST | grep ${host##/*/})" ] && continue
           fi

           # 
           host_ip=$(basename $host)
           echo "Setting the remote-linux text mode for node IP = $host_ip"
	   if [ -e /etc/debian_version ]; then
             CLIENT_INIT="2"
             default_dm="$($DRBL_SCRIPT_PATH/bin/check_dm -h $host_ip)"
             prepare_update_rc_d_env $host
             LC_ALL=C chroot $host/ /usr/sbin/update-rc.d -f $default_dm remove &> /dev/null
           else
             # RH-like or SUSE
             # set the init to 3, i.e. default is text mode
             CLIENT_INIT="3"
           fi
           perl -p -i -e "s/^id:[0-9]:initdefault:/id:$CLIENT_INIT:initdefault:/g" $host/etc/inittab
         done
	 echo "done!"
         #
         echo "-------------------------------------------------------"
         echo "Since some config files are modified in template client, creating template tarball for DRBL SSI..."
         $DRBL_SCRIPT_PATH/sbin/gen_ssi_files
         ;;
  "remote-memtest")
         echo -n "Setting client as remote-memtest mode..."
         stop_ocs_if_necessary
         $DRBL_SCRIPT_PATH/sbin/set-default-pxe-img -i memtest -c $PXE_CONF

	 # specify the nodes if assigned by user
         [ "$LIST_HOST" = "on" ] && set_specific_host_pxe_conf `cat $HOSTS_TMP`

	 echo "done!"
	 ;;
  "remote-fdos")
         echo -n "Setting client as remote-fdos mode..."
         stop_ocs_if_necessary
         $DRBL_SCRIPT_PATH/sbin/set-default-pxe-img -i fdos -c $PXE_CONF

	 # specify the nodes if assigned by user
         [ "$LIST_HOST" = "on" ] && set_specific_host_pxe_conf `cat $HOSTS_TMP`

	 echo "done!"
	 ;;
  "terminal")
         echo -n "Settinig client as DRBL terminal mode..."
         stop_ocs_if_necessary
         $DRBL_SCRIPT_PATH/sbin/set-default-pxe-img -i drbl-terminal -c $PXE_CONF -l "$FULL_OS_Version $thin_client_menu_label"

	 # specify the nodes if assigned by user
         [ "$LIST_HOST" = "on" ] && set_specific_host_pxe_conf `cat $HOSTS_TMP`

         if [ "$LIST_HOST" = "on" ]; then
           $DRBL_SCRIPT_PATH/sbin/drbl-client-system-select -e -h "$IP_LIST" on
	   $DRBL_SCRIPT_PATH/sbin/drbl-powerful-thin-client -t -h "$IP_LIST" -ln $lang
         else
           $DRBL_SCRIPT_PATH/sbin/drbl-client-system-select -e on
	   $DRBL_SCRIPT_PATH/sbin/drbl-powerful-thin-client -t -ln $lang
         fi
	 echo "done!"
	 ;;
  "netinstall")
     TMP="$(mktemp /tmp/menu.XXXXXX)"
     trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
     netinstall_list="$(grep -Ei "^[[:space:]]*label[[:space:]]+netinstall-" $PXELINUX_DIR/default | sed -e "s/^[[:space:]]*label[[:space:]]*//g" | sort)"
     if [ -z "$netinstall_list" ]; then
        $DIA --title "$msg_no_network_installation_img" --clear \
        --msgbox "$msg_no_network_installation_img_des" 0 0
       exit 0
     fi
     MENU=""
     numimages=0
     for i in $netinstall_list; do
        numimages=$((numimages + 1))
        # EX for i: netinstall-ubuntu-breezy-i386
        # create the description for the netinstall image
        des="$(echo $i | sed -e "s/^netinstall-//gi" | sed -e "s/-/_/g")"
        des=${des}_${msg_install_via_network}
        MENU="$MENU $i $des off "
     done
     if [ $numimages -gt 0 ]; then
       if [ $numimages -lt $MAX_DIALOG_HEIGHT ]; then
         height=$numimages
       else
         height="$MAX_DIALOG_HEIGHT"
       fi
       $DIA \
       --backtitle "$msg_nchc_title" \
       --title "$msg_netinstall" \
       --radiolist "$msg_choose_netinstall_imag" 0 80 $height \
       $MENU 2> $TMP
       OS_netinstall="$(cat $TMP)"
     fi
     [ -f "$TMP" ] && rm -f $TMP
     [ -z "$OS_netinstall" ] && echo "No distribution is selected! Program terminated!!!" && exit 1
     echo "This network installation is for: $OS_netinstall"
     echo "Setting client to the mode for installing this distribution via network..."
     stop_ocs_if_necessary
     echo -n "Set the PXE environment..."
     $DRBL_SCRIPT_PATH/sbin/set-default-pxe-img -i $OS_netinstall -c $PXE_CONF
     echo "done!"
     # specify the nodes if assigned by user
     [ "$LIST_HOST" = "on" ] && set_specific_host_pxe_conf `cat $HOSTS_TMP`
     ;;
  "clonezilla-start")
     if [ -z "$MODE2" ]; then
       TMP=$(mktemp /tmp/menu.XXXXXX)
       trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
       $DIA \
       --backtitle "$msg_nchc_title" \
       --title "$msg_start_clonezilla_mode" \
       --radiolist "$msg_choose_mode" 0 0 0 \
       "clonezilla-save-disk" "$msg_clonezilla_save_disk" off \
       "clonezilla-restore-disk" "$msg_clonezilla_restore_disk" off \
       "clonezilla-save-parts" "$msg_clonezilla_save_parts" off \
       "clonezilla-restore-parts" "$msg_clonezilla_restore_parts" off \
       "clonezilla-save-hda1" "$msg_clonezilla_save_hda1" off \
       "clonezilla-restore-hda1" "$msg_clonezilla_restore_hda1" off 2> $TMP
       ocs_mode=$(cat $TMP)
       [ -f "$TMP" ] && rm -f $TMP
     else
       ocs_mode="$MODE2"
     fi
     [ -z "$ocs_mode" ] && echo "No clonezilla mode is selected! Program terminated!!!" && exit 1
     echo "Now the clonezilla mode is: $ocs_mode"
     case "$ocs_mode" in
       "clonezilla-save-disk")
          echo -n "Setting client as clonezilla-save mode..."

	  # ask if want to input the saved name now
	  ask_if_input_save_image_name_in_server savedisk

	  # ask if want to set ocs extra param
          OCS_PARAM_TMP=`mktemp /tmp/ocs_param_tmp.XXXXXX`
          trap "[ -f "$OCS_PARAM_TMP" ] && rm -f $OCS_PARAM_TMP" HUP INT QUIT TERM EXIT
          ask_if_skip_set_ocs_extra_param save $OCS_PARAM_TMP
          OCS_OPTS="$(cat $OCS_PARAM_TMP)"
          [ -f "$OCS_PARAM_TMP" ] && rm -f $OCS_PARAM_TMP

          stop_ocs_if_necessary
          if [ "$LIST_HOST" = "on" ]; then
            $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -h "$IP_LIST" -l $lang startdisk save $input_save_img_name "$input_device_name"
            [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
            echo $msg_run_drbl_ocs_again_cmd
	    echo $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -h \"$IP_LIST\" -l $lang startdisk save $input_save_img_name \"$input_device_name\"
            [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
          else
            $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -l $lang startdisk save $input_save_img_name "$input_device_name"
            [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
            echo $msg_run_drbl_ocs_again_cmd 
	    echo $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -l $lang startdisk save $input_save_img_name \"$input_device_name\"
            [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
          fi
          echo "done!"
          ;;
       "clonezilla-restore-disk")
          echo -n "Setting client as clonezilla-restore-disk mode..."

	  # ask if want to set ocs extra param
          OCS_PARAM_TMP=`mktemp /tmp/ocs_param_tmp.XXXXXX`
          trap "[ -f "$OCS_PARAM_TMP" ] && rm -f $OCS_PARAM_TMP" HUP INT QUIT TERM EXIT
          ask_if_skip_set_ocs_extra_param restore $OCS_PARAM_TMP
          OCS_OPTS="$(cat $OCS_PARAM_TMP)"
          [ -f "$OCS_PARAM_TMP" ] && rm -f $OCS_PARAM_TMP

	  if [ -n "$(echo $OCS_OPTS | grep -E "\-[uy]")" ]; then
            # with -u, select image in the client, only unicast available.
            # with -y, client always has restore mode to use, only unicast available.
            [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
            echo "$msg_ocs_param_exclude_multicast"
            [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
            RESTORE_MODE="unicast"
          else
            stop_ocs_if_necessary
            TMP=$(mktemp /tmp/menu.XXXXXX)
            trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
            $DIA \
            --backtitle "$msg_nchc_title" \
            --title "$msg_nchc_clonezilla" \
            --radiolist "$msg_choose_the_mode_to_restore_disk" 0 0 0 \
            "multicast" "$msg_multicast_restore" on \
            "unicast" "$msg_unicast_restore" off \
	    2> $TMP
            RESTORE_MODE=$(cat $TMP) 
            [ -f "$TMP" ] && rm -f $TMP
	  fi

          [ -z "$RESTORE_MODE" ] && echo "No mode is selected! Program terminated!!!" && exit 1
          if [ "$RESTORE_MODE" = "unicast" ]; then
            if [ "$LIST_HOST" = "on" ]; then
              $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -h "$IP_LIST" -l $lang startdisk restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
              echo $msg_run_drbl_ocs_again_cmd 
	      echo $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -h \"$IP_LIST\" -l $lang startdisk restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
            else
              $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -l $lang startdisk restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
              echo $msg_run_drbl_ocs_again_cmd 
	      echo $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -l $lang startdisk restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
	    fi
          else
            # multicast
            if [ "$LIST_HOST" = "on" ]; then
              multicast_clonezilla_restore_warning
              $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -h "$IP_LIST" -l $lang startdisk multicast_restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
              echo $msg_run_drbl_ocs_again_cmd 
	      echo $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -h \"$IP_LIST\" -l $lang startdisk multicast_restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
            else
              $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -l $lang startdisk multicast_restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
              echo $msg_run_drbl_ocs_again_cmd 
	      echo $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -l $lang startdisk multicast_restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
            fi
          fi
          echo "done!"
          ;;
       "clonezilla-save-parts")
          echo -n "Setting client as clonezilla-save mode..."

	  # ask if want to input the saved name now
	  ask_if_input_save_image_name_in_server saveparts

	  # ask if want to set ocs extra param
          OCS_PARAM_TMP=`mktemp /tmp/ocs_param_tmp.XXXXXX`
          trap "[ -f "$OCS_PARAM_TMP" ] && rm -f $OCS_PARAM_TMP" HUP INT QUIT TERM EXIT
          ask_if_skip_set_ocs_extra_param save $OCS_PARAM_TMP
          OCS_OPTS="$(cat $OCS_PARAM_TMP)"
          [ -f "$OCS_PARAM_TMP" ] && rm -f $OCS_PARAM_TMP

          stop_ocs_if_necessary
          if [ "$LIST_HOST" = "on" ]; then
            $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -h "$IP_LIST" -l $lang startparts save $input_save_img_name "$input_device_name"
            [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
            echo $msg_run_drbl_ocs_again_cmd 
	    echo $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -h \"$IP_LIST\" -l $lang startparts save $input_save_img_name \"$input_device_name\"
            [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
          else
            $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -l $lang startparts save $input_save_img_name "$input_device_name"
            [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
            echo $msg_run_drbl_ocs_again_cmd 
	    echo $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -l $lang startparts save $input_save_img_name \"$input_device_name\"
            [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
          fi
          echo "done!"
          ;;
       "clonezilla-restore-parts")
          echo -n "Setting client as clonezilla-restore-parts mode..."

	  # ask if want to set ocs extra param
          OCS_PARAM_TMP=`mktemp /tmp/ocs_param_tmp.XXXXXX`
          trap "[ -f "$OCS_PARAM_TMP" ] && rm -f $OCS_PARAM_TMP" HUP INT QUIT TERM EXIT
          ask_if_skip_set_ocs_extra_param restore $OCS_PARAM_TMP
          OCS_OPTS="$(cat $OCS_PARAM_TMP)"
          [ -f "$OCS_PARAM_TMP" ] && rm -f $OCS_PARAM_TMP

	  if [ -n "$(echo $OCS_OPTS | grep -E "\-[uy]")" ]; then
            # with -u, select image in the client, only unicast available.
            # with -y, client always has restore mode to use, only unicast available.
            [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
            echo "$msg_ocs_param_exclude_multicast"
            [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
            RESTORE_MODE="unicast"
          else
            stop_ocs_if_necessary
            TMP=$(mktemp /tmp/menu.XXXXXX)
            trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
            $DIA \
            --backtitle "$msg_nchc_title" \
            --title "$msg_nchc_clonezilla" \
            --radiolist "$msg_choose_the_mode_to_restore_partitions" 0 0 0 \
            "multicast" "$msg_multicast_restore" on \
            "unicast" "$msg_unicast_restore" off \
	    2> $TMP
            RESTORE_MODE=$(cat $TMP) 
            [ -f "$TMP" ] && rm -f $TMP
          fi

          [ -z "$RESTORE_MODE" ] && echo "No mode is selected! Program terminated!!!" && exit 1
          if [ "$RESTORE_MODE" = "unicast" ]; then
            if [ "$LIST_HOST" = "on" ]; then
              $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -h "$IP_LIST" -l $lang startparts restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
              echo $msg_run_drbl_ocs_again_cmd 
	      echo $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -h \"$IP_LIST\" -l $lang startparts restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
            else
              $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -l $lang startparts restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
              echo $msg_run_drbl_ocs_again_cmd 
	      echo $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -l $lang startparts restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
	    fi
          else
            # multicast
            if [ "$LIST_HOST" = "on" ]; then
              multicast_clonezilla_restore_warning
              $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -h "$IP_LIST" -l $lang startparts multicast_restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
              echo $msg_run_drbl_ocs_again_cmd 
	      echo $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -h \"$IP_LIST\" -l $lang startparts multicast_restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
            else
              $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -l $lang startparts multicast_restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
              echo $msg_run_drbl_ocs_again_cmd 
	      echo $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -l $lang startparts multicast_restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
	    fi
          fi
          echo "done!"
          ;;
       "clonezilla-save-hda1")
          echo -n "Setting client as clonezilla-save-hda1 mode..."

	  # ask if want to input the saved name now
	  ask_if_input_save_image_name_in_server savehda1

	  # ask if want to set ocs extra param
          OCS_PARAM_TMP=`mktemp /tmp/ocs_param_tmp.XXXXXX`
          trap "[ -f "$OCS_PARAM_TMP" ] && rm -f $OCS_PARAM_TMP" HUP INT QUIT TERM EXIT
          ask_if_skip_set_ocs_extra_param save $OCS_PARAM_TMP
          OCS_OPTS="$(cat $OCS_PARAM_TMP)"
          [ -f "$OCS_PARAM_TMP" ] && rm -f $OCS_PARAM_TMP

          stop_ocs_if_necessary
          if [ "$LIST_HOST" = "on" ]; then
            [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
            $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -h "$IP_LIST" -l $lang start save $input_save_img_name "$input_device_name"
            echo $msg_run_drbl_ocs_again_cmd 
	    echo $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -h \"$IP_LIST\" -l $lang start save $input_save_img_name \"$input_device_name\"
            [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
          else
            $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -l $lang start save $input_save_img_name "$input_device_name"
            [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
            echo $msg_run_drbl_ocs_again_cmd 
	    echo $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -l $lang start save $input_save_img_name "$input_device_name"
            [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
	  fi
          echo "done!"
          ;;
       "clonezilla-restore-hda1")
          echo -n "Setting client as clonezilla-restore-hda1 mode..."

	  # ask if want to set ocs extra param
          OCS_PARAM_TMP=`mktemp /tmp/ocs_param_tmp.XXXXXX`
          trap "[ -f "$OCS_PARAM_TMP" ] && rm -f $OCS_PARAM_TMP" HUP INT QUIT TERM EXIT
          ask_if_skip_set_ocs_extra_param restore $OCS_PARAM_TMP
          OCS_OPTS="$(cat $OCS_PARAM_TMP)"
          [ -f "$OCS_PARAM_TMP" ] && rm -f $OCS_PARAM_TMP

	  if [ -n "$(echo $OCS_OPTS | grep -E "\-[uy]")" ]; then
            # with -u, select image in the client, only unicast available.
            # with -y, client always has restore mode to use, only unicast available.
            [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
            echo "$msg_ocs_param_exclude_multicast"
            [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
            RESTORE_MODE="unicast"
          else
            stop_ocs_if_necessary
            TMP=$(mktemp /tmp/menu.XXXXXX)
            trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
            $DIA \
            --backtitle "$msg_nchc_title" \
            --title "$msg_nchc_clonezilla" \
            --radiolist "$msg_choose_the_mode_to_restore_hda1" 0 0 0 \
            "multicast" "$msg_multicast_restore" on \
            "unicast" "$msg_unicast_restore" off \
	    2> $TMP
            RESTORE_MODE=$(cat $TMP) 
            [ -f "$TMP" ] && rm -f $TMP
          fi

          [ -z "$RESTORE_MODE" ] && echo "No mode is selected! Program terminated!!!" && exit 1
          if [ "$RESTORE_MODE" = "unicast" ]; then
            if [ "$LIST_HOST" = "on" ]; then
              $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -h "$IP_LIST" -l $lang start restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
              echo $msg_run_drbl_ocs_again_cmd 
	      echo $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -h \"$IP_LIST\" -l $lang start restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
            else
              $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -l $lang start restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
              echo $msg_run_drbl_ocs_again_cmd 
	      echo $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -l $lang start restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
	    fi
          else
            # multicast
            if [ "$LIST_HOST" = "on" ]; then
              multicast_clonezilla_restore_warning
              $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -h "$IP_LIST" -l $lang start multicast_restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
              echo $msg_run_drbl_ocs_again_cmd 
              echo $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -h \"$IP_LIST\" -l $lang start multicast_restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
            else
              $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -l $lang start multicast_restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
              echo $msg_run_drbl_ocs_again_cmd 
	      echo $DRBL_SCRIPT_PATH/sbin/drbl-ocs $OCS_OPTS -l $lang start multicast_restore
              [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
	    fi
          fi
          echo "done!"
          ;;
     esac
     # specify the nodes if assigned by user
     # [ "$LIST_HOST" = "on" ] && set_specific_host_pxe_conf `cat $HOSTS_TMP`
     ;;

  "clonezilla-stop")
     echo -n "Trying to stop the clonezilla mode..."
     stop_ocs_if_necessary
     # When clonezilla stops, we should make client boot locally.
     $DRBL_SCRIPT_PATH/sbin/set-default-pxe-img -i local -c $PXE_CONF
     # We can not specify the nodes if assigned by user, since for multicast, it will fail.
     # [ "$LIST_HOST" = "on" ] && set_specific_host_pxe_conf `cat $HOSTS_TMP`
     echo "done!"
     ;;

  "local")
         echo -n "Setting client as local mode..."
         stop_ocs_if_necessary
         $DRBL_SCRIPT_PATH/sbin/set-default-pxe-img -i local -c $PXE_CONF

         # specify the nodes if assigned by user
         [ "$LIST_HOST" = "on" ] && set_specific_host_pxe_conf `cat $HOSTS_TMP`

	 echo "done!"
	 ;;
  "reboot")
	 # TODO
         echo "Reboot DRBL clients now..."
	 echo "For DRBL clients..."
         if [ "$LIST_HOST" = "on" ]; then
	   $DRBL_SCRIPT_PATH/bin/drbl-doit -l $lang -b -u root -h "$IP_LIST" /sbin/reboot
         else
	   $DRBL_SCRIPT_PATH/bin/drbl-doit -l $lang -b -u root /sbin/reboot
	 fi
	 echo "For Cygwin clients..."
         if [ "$LIST_HOST" = "on" ]; then
	   $DRBL_SCRIPT_PATH/bin/drbl-doit -l $lang -b -u administrator -h "$IP_LIST" /usr/bin/shutdown -f -r now
         else
	   $DRBL_SCRIPT_PATH/bin/drbl-doit -l $lang -b -u administrator /usr/bin/shutdown -f -r now
	 fi
	 echo "done!"
	 ;;
  "shutdown")
         echo "Shutdown DRBL clients now..."
	 echo "For DRBL clients..."
         if [ "$LIST_HOST" = "on" ]; then
	   $DRBL_SCRIPT_PATH/bin/drbl-doit -l $lang -b -u root -h "$IP_LIST" /sbin/poweroff
         else
	   $DRBL_SCRIPT_PATH/bin/drbl-doit -l $lang -b -u root /sbin/poweroff
         fi
	 echo "For Cygwin clients..."
         if [ "$LIST_HOST" = "on" ]; then
	   $DRBL_SCRIPT_PATH/bin/drbl-doit -l $lang -b -u administrator -h "$IP_LIST" /usr/bin/shutdown -f -s now
         else
	   $DRBL_SCRIPT_PATH/bin/drbl-doit -l $lang -b -u administrator /usr/bin/shutdown -f -s now
         fi
	 echo "done!"
	 ;;
  "Wake-on-LAN")
         echo "Turn on DRBL clients by Wake-on-LAN now..."
         if [ "$LIST_HOST" = "on" ]; then
	   $DRBL_SCRIPT_PATH/bin/drbl-doit -l $lang -b -h "$IP_LIST" --wol
         else
	   $DRBL_SCRIPT_PATH/bin/drbl-doit -l $lang -b --wol
         fi
	 echo "done!"
	 ;;
  "switch-pxe-menu")
         echo "Switch DRBL client menus..."
	 $DRBL_SCRIPT_PATH/sbin/switch-pxe-menu -c $PXE_CONF -l $lang

	 # specify the nodes if assigned by user
         [ "$LIST_HOST" = "on" ] && set_specific_host_pxe_conf `cat $HOSTS_TMP`
	 ;;
  "drbl-ssi")
	 run_drbl_ssi_switch
	 ;;
  "login-switch")
         run_login_switch
	 ;;
  "others")
         if [ -z "$MODE2" ]; then
           TMP="$(mktemp /tmp/menu.XXXXXX)"
           trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT
           $DIA \
           --backtitle "$msg_nchc_title" \
           --title "$msg_nchc_drbl" \
           --no-shadow \
           --radiolist "$msg_switch_client_mode:" 0 0 0 \
           "switch-drbl-serv" "$msg_switch_drbl_service" off \
	   $client_reautologin_1 $client_reautologin_2 $client_reautologin_3 \
	   $clean_autologin_account_1 $clean_autologin_account_2 $clean_autologin_account_3 \
	   $reset_autologin_account_1 $reset_autologin_account_2 $reset_autologin_account_3 \
           "re-deploy" "$msg_re_deploy" off \
           "clean-dhcpd-lease" "$msg_clean_dhcpd_lease" off \
           "gen_3N_conf" "$msg_regenerate_nfs_nis_nat_config" off \
           2> $TMP
           OTHER_MODE=$(cat $TMP)
           [ -f "$TMP" ] && rm -f $TMP
         else
           OTHER_MODE=$MODE2
	 fi
	 case "$OTHER_MODE" in
          "switch-drbl-serv")
              run_switch_drbl_service
              ;;
          "client-reautologin")
              if [ "$LIST_HOST" = "on" ]; then
                $DRBL_SCRIPT_PATH/sbin/drbl-client-reautologin -h "$IP_LIST"
              else
                $DRBL_SCRIPT_PATH/sbin/drbl-client-reautologin
              fi
              ;;
          "clean-autologin-account")
              $DRBL_SCRIPT_PATH/sbin/drbl-clean-autologin-account -l $lang
              ;;
          "reset-autologin-account")
              $DRBL_SCRIPT_PATH/sbin/drbl-user-env-reset -l $lang --auto-login
              ;;
          "re-deploy")
              if [ ! -f "$drbl_syscfg/drblpush.conf" ]; then
                [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
                echo "Previously saved config file $drbl_syscfg/drblpush.conf is NOT found. Did you run \"$DRBL_SCRIPT_PATH/setup/drblpush -i\" before ?"
                echo "Program Terminated!!!"
                [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
                exit 1
              fi
              $DRBL_SCRIPT_PATH/setup/drblpush --ln $lang -c $drbl_syscfg/drblpush.conf
              ;;
          "clean-dhcpd-lease")
	      $DRBL_SCRIPT_PATH/sbin/clean-dhcpd-lease
	      ;;
          "gen_3N_conf")
	      $DRBL_SCRIPT_PATH/sbin/drbl-3n-conf generate
	      ;;
	 esac
	 ;;
  *)
         USAGE
	 ;;
esac
[ -f "$HOSTS_TMP" ] && rm -f $HOSTS_TMP
