This file is indexed.

/usr/sbin/drbl-login-switch is in drbl 2.6.15-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
#!/bin/bash
# Steven Shiau <steven _at_ nchc org tw>
# License: GPL
# Description: To set the login mode for DRBL clients

# Load DRBL setting and functions
DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"

. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions

#
PWD_NO_0_1_MSG="Note!!! To avoid confusion, these random password does NOT contain digit 0 (zero) and digit 1 (one)!!!"

#
usage() {
  echo "Switch the login mode for DRBL clients."
  echo "Usage: $0 [Options]"
  echo "Options:"
  language_help_prompt_by_idx_no
  echo "-a, --auto:   auto login for clients"
  echo "-g, --no-gen-ssi do NOT generate DRBL SSI template tarball."
  echo "-h, --host IP_ADDRESS:  set login mode ony for the host with IP_ADDRESS instead of all DRBL clients"
  echo "-n, --normal: normal login for clients"
  echo "-t, --timed:  timed login within time TIMED_LOGIN_TIME (sec)"
  echo "-p, --password_opt: the password option for auto and timed login."
  echo "-u, --no_nis_update:  do NOT run NIS update"
  echo "-v, --verbose:  verbose mode."
  echo "PASSWORD_OPT:"
  echo "If one digit, it's the length of randomly created password."
  echo "If more than one character, it's the password (i.e. if you enter \"drblclient\", then the password is \"drblclient\")."
  echo "If blank, it will be randomly generated with some (say:8) characters."
}

#
check_if_root

# Get the $GDM_CFG/$KDM_CFG filename
get_gdm_kdm_conf_filename

