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