This file is indexed.

/usr/sbin/ocs-live-netcfg 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
#!/bin/bash
# netcardconfig - A very light-weight text-based network configuration tool.
# (C) Klaus Knopper Nov 2002
# License: GPL
# This program was modified by B2D team (http://ftp3.tnc.edu.tw/b2d/netcardconfig/netcardconfig).
# 2007/09/18 Modified by Steven Shiau to be used in clonezilla live.

# Load DRBL setting and functions
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

# Load the config in ocs-live.conf. This is specially for Clonezilla live. It will overwrite some settings of /etc/drbl/drbl-ocs.conf, such as $DIA...
[ -e "/etc/ocs/ocs-live.conf" ] && . /etc/ocs/ocs-live.conf

# Settings
default_dns_server="8.8.8.8"
# Default timeout for getting linking status of each ethernet card. Unit: sec.
# For Cisco switch with STP (Spanning Tree Protocol) enabled, listening delay is 30 secs, and learning delay is 15 secs.
# Therefore total forwarding delay is 45 secs. This is old protocol.
# For network with RSTP (Rapid Spanning Tree Protocol), it could be only 6 secs (default: 3 times 2 seconds).
# Ref: https://en.wikipedia.org/wiki/Spanning_Tree_Protocol
# Here we set 30 secs as the default value.
default_link_det_timeout="30"

#
check_if_root

