xref: /freebsd/usr.sbin/bsdconfig/share/media/options.subr (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
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# $FreeBSD$
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_dprintf "%s: loading includes..." media/options.subr
34f_include $BSDCFG_SHARE/dialog.subr
35f_include $BSDCFG_SHARE/media/any.subr
36f_include $BSDCFG_SHARE/media/ftp.subr
37f_include $BSDCFG_SHARE/struct.subr
38f_include $BSDCFG_SHARE/variable.subr
39
40BSDCFG_LIBE="/usr/libexec/bsdconfig"
41f_include_lang $BSDCFG_LIBE/include/messages.subr
42
43OPTIONS_HELPFILE=$BSDCFG_LIBE/include/options.hlp
44
45############################################################ FUNCTIONS
46
47# f_media_options_menu
48#
49# Prompt the user to confirm/edit various media settings. Returns success.
50#
51f_media_options_menu()
52{
53	f_dialog_title "$msg_options_editor"
54	local title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE"
55	f_dialog_title_restore
56	local prompt=
57	local menu_list # Calculated below
58	local defaultitem=
59	local hline="$hline_arrows_tab_enter"
60
61	#
62	# A hack so that the dialogs below are always interactive in a script
63	#
64	local old_interactive=
65	if ! f_interactive; then
66		f_getvar $VAR_NONINTERACTIVE old_interactive
67		unset $VAR_NONINTERACTIVE
68	fi
69
70	local cp
71	while :; do
72		menu_list=
73
74		f_getvar $VAR_NFS_SECURE cp
75		if [ "$cp" = "YES" ]; then menu_list="$menu_list
76			' $msg_nfs_secure' 'YES'
77			    '$msg_nfs_server_talks_only_on_a_secure_port'"
78		else menu_list="$menu_list
79			' $msg_nfs_secure' 'NO'
80			    '$msg_nfs_server_talks_only_on_a_secure_port'"
81		fi
82
83		f_getvar $VAR_SLOW_ETHER cp
84		if [ "$cp" = "YES" ]; then menu_list="$menu_list
85			' $msg_nfs_slow' 'YES'
86			    '$msg_user_is_using_a_slow_pc_or_ethernet_card'"
87		else menu_list="$menu_list
88			' $msg_nfs_slow' 'NO'
89			    '$msg_user_is_using_a_slow_pc_or_ethernet_card'"
90		fi
91
92		f_getvar $VAR_NFS_TCP cp
93		if [ "$cp" = "YES" ]; then menu_list="$menu_list
94			' $msg_nfs_tcp' 'YES' '$msg_use_tcp_protocol_for_nfs'"
95		else menu_list="$menu_list
96			' $msg_nfs_tcp' 'NO' '$msg_use_tcp_protocol_for_nfs'"
97		fi
98
99		f_getvar $VAR_NFS_V3 cp
100		if [ "$cp" = "YES" ]; then menu_list="$menu_list
101			' $msg_nfs_version_3' 'YES' '$msg_use_nfs_version_3'"
102		else menu_list="$menu_list
103			' $msg_nfs_version_3' 'NO' '$msg_use_nfs_version_3'"
104		fi
105
106		f_getvar $VAR_DEBUG cp
107		if [ "$cp" ]; then menu_list="$menu_list
108			' $msg_debugging' 'YES'
109			    '$msg_emit_extra_debugging_output'"
110		else menu_list="$menu_list
111			' $msg_debugging' 'NO'
112			    '$msg_emit_extra_debugging_output'"
113		fi
114
115		f_getvar $VAR_NO_CONFIRM cp
116		if [ "$cp" ]; then menu_list="$menu_list
117			' $msg_yes_to_all' 'YES'
118			    '$msg_assume_yes_to_all_non_critical_dialogs'"
119		else menu_list="$menu_list
120			' $msg_yes_to_all' 'NO'
121			    '$msg_assume_yes_to_all_non_critical_dialogs'"
122		fi
123
124		f_getvar $VAR_TRY_DHCP cp
125		if [ "$cp" = "YES" ]; then menu_list="$menu_list
126			' $msg_dhcp' 'YES'
127			    '$msg_attempt_automatic_dhcp_configuration'"
128		else menu_list="$menu_list
129			' $msg_dhcp' 'NO'
130			    '$msg_attempt_automatic_dhcp_configuration'"
131		fi
132
133		f_getvar $VAR_TRY_RTSOL cp
134		if [ "$cp" = "YES" ]; then menu_list="$menu_list
135			' $msg_ipv6' 'YES'
136			    '$msg_attempt_ipv6_configuration_of_interfaces'"
137		else menu_list="$menu_list
138			' $msg_ipv6' 'NO'
139			    '$msg_attempt_ipv6_configuration_of_interfaces'"
140		fi
141
142		f_getvar $VAR_FTP_USER cp
143		menu_list="$menu_list
144			' $msg_ftp_username' '$cp'
145			    '$msg_username_and_password_to_use'"
146
147		f_getvar $VAR_EDITOR cp
148		menu_list="$menu_list
149			' $msg_editor' '$cp' '$msg_which_text_editor_to_use'"
150
151		f_getvar $VAR_RELNAME cp
152		menu_list="$menu_list
153			' $msg_release_name' '$cp'
154			    '$msg_which_release_to_attempt_to_load'"
155
156		if f_struct device_media; then
157			device_media get type cp
158			case "$cp" in
159			$DEVICE_TYPE_UFS|$DEVICE_TYPE_DISK)
160				cp="$msg_file_system" ;;
161			$DEVICE_TYPE_DIRECTORY)  cp="$msg_directory"   ;;
162			$DEVICE_TYPE_FLOPPY)     cp="$msg_floppy"      ;;
163			$DEVICE_TYPE_FTP)        cp="$msg_ftp"         ;;
164			$DEVICE_TYPE_HTTP_PROXY) cp="$msg_http_proxy"  ;;
165			$DEVICE_TYPE_HTTP)       cp="$msg_http_direct" ;;
166			$DEVICE_TYPE_CDROM)      cp="$msg_cdrom"       ;;
167			$DEVICE_TYPE_USB)        cp="$msg_usb"         ;;
168			$DEVICE_TYPE_DOS)        cp="$msg_dos"         ;;
169			$DEVICE_TYPE_NFS)        cp="$msg_nfs"         ;;
170			*)
171				cp="<$msg_unknown>"
172			esac
173		else
174			cp="<$msg_not_yet_set>"
175		fi
176		menu_list="$menu_list
177			' $msg_media_type' '$cp'
178			    '$msg_the_current_installation_media_type'"
179
180		f_getvar $VAR_MEDIA_TIMEOUT cp
181		menu_list="$menu_list
182			' $msg_media_timeout' '$cp'
183			    '$msg_timeout_value_in_seconds_for_slow_media'"
184
185		f_getvar $VAR_PKG_TMPDIR cp
186		menu_list="$menu_list
187			' $msg_package_temp' '$cp'
188			    '$msg_directory_where_package_temporary_files_go'"
189
190		menu_list="$menu_list
191			' $msg_rescan_devices' '<*>'
192			    '$msg_rerun_bsdconfig_initial_device_probe'
193			' $msg_use_defaults'   '[${msg_reset}]'
194			    '$msg_reset_all_values_to_startup_defaults'
195		" # END-QUOTE
196
197		local height width rows
198		eval f_dialog_menu_with_help_size height width rows \
199		                                  \"\$title\"  \
200		                                  \"\$btitle\" \
201		                                  \"\$prompt\" \
202		                                  \"\$hline\"  \
203		                                  $menu_list
204
205		local mtag
206		mtag=$( eval $DIALOG \
207			--title \"\$title\"              \
208			--backtitle \"\$btitle\"         \
209			--hline \"\$hline\"              \
210			--item-help                      \
211			--ok-label \"\$msg_ok\"          \
212			--cancel-label \"\$msg_done\"    \
213			--help-button                    \
214			--help-label \"\$msg_help\"      \
215			--default-item \"\$defaultitem\" \
216			${USE_XDIALOG:+--help \"\"}      \
217			--menu \"\$prompt\"              \
218			$height $width $rows             \
219			$menu_list                       \
220			2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
221		)
222		local retval=$?
223		f_dialog_data_sanitize mtag
224		defaultitem="$mtag"
225		f_dprintf "retval=%s mtag=[%s]" $retval "$mtag"
226
227		if [ $retval -eq $DIALOG_HELP ]; then
228			f_show_help "$OPTIONS_HELPFILE"
229			continue
230		elif [ $retval -ne $DIALOG_OK ]; then
231			break # to success
232		fi
233
234		case "$mtag" in
235		" $msg_nfs_secure")
236			f_getvar $VAR_NFS_SECURE cp
237			if [ "$cp" = "YES" ]; then
238				export $VAR_NFS_SECURE="NO"
239			else
240				export $VAR_NFS_SECURE="YES"
241			fi ;;
242		" $msg_nfs_slow")
243			f_getvar $VAR_SLOW_ETHER cp
244			if [ "$cp" = "YES" ]; then
245				export $VAR_SLOW_ETHER="NO"
246			else
247				export $VAR_SLOW_ETHER="YES"
248			fi ;;
249		" $msg_nfs_tcp")
250			f_getvar $VAR_NFS_TCP cp
251			if [ "$cp" = "YES" ]; then
252				export $VAR_NFS_TCP="NO"
253			else
254				export $VAR_NFS_TCP="YES"
255			fi ;;
256		" $msg_nfs_version_3")
257			f_getvar $VAR_NFS_V3 cp
258			if [ "$cp" = "YES" ]; then
259				export $VAR_NFS_V3="NO"
260			else
261				export $VAR_NFS_V3="YES"
262			fi ;;
263		" $msg_debugging")
264			if f_getvar $VAR_DEBUG cp && [ "$cp" ]; then
265				unset $VAR_DEBUG
266			else
267				export $VAR_DEBUG=1
268			fi ;;
269		" $msg_yes_to_all")
270			if f_getvar $VAR_NO_CONFIRM cp && [ "$cp" ]; then
271				unset $VAR_NO_CONFIRM
272			else
273				export $VAR_NO_CONFIRM=1
274			fi ;;
275		" $msg_dhcp")
276			f_getvar $VAR_TRY_DHCP cp
277			if [ "$cp" = "YES" ]; then
278				export $VAR_TRY_DHCP="NO"
279			else
280				export $VAR_TRY_DHCP="YES"
281			fi ;;
282		" $msg_ipv6")
283			f_getvar $VAR_TRY_RTSOL cp
284			if [ "$cp" = "YES" ]; then
285				export $VAR_TRY_RTSOL="NO"
286			else
287				export $VAR_TRY_RTSOL="YES"
288			fi ;;
289		" $msg_ftp_username")
290			f_media_set_ftp_userpass ;;
291		" $msg_editor")
292			f_variable_get_value $VAR_EDITOR \
293			    "$msg_please_specify_the_name_of_the_text_editor"
294			;;
295		" $msg_release_name")
296			f_variable_get_value $VAR_RELNAME \
297			    "$msg_please_specify_the_release_you_wish_to_load"
298			;;
299		" $msg_media_type")
300			f_media_get_type ;;
301		" $msg_media_timeout")
302			f_variable_get_value $VAR_MEDIA_TIMEOUT \
303			    "$msg_please_specify_the_number_of_seconds_to_wait"
304			;;
305		" $msg_package_temp")
306			f_variable_get_value $VAR_PKG_TMPDIR \
307			    "$msg_please_specify_a_temporary_directory"
308			;;
309		" $msg_rescan_devices")
310			f_device_rescan ;;
311		" $msg_use_defaults")
312			f_variable_set_defaults ;;
313		esac
314	done
315
316	# Restore old VAR_NONINTERACTIVE if needed.
317	[ "$old_interactive" ] &&
318		setvar $VAR_NONINTERACTIVE "$old_interactive"
319
320	return $SUCCESS
321}
322
323############################################################ MAIN
324
325f_dprintf "%s: Successfully loaded." media/options.subr
326
327fi # ! $_MEDIA_OPTIONS_SUBR
328