@@ -4,6 +4,13 @@ DRCOM_ORIGIN=latest-wired.py
4
4
DRCOM=drcom
5
5
DRCOM_PATH=/usr/bin
6
6
CONFIG_PATH=/etc
7
+ # for cli options
8
+ # "-" option is to rewrite long options which getopts do not support.
9
+ # ":" behind "-" is to undertake option string value of "-"
10
+ # like "--debug" option, "-" is a short option undertaking "-debug",
11
+ # and "debug" is the actual option handle by getopts
12
+ optspec=" -:Vh"
13
+
7
14
8
15
if [ ! -f " /etc/os-release" ]; then
9
16
echo " Recheck your package. You cannot run this script."
@@ -69,7 +76,7 @@ root_pwd_change() {
69
76
passwd root;;
70
77
N|n)
71
78
# shellcheck disable=SC2104
72
- break ;;
79
+ pass ;;
73
80
esac
74
81
clear
75
82
}
@@ -199,7 +206,7 @@ recheck() {
199
206
echo " $wifi_password1 " ;;
200
207
N|n|* )
201
208
# shellcheck disable=SC2104
202
- break ;;
209
+ pass ;;
203
210
esac
204
211
205
212
echo " Crontab:"
@@ -447,92 +454,112 @@ setup_done() {
447
454
echo " you may find only one ssid of your routine in the list."
448
455
echo " --------------------"
449
456
}
450
- if [[ $1 == " --dry-run" ]]; then
451
- clear
452
- echo " This flag is for test and will print most of the variables."
453
- hello
454
- network_config
455
- root_pwd_change
456
- inform_gather
457
- wlan_ssid_settings
458
- wlan_passwd_setting
459
- setup_confirm
460
- setup_done
461
- else
462
- # config renew after sys-upgrade
463
- read -p " Is is installation after system upgrade? [y/N]: " ifSet_upgrade
464
- case $ifSet_upgrade in
465
- n|N|" " )
457
+
458
+ setup_done_debug () {
459
+ echo " =========="
460
+ echo " Student number: "
461
+ echo $username
462
+ echo " Password: "
463
+ echo $password
464
+ echo " Wifi ssid (5Ghz) :" " $wifi_ssid0 "
465
+ echo " Passwd :" " $wifi_password0 "
466
+ echo " Wifi ssid (2.4Ghz) :" " $wifi_ssid1 "
467
+ echo " Passwd :" " $wifi_password1 "
468
+ echo " Crontab: "
469
+ echo $ifSet
470
+ echo " =========="
471
+ uname -a
472
+ echo $distro
473
+ cat /etc/os-release
474
+ }
475
+
476
+ # Handle actions without options
477
+ if [ ! $1 ]; then
478
+ # config renew after sys-upgrade
479
+ read -p " Is is installation after system upgrade? [y/N]: " ifSet_upgrade
480
+ case $ifSet_upgrade in
481
+ n|N|" " )
482
+ clear
483
+ hello
484
+ network_config
485
+ root_pwd_change
486
+ inform_gather
487
+ wlan_ssid_settings
488
+ wlan_passwd_setting
489
+ # recheck
490
+ setup_confirm
491
+ clean_up
492
+ setup_packages
493
+ setup_drcom
494
+ setup_crontab
495
+ setup_wlan
496
+ setup_done
497
+ ;;
498
+ y|Y)
499
+ clear
500
+ wifi_ssid0=" the one you have set"
501
+ wifi_ssid1=" the one you have set"
502
+ wifi_password0=" the one you have set"
503
+ wifi_password1=" the one you have set"
504
+ hello
505
+ network_config
506
+ inform_gather
507
+ # recheck
508
+ setup_confirm
509
+ setup_packages
510
+ setup_drcom
511
+ setup_crontab
512
+ setup_done
513
+ echo " All done!"
514
+ ;;
515
+ esac
516
+ else # When running with options
517
+ while getopts " $optspec " optchar; do
518
+ case $optchar in
519
+ -)
520
+ case $OPTARG in
521
+ dry-run)
466
522
clear
467
- hello
523
+ echo " This flag is for test and will print most of the variables. "
468
524
network_config
469
525
root_pwd_change
470
526
inform_gather
471
527
wlan_ssid_settings
472
528
wlan_passwd_setting
473
- # recheck
474
529
setup_confirm
475
- clean_up
476
- setup_packages
477
- setup_drcom
478
- setup_crontab
479
- setup_wlan
480
- setup_done
530
+ setup_done_debug
481
531
;;
482
- y|Y)
483
- clear
484
- wifi_ssid0=" the one you have set"
485
- wifi_ssid1=" the one you have set"
486
- wifi_password0=" the one you have set"
487
- wifi_password1=" the one you have set"
488
- hello
489
- network_config
490
- inform_gather
491
- # recheck
492
- setup_confirm
493
- setup_packages
494
- setup_drcom
495
- setup_crontab
496
- setup_done
497
- echo " All done!"
532
+ help)
533
+ echo " "
534
+ echo " USAGE: sh ./setup.sh [options]"
535
+ echo " "
536
+ echo " -V, --dry-run Verbose. Run the scripts without actually setting up."
537
+ echo " -h, --help Display this message."
498
538
;;
539
+ esac
540
+ ;;
541
+ V)
542
+ clear
543
+ echo " This flag is for test and will print most of the variables."
544
+ hello
545
+ network_config
546
+ root_pwd_change
547
+ inform_gather
548
+ wlan_ssid_settings
549
+ wlan_passwd_setting
550
+ setup_confirm
551
+ setup_done_debug
552
+ ;;
553
+ h)
554
+ echo " USAGE: sh ./setup.sh [options]"
555
+ echo " -V, --dry-run Verbose. Run the scripts without actually setting up."
556
+ echo " -h, --help Display this message."
557
+ ;;
558
+ * )
559
+ if [ " $OPTERR " != 1 ] || [ " ${optspec: 0: 1} " = " :" ]; then
560
+ echo " Non-option argument: '-${OPTARG} '" >&2
561
+ fi
562
+ ;;
499
563
esac
564
+ done
500
565
fi
501
- # config renew after sys-upgrade
502
- # read -p "Is is installation after system upgrade? [y/N]: " ifSet_upgrade
503
- # case $ifSet_upgrade in
504
- # n|N|"")
505
- # clear
506
- # hello
507
- # network_config
508
- # root_pwd_change
509
- # inform_gather
510
- # wlan_ssid_settings
511
- # wlan_passwd_setting
512
- # # recheck
513
- # setup_confirm
514
- # clean_up
515
- # setup_packages
516
- # setup_drcom
517
- # setup_crontab
518
- # setup_wlan
519
- # setup_done
520
- # ;;
521
- # y|Y)
522
- # clear
523
- # wifi_ssid0="the one you have set"
524
- # wifi_ssid1="the one you have set"
525
- # wifi_password0="the one you have set"
526
- # wifi_password1="the one you have set"
527
- # hello
528
- # network_config
529
- # inform_gather
530
- # # recheck
531
- # setup_confirm
532
- # setup_packages
533
- # setup_drcom
534
- # setup_crontab
535
- # setup_done
536
- # echo "All done!"
537
- # ;;
538
- # esac
0 commit comments