xref: /freebsd/usr.sbin/bsdconfig/share/media/any.subr (revision 8e37a7c8b904c50714931a3ef635023dd658499e)
17323adacSDevin Teskeif [ ! "$_MEDIA_ANY_SUBR" ]; then _MEDIA_ANY_SUBR=1
27323adacSDevin Teske#
37323adacSDevin Teske# Copyright (c) 2012-2013 Devin Teske
4f8ea072aSDevin Teske# All rights reserved.
57323adacSDevin Teske#
67323adacSDevin Teske# Redistribution and use in source and binary forms, with or without
77323adacSDevin Teske# modification, are permitted provided that the following conditions
87323adacSDevin Teske# are met:
97323adacSDevin Teske# 1. Redistributions of source code must retain the above copyright
107323adacSDevin Teske#    notice, this list of conditions and the following disclaimer.
117323adacSDevin Teske# 2. Redistributions in binary form must reproduce the above copyright
127323adacSDevin Teske#    notice, this list of conditions and the following disclaimer in the
137323adacSDevin Teske#    documentation and/or other materials provided with the distribution.
147323adacSDevin Teske#
157323adacSDevin Teske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16*8e37a7c8SDevin Teske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
177323adacSDevin Teske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
187323adacSDevin Teske# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
197323adacSDevin Teske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*8e37a7c8SDevin Teske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
217323adacSDevin Teske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
227323adacSDevin Teske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
237323adacSDevin Teske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
247323adacSDevin Teske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
257323adacSDevin Teske# SUCH DAMAGE.
267323adacSDevin Teske#
277323adacSDevin Teske# $FreeBSD$
287323adacSDevin Teske#
297323adacSDevin Teske############################################################ INCLUDES
307323adacSDevin Teske
317323adacSDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig"
327323adacSDevin Teske. $BSDCFG_SHARE/common.subr || exit 1
337323adacSDevin Teskef_dprintf "%s: loading includes..." media/any.subr
347323adacSDevin Teskef_include $BSDCFG_SHARE/dialog.subr
357323adacSDevin Teskef_include $BSDCFG_SHARE/media/cdrom.subr
367323adacSDevin Teskef_include $BSDCFG_SHARE/media/directory.subr
377323adacSDevin Teskef_include $BSDCFG_SHARE/media/dos.subr
387323adacSDevin Teskef_include $BSDCFG_SHARE/media/floppy.subr
397323adacSDevin Teskef_include $BSDCFG_SHARE/media/ftp.subr
4047b73aa2SDevin Teskef_include $BSDCFG_SHARE/media/http.subr
417323adacSDevin Teskef_include $BSDCFG_SHARE/media/httpproxy.subr
427323adacSDevin Teskef_include $BSDCFG_SHARE/media/nfs.subr
437323adacSDevin Teskef_include $BSDCFG_SHARE/media/options.subr
447323adacSDevin Teskef_include $BSDCFG_SHARE/media/ufs.subr
457323adacSDevin Teskef_include $BSDCFG_SHARE/media/usb.subr
461de60ff0SDevin Teskef_include $BSDCFG_SHARE/struct.subr
477323adacSDevin Teske
487323adacSDevin TeskeBSDCFG_LIBE="/usr/libexec/bsdconfig"
497323adacSDevin Teskef_include_lang $BSDCFG_LIBE/include/messages.subr
507323adacSDevin Teske
517323adacSDevin TeskeMEDIA_HELPFILE=$BSDCFG_LIBE/include/media.hlp
527323adacSDevin Teske
537323adacSDevin Teske############################################################ FUNCTIONS
547323adacSDevin Teske
557323adacSDevin Teske# f_media_get_type
567323adacSDevin Teske#
577323adacSDevin Teske# Prompt the user to select amongst the known media types (included above).
587323adacSDevin Teske#
597323adacSDevin Teske# If the user does not cancel or press Esc, invokes the f_media_set_* function
607323adacSDevin Teske# associated with the chosen media type. If after all that we have a struct
617323adacSDevin Teske# named `device_media' then success is returned, otherwise failure.
627323adacSDevin Teske#
637323adacSDevin Teske# NOTE: The f_media_set_* function should create the `device_media' struct.
647323adacSDevin Teske# See `struct.subr' and the above `media/*.subr' includes for more details.
657323adacSDevin Teske#
667323adacSDevin Teskef_media_get_type()
677323adacSDevin Teske{
687323adacSDevin Teske	f_dialog_title "$msg_choose_installation_media"
697323adacSDevin Teske	local title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE"
707323adacSDevin Teske	f_dialog_title_restore
717323adacSDevin Teske	local prompt="$msg_choose_installation_media_description"
72052f8969SDevin Teske	local menu_list="
737323adacSDevin Teske		'1 $msg_cd_dvd'    '$msg_install_from_a_freebsd_cd_dvd'
747323adacSDevin Teske		'2 $msg_ftp'       '$msg_install_from_an_ftp_server'
7547b73aa2SDevin Teske		'3 $msg_http_proxy'
7647b73aa2SDevin Teske		                '$msg_install_from_an_ftp_server_thru_proxy'
7747b73aa2SDevin Teske		'4 $msg_http_direct' '$msg_install_from_an_http_server'
787323adacSDevin Teske		'5 $msg_directory' '$msg_install_from_the_existing_filesystem'
797323adacSDevin Teske		'6 $msg_nfs'       '$msg_install_over_nfs'
807323adacSDevin Teske		'7 $msg_dos'       '$msg_install_from_a_dos_partition'
817323adacSDevin Teske		'8 $msg_ufs'       '$msg_install_from_a_ufs_partition'
827323adacSDevin Teske		'9 $msg_floppy'    '$msg_install_from_a_floppy_disk_set'
837323adacSDevin Teske		'A $msg_usb'       '$msg_install_from_a_usb_drive'
847323adacSDevin Teske		'X $msg_options'   '$msg_view_set_various_media_options'
857323adacSDevin Teske	" # END-QUOTE
86052f8969SDevin Teske	local hline="$hline_choose_help_for_more_information_on_media_types"
877323adacSDevin Teske
8874036c4dSDevin Teske	local height width rows
8974036c4dSDevin Teske	eval f_dialog_menu_size height width rows \
907323adacSDevin Teske	                        \"\$title\"  \
917323adacSDevin Teske	                        \"\$btitle\" \
927323adacSDevin Teske	                        \"\$prompt\" \
937323adacSDevin Teske	                        \"\$hline\"  \
9474036c4dSDevin Teske	                        $menu_list
957323adacSDevin Teske
96fd962ac6SDevin Teske	local mtag
977323adacSDevin Teske	while :; do
98fd962ac6SDevin Teske		mtag=$( eval $DIALOG \
997323adacSDevin Teske			--title \"\$title\"             \
1007323adacSDevin Teske			--backtitle \"\$btitle\"        \
1017323adacSDevin Teske			--hline \"\$hline\"             \
1027323adacSDevin Teske			--ok-label \"\$msg_ok\"         \
1037323adacSDevin Teske			--cancel-label \"\$msg_cancel\" \
1047323adacSDevin Teske			--help-button                   \
1057323adacSDevin Teske			--help-label \"\$msg_help\"     \
1067323adacSDevin Teske			${USE_XDIALOG:+--help \"\"}     \
10774036c4dSDevin Teske			--menu \"\$prompt\"             \
10874036c4dSDevin Teske			$height $width $rows            \
10974036c4dSDevin Teske			$menu_list                      \
1107323adacSDevin Teske			2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
1117323adacSDevin Teske		)
1127323adacSDevin Teske		local retval=$?
113fd962ac6SDevin Teske		f_dialog_data_sanitize mtag
1147323adacSDevin Teske		f_dprintf "retval=%s mtag=[%s]" $retval "$mtag"
1157323adacSDevin Teske
1167323adacSDevin Teske		if [ $retval -eq 2 ]; then
1177323adacSDevin Teske			# The Help button was pressed
1187323adacSDevin Teske			f_show_help "$MEDIA_HELPFILE"
1197323adacSDevin Teske			continue
1207323adacSDevin Teske		elif [ $retval -ne 0 ]; then
1217323adacSDevin Teske			return $FAILURE
1227323adacSDevin Teske		fi
1237323adacSDevin Teske
1247323adacSDevin Teske		case "$mtag" in
1257323adacSDevin Teske		?" $msg_cd_dvd")      f_media_set_cdrom ;;
126f184cec5SDevin Teske		?" $msg_ftp")         f_media_set_ftp ;;
12747b73aa2SDevin Teske		?" $msg_http_proxy")  f_media_set_http_proxy ;;
12847b73aa2SDevin Teske		?" $msg_http_direct") f_media_set_http ;;
1297323adacSDevin Teske		?" $msg_directory")   f_media_set_directory ;;
1307323adacSDevin Teske		?" $msg_dos")         f_media_set_dos ;;
1317323adacSDevin Teske		?" $msg_nfs")         f_media_set_nfs ;;
1327323adacSDevin Teske		?" $msg_ufs")         f_media_set_ufs ;;
1337323adacSDevin Teske		?" $msg_floppy")      f_media_set_floppy ;;
1347323adacSDevin Teske		?" $msg_usb")         f_media_set_usb ;;
1357323adacSDevin Teske		?" $msg_options")
1367323adacSDevin Teske			f_media_options_menu
1377323adacSDevin Teske			continue
1387323adacSDevin Teske			;;
1397323adacSDevin Teske		esac
1407323adacSDevin Teske		break
1417323adacSDevin Teske	done
1427323adacSDevin Teske
1437323adacSDevin Teske	f_struct device_media || return $FAILURE
1447323adacSDevin Teske}
1457323adacSDevin Teske
1467323adacSDevin Teske############################################################ MAIN
1477323adacSDevin Teske
1487323adacSDevin Teskef_dprintf "%s: Successfully loaded." media/any.subr
1497323adacSDevin Teske
1507323adacSDevin Teskefi # ! $_MEDIA_ANY_SUBR
151