xref: /freebsd/usr.sbin/bsdconfig/share/media/any.subr (revision 7323adac99d399e58bdec71236a0db9ee6bfb6d2)
1*7323adacSDevin Teskeif [ ! "$_MEDIA_ANY_SUBR" ]; then _MEDIA_ANY_SUBR=1
2*7323adacSDevin Teske#
3*7323adacSDevin Teske# Copyright (c) 2012-2013 Devin Teske
4*7323adacSDevin Teske# All Rights Reserved.
5*7323adacSDevin Teske#
6*7323adacSDevin Teske# Redistribution and use in source and binary forms, with or without
7*7323adacSDevin Teske# modification, are permitted provided that the following conditions
8*7323adacSDevin Teske# are met:
9*7323adacSDevin Teske# 1. Redistributions of source code must retain the above copyright
10*7323adacSDevin Teske#    notice, this list of conditions and the following disclaimer.
11*7323adacSDevin Teske# 2. Redistributions in binary form must reproduce the above copyright
12*7323adacSDevin Teske#    notice, this list of conditions and the following disclaimer in the
13*7323adacSDevin Teske#    documentation and/or other materials provided with the distribution.
14*7323adacSDevin Teske#
15*7323adacSDevin Teske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16*7323adacSDevin Teske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE
17*7323adacSDevin Teske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*7323adacSDevin Teske# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19*7323adacSDevin Teske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*7323adacSDevin Teske# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21*7323adacSDevin Teske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*7323adacSDevin Teske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*7323adacSDevin Teske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*7323adacSDevin Teske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*7323adacSDevin Teske# SUCH DAMAGE.
26*7323adacSDevin Teske#
27*7323adacSDevin Teske# $FreeBSD$
28*7323adacSDevin Teske#
29*7323adacSDevin Teske############################################################ INCLUDES
30*7323adacSDevin Teske
31*7323adacSDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig"
32*7323adacSDevin Teske. $BSDCFG_SHARE/common.subr || exit 1
33*7323adacSDevin Teskef_dprintf "%s: loading includes..." media/any.subr
34*7323adacSDevin Teskef_include $BSDCFG_SHARE/dialog.subr
35*7323adacSDevin Teskef_include $BSDCFG_SHARE/struct.subr
36*7323adacSDevin Teskef_include $BSDCFG_SHARE/media/cdrom.subr
37*7323adacSDevin Teskef_include $BSDCFG_SHARE/media/directory.subr
38*7323adacSDevin Teskef_include $BSDCFG_SHARE/media/dos.subr
39*7323adacSDevin Teskef_include $BSDCFG_SHARE/media/floppy.subr
40*7323adacSDevin Teskef_include $BSDCFG_SHARE/media/ftp.subr
41*7323adacSDevin Teskef_include $BSDCFG_SHARE/media/httpproxy.subr
42*7323adacSDevin Teskef_include $BSDCFG_SHARE/media/nfs.subr
43*7323adacSDevin Teskef_include $BSDCFG_SHARE/media/options.subr
44*7323adacSDevin Teskef_include $BSDCFG_SHARE/media/ufs.subr
45*7323adacSDevin Teskef_include $BSDCFG_SHARE/media/usb.subr
46*7323adacSDevin Teske
47*7323adacSDevin TeskeBSDCFG_LIBE="/usr/libexec/bsdconfig"
48*7323adacSDevin Teskef_include_lang $BSDCFG_LIBE/include/messages.subr
49*7323adacSDevin Teske
50*7323adacSDevin TeskeMEDIA_HELPFILE=$BSDCFG_LIBE/include/media.hlp
51*7323adacSDevin Teske
52*7323adacSDevin Teske############################################################ FUNCTIONS
53*7323adacSDevin Teske
54*7323adacSDevin Teske# f_media_get_type
55*7323adacSDevin Teske#
56*7323adacSDevin Teske# Prompt the user to select amongst the known media types (included above).
57*7323adacSDevin Teske#
58*7323adacSDevin Teske# If the user does not cancel or press Esc, invokes the f_media_set_* function
59*7323adacSDevin Teske# associated with the chosen media type. If after all that we have a struct
60*7323adacSDevin Teske# named `device_media' then success is returned, otherwise failure.
61*7323adacSDevin Teske#
62*7323adacSDevin Teske# NOTE: The f_media_set_* function should create the `device_media' struct.
63*7323adacSDevin Teske# See `struct.subr' and the above `media/*.subr' includes for more details.
64*7323adacSDevin Teske#
65*7323adacSDevin Teskef_media_get_type()
66*7323adacSDevin Teske{
67*7323adacSDevin Teske	f_dialog_title "$msg_choose_installation_media"
68*7323adacSDevin Teske	local title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE"
69*7323adacSDevin Teske	f_dialog_title_restore
70*7323adacSDevin Teske	local prompt="$msg_choose_installation_media_description"
71*7323adacSDevin Teske	local hline="$hline_choose_help_for_more_information_on_media_types"
72*7323adacSDevin Teske	local menu_list size
73*7323adacSDevin Teske
74*7323adacSDevin Teske	menu_list="
75*7323adacSDevin Teske		'1 $msg_cd_dvd'	   '$msg_install_from_a_freebsd_cd_dvd'
76*7323adacSDevin Teske		'2 $msg_ftp'	   '$msg_install_from_an_ftp_server'
77*7323adacSDevin Teske		'3 $msg_ftp_passive'
78*7323adacSDevin Teske		                '$msg_install_from_an_ftp_server_thru_firewall'
79*7323adacSDevin Teske		'4 $msg_http'      '$msg_install_from_an_ftp_server_thru_proxy'
80*7323adacSDevin Teske		'5 $msg_directory' '$msg_install_from_the_existing_filesystem'
81*7323adacSDevin Teske		'6 $msg_nfs'       '$msg_install_over_nfs'
82*7323adacSDevin Teske		'7 $msg_dos'       '$msg_install_from_a_dos_partition'
83*7323adacSDevin Teske		'8 $msg_ufs'       '$msg_install_from_a_ufs_partition'
84*7323adacSDevin Teske		'9 $msg_floppy'    '$msg_install_from_a_floppy_disk_set'
85*7323adacSDevin Teske		'A $msg_usb'       '$msg_install_from_a_usb_drive'
86*7323adacSDevin Teske		'X $msg_options'   '$msg_view_set_various_media_options'
87*7323adacSDevin Teske	" # END-QUOTE
88*7323adacSDevin Teske
89*7323adacSDevin Teske	size=$( eval f_dialog_menu_size \
90*7323adacSDevin Teske	        	\"\$title\"  \
91*7323adacSDevin Teske	        	\"\$btitle\" \
92*7323adacSDevin Teske	        	\"\$prompt\" \
93*7323adacSDevin Teske	        	\"\$hline\"  \
94*7323adacSDevin Teske	        	$menu_list   )
95*7323adacSDevin Teske
96*7323adacSDevin Teske	local dialog_menu
97*7323adacSDevin Teske
98*7323adacSDevin Teske	while :; do
99*7323adacSDevin Teske		dialog_menu=$( eval $DIALOG \
100*7323adacSDevin Teske			--title \"\$title\"                  \
101*7323adacSDevin Teske			--backtitle \"\$btitle\"             \
102*7323adacSDevin Teske			--hline \"\$hline\"                  \
103*7323adacSDevin Teske			--ok-label \"\$msg_ok\"              \
104*7323adacSDevin Teske			--cancel-label \"\$msg_cancel\"      \
105*7323adacSDevin Teske			--help-button                        \
106*7323adacSDevin Teske			--help-label \"\$msg_help\"          \
107*7323adacSDevin Teske			${USE_XDIALOG:+--help \"\"}          \
108*7323adacSDevin Teske			--menu \"\$prompt\" $size $menu_list \
109*7323adacSDevin Teske			2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
110*7323adacSDevin Teske		)
111*7323adacSDevin Teske		local retval=$?
112*7323adacSDevin Teske		setvar DIALOG_MENU_$$ "$dialog_menu"
113*7323adacSDevin Teske
114*7323adacSDevin Teske		local mtag
115*7323adacSDevin Teske		mtag=$( f_dialog_menutag )
116*7323adacSDevin Teske		f_dprintf "retval=%s mtag=[%s]" $retval "$mtag"
117*7323adacSDevin Teske
118*7323adacSDevin Teske		if [ $retval -eq 2 ]; then
119*7323adacSDevin Teske			# The Help button was pressed
120*7323adacSDevin Teske			f_show_help "$MEDIA_HELPFILE"
121*7323adacSDevin Teske			continue
122*7323adacSDevin Teske		elif [ $retval -ne 0 ]; then
123*7323adacSDevin Teske			return $FAILURE
124*7323adacSDevin Teske		fi
125*7323adacSDevin Teske
126*7323adacSDevin Teske		case "$mtag" in
127*7323adacSDevin Teske		?" $msg_cd_dvd")      f_media_set_cdrom ;;
128*7323adacSDevin Teske		?" $msg_ftp")         f_media_set_ftp_active ;;
129*7323adacSDevin Teske		?" $msg_ftp_passive") f_media_set_ftp_passive ;;
130*7323adacSDevin Teske		?" $msg_http")        f_media_set_http_proxy ;;
131*7323adacSDevin Teske		?" $msg_directory")   f_media_set_directory ;;
132*7323adacSDevin Teske		?" $msg_dos")         f_media_set_dos ;;
133*7323adacSDevin Teske		?" $msg_nfs")         f_media_set_nfs ;;
134*7323adacSDevin Teske		?" $msg_ufs")         f_media_set_ufs ;;
135*7323adacSDevin Teske		?" $msg_floppy")      f_media_set_floppy ;;
136*7323adacSDevin Teske		?" $msg_usb")         f_media_set_usb ;;
137*7323adacSDevin Teske		?" $msg_options")
138*7323adacSDevin Teske			f_media_options_menu
139*7323adacSDevin Teske			continue
140*7323adacSDevin Teske			;;
141*7323adacSDevin Teske		esac
142*7323adacSDevin Teske		break
143*7323adacSDevin Teske	done
144*7323adacSDevin Teske
145*7323adacSDevin Teske	f_struct device_media || return $FAILURE
146*7323adacSDevin Teske}
147*7323adacSDevin Teske
148*7323adacSDevin Teske############################################################ MAIN
149*7323adacSDevin Teske
150*7323adacSDevin Teskef_dprintf "%s: Successfully loaded." media/any.subr
151*7323adacSDevin Teske
152*7323adacSDevin Teskefi # ! $_MEDIA_ANY_SUBR
153