functions-mountoptical.sh revision 209513
1209513Simp#!/bin/sh 2209513Simp#- 3209513Simp# Copyright (c) 2010 iX Systems, Inc. All rights reserved. 4209513Simp# 5209513Simp# Redistribution and use in source and binary forms, with or without 6209513Simp# modification, are permitted provided that the following conditions 7209513Simp# are met: 8209513Simp# 1. Redistributions of source code must retain the above copyright 9209513Simp# notice, this list of conditions and the following disclaimer. 10209513Simp# 2. Redistributions in binary form must reproduce the above copyright 11209513Simp# notice, this list of conditions and the following disclaimer in the 12209513Simp# documentation and/or other materials provided with the distribution. 13209513Simp# 14209513Simp# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15209513Simp# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16209513Simp# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17209513Simp# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18209513Simp# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19209513Simp# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20209513Simp# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21209513Simp# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22209513Simp# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23209513Simp# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24209513Simp# SUCH DAMAGE. 25209513Simp# 26209513Simp# $FreeBSD: head/usr.sbin/pc-sysinstall/backend/functions-mountoptical.sh 209513 2010-06-24 22:21:47Z imp $ 27209513Simp 28209513Simp# Functions which perform mounting / unmounting and switching of 29209513Simp# optical / usb media 30209513Simp 31209513Simp. ${BACKEND}/functions.sh 32209513Simp. ${BACKEND}/functions-parse.sh 33209513Simp 34209513Simp# Displays an optical failure message 35209513Simpopt_fail() 36209513Simp{ 37209513Simp # If we got here, we must not have a DVD/USB we can find :( 38209513Simp get_value_from_cfg installInteractive 39209513Simp if [ "${VAL}" = "yes" ] 40209513Simp then 41209513Simp # We are running interactive, and didn't find a DVD, prompt user again 42209513Simp echo_log "DISK ERROR: Unable to find installation disk!" 43209513Simp echo_log "Please insert the installation disk and press enter." 44209513Simp read tmp 45209513Simp else 46209513Simp exit_err "ERROR: Unable to locate installation DVD/USB" 47209513Simp fi 48209513Simp}; 49209513Simp 50209513Simp# Performs the extraction of data to disk 51209513Simpopt_mount() 52209513Simp{ 53209513Simp FOUND="0" 54209513Simp 55209513Simp # Ensure we have a directory where its supposed to be 56209513Simp if [ ! -d "${CDMNT}" ] 57209513Simp then 58209513Simp mkdir -p ${CDMNT} 59209513Simp fi 60209513Simp 61209513Simp 62209513Simp # Start by checking if we already have a cd mounted at CDMNT 63209513Simp mount | grep "${CDMNT} " >/dev/null 2>/dev/null 64209513Simp if [ "$?" = "0" ] 65209513Simp then 66209513Simp if [ -e "${CDMNT}/${INSFILE}" ] 67209513Simp then 68209513Simp echo "MOUNTED" >${TMPDIR}/cdmnt 69209513Simp echo_log "FOUND DVD: MOUNTED" 70209513Simp FOUND="1" 71209513Simp return 72209513Simp fi 73209513Simp 74209513Simp # failed to find optical disk 75209513Simp opt_fail 76209513Simp return 77209513Simp fi 78209513Simp 79209513Simp# Setup our loop to search for installation media 80209513Simp while 81209513Simp z=1 82209513Simp do 83209513Simp 84209513Simp # Loop though and look for an installation disk 85209513Simp for i in `ls -1 /dev/acd* /dev/cd* /dev/scd* /dev/rscd* 2>/dev/null` 86209513Simp do 87209513Simp # Find the CD Device 88209513Simp /sbin/mount_cd9660 $i ${CDMNT} 89209513Simp 90209513Simp # Check the package type to see if we have our install data 91209513Simp if [ -e "${CDMNT}/${INSFILE}" ] 92209513Simp then 93209513Simp echo "${i}" >${TMPDIR}/cdmnt 94209513Simp echo_log "FOUND DVD: ${i}" 95209513Simp FOUND="1" 96209513Simp break 97209513Simp fi 98209513Simp /sbin/umount ${CDMNT} >/dev/null 2>/dev/null 99209513Simp done 100209513Simp 101209513Simp # If no DVD found, try USB 102209513Simp if [ "$FOUND" != "1" ] 103209513Simp then 104209513Simp # Loop though and look for an installation disk 105209513Simp for i in `ls -1 /dev/da* 2>/dev/null` 106209513Simp do 107209513Simp # Check if we can mount this device UFS 108209513Simp /sbin/mount -r $i ${CDMNT} 109209513Simp 110209513Simp # Check the package type to see if we have our install data 111209513Simp if [ -e "${CDMNT}/${INSFILE}" ] 112209513Simp then 113209513Simp echo "${i}" >${TMPDIR}/cdmnt 114209513Simp echo_log "FOUND USB: ${i}" 115209513Simp FOUND="1" 116209513Simp break 117209513Simp fi 118209513Simp /sbin/umount ${CDMNT} >/dev/null 2>/dev/null 119209513Simp 120209513Simp # Also check if it is a FAT mount 121209513Simp /sbin/mount -r -t msdosfs $i ${CDMNT} 122209513Simp 123209513Simp # Check the package type to see if we have our install data 124209513Simp if [ -e "${CDMNT}/${INSFILE}" ] 125209513Simp then 126209513Simp echo "${i}" >${TMPDIR}/cdmnt 127209513Simp echo_log "FOUND USB: ${i}" 128209513Simp FOUND="1" 129209513Simp break 130209513Simp fi 131209513Simp /sbin/umount ${CDMNT} >/dev/null 2>/dev/null 132209513Simp done 133209513Simp fi # End of USB Check 134209513Simp 135209513Simp 136209513Simp if [ "$FOUND" = "1" ] 137209513Simp then 138209513Simp break 139209513Simp fi 140209513Simp 141209513Simp # Failed to find a disk, take action now 142209513Simp opt_fail 143209513Simp 144209513Simp done 145209513Simp 146209513Simp}; 147209513Simp 148209513Simp# Function to unmount optical media 149209513Simpopt_umount() 150209513Simp{ 151209513Simp /sbin/umount ${CDMNT} >/dev/null 2>/dev/null 152209513Simp}; 153209513Simp 154