xref: /freebsd/usr.sbin/bsdconfig/share/media/common.subr (revision 1de60ff0f42859d11580dc1a6978148460b8c6f0)
17323adacSDevin Teskeif [ ! "$_MEDIA_COMMON_SUBR" ]; then _MEDIA_COMMON_SUBR=1
27323adacSDevin Teske#
37323adacSDevin Teske# Copyright (c) 2012-2013 Devin Teske
47323adacSDevin 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
167323adacSDevin 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
207323adacSDevin Teske# DAMAGES (INLUDING, 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/common.subr
347323adacSDevin Teskef_include $BSDCFG_SHARE/device.subr
35cd35d3c3SDevin Teskef_include $BSDCFG_SHARE/media/any.subr
36*1de60ff0SDevin Teskef_include $BSDCFG_SHARE/struct.subr
377323adacSDevin Teske
387323adacSDevin Teske############################################################ GLOBALS
397323adacSDevin Teske
407323adacSDevin Teske#
417323adacSDevin Teske# Where to mount media
427323adacSDevin Teske#
437323adacSDevin TeskeMOUNTPOINT=/dist
447323adacSDevin Teske
457323adacSDevin Teske############################################################ FUNCTIONS
467323adacSDevin Teske
477323adacSDevin Teske# f_media_open
487323adacSDevin Teske#
497323adacSDevin Teske# Returms success if able to initialize the media device.
507323adacSDevin Teske#
517323adacSDevin Teskef_media_open()
527323adacSDevin Teske{
5380ae9845SDevin Teske	f_dprintf "f_media_open: Verifying and initiliazing media device"
547323adacSDevin Teske	{ # Verify and initialize device media if-defined
557323adacSDevin Teske		f_struct device_media &&
567323adacSDevin Teske		f_media_verify &&
577323adacSDevin Teske		f_device_init media
587323adacSDevin Teske	} || return $FAILURE
597323adacSDevin Teske}
607323adacSDevin Teske
617323adacSDevin Teske# f_media_close
627323adacSDevin Teske#
637323adacSDevin Teske# Shuts down the media device, see f_device_shutdown() from device.subr for
647323adacSDevin Teske# more details.
657323adacSDevin Teske#
667323adacSDevin Teskef_media_close()
677323adacSDevin Teske{
6880ae9845SDevin Teske	f_dprintf "f_media_close: Shutting down media device"
697323adacSDevin Teske	f_struct device_media &&
707323adacSDevin Teske		f_device_shutdown media
717323adacSDevin Teske	f_struct_free device_media
727323adacSDevin Teske}
737323adacSDevin Teske
747323adacSDevin Teske# f_media_verify
757323adacSDevin Teske#
767323adacSDevin Teske# Returns success if the media device is available, and if not, prompts the
777323adacSDevin Teske# user to select a media type. See f_media_get_type() from media/any.subr for
787323adacSDevin Teske# more details.
797323adacSDevin Teske#
807323adacSDevin Teskef_media_verify()
817323adacSDevin Teske{
8280ae9845SDevin Teske	f_dprintf "f_media_verify: Verifying media device"
837323adacSDevin Teske	f_struct device_media || f_media_get_type
847323adacSDevin Teske}
857323adacSDevin Teske
867323adacSDevin Teske# f_media_generic_get $base $file
877323adacSDevin Teske#
887323adacSDevin Teske# A generic open which follows a well-known "path" of places to look.
897323adacSDevin Teske#
907323adacSDevin Teskef_media_generic_get()
917323adacSDevin Teske{
9280ae9845SDevin Teske	local base="$1" file="$2"
937323adacSDevin Teske
9480ae9845SDevin Teske	local fname=f_media_generic_get
9580ae9845SDevin Teske	f_dprintf "%s: base=[%s] files=[%s]" $fname "$base" "$file"
9680ae9845SDevin Teske
9780ae9845SDevin Teske	local rel path
987323adacSDevin Teske	f_getvar $VAR_RELNAME rel
997323adacSDevin Teske	for path in \
1007323adacSDevin Teske		"$base/$file" \
1017323adacSDevin Teske		"$base/FreeBSD/$file" \
1027323adacSDevin Teske		"$base/releases/$file" \
1037323adacSDevin Teske		"$base/$rel/$file" \
1047323adacSDevin Teske	; do
1057323adacSDevin Teske		if [ -f "$path" -a -r "$path" ]; then
10680ae9845SDevin Teske			f_dprintf "%s: file exists path=[%s]" $fname "$path"
1077323adacSDevin Teske			cat "$path"
1087323adacSDevin Teske			return
1097323adacSDevin Teske		fi
1107323adacSDevin Teske	done
1117323adacSDevin Teske	cat "$base/releases/$rel/$file" # Final path to try
1127323adacSDevin Teske}
1137323adacSDevin Teske
1147323adacSDevin Teske############################################################ MAIN
1157323adacSDevin Teske
1167323adacSDevin Teskef_dprintf "%s: Successfully loaded." media/common.subr
1177323adacSDevin Teske
1187323adacSDevin Teskefi # ! $_MEDIA_COMMON_SUBR
119