1209513Simp#!/bin/sh 2209513Simp#- 3209552Simp# Copyright (c) 2010 iXsystems, 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: releng/10.2/usr.sbin/pc-sysinstall/backend/functions-installcomponents.sh 240165 2012-09-06 14:59:53Z jpaetzel $ 27209513Simp 28209513Simp# Functions which check and load any optional modules specified in the config 29209513Simp 30209513Simp. ${BACKEND}/functions.sh 31209513Simp. ${BACKEND}/functions-parse.sh 32209513Simp 33209513Simpcopy_component() 34209513Simp{ 35209513Simp COMPONENT="$1" 36209513Simp FAILED="0" 37209513Simp CFILES="" 38209513Simp 39209513Simp # Check the type, and set the components subdir properly 40209513Simp TYPE="`grep 'type:' ${COMPDIR}/${COMPONENT}/component.cfg | cut -d ' ' -f 2`" 41209513Simp if [ "${TYPE}" = "PBI" ] 42209513Simp then 43209513Simp SUBDIR="PBI" 44209513Simp else 45209513Simp SUBDIR="components" 46209513Simp fi 47209513Simp 48209513Simp # Lets start by downloading / copying the files this component needs 49209513Simp while read line 50209513Simp do 51209513Simp CFILE="`echo $line | cut -d ':' -f 1`" 52209513Simp CFILEMD5="`echo $line | cut -d ':' -f 2`" 53209513Simp CFILE2MD5="`echo $line | cut -d ':' -f 3`" 54209513Simp 55209513Simp case ${INSTALLMEDIUM} in 56211730Simp dvd|usb) 57211730Simp # On both dvd / usb, we can just copy the file 58211730Simp cp ${CDMNT}/${COMPFILEDIR}/${SUBDIR}/${CFILE} \ 59211730Simp ${FSMNT}/${COMPTMPDIR} >>${LOGOUT} 2>>${LOGOUT} 60209513Simp RESULT="$?" 61211730Simp ;; 62209513Simp 63212337Simp ftp) 64211730Simp get_value_from_cfg ftpPath 65211730Simp if [ -z "$VAL" ] 66211730Simp then 67211730Simp exit_err "ERROR: Install medium was set to ftp, but no ftpPath was provided!" 68211730Simp fi 69211730Simp FTPPATH="${VAL}" 70211730Simp 71211730Simp fetch_file "${FTPPATH}/${COMPFILEDIR}/${SUBDIR}/${CFILE}" "${FSMNT}/${COMPTMPDIR}/${CFILE}" "0" 72211730Simp RESULT="$?" 73211730Simp ;; 74240165Sjpaetzel local) 75240165Sjpaetzel get_value_from_cfg localPath 76240165Sjpaetzel if [ -z "$VAL" ]; then 77240165Sjpaetzel exit_err "Install medium was set to local, but no localPath was provided!" 78240165Sjpaetzel fi 79240165Sjpaetzel LOCALPATH=$VAL 80240165Sjpaetzel cp ${LOCALPATH}/${COMPFILEDIR}/${SUBDIR}/${CFILE} \ 81240165Sjpaetzel ${FSMNT}/${COMPTMPDIR} >>${LOGOUT} 2>>${LOGOUT} 82240165Sjpaetzel RESULT="$?" 83240165Sjpaetzel ;; 84209513Simp esac 85209513Simp 86209513Simp if [ "${RESULT}" != "0" ] 87209513Simp then 88209513Simp echo_log "WARNING: Failed to copy ${CFILE}" 89209513Simp FAILED="1" 90209513Simp else 91209513Simp # Now lets check the MD5 to confirm the file is valid 92209513Simp CHECKMD5=`md5 -q ${FSMNT}/${COMPTMPDIR}/${CFILE}` 93209513Simp if [ "${CHECKMD5}" != "${CFILEMD5}" -a "${CHECKMD5}" != "${CFILE2MD5}" ] 94209513Simp then 95209513Simp echo_log "WARNING: ${CFILE} failed md5 checksum" 96209513Simp FAILED="1" 97209513Simp else 98209513Simp if [ -z "${CFILES}" ] 99209513Simp then 100209513Simp CFILES="${CFILE}" 101209513Simp else 102209513Simp CFILES="${CFILES},${CFILE}" 103209513Simp fi 104209513Simp fi 105209513Simp fi 106209513Simp 107209513Simp 108209513Simp done < ${COMPDIR}/${COMPONENT}/distfiles 109209513Simp 110209513Simp if [ "${FAILED}" = "0" ] 111209513Simp then 112209513Simp # Now install the component 113209513Simp run_component_install ${COMPONENT} ${CFILES} 114209513Simp fi 115209513Simp 116209513Simp}; 117209513Simp 118209513Simprun_component_install() 119209513Simp{ 120209513Simp COMPONENT="$1" 121209513Simp CFILES="$1" 122209513Simp 123209513Simp # Lets install this component now 124209513Simp # Start by making a wrapper script which sets the variables 125209513Simp # for the component to use 126209513Simp echo "#!/bin/sh 127209513SimpCOMPTMPDIR=\"${COMPTMPDIR}\" 128209513Simpexport COMPTMPDIR 129209513SimpCFILE=\"${CFILE}\" 130209513Simpexport CFILE 131222078Sjpaetzelmount -t devfs devfs /dev 132209513Simp 133209513Simpsh ${COMPTMPDIR}/install.sh 134209513Simp 135222078Sjpaetzelumount /dev 136209513Simp" >${FSMNT}/.componentwrapper.sh 137211730Simp chmod 755 ${FSMNT}/.componentwrapper.sh 138209513Simp 139211730Simp # Copy over the install script for this component 140211730Simp cp ${COMPDIR}/${COMPONENT}/install.sh ${FSMNT}/${COMPTMPDIR}/ 141209513Simp 142211730Simp echo_log "INSTALL COMPONENT: ${i}" 143211730Simp chroot ${FSMNT} /.componentwrapper.sh >>${LOGOUT} 2>>${LOGOUT} 144211730Simp rm ${FSMNT}/.componentwrapper.sh 145209513Simp 146209513Simp}; 147209513Simp 148209513Simp# Check for any modules specified, and begin loading them 149209513Simpinstall_components() 150209513Simp{ 151211730Simp # First, lets check and see if we even have any optional modules 152211730Simp get_value_from_cfg installComponents 153220059Sjpaetzel if [ -n "${VAL}" ] 154211730Simp then 155211730Simp # Lets start by cleaning up the string and getting it ready to parse 156211730Simp strip_white_space ${VAL} 157211730Simp COMPONENTS=`echo ${VAL} | sed -e "s|,| |g"` 158211730Simp for i in $COMPONENTS 159211730Simp do 160211730Simp if [ ! -e "${COMPDIR}/${i}/install.sh" -o ! -e "${COMPDIR}/${i}/distfiles" ] 161211730Simp then 162211730Simp echo_log "WARNING: Component ${i} doesn't seem to exist" 163211730Simp else 164209513Simp 165211730Simp # Make the tmpdir on the disk 166211730Simp mkdir -p ${FSMNT}/${COMPTMPDIR} >>${LOGOUT} 2>>${LOGOUT} 167209513Simp 168211730Simp # Start by grabbing the component files 169211730Simp copy_component ${i} 170209513Simp 171211730Simp # Remove the tmpdir now 172211730Simp rm -rf ${FSMNT}/${COMPTMPDIR} >>${LOGOUT} 2>>${LOGOUT} 173211730Simp fi 174211730Simp done 175211730Simp fi 176209513Simp 177209513Simp}; 178