# Functions
bailout(){
  rm -f "$TMP"
  exit $1
}
USAGE() {
   echo "Usage: $0 [OPTION] MODE [MODE2]"
   echo "OPTION"
   dialog_like_prog_help_prompt
   echo " -i, --ip-add  IP_ADD    Assign the IP address shown in the dialog as IP_ADD."
   echo " -n, --netmask NETMASK   Assign the netmask shown in the dialog as NETMASK."
   echo " -g, --gateway GATEWAY   Assign the gateway shown in the dialog as GATEWAY."
   echo " -s, --dns     DNS       Assign the domain name server shown in the dialog as DNS."
   echo " -t, --timeout TIME      Assign the timeout to get the linking status of each NIC. Unit: sec. Default is $default_link_det_timeout secs."
   echo  " --ignore-gw            Do not set default gateway."
   echo  " --ignore-dns           Do not set domain name server."
   echo  " -r, --ignore-dv  DV    Do not config network device DV, such as 'eth1 eth2'."
}
#
cfg_by_dhcp(){
  local dhclient_verbose_opt
  # Before using dhclient, we create /etc/resolv.conf to suppress the warning! Since /etc/resolv.conf is removed when Debian Live is created by live package.
  touch /etc/resolv.conf
  echo "$msg_send_dhcp_request_from $DV"
  # Test if "-v" is supported by dhclient
  # For version 4,
  # Usage: dhclient [-4|-6] [-SNTP1dvrx] [-nw] [-p <port>] [-s server]
  #                 [-cf config-file] [-lf lease-file][-pf pid-file] [-e VAR=val]
  #      	    [-sf script-file] [interface]
  # For version 3,
  # Usage: dhclient [-1dqrx] [-nw] [-p <port>] [-s server]
  #                 [-cf config-file] [-lf lease-file][-pf pid-file] [-e VAR=val]
  #       	    [-sf script-file] [interface]
  # 
  if [ -n "$(LC_ALL=C dhclient --help 2>&1 | grep -Ewo -- "-[[:alnum:]]*v[[:alnum:]]*")" ]; then
   dhclient_verbose_opt="-v"
  fi
  # Force to make timeout as 60. Debian uses 60, but Ubuntu uses 300. Too long.
  # Thanks to Cecile, Adam (Adam.Cecile _at_ hitec lu) for reporting this.
  perl -pi -e "s/^timeout.*/timeout 60;/g" /etc/dhcp/dhclient.conf
  dhclient $dhclient_verbose_opt $DV
  rc="$?"
  if [ "$rc" != "0" ]; then
    echo "$msg_failed"
    echo -n "$msg_press_enter_to_exit "
    read a
  else
    echo -n "OK. Now writing the setting to network config file... "
    # Debian: Add dhcp broadcast entry
    if [ -w /etc/network/interfaces ]; then
      # we need loopback device, otherwise portmap & nfs-common will fail
      if ! egrep -q -e "^auto[[:space:]]+lo" /etc/network/interfaces; then
        cat >/etc/network/interfaces <<EOF
# The loopback network interface
auto lo
iface lo inet loopback
EOF
        # turn it on now.
        ifconfig lo up
      fi
      rm -f "$TMP"
      awk '/iface/{if(/'"$DV"'/){found=1}else{found=0}}
           {if(!found){print}}
           END{print "\niface '"$DV"' inet dhcp\n\n"}' \
           /etc/network/interfaces >"$TMP"
      # Add an "auto" entry
      if egrep -q -e "^auto[ 	]+.*$DV" /etc/network/interfaces; then
        cat "$TMP" >/etc/network/interfaces
      else
        awk '{if(/^auto/){print $0 " '"$DV"'"}else{print}}' "$TMP" > /etc/network/interfaces
      fi
      rm -f "$TMP"
    fi
    echo "Done!"
  fi
  return $rc
} # end of cfg_by_dhcp
#
cfg_static_ip() {
# RedHat
if [ -f "/etc/sysconfig/network-scripts/ifcfg-$DV" ]
  then
  . "/etc/sysconfig/network-scripts/ifcfg-$DV"
  IP="$IPADDR"
  NM="$NETMASK"
fi

# RedHat
if [ -f "/etc/sysconfig/network" ]; then
  . "/etc/sysconfig/network"
  DG="$GATEWAY"
fi

# Debian
if [ -f /etc/network/interfaces ]; then
  awk '/iface/{if(/'"$DV"'/){found=1}else{found=0}} 
       /address/{if(found){address=$NF}}
       /netmask/{if(found){netmask=$NF}}
       /gateway/{if(found){gateway=$NF}}
     END{print address" "netmask" "broadcast" "gateway}' /etc/network/interfaces >"$TMP"
  read IP NM DG <"$TMP"
  rm -f "$TMP"
fi

#
if [ -f "/etc/resolv.conf" ]; then
  NS="$(awk '/^nameserver/{printf "%s ",$2}' /etc/resolv.conf)"
fi

# if IP address is assigned as a parameter
[ -n "$ip_add_prompt" ] && IP="$ip_add_prompt"
[ -n "$netmask_prompt" ] && NM="$netmask_prompt"
[ -n "$gateway_prompt" ] && DG="$gateway_prompt"
[ -n "$dns_prompt" ] && NS="$dns_prompt"

$DIA --inputbox "$msg_enter_IP_add_for_this_nic $DV" 10 45 "${IP:-$default_IP}" 2>"$TMP" || bailout 1
read IP <"$TMP" ; rm -f "$TMP"

$DIA --inputbox "$msg_enter_netmask_for_this_nic $DV" 10 45 "${NM:-$default_NM}" 2>"$TMP" || bailout 1
read NM <"$TMP" ; rm -f "$TMP"

# Steven commented this one. System can get broadcast from IP address and netmask. Therefore it's not necessary to ask.
#$DIA --inputbox "$MESSAGE8 $DV" 10 45 "${BC:-${IP%.*}.255}" 2>"$TMP" || bailout 1
#read BC <"$TMP" ; rm -f "$TMP"

if [ "$config_gw" = "yes" ]; then
  $DIA --inputbox "$msg_enter_default_gateway" 10 45 "${DG:-${IP%.*}.254}" 2>"$TMP"
  read DG <"$TMP" ; rm -f "$TMP"
else
  DG=""
fi

if [ "$config_dns" = "yes" ]; then
  $DIA --inputbox "$msg_enter_dns_server" 10 45 "$default_dns_server" 2>"$TMP"
  read NS <"$TMP" ; rm -f "$TMP"
else
  NS=""
fi

CMD="ifconfig $DV $IP netmask $NM up"
echo "$CMD"
$CMD

# Add entry for Redhat init scripts
if [ -d /etc/sysconfig/network-scripts ]; then
  cat >/etc/sysconfig/network-scripts/ifcfg-$DV <<EOF
DEVICE=$DV
IPADDR=$IP
NETMASK=$NM
ONBOOT=yes
EOF
  chmod 755 /etc/sysconfig/network-scripts/ifcfg-$DV
fi

if [ -n "$DG" ]; then
  CMD="route add default gw $DG"
  echo "$CMD"
  $CMD
  # Add entry to /etc/sysconfig/network
  if [ -w /etc/sysconfig/network ]; then
    grep -v ^GATEWAY /etc/sysconfig/network >"$TMP"
    cat >"$TMP" <<EOF
GATEWAY=$DG
GATEWAYDEV=$DV
EOF
    cat "$TMP" > /etc/sysconfig/network
    rm -f "$TMP"
  fi
fi

# Debian
if [ -w /etc/network/interfaces ]; then
  # we need loopback device, otherwise portmap & nfs-common will fail
  if ! egrep -q -e "^auto[[:space:]]+lo" /etc/network/interfaces; then
    cat >/etc/network/interfaces <<EOF
# The loopback network interface
auto lo
iface lo inet loopback
EOF
    # turn it on now.
    ifconfig lo up
  fi

  awk '/iface/{if(/'"$DV"'/){found=1}else{found=0}}
       {if(!found){print}}
       END{print "\niface '"$DV"' inet static\n\taddress '"$IP"'\n\tnetmask '"$NM"'\n\t";if("'"$DG"'"!=""){print "\tgateway '"$DG"'"};print "\n"}' \
       /etc/network/interfaces >"$TMP"
  # Add an "auto" entry
  if egrep -q -e "^auto[ 	]+.*$DV" /etc/network/interfaces; then
    cat "$TMP" >/etc/network/interfaces
  else
    awk '{if(/^auto/){print $0 " '"$DV"'"}else{print}}' "$TMP" > /etc/network/interfaces
  fi
fi

if [ -n "$NS" ]; then
  more=""
  for i in $NS; do
    if [ -z "$more" ]; then
      more=yes
      echo "$msg_put_dnsserver_to_resolv_conf $i"
      echo "nameserver $i" >/etc/resolv.conf
      else
      echo "$msg_append_dnsserver_to_resolv_conf $i"
      echo "nameserver $i" >>/etc/resolv.conf
    fi
  done
fi

# Steven commented this. Not ready for wifi.
#egrep -q "$DV" /proc/net/wireless 2>/dev/null && wlcardconfig "$DV"

echo "Done."
sleep 0.5
} # end of cfg_static_ip
#
cfg_pppoe(){
   pppoeconf
}


