xref: /freebsd/usr.sbin/bsdconfig/share/media/options.subr (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1if [ ! "$_MEDIA_OPTIONS_SUBR" ]; then _MEDIA_OPTIONS_SUBR=1
2#
3# Copyright (c) 2012-2013 Devin Teske
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
27#
28############################################################ INCLUDES
29
30BSDCFG_SHARE="/usr/share/bsdconfig"
31. $BSDCFG_SHARE/common.subr || exit 1
32f_dprintf "%s: loading includes..." media/options.subr
33f_include $BSDCFG_SHARE/dialog.subr
34f_include $BSDCFG_SHARE/media/any.subr
35f_include $BSDCFG_SHARE/struct.subr
36f_include $BSDCFG_SHARE/variable.subr
37
38BSDCFG_LIBE="/usr/libexec/bsdconfig"
39f_include_lang $BSDCFG_LIBE/include/messages.subr
40
41OPTIONS_HELPFILE=$BSDCFG_LIBE/include/options.hlp
42
43############################################################ FUNCTIONS
44
45# f_media_options_menu
46#
47# Prompt the user to confirm/edit various media settings. Returns success.
48#
49f_media_options_menu()
50{
51	f_dialog_title "$msg_options_editor"
52	local title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE"
53	f_dialog_title_restore
54	local prompt=
55	local menu_list # Calculated below
56	local defaultitem=
57	local hline="$hline_arrows_tab_enter"
58
59	#
60	# A hack so that the dialogs below are always interactive in a script
61	#
62	local old_interactive=
63	if ! f_interactive; then
64		f_getvar $VAR_NONINTERACTIVE old_interactive
65		unset $VAR_NONINTERACTIVE
66	fi
67
68	local cp
69	while :; do
70		menu_list=
71
72		f_getvar $VAR_NFS_SECURE cp
73		if [ "$cp" = "YES" ]; then menu_list="$menu_list
74			' $msg_nfs_secure' 'YES'
75			    '$msg_nfs_server_talks_only_on_a_secure_port'"
76		else menu_list="$menu_list
77			' $msg_nfs_secure' 'NO'
78			    '$msg_nfs_server_talks_only_on_a_secure_port'"
79		fi
80
81		f_getvar $VAR_SLOW_ETHER cp
82		if [ "$cp" = "YES" ]; then menu_list="$menu_list
83			' $msg_nfs_slow' 'YES'
84			    '$msg_user_is_using_a_slow_pc_or_ethernet_card'"
85		else menu_list="$menu_list
86			' $msg_nfs_slow' 'NO'
87			    '$msg_user_is_using_a_slow_pc_or_ethernet_card'"
88		fi
89
90		f_getvar $VAR_NFS_TCP cp
91		if [ "$cp" = "YES" ]; then menu_list="$menu_list
92			' $msg_nfs_tcp' 'YES' '$msg_use_tcp_protocol_for_nfs'"
93		else menu_list="$menu_list
94			' $msg_nfs_tcp' 'NO' '$msg_use_tcp_protocol_for_nfs'"
95		fi
96
97		f_getvar $VAR_NFS_V3 cp
98		if [ "$cp" = "YES" ]; then menu_list="$menu_list
99			' $msg_nfs_version_3' 'YES' '$msg_use_nfs_version_3'"
100		else menu_list="$menu_list
101			' $msg_nfs_version_3' 'NO' '$msg_use_nfs_version_3'"
102		fi
103
104		f_getvar $VAR_DEBUG cp
105		if [ "$cp" ]; then menu_list="$menu_list
106			' $msg_debugging' 'YES'
107			    '$msg_emit_extra_debugging_output'"
108		else menu_list="$menu_list
109			' $msg_debugging' 'NO'
110			    '$msg_emit_extra_debugging_output'"
111		fi
112
113		f_getvar $VAR_NO_CONFIRM cp
114		if [ "$cp" ]; then menu_list="$menu_list
115			' $msg_yes_to_all' 'YES'
116			    '$msg_assume_yes_to_all_non_critical_dialogs'"
117		else menu_list="$menu_list
118			' $msg_yes_to_all' 'NO'
119			    '$msg_assume_yes_to_all_non_critical_dialogs'"
120		fi
121
122		f_getvar $VAR_TRY_DHCP cp
123		if [ "$cp" = "YES" ]; then menu_list="$menu_list
124			' $msg_dhcp' 'YES'
125			    '$msg_attempt_automatic_dhcp_configuration'"
126		else menu_list="$menu_list
127			' $msg_dhcp' 'NO'
128			    '$msg_attempt_automatic_dhcp_configuration'"
129		fi
130
131		f_getvar $VAR_TRY_RTSOL cp
132		if [ "$cp" = "YES" ]; then menu_list="$menu_list
133			' $msg_ipv6' 'YES'
134			    '$msg_attempt_ipv6_configuration_of_interfaces'"
135		else menu_list="$menu_list
136			' $msg_ipv6' 'NO'
137			    '$msg_attempt_ipv6_configuration_of_interfaces'"
138		fi
139
140		f_getvar $VAR_EDITOR cp
141		menu_list="$menu_list
142			' $msg_editor' '$cp' '$msg_which_text_editor_to_use'"
143
144		f_getvar $VAR_RELNAME cp
145		menu_list="$menu_list
146			' $msg_release_name' '$cp'
147			    '$msg_which_release_to_attempt_to_load'"
148
149		if f_struct device_media; then
150			device_media get type cp
151			case "$cp" in
152			$DEVICE_TYPE_UFS|$DEVICE_TYPE_DISK)
153				cp="$msg_file_system" ;;
154			$DEVICE_TYPE_DIRECTORY)  cp="$msg_directory"   ;;
155			$DEVICE_TYPE_HTTP_PROXY) cp="$msg_http_proxy"  ;;
156			$DEVICE_TYPE_HTTP)       cp="$msg_http_direct" ;;
157			$DEVICE_TYPE_CDROM)      cp="$msg_cdrom"       ;;
158			$DEVICE_TYPE_USB)        cp="$msg_usb"         ;;
159			$DEVICE_TYPE_DOS)        cp="$msg_dos"         ;;
160			$DEVICE_TYPE_NFS)        cp="$msg_nfs"         ;;
161			*)
162				cp="<$msg_unknown>"
163			esac
164		else
165			cp="<$msg_not_yet_set>"
166		fi
167		menu_list="$menu_list
168			' $msg_media_type' '$cp'
169			    '$msg_the_current_installation_media_type'"
170
171		f_getvar $VAR_MEDIA_TIMEOUT cp
172		menu_list="$menu_list
173			' $msg_media_timeout' '$cp'
174			    '$msg_timeout_value_in_seconds_for_slow_media'"
175
176		f_getvar $VAR_PKG_TMPDIR cp
177		menu_list="$menu_list
178			' $msg_package_temp' '$cp'
179			    '$msg_directory_where_package_temporary_files_go'"
180
181		menu_list="$menu_list
182			' $msg_rescan_devices' '<*>'
183			    '$msg_rerun_bsdconfig_initial_device_probe'
184			' $msg_use_defaults'   '[${msg_reset}]'
185			    '$msg_reset_all_values_to_startup_defaults'
186		" # END-QUOTE
187
188		local height width rows
189		eval f_dialog_menu_with_help_size height width rows \
190		                                  \"\$title\"  \
191		                                  \"\$btitle\" \
192		                                  \"\$prompt\" \
193		                                  \"\$hline\"  \
194		                                  $menu_list
195
196		local mtag
197		mtag=$( eval $DIALOG \
198			--title \"\$title\"              \
199			--backtitle \"\$btitle\"         \
200			--hline \"\$hline\"              \
201			--item-help                      \
202			--ok-label \"\$msg_ok\"          \
203			--cancel-label \"\$msg_done\"    \
204			--help-button                    \
205			--help-label \"\$msg_help\"      \
206			--default-item \"\$defaultitem\" \
207			${USE_XDIALOG:+--help \"\"}      \
208			--menu \"\$prompt\"              \
209			$height $width $rows             \
210			$menu_list                       \
211			2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
212		)
213		local retval=$?
214		f_dialog_data_sanitize mtag
215		defaultitem="$mtag"
216		f_dprintf "retval=%s mtag=[%s]" $retval "$mtag"
217
218		if [ $retval -eq $DIALOG_HELP ]; then
219			f_show_help "$OPTIONS_HELPFILE"
220			continue
221		elif [ $retval -ne $DIALOG_OK ]; then
222			break # to success
223		fi
224
225		case "$mtag" in
226		" $msg_nfs_secure")
227			f_getvar $VAR_NFS_SECURE cp
228			if [ "$cp" = "YES" ]; then
229				export $VAR_NFS_SECURE="NO"
230			else
231				export $VAR_NFS_SECURE="YES"
232			fi ;;
233		" $msg_nfs_slow")
234			f_getvar $VAR_SLOW_ETHER cp
235			if [ "$cp" = "YES" ]; then
236				export $VAR_SLOW_ETHER="NO"
237			else
238				export $VAR_SLOW_ETHER="YES"
239			fi ;;
240		" $msg_nfs_tcp")
241			f_getvar $VAR_NFS_TCP cp
242			if [ "$cp" = "YES" ]; then
243				export $VAR_NFS_TCP="NO"
244			else
245				export $VAR_NFS_TCP="YES"
246			fi ;;
247		" $msg_nfs_version_3")
248			f_getvar $VAR_NFS_V3 cp
249			if [ "$cp" = "YES" ]; then
250				export $VAR_NFS_V3="NO"
251			else
252				export $VAR_NFS_V3="YES"
253			fi ;;
254		" $msg_debugging")
255			if f_getvar $VAR_DEBUG cp && [ "$cp" ]; then
256				unset $VAR_DEBUG
257			else
258				export $VAR_DEBUG=1
259			fi ;;
260		" $msg_yes_to_all")
261			if f_getvar $VAR_NO_CONFIRM cp && [ "$cp" ]; then
262				unset $VAR_NO_CONFIRM
263			else
264				export $VAR_NO_CONFIRM=1
265			fi ;;
266		" $msg_dhcp")
267			f_getvar $VAR_TRY_DHCP cp
268			if [ "$cp" = "YES" ]; then
269				export $VAR_TRY_DHCP="NO"
270			else
271				export $VAR_TRY_DHCP="YES"
272			fi ;;
273		" $msg_ipv6")
274			f_getvar $VAR_TRY_RTSOL cp
275			if [ "$cp" = "YES" ]; then
276				export $VAR_TRY_RTSOL="NO"
277			else
278				export $VAR_TRY_RTSOL="YES"
279			fi ;;
280		" $msg_editor")
281			f_variable_get_value $VAR_EDITOR \
282			    "$msg_please_specify_the_name_of_the_text_editor"
283			;;
284		" $msg_release_name")
285			f_variable_get_value $VAR_RELNAME \
286			    "$msg_please_specify_the_release_you_wish_to_load"
287			;;
288		" $msg_media_type")
289			f_media_get_type ;;
290		" $msg_media_timeout")
291			f_variable_get_value $VAR_MEDIA_TIMEOUT \
292			    "$msg_please_specify_the_number_of_seconds_to_wait"
293			;;
294		" $msg_package_temp")
295			f_variable_get_value $VAR_PKG_TMPDIR \
296			    "$msg_please_specify_a_temporary_directory"
297			;;
298		" $msg_rescan_devices")
299			f_device_rescan ;;
300		" $msg_use_defaults")
301			f_variable_set_defaults ;;
302		esac
303	done
304
305	# Restore old VAR_NONINTERACTIVE if needed.
306	[ "$old_interactive" ] &&
307		setvar $VAR_NONINTERACTIVE "$old_interactive"
308
309	return $SUCCESS
310}
311
312############################################################ MAIN
313
314f_dprintf "%s: Successfully loaded." media/options.subr
315
316fi # ! $_MEDIA_OPTIONS_SUBR
317