#
set_gdm_auto_login() {
  # To config these two parameters:
  # AutomaticLoginEnable=false/true
  # AutomaticLogin=
  local inode="$1"
  local iauto_login_id="$2"
  if [ ! -f "$inode/$GDM_CFG" ]; then
    [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING 
    echo "GDM config in $inode NOT found, assume it's DRBL SSI mode!"  
    [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
    return 1
  fi
  # disable other types login (timed login) if exists
  perl -p -i -e "s/^[[:space:]]*#*[[:space:]]*TimedLoginEnable=.*/TimedLoginEnable=false/" $inode/$GDM_CFG
  perl -p -i -e "s/^[[:space:]]*#*[[:space:]]*TimedLogin=.*/TimedLogin=/" $inode/$GDM_CFG
  perl -p -i -e "s/^[[:space:]]*#*[[:space:]]*TimedLoginDelay=.*/TimedLoginDelay=/" $inode/$GDM_CFG

  # enable autologin
  lines="$(get_block_line_in_gdm_kdm daemon $inode/$GDM_CFG)"
  begin_line=$(echo $lines | awk -F" " '{print $1}')
  end_line=$(echo $lines | awk -F" " '{print $2}')
  chk_cmd="if ($begin_line..$end_line) {print}"
  if [ -n "$(perl -n -e "$chk_cmd" $inode/$GDM_CFG | grep -i "^AutomaticLoginEnable=")" ]; then
    sub_cmd="if ($begin_line..$end_line) {s/^AutomaticLoginEnable=.*/AutomaticLoginEnable=true/}"
    perl -pi -e "$sub_cmd" $inode/$GDM_CFG
  else
    # insert 1 blank line
    sub_cmd="if ($((end_line))..$((end_line))) {s/^(.*)$/\$1\n/gi}"
    perl -pi -e "$sub_cmd" $inode/$GDM_CFG
    # replace the one we want in the added blank line
    sub_cmd="if ($((end_line+1))..$((end_line+1))) {s/^$/AutomaticLoginEnable=true/gi}"
    perl -pi -e "$sub_cmd" $inode/$GDM_CFG
  fi
  # put the autologin id
  lines="$(get_block_line_in_gdm_kdm daemon $inode/$GDM_CFG)"
  begin_line=$(echo $lines | awk -F" " '{print $1}')
  end_line=$(echo $lines | awk -F" " '{print $2}')
  chk_cmd="if ($begin_line..$end_line) {print}"
  if [ -n "$(perl -n -e "$chk_cmd" $inode/$GDM_CFG | grep -i "^AutomaticLogin=")" ]; then
    sub_cmd="if ($begin_line..$end_line) {s/^AutomaticLogin=.*/AutomaticLogin=$iauto_login_id/}"
    perl -pi -e "$sub_cmd" $inode/$GDM_CFG
  else
    # insert 1 blank line
    sub_cmd="if ($((end_line))..$((end_line))) {s/^(.*)$/\$1\n/gi}"
    perl -pi -e "$sub_cmd" $inode/$GDM_CFG
    # replace the one we want in the added blank line
    sub_cmd="if ($((end_line+1))..$((end_line+1))) {s/^$/AutomaticLogin=$iauto_login_id/gi}"
    perl -pi -e "$sub_cmd" $inode/$GDM_CFG
  fi
} # end of set_gdm_auto_login
#
set_gdm_timed_login() {
  local inode="$1"
  local iauto_login_id="$2"
  local tlogin_time="$3"
  if [ ! -f $inode/$GDM_CFG ]; then
    [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING 
    echo "$inode/$GDM_CFG is NOT found!!! Assume it's DRBL SSI mode!"  
    [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
    return 1
  fi
  # set the timed login time
  [ -z "$tlogin_time" ] && tlogin_time="$TIMED_GDM_TIME_DEFAULT"
  # disable other types login (auto login) if they exists
  perl -p -i -e "s/^[[:space:]]*#*[[:space:]]*AutomaticLoginEnable=.*/AutomaticLoginEnable=false/" $inode/$GDM_CFG
  perl -p -i -e "s/^[[:space:]]*#*[[:space:]]*AutomaticLogin=.*/AutomaticLogin=/" $inode/$GDM_CFG

  # enable timed login
  lines="$(get_block_line_in_gdm_kdm daemon $inode/$GDM_CFG)"
  begin_line=$(echo $lines | awk -F" " '{print $1}')
  end_line=$(echo $lines | awk -F" " '{print $2}')
  chk_cmd="if ($begin_line..$end_line) {print}"
  if [ -n "$(perl -n -e "$chk_cmd" $inode/$GDM_CFG | grep -i "^TimedLoginEnable=")" ]; then
    sub_cmd="if ($begin_line..$end_line) {s/^TimedLoginEnable=.*/TimedLoginEnable=true/}"
    perl -pi -e "$sub_cmd" $inode/$GDM_CFG
  else
    # insert 1 blank line
    sub_cmd="if ($((end_line))..$((end_line))) {s/^(.*)$/\$1\n/gi}"
    perl -pi -e "$sub_cmd" $inode/$GDM_CFG
    # replace the one we want in the added blank line
    sub_cmd="if ($((end_line+1))..$((end_line+1))) {s/^$/TimedLoginEnable=true/gi}"
    perl -pi -e "$sub_cmd" $inode/$GDM_CFG
  fi
  # put the timedlogin delay time
  lines="$(get_block_line_in_gdm_kdm daemon $inode/$GDM_CFG)"
  begin_line=$(echo $lines | awk -F" " '{print $1}')
  end_line=$(echo $lines | awk -F" " '{print $2}')
  chk_cmd="if ($begin_line..$end_line) {print}"
  if [ -n "$(perl -n -e "$chk_cmd" $inode/$GDM_CFG | grep -i "^TimedLoginDelay=")" ]; then
    sub_cmd="if ($begin_line..$end_line) {s/^TimedLoginDelay=.*/TimedLoginDelay=$tlogin_time/}"
    perl -pi -e "$sub_cmd" $inode/$GDM_CFG
  else
    # insert 1 blank line
    sub_cmd="if ($((end_line))..$((end_line))) {s/^(.*)$/\$1\n/gi}"
    perl -pi -e "$sub_cmd" $inode/$GDM_CFG
    # replace the one we want in the added blank line
    sub_cmd="if ($((end_line+1))..$((end_line+1))) {s/^$/TimedLoginDelay=$tlogin_time/gi}"
    perl -pi -e "$sub_cmd" $inode/$GDM_CFG
  fi
  # put the timedlogin id
  lines="$(get_block_line_in_gdm_kdm daemon $inode/$GDM_CFG)"
  begin_line=$(echo $lines | awk -F" " '{print $1}')
  end_line=$(echo $lines | awk -F" " '{print $2}')
  chk_cmd="if ($begin_line..$end_line) {print}"
  if [ -n "$(perl -n -e "$chk_cmd" $inode/$GDM_CFG | grep -i "^TimedLogin=")" ]; then
    sub_cmd="if ($begin_line..$end_line) {s/^TimedLogin=.*/TimedLogin=$iauto_login_id/}"
    perl -pi -e "$sub_cmd" $inode/$GDM_CFG
  else
    # insert 1 blank line
    sub_cmd="if ($((end_line))..$((end_line))) {s/^(.*)$/\$1\n/gi}"
    perl -pi -e "$sub_cmd" $inode/$GDM_CFG
    # replace the one we want in the added blank line
    sub_cmd="if ($((end_line+1))..$((end_line+1))) {s/^$/TimedLogin=$iauto_login_id/gi}"
    perl -pi -e "$sub_cmd" $inode/$GDM_CFG
  fi
} # end of set_gdm_timed_login
#
set_gdm_normal_login() {
    local inode="$1"
    if [ ! -f $inode/$GDM_CFG ]; then
      [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING 
      echo "$inode/$GDM_CFG is NOT found!!! Assume it's DRBL SSI mode!"  
      [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
      return 1
    fi
    # disable auto and timed login, then it will be normal login since this is the default setting.
    perl -p -i -e "s/^[[:space:]]*#*[[:space:]]*AutomaticLoginEnable=.*/AutomaticLoginEnable=false/" $inode/$GDM_CFG
    perl -p -i -e "s/^[[:space:]]*#*[[:space:]]*AutomaticLogin=.*/AutomaticLogin=/" $inode/$GDM_CFG
    perl -p -i -e "s/^[[:space:]]*#*[[:space:]]*TimedLoginEnable=.*/TimedLoginEnable=false/" $inode/$GDM_CFG
    perl -p -i -e "s/^[[:space:]]*#*[[:space:]]*TimedLogin=.*/TimedLogin=/" $inode/$GDM_CFG
    perl -p -i -e "s/^[[:space:]]*#*[[:space:]]*TimedLoginDelay=.*/TimedLoginDelay=/" $inode/$GDM_CFG
} # end of set_gdm_normal_login
#
set_lightdm_auto_login() {
  # To config these two parameters:
  # autologin-user=<YOUR USER>
  # autologin-user-timeout=0
  local inode="$1"
  local iauto_login_id="$2"
  if [ ! -f "$inode/$LIGHTDM_CFG" -a \
         -d "$inode/etc/lightdm/lightdm.conf.d" ]; then
    # For Ubuntu 13.10, lightdm 1.8.4 has different initial configration file. 
    # "/etc/lightdm/lightdm.conf" does not exist in the initial installation. 
    # While it will exist when a user configures that in the GUI.
    # We create one here.
    echo "[SeatDefaults]" > $inode/$LIGHTDM_CFG
  fi
  if [ ! -f "$inode/$LIGHTDM_CFG" ]; then
    [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING 
    echo "LightDM config in $inode NOT found, assume it's DRBL SSI mode!"  
    [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
    return 1
  fi
  # disable other types login (timed login) if exists
  perl -p -i -e "s/^[[:space:]]*#*[[:space:]]*autologin-user-timeout=.*/autologin-user-timeout=0/" $inode/$LIGHTDM_CFG

  # put the autologin id
  lines="$(get_block_line_in_gdm_kdm SeatDefaults $inode/$LIGHTDM_CFG)"
  begin_line=$(echo $lines | awk -F" " '{print $1}')
  end_line=$(echo $lines | awk -F" " '{print $2}')
  chk_cmd="if ($begin_line..$end_line) {print}"
  if [ -n "$(perl -n -e "$chk_cmd" $inode/$LIGHTDM_CFG | grep -i "^autologin-user=")" ]; then
    sub_cmd="if ($begin_line..$end_line) {s/^autologin-user=.*/autologin-user=$iauto_login_id/}"
    perl -pi -e "$sub_cmd" $inode/$LIGHTDM_CFG
  else
    # insert 1 blank line
    sub_cmd="if ($((end_line))..$((end_line))) {s/^(.*)$/\$1\n/gi}"
    perl -pi -e "$sub_cmd" $inode/$LIGHTDM_CFG
    # replace the one we want in the added blank line
    sub_cmd="if ($((end_line+1))..$((end_line+1))) {s/^$/autologin-user=$iauto_login_id/gi}"
    perl -pi -e "$sub_cmd" $inode/$LIGHTDM_CFG
  fi
} # end of set_lightdm_auto_login
#
set_lightdm_timed_login() {
  # //NOTE// Due to a bug, this /autologin-user-timeout=* actually won't work on Ubuntu 11.10 and 12.04.
  # Ref: https://bugs.launchpad.net/ubuntu/+source/lightdm/+bug/902852
  local inode="$1"
  local iauto_login_id="$2"
  local tlogin_time="$3"
  if [ ! -f "$inode/$LIGHTDM_CFG" -a \
         -d "$inode/etc/lightdm/lightdm.conf.d" ]; then
    # For Ubuntu 13.10, lightdm 1.8.4 has different initial configration file. 
    # "/etc/lightdm/lightdm.conf" does not exist in the initial installation. 
    # While it will exist when a user configures that in the GUI.
    # We create one here.
    echo "[SeatDefaults]" > $inode/$LIGHTDM_CFG
  fi
  if [ ! -f $inode/$LIGHTDM_CFG ]; then
    [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING 
    echo "$inode/$LIGHTDM_CFG is NOT found!!! Assume it's DRBL SSI mode!"  
    [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
    return 1
  fi
  # set the timed login time
  [ -z "$tlogin_time" ] && tlogin_time="$TIMED_LIGHTDM_TIME_DEFAULT"

  # put the timedlogin delay time
  lines="$(get_block_line_in_gdm_kdm SeatDefaults $inode/$LIGHTDM_CFG)"
  begin_line=$(echo $lines | awk -F" " '{print $1}')
  end_line=$(echo $lines | awk -F" " '{print $2}')
  chk_cmd="if ($begin_line..$end_line) {print}"
  if [ -n "$(perl -n -e "$chk_cmd" $inode/$LIGHTDM_CFG | grep -i "^autologin-user-timeout=")" ]; then
    sub_cmd="if ($begin_line..$end_line) {s/^autologin-user-timeout=.*/autologin-user-timeout=$tlogin_time/}"
    perl -pi -e "$sub_cmd" $inode/$LIGHTDM_CFG
  else
    # insert 1 blank line
    sub_cmd="if ($((end_line))..$((end_line))) {s/^(.*)$/\$1\n/gi}"
    perl -pi -e "$sub_cmd" $inode/$LIGHTDM_CFG
    # replace the one we want in the added blank line
    sub_cmd="if ($((end_line+1))..$((end_line+1))) {s/^$/autologin-user-timeout=$tlogin_time/gi}"
    perl -pi -e "$sub_cmd" $inode/$LIGHTDM_CFG
  fi
  # put the timedlogin id
  lines="$(get_block_line_in_gdm_kdm SeatDefaults $inode/$LIGHTDM_CFG)"
  begin_line=$(echo $lines | awk -F" " '{print $1}')
  end_line=$(echo $lines | awk -F" " '{print $2}')
  chk_cmd="if ($begin_line..$end_line) {print}"
  if [ -n "$(perl -n -e "$chk_cmd" $inode/$LIGHTDM_CFG | grep -i "^autologin-user=")" ]; then
    sub_cmd="if ($begin_line..$end_line) {s/^autologin-user=.*/autologin-user=$iauto_login_id/}"
    perl -pi -e "$sub_cmd" $inode/$LIGHTDM_CFG
  else
    # insert 1 blank line
    sub_cmd="if ($((end_line))..$((end_line))) {s/^(.*)$/\$1\n/gi}"
    perl -pi -e "$sub_cmd" $inode/$LIGHTDM_CFG
    # replace the one we want in the added blank line
    sub_cmd="if ($((end_line+1))..$((end_line+1))) {s/^$/autologin-user=$iauto_login_id/gi}"
    perl -pi -e "$sub_cmd" $inode/$LIGHTDM_CFG
  fi
  # Append greeter-show-manual-login=true
  tune_lightdm_manual_login $inode true
} # end of set_lightdm_timed_login
#
tune_lightdm_manual_login() {
  local inode="$1" # Path to $LIGHTDM_CFG
  local manual_login_mode="$2"  # true or false
  # To config greeter-show-manual-login=true
  if [ ! -f "$inode/$LIGHTDM_CFG" ]; then
    [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING 
    echo "LightDM config in $inode NOT found, assume it's DRBL SSI mode!"  
    [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
    return 1
  fi

  # put the greeter-show-manual-login 
  lines="$(get_block_line_in_gdm_kdm SeatDefaults $inode/$LIGHTDM_CFG)"
  begin_line=$(echo $lines | awk -F" " '{print $1}')
  end_line=$(echo $lines | awk -F" " '{print $2}')
  chk_cmd="if ($begin_line..$end_line) {print}"
  if [ -n "$(perl -n -e "$chk_cmd" $inode/$LIGHTDM_CFG | grep -i "^greeter-show-manual-login=")" ]; then
    sub_cmd="if ($begin_line..$end_line) {s/^greeter-show-manual-login=.*/greeter-show-manual-login=$manual_login_mode/}"
    perl -pi -e "$sub_cmd" $inode/$LIGHTDM_CFG
  else
    # insert 1 blank line
    sub_cmd="if ($((end_line))..$((end_line))) {s/^(.*)$/\$1\n/gi}"
    perl -pi -e "$sub_cmd" $inode/$LIGHTDM_CFG
    # replace the one we want in the added blank line
    sub_cmd="if ($((end_line+1))..$((end_line+1))) {s/^$/greeter-show-manual-login=$manual_login_mode/gi}"
    perl -pi -e "$sub_cmd" $inode/$LIGHTDM_CFG
  fi
} # end of tune_lightdm_manual_login
#
set_lightdm_normal_login() {
    local inode="$1"
    if [ ! -f "$inode/$LIGHTDM_CFG" -a \
           -d "$inode/etc/lightdm/lightdm.conf.d" ]; then
      # For Ubuntu 13.10, lightdm 1.8.4 has different initial configration file. 
      # "/etc/lightdm/lightdm.conf" does not exist in the initial installation. 
      # While it will exist when a user configures that in the GUI.
      # We create one here.
      echo "[SeatDefaults]" > $inode/$LIGHTDM_CFG
    fi
    if [ ! -f $inode/$LIGHTDM_CFG ]; then
      [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING 
      echo "$inode/$LIGHTDM_CFG is NOT found!!! Assume it's DRBL SSI mode!"  
      [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
      return 1
    fi
    # disable auto and timed login, then it will be normal login since this is the default setting.
    perl -p -i -e "s/^[[:space:]]*#*[[:space:]]*autologin-user=.*/#autologin-user=/" $inode/$LIGHTDM_CFG
    perl -p -i -e "s/^[[:space:]]*#*[[:space:]]*autologin-user-timeout=.*/#autologin-user-timeout=/" $inode/$LIGHTDM_CFG
    # Append greeter-show-manual-login=true
    tune_lightdm_manual_login $inode true
} # end of set_lightdm_normal_login
#
set_kdm_auto_login() {
    local inode="$1"
    if [ ! -f "$inode/$KDM_CFG" ]; then
      [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING 
      echo "KDM config in $inode NOT found!!! Assume it's DRBL SSI mode!"  
      [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
      return 1
    fi
    perl -p -i -e "s/^[[:space:]]*#*[[:space:]]*AutoLoginEnable=.*/AutoLoginEnable=true/" $inode/$KDM_CFG
    perl -p -i -e "s/^[[:space:]]*#*[[:space:]]*AutoLoginUser=.*/AutoLoginUser=$auto_login_id/" $inode/$KDM_CFG
} # end of set_kdm_auto_login
#
create_autologin_account() {
    # $create_account, $auto_login_id and $echo_no_digit_0_1 are global variables
    local ihost="$1"
    local shell_opt
    get_autologin_account $ihost
    # auto_login_id is got from get_autologin_account
    [ -z "$auto_login_id" ] && echo "Unable to get $ip client's hostname! Skip this one!" && return 1
    if ! grep -q -E "^$auto_login_id:" /etc/passwd ; then
      # account $auto_login_id does not exists, create it.
      create_account=1
      # If /bin/bash is found, we try to se /bin/bash as default shell.
      shell_opt=""
      [ -e /bin/bash ] && shell_opt="-s /bin/bash"
      echo -n "Creating account $auto_login_id... "
      useradd -m $auto_login_id $shell_opt
    fi

    # set password when accounts are created (at that time the passwords are empty) or when password_opt is assigned
    if [ "$create_account" = "1" -o -n "$password_opt" ]; then
      # clean the old file
      clean_old_auto_login_id_passwd_file $AUTO_LOGIN_ID_PASSWD $auto_login_id
      # set the passwd
      set_client_autologin_passwd=1
      case "$password_opt" in
       [0-9]|"")
          echo -n "The password_opt is set as \"$password_opt\". " 
          # echo the message $PWD_NO_0_1_MSG in the file $AUTO_LOGIN_ID_PASSWD
          # if it does not exist.
          if [ -z "`grep $PWD_NO_0_1_MSG  $AUTO_LOGIN_ID_PASSWD 2>/dev/null`" ]; then
            [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING 
            echo $PWD_NO_0_1_MSG | tee -a $AUTO_LOGIN_ID_PASSWD
            [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
          fi
          echo_no_digit_0_1=1
          # get one digit, so it must be the length of password
          # or it's empty, we set it as $password_opt_default
          if [ -z "$password_opt" ]; then
            echo -n "You did NOT set the length of password, set it as $PASSWD_LENGTH_DEFAULT. " 
            password_opt="$PASSWD_LENGTH_DEFAULT"
          fi
          echo -n "Generating random password from password length $password_opt... " 
		  make_random_password $password_opt
		  passwd_now=$random_password
          echo "$auto_login_id:$passwd_now" | chpasswd
          ;;
       *)
          echo -n "Set password from input..." 
          passwd_now="$password_opt"
          echo "$auto_login_id:$passwd_now" | chpasswd
      esac  
      echo "$auto_login_id $passwd_now" >> $AUTO_LOGIN_ID_PASSWD
    fi
} # end of create_autologin_account
#
clean_old_auto_login_id_passwd_file() {
    local local_autologin_id_pwd_file="$1"
    local local_auto_login_id="$2"
    [ -z "$local_auto_login_id" ] && echo "Unable to get auto login id! Skip this one!" && return 1
    # rename the old file, local_auto_login_id is a tag so that we will rename it just onece, not for every accounts.
    if [ -f "$local_autologin_id_pwd_file" ]; then
      if grep -q -E "\<$local_auto_login_id\>" $local_autologin_id_pwd_file; then
     	[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING 
	echo "An existing file \"$local_autologin_id_pwd_file\" is found. Rename it as \"$local_autologin_id_pwd_file.drblsave\""
        [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
	mv -f $local_autologin_id_pwd_file ${local_autologin_id_pwd_file}.drblsave
      fi
    fi
} # end of clean_old_auto_login_id_passwd_file
#
output_result_and_update_yp() {
  # $create_account, $no_nis_update and $set_client_autologin_passwd are global variables
  if [ "$set_client_autologin_passwd" = "1" ]; then
    [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING 
    echo $msg_created_autologin_ID_passwd_file
    #echo $PWD_NO_0_1_MSG | tee -a $AUTO_LOGIN_ID_PASSWD
    [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
    # update the NIS
    [ "$no_nis_update" != "on" ] && make -C /var/yp
  fi
} # end of output_result_and_update_yp
     
##############
###  MAIN  ###
##############
# set the flag for create account and echo prompt
# $create_account, $auto_login_id, $no_nis_update, $set_client_autologin_passwd and $echo_no_digit_0_1 are global variables
create_account=0
echo_no_digit_0_1=0
set_client_autologin_passwd=0

# If clonezilla box or drbl-ssi mode
[ -f /etc/drbl/drbl_deploy.conf ] && . /etc/drbl/drbl_deploy.conf
if [ "$clonezilla_mode" = "clonezilla_box_mode" -o "$drbl_mode" = "drbl_ssi_mode" ]; then
  gen_ssi="yes"
else
  gen_ssi="no"
fi
     
while [ $# -gt 0 ]; do
  case "$1" in
    -n|--normal)
		shift; login_dm_mode="normal_login"
                ;;
    -a|--auto)
		shift; login_dm_mode="auto_login"
                ;;
    -t|--timed)
		shift; login_dm_mode="timed_login"
                if [ -z "$(echo $1 |grep ^-.)" ]; then
                  # skip the -xx option, in case 
		  timed_login_time="$1"
		  shift
                fi
                ;;
    -l|--language)
		shift
                if [ -z "$(echo $1 |grep ^-.)" ]; then
                  # skip the -xx option, in case 
		  specified_lang="$1"
		  shift
                fi
		;;
    -h|--host)
		shift
                if [ -z "$(echo $1 |grep ^-.)" ]; then
                  # skip the -xx option, in case 
		  specified_host="$1"
		  shift
                fi
		;;
    -g|--no-gen-ssi)
		gen_ssi="no"
                shift;;
    -v|--verbose)
		shift; verbose="on"
                ;;
    -u|--no_nis_update)
		shift; no_nis_update="on"
                ;;
    -p|--password_opt)
		shift
                if [ -z "$(echo $1 |grep ^-.)" ]; then
                  # skip the -xx option, in case 
		  password_opt="$1"
		  shift
                fi
		;;
    -*)		echo "${0}: ${1}: invalid option" >&2
		usage >& 2
		exit 2 ;;
    *)		break ;;
  esac
done

#
ask_and_load_lang_set $specified_lang

# check if the mode is set or net 
[ -z "$login_dm_mode" ] && usage && exit 1

#
if [ -n "$specified_host" ]; then
 [ ! -d "$drblroot/$specified_host" ] && echo "Can NOT find DRBL client $specified_host (i.e. no $drblroot/$specified_host)! Assume it's DRBL SSI client."
 [ -n "$verbose" ] && echo "specified_host: $specified_host"
fi

# set the login option for GDM
 [ -n "$verbose" ] && echo -n "The GDM login option: $login_dm_mode..."

# set the host to be processed
# host_list is the IP address of client, like 192.168.1.1...
host_list=""
if [ -n "$specified_host" ]; then
   # set the host path
   host_list=$drblroot/$specified_host
else
   # withoud specified_host, it must be all clients, append each one to $host_list
   for ihost in `get-client-ip-list`; do
     host_list="$host_list $drblroot/$ihost"
   done
fi

RC=""
preferred="$(drbl-check-dm)"
RC=$?

[ $RC -eq 0 ] && echo "Display manager:\"$preferred\"..."

if [ -z "$preferred" ]; then
    echo "No display manager was found!"
    echo "Skip changing client's login mode of graphical interface."
    exit 3
fi

#
case "$preferred" in
   gdm*)
    for ihost in $host_list; do
     echo -n "Setting node `basename $ihost` as $login_dm_mode... "
     case "$login_dm_mode" in
       "auto_login"|"timed_login")
	  # create auto login account if necessary
	  create_autologin_account $ihost
	  # set the mode for $AUTO_LOGIN_ID_PASSWD as root access only
	  [ -f "$AUTO_LOGIN_ID_PASSWD" ] && chmod 600 $AUTO_LOGIN_ID_PASSWD
     	  case "$login_dm_mode" in
     	    "auto_login")
     	       set_gdm_auto_login $ihost $auto_login_id
     	       ;;
     	    "timed_login")
     	       set_gdm_timed_login $ihost $auto_login_id $timed_login_time
     	       ;;
     	  esac
     	  echo "done!"
          ;;
       "normal_login")
     	  set_gdm_normal_login $ihost
     	  echo "done!"
          ;;
     esac
    done
    # output result and update yp
    output_result_and_update_yp
    ;;
  kdm|mdkkdm)
    # No timed_login for KDE... only auto_login or nornam_login
    [ "$login_dm_mode" = "timed_login" ] && echo "No timed login for KDE... only auto login or normal login, so set it as auto login..."
    for ihost in $host_list; do
      echo -n "Setting node `basename $ihost` as $login_dm_mode... "
      case "$login_dm_mode" in
        "auto_login"|"timed_login")
          # create auto login account if necessary
          create_autologin_account $ihost
          # set the mode for $AUTO_LOGIN_ID_PASSWD as root access only
          [ -f "$AUTO_LOGIN_ID_PASSWD" ] && chmod 600 $AUTO_LOGIN_ID_PASSWD
          set_kdm_auto_login $ihost
          echo "done!"
          ;;
        "normal_login")
          [ -f "$ihost/$SYSCONF_PATH/autologin" ] && rm -f $ihost/$SYSCONF_PATH/autologin
          echo "done!"
          ;;
      esac
    done
    # output result and update yp
    output_result_and_update_yp
    ;;
  lightdm)
    for ihost in $host_list; do
     echo -n "Setting node `basename $ihost` as $login_dm_mode... "
     case "$login_dm_mode" in
       "auto_login"|"timed_login")
	  # create auto login account if necessary
	  create_autologin_account $ihost
	  # set the mode for $AUTO_LOGIN_ID_PASSWD as root access only
	  [ -f "$AUTO_LOGIN_ID_PASSWD" ] && chmod 600 $AUTO_LOGIN_ID_PASSWD
     	  case "$login_dm_mode" in
     	    "auto_login")
     	       set_lightdm_auto_login $ihost $auto_login_id
     	       ;;
     	    "timed_login")
     	       set_lightdm_timed_login $ihost $auto_login_id $timed_login_time
     	       ;;
     	  esac
     	  echo "done!"
          ;;
       "normal_login")
     	  set_lightdm_normal_login $ihost
     	  echo "done!"
          ;;
     esac
    done
    # output result and update yp
    output_result_and_update_yp
    ;;
  *)
    [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
    echo "Unknown display manager! This display manager \"$preferred\" is not supported by `basename $0`."
    [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
    echo "$msg_program_stop"
    exit 1
    ;;
esac

#
if [ "$gen_ssi" = "yes" ]; then
  echo "-------------------------------------------------------"
  echo "Since some config files are modified in template client, creating template tarball for DRBL SSI..."
  drbl-gen-ssi-files
fi