# Default settings
default_IP="192.168.120.1"
default_NM="255.255.255.0"
config_gw="yes"
config_dns="yes"
#
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
	    ;;
    -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;;
    -i|--ip-add)
	shift
        if [ -z "$(echo $1 |grep ^-.)" ]; then
          # skip the -xx option, in case 
	  ip_add_prompt="$1"
	  shift
        fi
	;;
    -n|--netmask)
	shift
        if [ -z "$(echo $1 |grep ^-.)" ]; then
          # skip the -xx option, in case 
	  netmask_prompt="$1"
	  shift
        fi
	;;
    -g|--gateway)
	shift
        if [ -z "$(echo $1 |grep ^-.)" ]; then
          # skip the -xx option, in case 
	  gateway_prompt="$1"
	  shift
        fi
	;;
    -s|--dns)
	shift
        if [ -z "$(echo $1 |grep ^-.)" ]; then
          # skip the -xx option, in case 
	  dns_prompt="$1"
	  shift
        fi
	;;
    -t|--timeout)
	shift
        if [ -z "$(echo $1 |grep ^-.)" ]; then
          # skip the -xx option, in case 
	  link_det_timeout="$1"
	  shift
        fi
	;;
    --ignore-gw)
            config_gw="no"
	    shift;;
    --ignore-dns)
            config_dns="no"
	    shift;;
    -r|--ignore-dv)
	shift
        if [ -z "$(echo $1 |grep ^-.)" ]; then
          # skip the -xx option, in case 
          skip_nic_dv="$1"
	  shift
        fi
	;;
    -*)     echo "${0}: ${1}: invalid option" >&2
            USAGE >& 2
            exit 2 ;;
    *)      break ;;
  esac
done
#
#
ask_and_load_lang_set $specified_lang

# check DIA
check_DIA_set_ESC $DIA

# 
[ -z "$link_det_timeout" ] && link_det_timeout="$default_link_det_timeout"

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

TMP="$(mktemp /tmp/netmenu.XXXXXX)"
trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT

NETDEVICES="$(cat /proc/net/dev | awk -F: '/eth.*:|tr.*:|wlan.*:|en.*:/{print $1}' | sort)"
# make it in a single line
NETDEVICES="$(echo $NETDEVICES)"

if [ -n "$skip_nic_dv" ]; then
  for i in $skip_nic_dv; do
    # remove those we do not want to config.
    NETDEVICES="$(echo $NETDEVICES | sed -e "s/\<$i\>//g")"
  done
