1#!/bin/sh 2#- 3# SPDX-License-Identifier: BSD-2-Clause-FreeBSD 4# 5# Copyright (c) 2010 iXsystems, Inc. All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# 2. Redistributions in binary form must reproduce the above copyright 13# notice, this list of conditions and the following disclaimer in the 14# documentation and/or other materials provided with the distribution. 15# 16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26# SUCH DAMAGE. 27# 28# $FreeBSD$ 29 30# Functions which perform mounting / unmounting and switching of 31# optical / usb media 32 33. ${BACKEND}/functions.sh 34. ${BACKEND}/functions-parse.sh 35 36# Displays an optical failure message 37opt_fail() 38{ 39 # If we got here, we must not have a DVD/USB we can find :( 40 get_value_from_cfg installInteractive 41 if [ "${VAL}" = "yes" ] 42 then 43 # We are running interactive, and didn't find a DVD, prompt user again 44 echo_log "DISK ERROR: Unable to find installation disk!" 45 echo_log "Please insert the installation disk and press enter." 46 read tmp 47 else 48 exit_err "ERROR: Unable to locate installation DVD/USB" 49 fi 50}; 51 52# Performs the extraction of data to disk 53opt_mount() 54{ 55 FOUND="0" 56 57 # Ensure we have a directory where its supposed to be 58 if [ ! -d "${CDMNT}" ] 59 then 60 mkdir -p ${CDMNT} 61 fi 62 63 64 # Start by checking if we already have a cd mounted at CDMNT 65 mount | grep -q "${CDMNT} " 2>/dev/null 66 if [ $? -eq 0 ] 67 then 68 if [ -e "${CDMNT}/${INSFILE}" ] 69 then 70 echo "MOUNTED" >${TMPDIR}/cdmnt 71 echo_log "FOUND DVD: MOUNTED" 72 FOUND="1" 73 return 74 fi 75 76 # failed to find optical disk 77 opt_fail 78 return 79 fi 80 81 # Setup our loop to search for installation media 82 while 83 z=1 84 do 85 86 # Loop though and look for an installation disk 87 for i in `ls -1 /dev/cd* 2>/dev/null` 88 do 89 # Find the CD Device 90 /sbin/mount_cd9660 $i ${CDMNT} 91 92 # Check the package type to see if we have our install data 93 if [ -e "${CDMNT}/${INSFILE}" ] 94 then 95 echo "${i}" >${TMPDIR}/cdmnt 96 echo_log "FOUND DVD: ${i}" 97 FOUND="1" 98 break 99 fi 100 /sbin/umount ${CDMNT} >/dev/null 2>/dev/null 101 done 102 103 # If no DVD found, try USB 104 if [ "$FOUND" != "1" ] 105 then 106 # Loop though and look for an installation disk 107 for i in `ls -1 /dev/da* 2>/dev/null` 108 do 109 # Check if we can mount this device UFS 110 /sbin/mount -r $i ${CDMNT} 111 112 # Check the package type to see if we have our install data 113 if [ -e "${CDMNT}/${INSFILE}" ] 114 then 115 echo "${i}" >${TMPDIR}/cdmnt 116 echo_log "FOUND USB: ${i}" 117 FOUND="1" 118 break 119 fi 120 /sbin/umount ${CDMNT} >/dev/null 2>/dev/null 121 122 # Also check if it is a FAT mount 123 /sbin/mount -r -t msdosfs $i ${CDMNT} 124 125 # Check the package type to see if we have our install data 126 if [ -e "${CDMNT}/${INSFILE}" ] 127 then 128 echo "${i}" >${TMPDIR}/cdmnt 129 echo_log "FOUND USB: ${i}" 130 FOUND="1" 131 break 132 fi 133 /sbin/umount ${CDMNT} >/dev/null 2>/dev/null 134 done 135 fi # End of USB Check 136 137 138 if [ "$FOUND" = "1" ] 139 then 140 break 141 fi 142 143 # Failed to find a disk, take action now 144 opt_fail 145 146 done 147 148}; 149 150# Function to unmount optical media 151opt_umount() 152{ 153 /sbin/umount ${CDMNT} >/dev/null 2>/dev/null 154}; 155