xref: /freebsd/usr.sbin/bsdconfig/share/media/any.subr (revision e5b786625f7f82a1fa91e41823332459ea5550f9)
1if [ ! "$_MEDIA_ANY_SUBR" ]; then _MEDIA_ANY_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/any.subr
33f_include $BSDCFG_SHARE/dialog.subr
34f_include $BSDCFG_SHARE/media/cdrom.subr
35f_include $BSDCFG_SHARE/media/directory.subr
36f_include $BSDCFG_SHARE/media/dos.subr
37f_include $BSDCFG_SHARE/media/http.subr
38f_include $BSDCFG_SHARE/media/httpproxy.subr
39f_include $BSDCFG_SHARE/media/nfs.subr
40f_include $BSDCFG_SHARE/media/options.subr
41f_include $BSDCFG_SHARE/media/ufs.subr
42f_include $BSDCFG_SHARE/media/usb.subr
43f_include $BSDCFG_SHARE/struct.subr
44
45BSDCFG_LIBE="/usr/libexec/bsdconfig"
46f_include_lang $BSDCFG_LIBE/include/messages.subr
47
48MEDIA_HELPFILE=$BSDCFG_LIBE/include/media.hlp
49
50############################################################ FUNCTIONS
51
52# f_media_get_type
53#
54# Prompt the user to select amongst the known media types (included above).
55#
56# If the user does not cancel or press Esc, invokes the f_media_set_* function
57# associated with the chosen media type. If after all that we have a struct
58# named `device_media' then success is returned, otherwise failure.
59#
60# NOTE: The f_media_set_* function should create the `device_media' struct.
61# See `struct.subr' and the above `media/*.subr' includes for more details.
62#
63f_media_get_type()
64{
65	f_dialog_title "$msg_choose_installation_media"
66	local title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE"
67	f_dialog_title_restore
68	local prompt="$msg_choose_installation_media_description"
69	local menu_list="
70		'1 $msg_cd_dvd'    '$msg_install_from_a_freebsd_cd_dvd'
71		'2 $msg_http_proxy'
72		                '$msg_install_from_an_ftp_server_thru_proxy'
73		'3 $msg_http_direct' '$msg_install_from_an_http_server'
74		'4 $msg_directory' '$msg_install_from_the_existing_filesystem'
75		'6 $msg_nfs'       '$msg_install_over_nfs'
76		'6 $msg_dos'       '$msg_install_from_a_dos_partition'
77		'7 $msg_ufs'       '$msg_install_from_a_ufs_partition'
78		'8 $msg_usb'       '$msg_install_from_a_usb_drive'
79		'X $msg_options'   '$msg_view_set_various_media_options'
80	" # END-QUOTE
81	local hline="$hline_choose_help_for_more_information_on_media_types"
82
83	local height width rows
84	eval f_dialog_menu_size height width rows \
85	                        \"\$title\"  \
86	                        \"\$btitle\" \
87	                        \"\$prompt\" \
88	                        \"\$hline\"  \
89	                        $menu_list
90
91	local mtag
92	while :; do
93		mtag=$( eval $DIALOG \
94			--title \"\$title\"             \
95			--backtitle \"\$btitle\"        \
96			--hline \"\$hline\"             \
97			--ok-label \"\$msg_ok\"         \
98			--cancel-label \"\$msg_cancel\" \
99			--help-button                   \
100			--help-label \"\$msg_help\"     \
101			${USE_XDIALOG:+--help \"\"}     \
102			--menu \"\$prompt\"             \
103			$height $width $rows            \
104			$menu_list                      \
105			2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
106		)
107		local retval=$?
108		f_dialog_data_sanitize mtag
109		f_dprintf "retval=%s mtag=[%s]" $retval "$mtag"
110
111		if [ $retval -eq $DIALOG_HELP ]; then
112			f_show_help "$MEDIA_HELPFILE"
113			continue
114		elif [ $retval -ne $DIALOG_OK ]; then
115			return $FAILURE
116		fi
117
118		case "$mtag" in
119		?" $msg_cd_dvd")      f_media_set_cdrom ;;
120		?" $msg_http_proxy")  f_media_set_http_proxy ;;
121		?" $msg_http_direct") f_media_set_http ;;
122		?" $msg_directory")   f_media_set_directory ;;
123		?" $msg_dos")         f_media_set_dos ;;
124		?" $msg_nfs")         f_media_set_nfs ;;
125		?" $msg_ufs")         f_media_set_ufs ;;
126		?" $msg_usb")         f_media_set_usb ;;
127		?" $msg_options")
128			f_media_options_menu
129			continue
130			;;
131		esac
132		break
133	done
134
135	f_struct device_media || return $FAILURE
136}
137
138############################################################ MAIN
139
140f_dprintf "%s: Successfully loaded." media/any.subr
141
142fi # ! $_MEDIA_ANY_SUBR
143