fi

if [ -z "$NETDEVICES" ]; then
  $DIA --msgbox "$msg_no_nic_is_found" 0 0
  bailout
else
  # We have to up the network card first so that ethtool can detect if it's linked or not.
  echo -n "Try to up "
  for DEVICE in $NETDEVICES; do
    if [ -z "$(drbl-get-ipadd $DEVICE)" ]; then
      echo -n "$DEVICE... "
      ifconfig $DEVICE 0.0.0.0
    fi
  done
  echo
fi

count="$(echo "$NETDEVICES" | wc -w)"

if [ "$count" -gt 1 ]; then
  hw_scan_tmp="$(mktemp /tmp/hw_scan.XXXXXX)"
  if type lshw &>/dev/null; then
    echo -n "Collecting the info of network devices... "
    lshw -businfo -class network 2>/dev/null > $hw_scan_tmp
    echo "done!"
  fi
  DEVICELIST=""
  dev_model=""
  link_status=""
  for DEVICE in $NETDEVICES; do
    dev_model="$(LC_ALL=C grep -Ew "$DEVICE" $hw_scan_tmp | sed -e "s/^.*$DEVICE[[:space:]]*network[[:space:]]*//g" | sed -e "s/ /_/g")"
    [ -z "$dev_model" ] && dev_model="Unknown_NIC"
    # only first 26 characters.
    dev_model="${dev_model:0:25}.."
    echo -n "Getting the linking status of $DEVICE. Timeout in $link_det_timeout secs."
    TIMEOUT="$link_det_timeout"
    link_status=""
    while [ "$link_status" = "no" -o -z "$link_status" ]; do
      sleep 1
      link_status="$(LC_ALL=C ethtool $DEVICE | grep -i "Link detected:" | cut -d":" -f2 | sed -e "s/ //g")"
      TIMEOUT="$(( $TIMEOUT - 1 ))"
      if [ "$TIMEOUT" -le 0 ]; then
        echo
        echo -n "Timeout when finding linking status of $DEVICE."
	sleep 2
        break
      else
        echo -n "."
      fi
    done
    if [ "$link_status" = "yes" ]; then
      echo " Found status \"linked\"."
    else
      echo " Status \"not linked\" or \"unknown\"."
    fi
    if [ -z "$link_status" ]; then
      link_status="Unknown"     
    fi
    hwaddr="$(drbl-get-macadd $DEVICE)"
    DEVICELIST="$DEVICELIST ${DEVICE} $(rep_whspc_w_udrsc "$msg_link_detected"):${link_status}(${dev_model}|${hwaddr})"
  done
  rm -f "$TMP"
  [ -f "$hw_scan_tmp" -a -n "$hw_scan_tmp" ] && rm -f $hw_scan_tmp
  $DIA --menu "$msg_choose_nic ?" 0 0 0 $DEVICELIST 2>"$TMP" || bailout
  read DV <"$TMP" ; rm -f "$TMP"
else
  # Remove additional spaces
  DV="$(echo $NETDEVICES)"
fi

#
if [ "$ocs_net_show_pppoe" != "no" ]; then
  pppoe_msg_1="pppoe"
  pppoe_msg_2="$(rep_whspc_w_udrsc "$msg_use_pppoe_conf")"
fi
if [ "$ocs_net_show_enter_shell" != "no" ]; then
  enter_shell_msg_1="enter_shell"
  enter_shell_msg_2="$(rep_whspc_w_udrsc "$msg_enter_cml. $msg_do_it_manually")"
fi

#
$DIA  --title  \
"$msg_Network_config" --menu "$msg_choose_mode_to_setup_net: $DV" \
0 0 0 $DIA_ESC \
"dhcp"  "$msg_use_dhcp_broadcast" \
"static" "$msg_use_static_ip" \
$pppoe_msg_1 $pppoe_msg_2 \
$enter_shell_msg_1 $enter_shell_msg_2 \
2> $TMP
net_setup_mode="$(cat $TMP)"
[ -f "$TMP" ] && rm -f $TMP

case "$net_setup_mode" in
  dhcp) cfg_by_dhcp;;
  static) cfg_static_ip;;
  pppoe) cfg_pppoe;;
  enter_shell) 
      echo $msg_enter_another_shell_hint_wo_netcfg_prompt
      echo -n "$msg_press_enter_to_continue..."
      read
      /bin/bash
      ;;
esac

rc=$?
exit $rc