-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings-tui.subr
1068 lines (904 loc) · 26.2 KB
/
settings-tui.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
# Custom GENERIC TUI function
if [ ! "$_CBSD_SETTINGS_TUI_SUBR" ]; then
_CBSD_SETTINGS_TUI_SUBR=1
###
#required for . ${dialog}
TMPFILE="${ftmpdir}/inputbox.$$"
# load emulator-specific function
[ -n "${emulator}" ] && . ${distdir}/settings-tui-${emulator}.subr
astart_msg="1,yes - Automatically start Jail when system boot"
hidden_msg="Invisible environment flag. 1 - hide environment for frontend"
host_hostname_msg="Jail Fully Qualified Domain Name"
interface_msg="Auto create and auto remove IP on selected NICs. 0 for disable, auto - for auto detect"
jname_msg="Jail name. Name must begin with a letter / a-z / and not have any special symbols: -,.=%"
protected_msg="Prevent modification or deletion of a environment. 1 - protect/lock"
runasap_msg="Start jail ASAP upon creation"
stop_timeout_msg="The maximum amount of time to wait for a jailed processes to exit after sending them a SIGTERM signal"
zfs_snapsrc_msg="Use this ZFS snapshot as source for jail data, e.g zmirror/jails/jail1@init"
mnt_start_msg="External script for mount env data, 0 - disable"
mnt_stop_msg="External script for unmount env data, 0 - disable"
uuid_msg="Use UUID in form: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\n'0' - auto"
GET_ALLOW_READ_MSGBUF_MSG="Select READ_MSGBUF behaviour"
GET_ALLOW_VMM_MSG="Select allow.vmm behaviour"
GET_JAILPROFILE_MSG="Profile for jcreate"
GET_NODENAME_MSG="Change nodename. Warning: this operation will recreate the ssh keys in $workdir/.ssh dir"
# show [] * for empty $1 values
# for Option list from -tui
curval()
{
local T
[ -z "${1}" ] && return 0
eval T="\$$1"
if [ -n "${T}" ]; then
printf "${T}"
else
printf " "
fi
return 0
}
# Increment index for menu counter
# required cbsd as shell for is_number
inc_menu_index()
{
local T
[ -z "${1}" ] && return 0
eval T="\$$1"
if ! is_number ${T}; then
T=$(( T + 1 ))
else
T=$( echo ${T} | ${TR_CMD} '[ABCDEFGHIJKLMNOPQRSTUVWXYZ]' '[BCDEFGHIJKLMNOPQRSTUVWXYZA]' )
fi
eval "${1}=${T}"
return 0
}
# generic form for $srvlist
get_construct_add_user()
{
adduser="${ftmpdir}/adduser.$$"
adduser-tui controlmaster="${adduser}"
[ ! -s "${adduser}" ] && adduser=
}
# generic form for $jname
# if $1 = "nosearch" than skip for searching/testing of available jname
get_construct_jname()
{
local _ok _message _input _retval _oldjname
_oldjname="${jname}"
f_dialog_title " jname "
if [ "$1" = "nosearch" ]; then
freejname=${jname}
else
if [ -n "${jname}" ]; then
freejname="${jname}"
else
freejname=$( freejname default_jailname=${default_jailname} )
fi
fi
_ok=0
while [ ${_ok} -ne 1 ]; do
f_dialog_input _input "${jname_msg}" "${freejname}" \
"${_message}" || return $?
validate_jname "${_input}"
case $? in
0)
jstatus jname="${_input}" >/dev/null 2>&1
if [ $? -ne 0 ]; then
_message="ERROR: Jail ${_input} already exist"
else
_ok=1
fi
;;
*)
_message="ERROR: Bad name. Choose other one"
;;
esac
done
[ -n "${_input}" ] && jname="${_input}"
# reload some dynamic variables depended from jname
[ -z "${jname}" ] && return 0
if [ "${_oldjname}" != "${jname}" ]; then
#merge_apply_profiles ${etcdir}/defaults/${zero_profile} ${global_profile_file}
host_hostname="${jname}.${default_domain}"
path="${jaildir}/${jname}"
data="${jaildatadir}/${jname}-${jaildatapref}"
mount_fstab_old="${jailfstabdir}/${jailfstabpref}${jname}"
mount_fstab="${jailfstabdir}/${jname}/fstab"
rcconf="${jailrcconfdir}/rc.conf_${jname}"
fi
}
# generic form for $host_hostname
get_construct_host_hostname()
{
local _input _defdomain
f_dialog_title " host_hostname "
if [ -n "${host_hostname}" ]; then
_defdomain="${host_hostname}"
else
if [ -n "${default_domain}" ]; then
if [ -z "${jname}" ]; then
_defdomain="${jname}.${default_domain}"
else
_defdomain="jail1.${default_domain}"
fi
else
_defdomain="my.domain"
fi
fi
f_dialog_input _input "${host_hostname_msg}" "${_defdomain}" \
"${_message}" || return $?
[ -n "${_input}" ] && host_hostname="${_input}"
}
# generic form for $ip4_addr
get_construct_ip4_addr()
{
local _ok=0 _input _retval _i _j _existing_ipjail _existing_ip _myip
local msg_yes msg_no IFS _jname _ips _mod=0 _tmp_input=
. ${distdir}/vnet.subr # is_nic_exist
f_dialog_title " ip_addr "
while [ ${_ok} -ne 1 ]; do
if [ -z "${ip4_addr}" ]; then
ip4_addr=$( dhcpd 2>/dev/null )
if [ $? -eq 2 ]; then
ip4_addr="DHCP"
local msg_ok="It's a pity"
f_dialog_msgbox "No free IP address for DHCP in nodeippool"
return 0
fi
fi
f_dialog_input _input "${ip4_addr_desc}" "${ip4_addr}" "IP4 or IP6 Address"
_retval=$?
[ ${_retval} -ne 0 ] && return 0
#check ip in two phases:
# 1) via sqlite database for other's jails ips
# 2) for ip in LAN
# Yes, we wrote in the example that the valid separator between NIC and address
# is '#' and not '|' as experienced jail.conf users can get used to.
# But we will still try to convert the input with '|' to correct form
strpos --str="${_input}" --search="|"
_pos=$?
[ ${_pos} -ne 0 ] && _input=$( echo ${_input} | ${TR_CMD} '|' '#' )
msg_yes="Ok"
msg_no="Not Ok"
_existing_ipjail=""
_existing_ip=""
_myip=""
IFS=","
for _i in ${_input}; do
case "${_i}" in
[Dd][Hh][Cc][Pp])
f_dialog_info "Internal DHCPv4: please wait..."
_i=$( dhcpd 2>/dev/null )
if [ $? -eq 2 ]; then
local msg_ok="It's a pity"
f_dialog_msgbox "No free IP address for DHCP in nodeippool"
return 0
fi
_mod=1 # modify real input by _tmp_input string ( with DHCP-obtained IP address )
;;
[Dd][Hh][Cc][Pp][vV]6)
f_dialog_info "Internal DHCPv6: please wait..."
_i=$( dhcpdv6 2>/dev/null )
if [ $? -eq 2 ]; then
local msg_ok="It's a pity"
f_dialog_msgbox "No free IP address for DHCP in nodeippool"
return 0
fi
_mod=1 # modify real input by _tmp_input string ( with DHCP-obtained IP address )
;;
esac
if [ -z "${_tmp_input}" ]; then
_tmp_input="${_i}"
else
_tmp_input="${_tmp_input},${_i}"
fi
ipwmask ${_i}
[ -z "${IWM}" -o "${_i}" = "0" ] && continue
iptype ${IWM}
_ret=$?
case ${_ret} in
0)
# unknown ip
;;
1|2)
if [ ${_ret} -eq 2 ]; then
# normalize IPv6 to compressed form
eval $( ${miscdir}/sipcalc ${_i} )
IWM="${_compressed_ipv6_address}"
fi
# IPv4 or IPv6
if [ -n "${V_INTERFACE}" -a -n "${V_IP}" ]; then
if ! is_nic_exist -n ${V_INTERFACE}; then
local msg_ok="I was wrong"
f_dialog_msgbox "Interface ${V_INTERFACE} not exist!"
return 0
fi
_myip="${_myip} ${V_IP}"
else
_myip="${_myip} ${IWM}"
fi
;;
esac
done
[ ${_mod} -eq 1 ] && _input="${_tmp_input}"
# check for other jail
IFS="|"
_i=0
eval $( cbsdsqlro local SELECT jname,ip4_addr FROM jails WHERE ip4_addr!="0" 2>/dev/null | while read _jname _ips; do
echo jname${_i}=\"$_jname\"
echo ips${_i}=\"${_ips}\"
_i=$(( _i + 1 ))
done )
unset IFS
_ok=1
for _i in $( ${SEQ_CMD} 0 255 ); do
unset _existing_ipjail _existing_ip
eval _jname="\$jname$_i"
[ -z "${_jname}" ] && break
# skip for myself
[ "${_jname}" = "${jname}" ] && continue
eval _existing_ipjail="\$ips$_i"
[ -z "${_existing_ipjail}" ] && break
_existing_ipjail=$( echo ${_existing_ipjail} | ${TR_CMD} "," " " )
for _x in ${_existing_ipjail}; do
case "${_x}" in
[Dd][Hh][Cc][Pp]|[Hh][Cc][Pp][Vv]6)
continue
;;
esac
ipwmask ${_x}
[ -z "${IWM}" ] && continue
iptype ${IWM}
[ $? -eq 1 ] && _existing_ip="${_existing_ip} ${IWM}"
done
for _x in ${_existing_ip}; do
for _j in ${_myip}; do
[ "${_x}" = "${_j}" ] && _ok=0 && break
done
[ ${_ok} -eq 0 ] && break
done
if [ ${_ok} -eq 0 ]; then
f_dialog_noyes "${_j} already assigned to jail: ${_jname}.\nIf you believe that it's ok, choose 'ok' to continue or 'not ok' for another IP address" "WARNING"
if [ $? -eq 1 ]; then
_ok=0
break
fi
_ok=2
break
fi
done # check for local jail end
[ ${_ok} -eq 0 ] && continue # if not ok from previous stage - repeat
[ ${_ok} -eq 2 ] && _ok=1 && continue
_ok=1
local _ipexist=
# check for ip existance in LAN
for _i in ${_myip}; do
IFS=" "
f_dialog_info "Probing for ${_i} availability. Please wait..."
unset IFS
checkip ip=${_i} check=1 2>/dev/null
if [ $? -eq 2 ]; then
_ok=0
_ipexist="${_ipexist} ${_i}"
fi
done
if [ ${_ok} -eq 0 ]; then
f_dialog_noyes "Seems like ${_ipexist} address already used on several devices on the LAN\nYou can found MAC address by \"arp -an\" command.\n If you believe that it's ok, choose 'ok' to continue or 'not ok' for another IP address" "WARNING"
[ $? -eq 0 ] && _ok=1
fi
done
ip4_addr="${_input}"
return 0
}
# generic form for $interface
# -b 1 - add "bridge" device
# -c choose_default item - defaultitem set to this value
# -s "skip this network list"
# -d 1 - add "disable" choice
# -m 1 - add "manual" choice
# -v 1 - add "vale" device
# -n 1 - add VPC choice
get_construct_interface()
{
local _input _def_iface _mynic _mydesc _mystatus
local defaultitem _skipnics="" _disable=0 _choose
local _manual=0 _vale=0 _bridge=0 _vpc=0
local VPC_ROOT_DIR="${dbdir}/vpc"
local title=" interface "
local prompt="${interface_msg}"
hline=
local menu_list="
'EXIT' 'EXIT' 'Exit'
" # END-QUOTE
while getopts "b:c:s:d:m:n:v:" opt; do
case "${opt}" in
b) _bridge="${OPTARG}" ;;
c) _choose="${OPTARG}" ;;
s) _skipnics="${OPTARG}" ;;
d) _disable="${OPTARG}" ;;
m) _manual="${OPTARG}" ;;
n) _vpc="${OPTARG}" ;;
o) _optional="${OPTARG}" ;;
v) _vale="${OPTARG}" ;;
esac
shift $(($OPTIND - 1))
done
menu_list="${menu_list} 'auto' 'auto' 'Recommended: determine nic for jail IP via route table.'"
if [ "${_manual}" = "1" ]; then
menu_list="${menu_list} 'manual' 'manual' 'Enter interface by hand.'"
fi
if [ ${_disable} -eq 1 ]; then
menu_list="${menu_list} 'disable' 'disable' 'Do not create/remove IP automatically: IP of jail must be already initialized or for vnet mode'"
fi
menu_list="${menu_list} '-' '-' ''"
local OLDIFS="${IFS}"
local IFS=":"
local _num=1
eval $( ${miscdir}/nics-list -da -s "${_skipnics}" | while read _nicname _nicdesc _nicstatus; do
echo "nic${_num}_name=\"${_nicname}\""
echo "nic${_num}_desc=\"${_nicdesc}\""
echo "nic${_num}_status=\"${_nicstatus}\""
_num=$(( _num + 1 ))
echo "_num=\"${_num}\""
done )
if [ "${_vale}" = "1" ]; then
eval $( cbsdsqlro local SELECT name FROM vale | while read name; do
echo "nic${_num}_name=\"cbsdvale_${name}\""
echo "nic${_num}_desc=\"VALE SWITCH: ${name}\""
echo "nic${_num}_status=\"UP\""
_num=$(( _num + 1 ))
echo "_num=\"${_num}\""
done )
# eval "nic${_num}_name='vale'"
# eval "nic${_num}_desc='very fast Virtual Local Ethernet using the netmap API'"
# eval "nic${_num}_status='UP'"
fi
if [ "${_bridge}" = "1" ]; then
#menu_list="${menu_list} '-' 'Existing bridges' 'Use existing bridges'"
eval $( ${miscdir}/nics-list -o "bridge" | while read _nicname; do
echo "nic${_num}_name=\"${_nicname}\""
echo "nic${_num}_status=\"initialized\""
_num=$(( _num + 1 ))
echo "_num=\"${_num}\""
done )
fi
if [ "${_vpc}" = "1" ]; then
if [ -d ${VPC_ROOT_DIR} ]; then
_list=$( ${LS_CMD} -1 ${VPC_ROOT_DIR} | ${SED_CMD} 's:.sqlite::g' | ${EGREP_CMD} -v "\-wal|\-shm" )
eval $( for i in ${_list}; do
echo "nic${_num}_name=\"vpc-${i}\""
echo "nic${_num}_desc=\"CBSD VPC: ${i}\""
echo "nic${_num}_status=\"UP\""
_num=$(( _num + 1 ))
echo "_num=\"${_num}\""
done )
fi
fi
IFS="${OLDIFS}"
if [ -n "${interface}" ]; then
case "${interface}" in
"0")
defaultitem="disable"
;;
*)
defaultitem="${interface}"
;;
esac
else
if [ -n "${_choose}" ]; then
defaultitem="${_choose}"
elif [ -n "${interface}" ]; then
defaultitem="${interface}"
else
interface="auto"
defaultitem="auto"
fi
fi
[ -n "${_choose}" ] && defaultitem="${_choose}"
for _num in $( ${SEQ_CMD} 1 9999 ); do
unset _mynic _mydesc _mystatus
eval _mynic="\$nic${_num}_name"
[ -z "${_mynic}" ] && break
eval _mydesc="\$nic${_num}_desc"
eval _mystatus="\$nic${_num}_status"
case "${_mynic%%[0-9]*}" in
tun|bridge|epair|tap|vlan)
_mydesc="Pseudo interface"
;;
lo)
_mydesc="Loopback interface"
;;
esac
[ -z "${_mydesc}" ] && _mydesc="Not available"
menu_list="${menu_list} '${_mynic}' '${_mynic} (${_mystatus} )' 'Description: ${_mydesc}'"
done
cbsd_menubox
retval=$?
case ${retval} in
${DIALOG_OK})
case "${mtag}" in
"-")
continue
;;
EXIT)
return 1
;;
disable)
interface="0"
;;
manual)
defaultitem="auto"
title=" interface "
prompt="Enter interface"
cbsd_inputbox_simple && interface="${mtag}"
;;
*)
[ -n "${mtag}" ] && interface="${mtag}"
;;
esac
;;
*)
;;
esac
return ${retval}
}
# generic form for $zfs_snapsrc
get_construct_zfs_snapsrc()
{
title=" zfs_snapsrc "
prompt="${zfs_snapsrc_msg}"
defaultitem="${zfs_snapsrc}"
if cbsd_inputbox_simple; then
if [ -n "${mtag}" ]; then
zfs_snapsrc="${mtag}"
else
unset zfs_snapsrc
fi
fi
}
# generic form for select password
# if $1 - can_empty than allow empty passowrd
get_password()
{
local prompt1="Enter New Password"
local prompt2="Re-enter Password"
local hline="Use alpha-numeric, punctuation, TAB or ENTER"
if [ "${1}" = "can_empty" ]; then
local can_empty=1
else
local can_empty=0
fi
f_dialog_title " Select Password "
local height1 width1
f_dialog_inputbox_size height1 width1 \
"$DIALOG_TITLE" \
"$DIALOG_BACKTITLE" \
"$prompt1" \
"" \
"$hline"
local height2 width2
f_dialog_inputbox_size height2 width2 \
"$DIALOG_TITLE" \
"$DIALOG_BACKTITLE" \
"$prompt2" \
"" \
"$hline"
#
# Loop until the user provides taint-free/valid input
#
local _password1 _password2
while :; do
_password1=$( $DIALOG \
--title "$DIALOG_TITLE" \
--backtitle "$DIALOG_BACKTITLE" \
--hline "$hline" \
--ok-label "$msg_ok" \
--cancel-label "$msg_cancel" \
--insecure \
--passwordbox "$prompt1" \
$height1 $width1 \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
) || return $?
# Return if user either pressed ESC or chose Cancel/No
debug= f_dialog_line_sanitize _password1
_password2=$( $DIALOG \
--title "$DIALOG_TITLE" \
--backtitle "$DIALOG_BACKTITLE" \
--hline "$hline" \
--ok-label "$msg_ok" \
--cancel-label "$msg_cancel" \
--insecure \
--passwordbox "$prompt2" \
$height2 $width2 \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
) || return $?
# Return if user either pressed ESC or chose Cancel/No
debug= f_dialog_line_sanitize _password2
if [ ${can_empty} -eq 0 ]; then
# Check for NULL entry
if ! [ "$_password1" -o "$_password2" ]; then
f_show_msg "Password is empty"
continue
fi
mtag=''
fi
# Check for password mismatch
if [ "$_password1" != "$_password2" ]; then
f_show_msg "Password do not match"
continue
fi
# Check for password mismatch
if [ "$_password1" = "0" ]; then
f_show_msg "0 is not allowed, reserved for empty password"
continue
fi
mtag="$_password1"
break
done
return ${DIALOG_OK}
}
# generic forms for yesno
# $1 - 1,0 - default values
get_construct_yesno()
{
local _default=1
msg_yes="no"
msg_no="yes"
[ -n "${1}" ] && _default="${1}"
if [ ${_default} -eq 0 ]; then
f_dialog_yesno "${msg}" "${hline}"
else
f_dialog_noyes "${msg}" "${hline}"
fi
return $?
}
# generic form for $profile
# if $1 not empty, just load $1 profile without dialogizing
get_construct_profile()
{
local _input _retval _search_profile="${emulator}-freebsd-" jail_profile _res _myprofiles="" _myfile
local _old_profile="${profile}" _all
local menu_list _menu_list_cache
local defaultitem="${profile}"
local title=" profile "
local prompt="${GET_JAILPROFILE_MSG}"
# use menu item cache
if [ -r ${tmpdir}/get_construct_profile.menu ]; then
#_menu_list_cache=$( ${CAT_CMD} ${tmpdir}/get_construct_profile.menu )
. ${tmpdir}/get_construct_profile.menu
else
f_dialog_info "scan and build menu entry..."
_menu_list_cache=
fi
if [ -z "${_menu_list_cache}" ]; then
# default must be first due to last dir with user settings must overwrite
_res=$( env NOCOLOR=1 show_profile_list show_jail=1 search_profile=${_search_profile} display=path header=0 )
for i in ${_res}; do
unset jail_profile
eval $( ${GREP_CMD} ^jail_profile= ${i} )
eval $( ${GREP_CMD} ^long_description= ${i} )
_mypath=$( echo ${i} | ${SED_CMD} s:^${workdir}/::g )
menu_list="${menu_list} '${jail_profile}' '${_mypath}' '${long_description}'"
#store filename
local file_${jail_profile}="${i}"
done
else
menu_list="${_menu_list_cache}"
_all="${_all_cache}"
fi
[ -z "${menu_list}" ] && unset jail_profile && return 0
# store menu item cache
${SYSRC_CMD} -qf ${tmpdir}/get_construct_profile.menu _menu_list_cache="${menu_list}" > /dev/null 2>&1
${SYSRC_CMD} -qf ${tmpdir}/get_construct_profile.menu _all_cache="${_all}" > /dev/null 2>&1
# unset for previous template package list
unset tpl_pkglist
if [ -z "${1}" ]; then
cbsd_menubox
case $retval in
${DIALOG_OK})
pkgnum=0
. ${distsharedir}/jail-arg
# unset old variables
for i in pkglist tpl_pkglist from_jail vm_profile profile runasap pkg_bootstrap vnet vimage default_jailname default_domain jname host_hostname vnet ${JARG}; do
unset ${i}
done
readconf ${zero_profile}
if [ -n "${mtag}" ]; then
profile="${mtag}"
else
profile="${_old_profile}"
fi
;;
*)
;;
esac
else
profile="${1}"
fi
if [ "${emulator}" = "jail" ]; then
if [ -r ${etcdir}/${emulator}-freebsd-${profile}.conf ]; then
_myfile="${etcdir}/${emulator}-freebsd-${profile}.conf"
elif [ -r ${etcdir}/defaults/${emulator}-freebsd-${profile}.conf ]; then
_myfile="${etcdir}/defaults/${emulator}-freebsd-${profile}.conf"
fi
fi
if [ -f "${_myfile}" ]; then
. ${_myfile}
global_profile_file="${_myfile}"
# reload some dynamic variables depended from jname
if [ -f ${etcdir}/${zero_profile} ]; then
merge_apply_profiles ${global_profile_file} ${etcdir}/${zero_profile}
merge_apply_profiles ${etcdir}/${zero_profile} ${_myfile}
else
merge_apply_profiles ${global_profile_file} ${etcdir}/defaults/${zero_profile}
merge_apply_profiles ${etcdir}/defaults/${zero_profile} ${_myfile}
fi
fi
# populate pkglist from tpl_pkglist if not empty
if [ -n "${tpl_pkglist}" ]; then
if [ -r "${tpl_pkglist}" ]; then
# its file
pkglist="${tpl_pkglist}"
else
pkglist="${ftmpdir}/tui.$$"
trap "${RM_CMD} -f ${pkglist}" HUP INT ABRT BUS TERM EXIT
for _i in ${tpl_pkglist}; do
echo ${_i} >> ${pkglist}
done
fi
fi
return ${retval}
}
# generic form for $nodename
get_construct_nodename()
{
title=" nodename "
prompt="${nodename_msg}"
defaultitem="${nodename}"
cbsd_inputbox_simple && nodename="${mtag}"
}
# generic part for generate .jconf
gen_jconf()
{
local TMPFILE="${ftmpdir}/${jname}.$$.jconf"
local rcconf="${jailrcconfdir}/rc.conf_${jname}"
local _emulator_letter
_emulator_letter=$( substr --pos=0 --len=1 --str=${emulator} )
# original jail area
${CAT_CMD} > ${TMPFILE} << EOF
# DO NOT EDIT THIS FILE. PLEASE USE INSTEAD:
# cbsd ${_emulator_letter}config jname=${jname}
relative_path="1";
jname="${jname}";
path="${path}";
data="${data}";
rcconf="${jailrcconfdir}/rc.conf_${jname}";
# FQDN for environment
host_hostname="${host_hostname}";
# default environment IP
ip4_addr="${ip4_addr}";
# start with system boot?
astart="${astart}";
# first NIC hardware address
nic_hwaddr="${nic_hwaddr}";
# create from ZFS snapshot?
zfs_snapsrc="${zfs_snapsrc}";
# run immediately upon creation
runasap="${runasap}";
EOF
[ -n "${interface}" ] && ${CAT_CMD} >> ${TMPFILE} <<EOF
# bind to interface
interface="${interface}";
EOF
# additional area
[ -n "${user_pw_root_crypt}" ] && ${CAT_CMD} >> ${TMPFILE} <<EOF
# root password
user_pw_root_crypt='${user_pw_root_crypt}';
EOF
[ -n "${user_pw_root}" ] && ${CAT_CMD} >> ${TMPFILE} <<EOF
# root password
user_pw_root='${user_pw_root}';
EOF
# rctl settings if set
. ${distsharedir}/rctl.conf
for i in ${RCTL} ${RCTL_EXTRA}; do
_val=
eval _val="\$rctl_${i}"
[ -n "${_val}" ] && ${CAT_CMD} >> ${TMPFILE} <<EOF
rctl_${i}="${_val}"
EOF
done
[ -n "${pkglist}" ] && echo "pkglist=\"${pkglist}\";" >> ${TMPFILE}
if [ -n "${srvlist}" -a -r "${srvlist}" ]; then
${CAT_CMD} ${srvlist} >> ${TMPFILE}
${RM_CMD} -f ${srvlist}
fi
if [ -n "${adduser}" -a -r "${adduser}" ]; then
${CAT_CMD} ${adduser} >> ${TMPFILE}
${RM_CMD} -f ${adduser}
fi
# end of additional area
# load make_${emulator_part} function
[ -r ${distdir}/settings-tui-${emulator} ] && . ${distdir}/settings-tui-${emulator}.subr
case "${emulator}" in
bhyve)
make_bhyve_part
getyesno "Do you want to create vm immediately?"
[ $? -eq 1 -o $? -eq 3 ] && err 0 "${N1_COLOR}You can make now: ${N2_COLOR}cbsd bcreate jconf=${TMPFILE}${N0_COLOR}"
bcreate jconf=${TMPFILE} delpkglist=${delpkglist} removejconf=${removejconf}
[ $? -ne 0 ] && err 0 "${N1_COLOR}Config file for jconf: ${N2_COLOR}${TMPFILE}${N0_COLOR}"
;;
virtualbox)
make_virtualbox_part
getyesno "Do you want to create vm immediately?"
[ $? -eq 1 -o $? -eq 3 ] && err 0 "${N1_COLOR}You can make now: ${N2_COLOR}cbsd vcreate jconf=${TMPFILE}${N0_COLOR}"
vcreate jconf=${TMPFILE} delpkglist=${delpkglist} removejconf=${removejconf}
[ $? -ne 0 ] && err 0 "${N1_COLOR}Config file for jconf: ${N2_COLOR}${TMPFILE}${N0_COLOR}"
;;
xen)
make_xen_part
getyesno "Do you want to create vm immediately?"
[ $? -eq 1 -o $? -eq 3 ] && err 0 "${N1_COLOR}You can make now: ${N2_COLOR}cbsd xcreate jconf=${TMPFILE}${N0_COLOR}"
xcreate jconf=${TMPFILE} delpkglist=${delpkglist} removejconf=${removejconf}
[ $? -ne 0 ] && err 0 "${N1_COLOR}Config file for jconf: ${N2_COLOR}${TMPFILE}${N0_COLOR}"
;;
jail)
make_jail_part
echo "emulator=\"${emulator}\"" >> ${TMPFILE}
getyesno "Do you want to create jail immediately?"
if [ $? -eq 1 -o $? -eq 3 ]; then
# unset trap ( e.g: rm -f for ${jailnic_temp_sql} )
trap "" HUP INT ABRT BUS TERM EXIT
err 0 "${N1_COLOR}You can make now: ${N2_COLOR}cbsd jcreate jconf=${TMPFILE}${N0_COLOR}"
fi
jcreate jconf=${TMPFILE} delpkglist=${delpkglist} removejconf=${removejconf}
[ $? -ne 0 ] && err 0 "${N1_COLOR}Config file for jconf: ${N2_COLOR}${TMPFILE}${N0_COLOR}"
;;
qemu-arm-static|qemu-mips64-static|qemu-aarch64-static|qemu-ppc64-static)
make_emulator_part
echo "emulator=\"${emulator}\"" >> ${TMPFILE}
getyesno "Do you want to create jail immediately?"
[ $? -eq 1 -o $? -eq 3 ] && err 0 "${N1_COLOR}You can make now: ${N2_COLOR}cbsd jcreate jconf=${TMPFILE}${N0_COLOR}"
jcreate jconf=${TMPFILE} delpkglist=${delpkglist} removejconf=${removejconf}
[ $? -ne 0 ] && err 0 "${N1_COLOR}Config file for jconf: ${N2_COLOR}${TMPFILE}${N0_COLOR}"
;;
*)
err 1 "${N1_COLOR}Unsupported emulator type: ${N2_COLOR}${emulator}${N0_COLOR}"
;;
esac
return 0
}
# generic func for merge profiles
merge_apply_profiles()
{
local _out
[ -z "${1}" ] && return 0
local _orig="$1"; shift
local _custom="$1"; shift
local _i
[ ! -f "${_orig}" ] && return 0
if [ ! -f "${_custom}" ]; then
. ${_orig}
return 0
fi
_out=$( ${MKTEMP_CMD} )
merge from=${_orig} to=${_custom} out=${_out}
. ${_out}
${RM_CMD} -f ${_out}
}
# generic func for invert boolean value for \$$1
# example: invert_checkbox $astart
invert_checkbox()
{
[ -z "${1}" ] && return 1
eval _mytest=\$$1
if [ "${_mytest}" = "1" ]; then
export ${1}=0
else
export ${1}=1
fi
}
# generic func for $nic_hwaddr
get_construct_nic_hwaddr()
{
. ${distdir}/vnet.subr # ip2mac
local tpl_ip
if [ -n "${ip4_addr}" ]; then
ipwmask ${ip4_addr}
iptype ${IWM}
if [ $? -ne 0 ]; then
tpl_ip="${IWM}"
else
tpl_ip="123.234.254.192" # random IP
fi
else
tpl_ip="123.234.254.192" # random IP
fi
local _input
local _defhwaddr=$( ip2mac ${tpl_ip} )
f_dialog_title " NIC hwaddr "
[ -n "${nic_hwaddr}" ] && new_defhwaddr="${nic_hwaddr}"
f_dialog_input _input "Input MAC address ( 0 - random ), eg: ${_defhwaddr}" "${new_defhwaddr}" \
"${_message}" || return $?
# todo: scan for dup
[ -n "${_input}" ] && nic_hwaddr="${_input}"
}
# generic form for $nic_mtu
get_construct_nic_mtu()
{
local _input
f_dialog_title " NIC MTU. 0 - auto, inherits parent MTU "
f_dialog_input _input "Input MTU size ( 0 - auto ), eg: 0, 1500, 9000" "${nic_mtu}" \
"${_message}" || return $?
[ -n "${_input}" ] && nic_mtu="${_input}"
}
# generic form for $nic_ratelimit
get_construct_nic_ratelimit()
{
local _input
f_dialog_title " NIC RATELIMIT. 0 - disable, {tx}/{rx} in MBit/s, {txrx} in MBit/s "
f_dialog_input _input "Input Ratelimit in MBit/s ( 0 - disable, {tx}/{rx}, {txrx} ), eg: 0, 100/10, 100" "${nic_ratelimit}" \
"${_message}" || return $?
[ -n "${_input}" ] && nic_ratelimit="${_input}"
}
# jail form for $mnt_stop
get_construct_mnt_stop()
{