-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings-tui-virtual.subr
1348 lines (1133 loc) · 34.9 KB
/
settings-tui-virtual.subr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# GENERIC VIRTUAL-related TUI function ( vbox, xen, bhyve )
if [ ! "$_CBSD_SETTINGS_TUI_VIRTUAL_SUBR" ]; then
_CBSD_SETTINGS_TUI_VIRTUAL_SUBR=1
###
ip4_addr_msg="VM IPv4 and/or IPv6 address"
ip4_addr_desc="Current CBSD IPv4 pool: ${nodeippool}\n\
Useful with cloud-init and/or hook script\n\
'DHCP' for determine free IPv4 automatically\n"
GET_CD_BOOT_FIRMWARE_MSG="Choose CD boot firmware"
GET_HDD_BOOT_FIRMWARE_MSG="Choose HDD boot firmware"
GET_CONSOLE_MSG="Choose default console"
GET_CPUS_MSG="Number of CPUs: 1, max: ${vm_cpus_max}"
GET_EFI_MSG="Choose UEFI firmware"
GET_GUESTFS_MSG="Choose FS for boot image"
GET_GW4_MSG="Enter default gateway inside VMs or jail"
GET_HOSTBRIDGE_MSG="Hostbridge for VMs, eg: hostbridge or amd_hostbridge"
GET_IMGSIZE_MSG="Allocate X size of image free space: 100m, 1g"
GET_IMGTYPE_MSG="Choose disk image type"
GET_ISOPATH_MSG="Path to ISO image in srcdir/iso, eg: release.iso. 0 - for default img_iso"
GET_RAM_MSG="RAM in MB, eg: 512, 1024M, 2g"
GET_SWAPSIZE_MSG="Configure swap partitional in X size (usual RAMx2), 0 - for disable, e.g: 4g"
GET_VM_CPU_TOPOLOGY_MSG="Select CPU topology profile name"
GET_VM_ISOPATH_MSG="Select available/registered ISO"
GET_VM_PACKAGE_MSG="Choose package name"
GET_VM_VNC_PORT_MSG="VNC port. 0 - for auto, 1 - disable"
GET_VMPROFILE_MSG="- Use 'Update/GIT' button to keep profiles up to date via official\n CBSD public repo: https://github.com/cbsd/cbsd-vmprofiles"
GET_VMPROFILE_MSG_GIT="${GET_VMPROFILE_MSG}\n- Use 'Clean/GIT' button to revert GIT updates and reset to contrib settings"
GET_SOUNDHW_MSG="Choose sound harware"
# virtual form for $vnc_password
get_construct_vnc_password()
{
if get_password can_empty; then
vnc_password="${mtag}"
fi
[ -z "${vnc_password}" ] && vnc_password="0"
return 0
}
# virtual form for $spice_password
get_construct_spice_password()
{
if get_password can_empty; then
spice_password="${mtag}"
else
unset spice_password
fi
[ -z "${spice_password}" ] && spice_password="0"
}
# virtual forms for $imgsize
get_construct_imgsize()
{
local _input
local _minbytes= _maxbytes= _minbytes_human= _maxbytes_human= _minbytes_human_mb
local _ret=1 _ret2=
local _add_help_msg= _input_bytes=
local _message
# determine min/max threshold for input validation
if [ -n "${imgsize_min}" ]; then
_minbytes=$( get_bytes ${imgsize_min} )
_minbytes=$(( _minbytes + 536870912 )) # + 512 MB for stock
if conv2human "${_minbytes}"; then
_minbytes_human="${convval}"
else
_minbytes_human="${_minbytes}"
fi
_add_help_msg="min:${_minbytes_human}"
fi
if [ -n "${imgsize_max}" ]; then
_maxbytes=$( get_bytes ${imgsize_max} )
if conv2human "${_maxbytes}"; then
_maxbytes_human="${convval}"
else
_maxbytes_human="${_minbytes}"
fi
_add_help_msg="${_add_help_msg} max:${_maxbytes_human}"
fi
f_dialog_title " imgsize "
while [ ${_ret} -ne 0 ]; do
f_dialog_input _input "${GET_IMGSIZE_MSG}\n${_add_help_msg}" "${imgsize}" \
"${_message}" || return $?
if ! is_number "${_input}"; then
# is number. assume user's input value in MB, so convert to bytes
_input="${_input}m"
fi
if conv2human "${_input}"; then
_input_bytes="${convval}"
else
_input_bytes="${_minbytes}"
fi
if [ -n "${_minbytes}" ]; then
if [ ${_input_bytes} -lt ${_minbytes} ]; then
_minbytes_human_mb=$(( _minbytes / 1024 / 1024 ))
#f_show_msg "Values ${_tmp} too small, minimal > ${_minbytes_human_mb}m+"
omsg_help="${msg_help}"
msg_help="Ignore"
cbsd_msgbox_with_extra_button "Values ${_tmp} too small, minimal > ${_minbytes_human_mb}m+"
_ret2=$?
msg_help="${omsg_help}"
if [ ${_ret2} -eq 2 ]; then
# ignore
else
imgsize="${_minbytes_human_mb}m"
continue
fi
fi
fi
if [ -n "${_maxbytes}" ]; then
if [ ${_input_bytes} -gt ${_maxbytes} ]; then
if ! getyesno "Warning! Values too high: ${_maxbytes_human}. Overcommitting size anyway?"; then
continue
fi
fi
fi
_ret=0
done
imgsize="${_input}"
}
# virtual forms for swapsize
get_construct_swapsize()
{
local _input
f_dialog_title " swapsize "
f_dialog_input _input "${GET_SWAPSIZE_MSG}:" "${swapsize}" \
"${_message}" || return $?
swapsize="${_input}"
}
# virtual form for $cpus
get_construct_vm_cpus()
{
local _input _message=" current hoster logical CPUs: ${ncpu} "
local _ret=1
f_dialog_title " vCpus "
while [ ${_ret} -ne 0 ]; do
f_dialog_input _input "${GET_CPUS_MSG}" "${vm_cpus}" \
"${_message}" || return $?
if is_number ${_input}; then
f_show_msg "Only number is valid input for cpu"
continue
fi
if [ ${_input} -gt ${ncpu} -a ${_input} -lt ${vm_cpus_max} ]; then
if ! getyesno "Warning! Current node cpu: ${ncpu}. Overcommitting vCPUs can hurt perfomance.\nContinue anyway?"; then
continue
fi
elif [ ${_input} -lt 1 -o ${_input} -gt ${vm_cpus_max} ]; then
f_show_msg "Valid number of guest CPUs within 1 - ${vm_cpus_max} range"
continue
fi
_ret=0
done
vm_cpus="${_input}"
}
# virtual form for $vm_vnc_port
get_construct_vm_vnc_port()
{
local _input
f_dialog_title " vnc port "
f_dialog_input _input "${GET_VM_VNC_PORT_MSG}" "${vm_vnc_port}" \
"${_message}" || return $?
vm_vnc_port="${_input}"
}
# virtual form for $ram
get_construct_vm_ram()
{
local _input _tmp
local _minbytes= _maxbytes= _minbytes_human= _maxbytes_human= _minbytes_human_mb=
local _ret=1
local _add_help_msg= _input_bytes=
local _message
local _local_physmem_bytes=
local _local_physmem_human=
_local_physmem_bytes="${physmem}"
if conv2human "${_local_physmem_bytes}"; then
_local_physmem_human="${convval}"
else
_local_physmem_human="${_local_physmem_bytes}"
fi
_message=" current hoster physmem: ${_local_physmem_human} "
# determine min/max threshold for input validation
if [ -n "${vm_ram_min}" ]; then
_minbytes=$( get_bytes ${vm_ram_min} )
if conv2human "${_minbytes}"; then
_minbytes_human="${convval}"
else
_minbytes_human="${_minbytes}"
fi
_add_help_msg="min:${_minbytes_human}"
fi
if [ -n "${vm_ram_max}" ]; then
[ "${vm_ram_max}" = "native" ] && vm_ram_max="${physmem}"
_maxbytes=$( get_bytes ${vm_ram_max} )
if conv2human "${_maxbytes}"; then
_maxbytes_human="${convval}"
else
_maxbytes_human="${_minbytes}"
fi
_add_help_msg="${_add_help_msg} max:${_maxbytes_human}"
fi
f_dialog_title " RAM amount "
while [ ${_ret} -ne 0 ]; do
f_dialog_input _input "${GET_RAM_MSG}\n${_add_help_msg}" "${vm_ram}" \
"${_message}" || return $?
# test for human
if ! is_number "${_input}"; then
# is number. assume user's input value in MB, so convert to bytes
_input="${_input}m"
fi
_tmp="${_input}"
if conv2human "${_input}"; then
_input_bytes="${convval}"
else
_input_bytes="${_minbytes}"
fi
if [ -n "${_minbytes}" ]; then
if [ ${_input_bytes} -lt ${_minbytes} ]; then
_minbytes_human_mb=$(( _minbytes / 1024 / 1024 ))
f_show_msg "Values ${_tmp} too small, minimal > ${_minbytes_human_mb}m+"
vm_ram="${_minbytes_human_mb}m"
continue
fi
fi
if [ -n "${_maxbytes}" ]; then
if [ ${_input_bytes} -gt ${_maxbytes} ]; then
if ! getyesno "Warning! Values too high: ${_maxbytes_human}. Overcommitting RAM anyway?"; then
continue
fi
fi
fi
_ret=0
done
vm_ram="${_tmp}"
}
# virtual form for $vm_iso_path
get_construct_isopath()
{
local _input
f_dialog_title " isopath "
f_dialog_input _input "${GET_ISOPATH_MSG}" "${vm_iso_path}" \
"${_message}" || return $?
vm_iso_path="${_input}"
}
# virtual form for cloud init helper
get_construct_cloud_init_menu()
{
local _input _res item_let=A _ret
local _pubkey_len _ip1 _ip2 _ip3 _ip4
local prompt="choose cloud-init settings to modify"
local title="Cloud-init helper options"
local defaultitem=
local menu_choice=
local _checkbox="ci_user_pw_root_lock ci_user_pw_user_lock"
f_dialog_default_fetch defaultitem
# read global default vars
readconf cloud-init.conf
[ -z "${ci_password_salt}" ] && ci_password_salt="${default_ci_password_salt}"
[ -z "${ci_user_pw_root_lock}" ] && ci_user_pw_root_lock="${default_ci_user_pw_root_lock}"
[ -z "${ci_user_pw_user_lock}" ] && ci_user_pw_user_lock="${default_ci_user_pw_user_lock}"
[ -z "${ci_user_pw_user}" ] && ci_user_pw_user="${default_ci_user_pw_user}"
[ -z "${ci_user_pw_root}" ] && ci_user_pw_root="${default_ci_user_pw_root}"
[ -z "${ci_user_add}" ] && ci_user_add="${default_ci_user_add}"
[ -z "${ci_interface}" ] && ci_interface="${default_ci_interface}"
[ -z "${ci_interface_mtu}" ] && ci_interface_mtu="${default_ci_interface_mtu}"
[ -z "${ci_ip4_addr}" ] && ci_ip4_addr="${default_ci_ip4_addr}"
[ -z "${ci_gw4}" ] && ci_gw4="${default_ci_gw4}"
[ -z "${ci_nameserver_address}" ] && ci_nameserver_address="${default_ci_nameserver_address}"
[ -z "${ci_nameserver_search}" ] && ci_nameserver_search="${default_ci_nameserver_search}"
[ -z "${ci_adjust_inteface_helper}" ] && ci_adjust_inteface_helper="${default_ci_adjust_inteface_helper}"
[ -z "${ci_jname}" ] && ci_jname="${jname}"
[ -z "${ci_fqdn}" ] && ci_fqdn="${host_hostname}"
case "${ci_ip4_addr}" in
[Dd][Hh][Cc][Pp])
ci_ip4_addr=$( dhcpd )
;;
esac
case "${ci_gw4}" in
[Aa][Uu][Tt][Oo])
iptype ${ci_ip4_addr}
case $? in
1)
_ip1=${IWM%.*.*.*}
_ip2=${IWM%.*.*}; _ip2=${_ip2#*.}
_ip3=${IWM#*.*.}; _ip3=${_ip3%.*}
_ip4=${IWM#*.*.*.}
ci_gw4="${_ip1}.${_ip2}.${_ip3}.1"
;;
*)
;;
esac
;;
*)
;;
esac
local menu_list=""
if [ -z "${ci_user_pw_user}" -o "${ci_user_pw_user}" = '*' ]; then
ci_user_pw_user_mark='*locked*'
else
ci_user_pw_user_mark='*specified*'
fi
if [ -z "${ci_user_pw_root}" -o "${ci_user_pw_root}" = '*' ]; then
ci_user_pw_root_mark='*locked*'
else
ci_user_pw_root_mark='*specified*'
fi
menu_list="${menu_list} '${item_let} ci_jname' '[${ci_jname}]' 'Default: ${jname}'"
inc_menu_index item_let
menu_list="${menu_list} '${item_let} ci_fqdn' '[${ci_fqdn}]' 'Default: ${host_hostname}'"
inc_menu_index item_let
menu_list="${menu_list} '${item_let} ci_user_add' '[${ci_user_add}]' 'Default: ${default_ci_user_add}'"
inc_menu_index item_let
menu_list="${menu_list} '${item_let} ci_ip4_addr' '[${ci_ip4_addr}]' 'Default: ${default_ci_ip4_addr}'"
inc_menu_index item_let
menu_list="${menu_list} '${item_let} ci_gw4' '[${ci_gw4}]' 'Default: ${default_ci_gw4}'"
inc_menu_index item_let
menu_list="${menu_list} '${item_let} ci_nameserver_address' '[${ci_nameserver_address}]' 'Default: ${default_ci_nameserver_address}'"
inc_menu_index item_let
menu_list="${menu_list} '${item_let} ci_nameserver_search' '[${ci_nameserver_search}]' 'Default: ${default_ci_nameserver_search}'"
inc_menu_index item_let
menu_list="${menu_list} '${item_let} ci_user_pw_user' '[${ci_user_pw_user_mark}]' 'Default: ${default_ci_user_pw_user}'"
inc_menu_index item_let
menu_list="${menu_list} '${item_let} ci_user_pw_root' '[${ci_user_pw_root_mark}]' 'Default: ${default_ci_user_pw_root}'"
inc_menu_index item_let
menu_list="${menu_list} '${item_let} ci_interface_mtu' '[${ci_interface_mtu}]' 'Default: ${default_ci_interface_mtu}'"
inc_menu_index item_let
menu_list="${menu_list} '-' '-' ''"
for i in ${ci_user_add}; do
inc_menu_index item_let
eval _home="\$ci_user_home_${i}"
menu_list="${menu_list} '${item_let} ci_user_home_${i}' '[${_home}]' 'user home'"
inc_menu_index item_let
eval _pubkey="\$ci_user_pubkey_${i}"
_pubkey_len=$( strlen "${_pubkey}" )
if [ ${_pubkey_len} -gt 30 ]; then
_pubkey=$( substr --pos=0 --len=30 --str="${_pubkey}" )
_pubkey="${_pubkey} ..."
fi
menu_list="${menu_list} '${item_let} ci_user_pubkey_${i}' '[${_pubkey}]' 'user pubkey'"
inc_menu_index item_let
done
menu_list="${menu_list} 'Save' 'Save changes and quit' 'Save!'"
cbsd_menubox
retval=$?
f_dialog_data_sanitize menu_choice
f_dialog_menutag_store "${menu_choice}"
f_dialog_default_store "${menu_choice}"
iptype ${ci_ip4_addr}
_ret=$?
case ${_ret} in
1)
ip4_addr="${IWM}"
;;
*)
ip4_addr="${ci_ip4_addr}"
;;
esac
return ${retval}
}
# check $1 as valid ssh pubkey
# return 0 if valid
# return 1 when invald
# if ! is_valid_ssh_key "TEST"; then
# echo "bad key"
# fi
is_valid_ssh_key()
{
local _pos _keystart
strpos --str="${1}" --search=" "
_pos=$?
[ ${_pos} -eq 0 ] && return 1
_keystart=$( substr --pos=0 --len=${_pos} --str="${1}" )
case "${_keystart}" in
ssh-rsa*|ssh-ed25519*|ecdsa*|ssh-dsa*)
;;
*)
return 1
;;
esac
return 0
}
# Submenu for get_construct_cloud_init
get_construct_cloud_init_options()
{
local mychoice index
local old_defaultitem="${mtag}"
local _defaults _pos _keystart= _keytest
local _ci_gw4_mod=0 _ci_ip4_addr_mod=0
local _i1 _i2 _i3 _i4 _g1 _g2 _g3 _g4 _ip4_addr_with_mask
while [ 1 ]; do
get_construct_cloud_init_menu || break
index=${mtag%% *}
mychoice=${mtag##* }
case "${mychoice}" in
-)
continue
;;
Save)
break
;;
ci_jname)
title=" ci_jname "
prompt=" adjust short host name "
eval defaultitem="\$${mychoice}"
cbsd_inputbox_simple && ci_jname="${mtag}"
;;
ci_fqdn)
title=" ci_fqdn "
prompt=" adjust host FQDN "
eval defaultitem="\$${mychoice}"
cbsd_inputbox_simple && ci_fqdn="${mtag}"
;;
ci_gw4)
title=" ${mychoice} "
prompt=" adjust ${mychoice} "
#eval _defaults="\$default_${mychoice}"
eval defaultitem="\$${mychoice}"
cbsd_inputbox_simple && eval ${mychoice}="${mtag}"
_ci_gw4_mod=1 # trigger to re-check IP
;;
ci_user_add|ci_nameserver_address|ci_nameserver_search|ci_interface_mtu)
title=" ${mychoice} "
prompt=" adjust ${mychoice} "
#eval _defaults="\$default_${mychoice}"
eval defaultitem="\$${mychoice}"
cbsd_inputbox_simple && eval ${mychoice}="${mtag}"
;;
ci_ip4_addr)
title=" ${mychoice} "
prompt=" adjust ${mychoice} "
eval defaultitem="\$${mychoice}"
ip4_addr="${defaultitem}"
get_construct_ip4_addr && eval ${mychoice}="${ip4_addr}"
_ci_ip4_addr_mod=1 # trigger to re-check GW
# assume new GW4 when ci_gw4 not in ci_ip4_addr network (todo: mask/prefix)
if [ ${_ci_gw4_mod} -eq 0 ]; then
# GW in network?
strpos --str="${ci_ip4_addr}" --search="/"
if [ $? -ne 0 ]; then
_ip4_addr_with_mask="${ci_ip4_addr}"
else
_ip4_addr_with_mask="${ci_ip4_addr}/24" # /24 prefix by default
fi
eval $( ${miscdir}/sipcalc ${_ip4_addr_with_mask} )
[ -z "${_usable_range_start}" ] && err 1 "${N1_COLOR}${CBSD_APP}: unable to determine usable range start: ${_ip4_addr_with_mask}${N0_COLOR}"
sqllistdelimer="."
sqllist "${_usable_range_start}" _i1 _i2 _i3 _i4
sqllist "${ci_gw4}" _g1 _g2 _g3 _g4
if [ "${_i}.${_i2}.${_i3}" != "${_g}.${_g2}.${_g3}" ]; then
# assume new GW4
ci_gw4="${_i1}.${_i2}.${_i3}.${_i4}"
fi
fi
;;
ci_user_pubkey_*)
title=" ${mychoice} "
prompt=" adjust ${mychoice} (ctrl+u to erase)\n enter ssh key or path to authorized_keys\n use .ssh/authorized_keys for default node key"
eval defaultitem="\$${mychoice}"
cbsd_inputbox_simple
if [ $? -eq 0 ]; then
if [ -r "${workdir}/${mtag}" ]; then
_keytest=$( ${GREP_CMD} -v '#' ${workdir}/${mtag} | ${GREP_CMD} . | ${HEAD_CMD} -n1 )
if ! is_valid_ssh_key "${_keytest}"; then
f_dialog_msgbox "invalid key. valid key: ssh-rsa,ssh-ed25519,ecdsa-*,ssh-dsa"
continue
fi
eval ${mychoice}="\"${mtag}\""
elif [ -r "${mtag}" ]; then
_keytest=$( ${GREP_CMD} -v '#' ${mtag} | ${GREP_CMD} . | ${HEAD_CMD} -n1 )
if ! is_valid_ssh_key "${_keytest}"; then
f_dialog_msgbox "invalid key. valid key: ssh-rsa,ssh-ed25519,ecdsa-*,ssh-dsa"
continue
fi
eval ${mychoice}="\"${mtag}\""
else
if ! is_valid_ssh_key "${mtag}"; then
f_dialog_msgbox "invalid key. valid key: ssh-rsa,ssh-ed25519,ecdsa-*,ssh-dsa"
continue
fi
eval ${mychoice}="\"${mtag}\""
fi
fi
;;
ci_user_home_*|ci_user_gecos_*|ci_user_pubkey_*)
title=" ${mychoice} "
prompt=" adjust ${mychoice} (ctrl+u to erase) "
#eval _defaults="\$default_${mychoice}"
eval defaultitem="\$${mychoice}"
cbsd_inputbox_simple && eval ${mychoice}="\"${mtag}\""
;;
ci_user_pw_user)
if get_password; then
# crypt password problem in some cases: need for r&d https://cloudinit.readthedocs.io/en/latest/topics/modules.html#set-passwords
case "${vm_os_type}" in
freebsd)
ci_user_pw_user=$( ${miscdir}/pwcrypt "${mtag}" )
if [ $? -ne 0 ]; then
unset ci_user_pw_user
fi
;;
*)
ci_user_pw_user="${mtag}"
;;
esac
fi
;;
ci_user_pw_root)
if get_password; then
# crypt password problem in some cases: need for r&d https://cloudinit.readthedocs.io/en/latest/topics/modules.html#set-passwords
case "${vm_os_type}" in
freebsd)
ci_user_pw_root=$( ${miscdir}/pwcrypt "${mtag}" )
if [ $? -ne 0 ]; then
unset ci_user_pw_root
fi
;;
*)
ci_user_pw_root="${mtag}"
;;
esac
fi
;;
*)
invert_checkbox ${mychoice}
continue
;;
esac
done
[ -n "${ci_jname}" ] && cloud_init_options="[configured]"
f_dialog_default_store "${old_defaultitem}"
}
# virtual form for exit behavior
get_construct_exit_behavior_menu()
{
local _input _res item_let=A
local title="Exit behavior"
local defaultitem=
local menu_choice=
f_dialog_default_fetch defaultitem
[ -z "${on_poweroff}" ] && on_poweroff="destroy"
[ -z "${on_reboot}" ] && on_reboot="restart"
[ -z "${on_crash}" ] && on_crash="destroy"
local menu_list=""
menu_list="${menu_list} '${item_let} on_poweroff' '[${on_poweroff}]' 'Action to take when the guest requests a poweroff'"
inc_menu_index item_let
menu_list="${menu_list} '${item_let} on_reboot' '[${on_reboot}]' 'Action to take when the guest requests a reboot'"
inc_menu_index item_let
menu_list="${menu_list} '${item_let} on_crash' '[${on_crash}]' 'Action to take when the guest crashes'"
menu_list="${menu_list} 'Save' 'Save changes and quit' 'Save!'"
cbsd_menubox
retval=$?
f_dialog_data_sanitize menu_choice
f_dialog_menutag_store "$menu_choice"
f_dialog_default_store "$menu_choice"
return ${retval}
}
# virtual form for exit behavior
# $1 - variable to set, e.g: on_poweroff, on_reboot, on_crash
get_exit_behavior()
{
local _input _res
local _action="${1}"
[ -z "${_action}" ] && return 1
local title="Exit behaviour for ${_action}"
local defaultitem=
eval defaultitem="\$${_action}"
[ -z "${defaultitem}" ] && defaultitem="destroy"
local menu_list="
'destroy' 'destroy' 'The domain will be terminated completely and all resources released'
'restart' 'restart' 'The domain will be terminated and then restarted with the same configuration'
" # END-QUOTE
cbsd_menubox
retval=$?
case ${retval} in
${DIALOG_OK})
[ -n "${mtag}" ] && export ${_action}="${mtag}"
;;
*)
;;
esac
return ${retval}
}
# virtual form for exit behavior
get_construct_exit_behavior()
{
local mychoice index
local old_defaultitem="${mtag}"
while [ 1 ]; do
get_construct_exit_behavior_menu || break
index=${mtag%% *}
mychoice=${mtag##* }
case "${mychoice}" in
"-")
continue
;;
"Save")
break
;;
on_poweroff|on_reboot|on_crash)
get_exit_behavior ${mychoice}
;;
esac
done
f_dialog_default_store "${old_defaultitem}"
}
# virtual form for $vm_guestfs
get_construct_vm_guestfs()
{
local _input _res
local title="${GET_GUESTFS_MSG}"
local defaultitem="${vm_guestfs}"
local menu_list="
'zfs' 'zfs' 'ZFS filesystem'
'ufs' 'ufs' 'UFS filesystem'
" # END-QUOTE
cbsd_menubox
retval=$?
case $retval in
${DIALOG_OK})
[ -n "${mtag}" ] && vm_guestfs="${mtag}"
;;
*)
;;
esac
return ${retval}
}
# virtual form for $vm_boot
get_construct_vm_boot()
{
local _res
local vm_boot_data="${ftmpdir}/vm_boot.$$"
bootmgmt selected=${vm_boot} controlmaster=${vm_boot_data}
retval=$?
case $retval in
${DIALOG_OK})
. ${vm_boot_data}
;;
*)
;;
esac
${RM_CMD} -f ${vm_boot_data}
return ${retval}
}
# virtual form for vm_package
# update vm_\* values according to $vm_package data
# if $1 - "force", all variables will be overwrited
# otherwise, assign variables only vm_\* is empty
# $vm_package variables must be set
apply_vm_package()
{
[ -z "${vm_package}" ] && return 0
[ "${1}" = "force" ] && unset vm_cpus vm_ram imgsize
[ -z "${vm_cpus}" ] && vm_cpus=$( cbsdsqlro local SELECT pkg_vm_cpus FROM vmpackages WHERE name=\"${vm_package}\" )
[ -z "${vm_ram}" ] && vm_ram=$( cbsdsqlro local SELECT pkg_vm_ram FROM vmpackages WHERE name=\"${vm_package}\" )
[ -z "${imgsize}" ] && imgsize=$( cbsdsqlro local SELECT pkg_vm_disk FROM vmpackages WHERE name=\"${vm_package}\" )
return 0
}
# virtual form for vm_package
get_construct_vm_package()
{
local _input _res
local title="${GET_VM_PACKAGE_MSG}"
local defaultitem="${vm_package}"
local sqldelimer=" "
local menu_list=$( cbsdsqlro local SELECT name,pkg_vm_cpus,pkg_vm_ram,pkg_vm_disk FROM vmpackages | while read name pkg_vm_cpus pkg_vm_ram pkg_vm_disk; do
echo "'${name}' '[${mark}] name=${name} CPU=${pkg_vm_cpus} RAM=${pkg_vm_ram} DISK=${pkg_vm_disk}' 'description'"
done ) || err 1 "${N1_COLOR}Error while create packages map${N0_COLOR}"
cbsd_menubox
retval=$?
case $retval in
${DIALOG_OK})
[ -n "${mtag}" ] && vm_package="${mtag}"
apply_vm_package force
;;
*)
;;
esac
return ${retval}
}
# virtual form for $imgtype
get_construct_imgtype()
{
local _input _res
local title="${GET_IMGTYPE_MSG}"
local defaultitem="${imgtype}"
local menu_list="
'zvol' 'ZFS volume' 'Use ZVOL. This is a faster bakend than md'
'md' 'use mdconfig(8) as backend' 'Use MD if your want to have guest FS-in-file on the hoster FS'
'raw' 'RAW disk, /dev/XXX' 'RAW/Direct attached disk /dev/devices'
" # END-QUOTE
cbsd_menubox
retval=$?
case ${retval} in
${DIALOG_OK})
[ -n "${mtag}" ] && imgtype="${mtag}"
;;
*)
;;
esac
return ${retval}
}
# virtual form for $vm_os_type
# if $1 = "value" apply value without dialog
get_construct_vm_os_type()
{
local _input
local defaultitem="${vm_os_type}"
local _vm_os_type_old="${vm_os_type}"
if [ -n "${1}" ]; then
vm_os_type="${1}"
retval=${DIALOG_OK}
else
unset menu_list
# load menu_list from external source by emulator opportunity
if [ -f "${sharedir}/emulators/ostype_${emulator}.subr" ]; then
. ${sharedir}/emulators/ostype_${emulator}.subr
else
f_dialog_msgbox "No such menu_list for emulator ${emulator}:\n${sharedir}/emulators/ostype_${emulator}.subr"
return 0
fi
cbsd_menubox
retval=$?
fi
case ${retval} in
${DIALOG_OK})
[ "${_vm_os_type_old}" = "${mtag}" ] && return 0 # not changed
${RM_CMD} -f ${tmpdir}/get_construct_vm_os_profile.menu
[ -n "${mtag}" ] && vm_os_type="${mtag}"
unset vm_os_profile jname imgsize vm_ram vm_cpus cd_boot_firmware hdd_boot_firmware ci_interface
unset ci_interface_mtu
apply_vm_package
# set default
[ -z "${cd_boot_firmware}" ] && cd_boot_firmware="bhyve"
[ -z "${hdd_boot_firmware}" ] && hdd_boot_firmware="${cd_boot_firmware}"
[ -z "${ci_interface_mtu}" ] && ci_interface_mtu="${default_ci_interface_mtu}"
;;
*)
;;
esac
return ${retval}
}
# virtual form for vm_iso_path
get_construct_vm_iso_path()
{
local menu_list=
local vm_res
local i
local title=" Select ISO "
local prompt="${GET_VM_ISOPATH_MSG}"
local iso_path
vm_res=$( cbsdsqlro storage_media SELECT name FROM media WHERE type=\"iso\" )
[ -z "${vm_res}" ] && return 0
for i in ${vm_res}; do
menu_list="${menu_list} '${i}' '${i}' '${i}'"
done
menu_list="${menu_list} 'Detach' 'Detach' 'Detach any CD ISO'"
defaultitem="${vm_iso_path}"
mtag=
cbsd_menubox
case $retval in
${DIALOG_OK})
if [ -n "${mtag}" ]; then
case "${mtag}" in
Detach)
cbsdsqlrw storage_media "UPDATE media SET jname='-' WHERE jname=\"${jname}\" AND type=\"iso\""
register_iso_as=
vm_iso_path=
alt_iso=
;;
*)
register_iso_as="${mtag}"
vm_iso_path="${mtag}"
alt_iso="${mtag}"
iso_path=$( cbsdsqlro storage_media SELECT path FROM media WHERE type=\"iso\" AND name=\"${mtag}\" )
# remove old disk if exist
cbsdsqlrw storage_media "UPDATE media SET jname='-' WHERE jname=\"${jname}\" AND type=\"iso\""
echo "media mode=attach type=iso name=${mtag} path=${iso_path} jname=${jname}"
media mode=attach type=iso name=${mtag} path=${iso_path} jname=${jname}
;;
esac
fi
;;
*)
;;
esac
return ${retval}
}
# virtual form for cpu topology
get_construct_vm_cpu_topology()
{
local menu_list=
local vm_res
local i
local _query _sockets _cores _threads _vm_cores
local title=" Select CPU topology "
local prompt="${GET_VM_CPU_TOPOLOGY_MSG}"
local iso_path
vm_res=$( cbsdsqlro local SELECT name FROM vm_cpu_topology | ${XARGS_CMD} )
[ -z "${vm_res}" ] && return 0
. ${strings}
. ${distdir}/virtual.subr
for i in ${vm_res}; do
_query=$( cbsdsqlro local SELECT sockets,cores,threads FROM vm_cpu_topology WHERE name=\"${i}\" )
[ -z "${_query}" ] && return 0
OIFS="${IFS}"
IFS="|"
sqllist "${_query}" _sockets _cores _threads
IFS="${OIFS}"
_vm_cores=$( get_vm_cores_by_topology ${_sockets} ${_cores} ${_threads} )
local topology_${i}_cpus="${_vm_cores}"
menu_list="${menu_list} '${i}' 'sockets=${_sockets},cores=${_cores},threads=${_threads}' 'sockets=${_sockets},cores=${_cores},threads=${_threads}, Core: ${_vm_cores}'"
done
menu_list="${menu_list}"
defaultitem="${vm_cpu_topology}"
mtag=
cbsd_menubox
case ${retval} in
${DIALOG_OK})
if [ -n "${mtag}" ]; then
vm_cpu_topology="${mtag}"
eval vm_cpus="\$topology_${mtag}_cpus"
fi
;;
*)
;;
esac
return ${retval}
}
# virtual form for profiles update
# try to update profiles from GitHub via Internet
get_profiles_update()
{
local _git
local _logfile
_git=$( which git )
if [ -z "${_git}" ]; then
local msg_ok="It's a pity"
f_dialog_msgbox "No git in system. Please install git first: pkg install -y devel/git"
return 0