common.subr revision 247280
1if [ ! "$_MEDIA_COMMON_SUBR" ]; then _MEDIA_COMMON_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 (INLUDING, 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: head/usr.sbin/bsdconfig/share/media/common.subr 247280 2013-02-25 19:55:32Z dteske $ 28# 29############################################################ INCLUDES 30 31BSDCFG_SHARE="/usr/share/bsdconfig" 32. $BSDCFG_SHARE/common.subr || exit 1 33f_dprintf "%s: loading includes..." media/common.subr 34f_include $BSDCFG_SHARE/struct.subr 35f_include $BSDCFG_SHARE/device.subr 36 37############################################################ GLOBALS 38 39# 40# Where to mount media 41# 42MOUNTPOINT=/dist 43 44############################################################ FUNCTIONS 45 46# f_media_open 47# 48# Returms success if able to initialize the media device. 49# 50f_media_open() 51{ 52 { # Verify and initialize device media if-defined 53 f_struct device_media && 54 f_media_verify && 55 f_device_init media 56 } || return $FAILURE 57} 58 59# f_media_close 60# 61# Shuts down the media device, see f_device_shutdown() from device.subr for 62# more details. 63# 64f_media_close() 65{ 66 f_struct device_media && 67 f_device_shutdown media 68 f_struct_free device_media 69} 70 71# f_media_verify 72# 73# Returns success if the media device is available, and if not, prompts the 74# user to select a media type. See f_media_get_type() from media/any.subr for 75# more details. 76# 77f_media_verify() 78{ 79 f_struct device_media || f_media_get_type 80} 81 82# f_media_generic_get $base $file 83# 84# A generic open which follows a well-known "path" of places to look. 85# 86f_media_generic_get() 87{ 88 local base="$1" file="$2" rel path 89 90 f_getvar $VAR_RELNAME rel 91 for path in \ 92 "$base/$file" \ 93 "$base/FreeBSD/$file" \ 94 "$base/releases/$file" \ 95 "$base/$rel/$file" \ 96 ; do 97 if [ -f "$path" -a -r "$path" ]; then 98 cat "$path" 99 return 100 fi 101 done 102 cat "$base/releases/$rel/$file" # Final path to try 103} 104 105############################################################ MAIN 106 107f_dprintf "%s: Successfully loaded." media/common.subr 108 109fi # ! $_MEDIA_COMMON_SUBR 110