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.3/usr.sbin/pc-sysinstall/backend/functions-extractimage.sh 247705 2013-03-03 09:47:47Z jpaetzel $
27209513Simp
28209513Simp# Functions which perform the extraction / installation of system to disk
29209513Simp
30209513Simp. ${BACKEND}/functions-mountoptical.sh
31209513Simp
32247705Sjpaetzel# Performs the extraction of data to disk from FreeBSD dist files
33247705Sjpaetzelstart_extract_dist()
34247705Sjpaetzel{
35247705Sjpaetzel  if [ -z "$1" ] ; then exit_err "Called dist extraction with no directory set!"; fi
36247705Sjpaetzel  if [ -z "$INSFILE" ]; then exit_err "Called extraction with no install file set!"; fi
37247705Sjpaetzel  local DDIR="$1"
38247705Sjpaetzel
39247705Sjpaetzel  # Check if we are doing an upgrade, and if so use our exclude list
40247705Sjpaetzel  if [ "${INSTALLMODE}" = "upgrade" ]; then
41247705Sjpaetzel   TAROPTS="-X ${PROGDIR}/conf/exclude-from-upgrade"
42247705Sjpaetzel  else
43247705Sjpaetzel   TAROPTS=""
44247705Sjpaetzel  fi
45247705Sjpaetzel
46247705Sjpaetzel  # Loop though and extract dist files
47247705Sjpaetzel  for di in $INSFILE
48247705Sjpaetzel  do
49247705Sjpaetzel      # Check the MANIFEST see if we have an archive size / count
50247705Sjpaetzel      if [ -e "${DDIR}/MANIFEST" ]; then 
51247705Sjpaetzel         count=`grep "^${di}.txz" ${DDIR}/MANIFEST | awk '{print $3}'`
52247705Sjpaetzel	 if [ ! -z "$count" ] ; then
53247705Sjpaetzel            echo "INSTALLCOUNT: $count"
54247705Sjpaetzel	 fi
55247705Sjpaetzel      fi
56247705Sjpaetzel      echo_log "pc-sysinstall: Starting Extraction (${di})"
57247705Sjpaetzel      tar -xpv -C ${FSMNT} -f ${DDIR}/${di}.txz ${TAROPTS} >&1 2>&1
58247705Sjpaetzel      if [ $? -ne 0 ]; then
59247705Sjpaetzel        exit_err "ERROR: Failed extracting the dist file: $di"
60247705Sjpaetzel      fi
61247705Sjpaetzel  done
62247705Sjpaetzel
63247705Sjpaetzel  # Check if this was a FTP download and clean it up now
64247705Sjpaetzel  if [ "${INSTALLMEDIUM}" = "ftp" ]; then
65247705Sjpaetzel    echo_log "Cleaning up downloaded archives"
66247705Sjpaetzel    rm -rf ${DDIR}
67247705Sjpaetzel  fi
68247705Sjpaetzel
69247705Sjpaetzel  echo_log "pc-sysinstall: Extraction Finished"
70247705Sjpaetzel}
71247705Sjpaetzel
72209513Simp# Performs the extraction of data to disk from a uzip or tar archive
73209513Simpstart_extract_uzip_tar()
74209513Simp{
75247705Sjpaetzel  if [ -z "$INSFILE" ]; then
76209513Simp    exit_err "ERROR: Called extraction with no install file set!"
77209513Simp  fi
78209513Simp
79209513Simp  # Check if we have a .count file, and echo it out for a front-end to use in progress bars
80247705Sjpaetzel  if [ -e "${INSFILE}.count" ]; then
81209513Simp    echo "INSTALLCOUNT: `cat ${INSFILE}.count`"
82209513Simp  fi
83209513Simp
84209513Simp  # Check if we are doing an upgrade, and if so use our exclude list
85247705Sjpaetzel  if [ "${INSTALLMODE}" = "upgrade" ]; then
86209513Simp   TAROPTS="-X ${PROGDIR}/conf/exclude-from-upgrade"
87209513Simp  else
88209513Simp   TAROPTS=""
89209513Simp  fi
90209513Simp
91209513Simp  echo_log "pc-sysinstall: Starting Extraction"
92209513Simp
93209513Simp  case ${PACKAGETYPE} in
94211730Simp    uzip)
95225657Sjpaetzel      if ! kldstat -v | grep -q "geom_uzip" ; then
96225657Sjpaetzel	exit_err "Kernel module geom_uzip not loaded"
97225657Sjpaetzel      fi
98225657Sjpaetzel
99211730Simp	  # Start by mounting the uzip image
100211730Simp      MDDEVICE=`mdconfig -a -t vnode -o readonly -f ${INSFILE}`
101211730Simp      mkdir -p ${FSMNT}.uzip
102211730Simp      mount -r /dev/${MDDEVICE}.uzip ${FSMNT}.uzip
103220059Sjpaetzel      if [ $? -ne 0 ]
104211730Simp      then
105211730Simp        exit_err "ERROR: Failed mounting the ${INSFILE}"
106211730Simp      fi
107211730Simp      cd ${FSMNT}.uzip
108209513Simp
109211730Simp      # Copy over all the files now!
110211730Simp      tar cvf - . 2>/dev/null | tar -xpv -C ${FSMNT} ${TAROPTS} -f - 2>&1 | tee -a ${FSMNT}/.tar-extract.log
111220059Sjpaetzel      if [ $? -ne 0 ]
112211730Simp      then
113211730Simp        cd /
114214189Simp        echo "TAR failure occurred:" >>${LOGOUT}
115211730Simp        cat ${FSMNT}/.tar-extract.log | grep "tar:" >>${LOGOUT}
116211730Simp        umount ${FSMNT}.uzip
117211730Simp        mdconfig -d -u ${MDDEVICE}
118211730Simp        exit_err "ERROR: Failed extracting the tar image"
119211730Simp      fi
120209513Simp
121211730Simp      # All finished, now lets umount and cleanup
122211730Simp      cd /
123211730Simp      umount ${FSMNT}.uzip
124211730Simp      mdconfig -d -u ${MDDEVICE}
125211730Simp       ;;
126211730Simp    tar)
127247705Sjpaetzel      tar -xpv -C ${FSMNT} -f ${INSFILE} ${TAROPTS} >&1 2>&1
128247705Sjpaetzel      if [ $? -ne 0 ]; then
129211730Simp        exit_err "ERROR: Failed extracting the tar image"
130211730Simp      fi
131211730Simp      ;;
132209513Simp  esac
133209513Simp
134209513Simp  # Check if this was a FTP download and clean it up now
135209513Simp  if [ "${INSTALLMEDIUM}" = "ftp" ]
136209513Simp  then
137209513Simp    echo_log "Cleaning up downloaded archive"
138209513Simp    rm ${INSFILE} 
139209513Simp    rm ${INSFILE}.count >/dev/null 2>/dev/null 
140209513Simp    rm ${INSFILE}.md5 >/dev/null 2>/dev/null
141209513Simp  fi
142209513Simp
143209513Simp  echo_log "pc-sysinstall: Extraction Finished"
144209513Simp
145209513Simp};
146209513Simp
147209513Simp# Performs the extraction of data to disk from a directory with split files
148209513Simpstart_extract_split()
149209513Simp{
150209513Simp  if [ -z "${INSDIR}" ]
151209513Simp  then
152209513Simp    exit_err "ERROR: Called extraction with no install directory set!"
153209513Simp  fi
154209513Simp
155209513Simp  echo_log "pc-sysinstall: Starting Extraction"
156209513Simp
157209513Simp  # Used by install.sh
158209513Simp  DESTDIR="${FSMNT}"
159209513Simp  export DESTDIR
160209513Simp
161209513Simp  HERE=`pwd`
162209513Simp  DIRS=`ls -d ${INSDIR}/*|grep -Ev '(uzip|kernels|src)'`
163209513Simp  for dir in ${DIRS}
164209513Simp  do
165211730Simp    cd "${dir}"
166211730Simp    if [ -f "install.sh" ]
167211730Simp    then
168211730Simp      echo_log "Extracting" `basename ${dir}`
169209513Simp      echo "y" | sh install.sh >/dev/null
170220059Sjpaetzel      if [ $? -ne 0 ]
171209513Simp      then
172209513Simp        exit_err "ERROR: Failed extracting ${dir}"
173209513Simp      fi
174209513Simp    else
175209513Simp      exit_err "ERROR: ${dir}/install.sh does not exist"
176209513Simp    fi
177209513Simp  done
178209513Simp  cd "${HERE}"
179209513Simp  
180209513Simp  KERNELS=`ls -d ${INSDIR}/*|grep kernels`
181209513Simp  cd "${KERNELS}"
182209513Simp  if [ -f "install.sh" ]
183209513Simp  then
184211730Simp    echo_log "Extracting" `basename ${KERNELS}`
185209513Simp    echo "y" | sh install.sh generic >/dev/null
186220059Sjpaetzel    if [ $? -ne 0 ]
187209513Simp    then
188209513Simp      exit_err "ERROR: Failed extracting ${KERNELS}"
189209513Simp    fi
190213650Simp    rm -rf "${FSMNT}/boot/kernel"
191211730Simp    mv "${FSMNT}/boot/GENERIC" "${FSMNT}/boot/kernel"
192209513Simp  else
193209513Simp    exit_err "ERROR: ${KERNELS}/install.sh does not exist"
194209513Simp  fi
195209513Simp  cd "${HERE}"
196209513Simp
197209513Simp  SOURCE=`ls -d ${INSDIR}/*|grep src`
198209513Simp  cd "${SOURCE}"
199209513Simp  if [ -f "install.sh" ]
200209513Simp  then
201211730Simp    echo_log "Extracting" `basename ${SOURCE}`
202209513Simp    echo "y" | sh install.sh all >/dev/null
203220059Sjpaetzel    if [ $? -ne 0 ]
204209513Simp    then
205209513Simp      exit_err "ERROR: Failed extracting ${SOURCE}"
206209513Simp    fi
207209513Simp  else
208209513Simp    exit_err "ERROR: ${SOURCE}/install.sh does not exist"
209209513Simp  fi
210209513Simp  cd "${HERE}"
211209513Simp
212209513Simp  echo_log "pc-sysinstall: Extraction Finished"
213209513Simp};
214209513Simp
215247705Sjpaetzel# Function which will attempt to fetch the dist file(s) before we start
216247705Sjpaetzelfetch_dist_file()
217247705Sjpaetzel{
218247705Sjpaetzel  get_value_from_cfg ftpPath
219247705Sjpaetzel  if [ -z "$VAL" ]
220247705Sjpaetzel  then
221247705Sjpaetzel    exit_err "ERROR: Install medium was set to ftp, but no ftpPath was provided!" 
222247705Sjpaetzel  fi
223247705Sjpaetzel
224247705Sjpaetzel  FTPPATH="${VAL}"
225247705Sjpaetzel  
226247705Sjpaetzel  # Check if we have a /usr partition to save the download
227247705Sjpaetzel  if [ -d "${FSMNT}/usr" ]
228247705Sjpaetzel  then
229247705Sjpaetzel    DLDIR="${FSMNT}/usr/.fetch.$$"
230247705Sjpaetzel  else
231247705Sjpaetzel    DLDIR="${FSMNT}/.fetch.$$"
232247705Sjpaetzel  fi
233247705Sjpaetzel  mkdir -p ${DLDIR}
234247705Sjpaetzel
235247705Sjpaetzel  # Do the fetch of the dist archive(s) now
236247705Sjpaetzel  for di in $INSFILE
237247705Sjpaetzel  do
238247705Sjpaetzel    fetch_file "${FTPPATH}/${di}.txz" "${DLDIR}/${di}.txz" "1"
239247705Sjpaetzel  done
240247705Sjpaetzel
241247705Sjpaetzel  # Check to see if there is a MANIFEST file for this install
242247705Sjpaetzel  fetch_file "${FTPPATH}/MANIFEST" "${DLDIR}/MANIFEST" "0"
243247705Sjpaetzel
244247705Sjpaetzel  export DLDIR
245247705Sjpaetzel};
246247705Sjpaetzel
247209513Simp# Function which will attempt to fetch the install file before we start
248209513Simp# the install
249209513Simpfetch_install_file()
250209513Simp{
251209513Simp  get_value_from_cfg ftpPath
252209513Simp  if [ -z "$VAL" ]
253209513Simp  then
254209513Simp    exit_err "ERROR: Install medium was set to ftp, but no ftpPath was provided!" 
255209513Simp  fi
256209513Simp
257209513Simp  FTPPATH="${VAL}"
258209513Simp  
259209513Simp  # Check if we have a /usr partition to save the download
260209513Simp  if [ -d "${FSMNT}/usr" ]
261209513Simp  then
262209513Simp    OUTFILE="${FSMNT}/usr/.fetch-${INSFILE}"
263209513Simp  else
264209513Simp    OUTFILE="${FSMNT}/.fetch-${INSFILE}"
265209513Simp  fi
266209513Simp
267209513Simp  # Do the fetch of the archive now
268209513Simp  fetch_file "${FTPPATH}/${INSFILE}" "${OUTFILE}" "1"
269209513Simp
270209513Simp  # Check to see if there is a .count file for this install
271209513Simp  fetch_file "${FTPPATH}/${INSFILE}.count" "${OUTFILE}.count" "0"
272209513Simp
273209513Simp  # Check to see if there is a .md5 file for this install
274209513Simp  fetch_file "${FTPPATH}/${INSFILE}.md5" "${OUTFILE}.md5" "0"
275209513Simp
276209513Simp  # Done fetching, now reset the INSFILE to our downloaded archived
277220059Sjpaetzel  export INSFILE="${OUTFILE}"
278209513Simp
279209513Simp};
280209513Simp
281211486Simp# Function which will download freebsd install files
282211486Simpfetch_split_files()
283211486Simp{
284211730Simp  get_ftpHost
285211486Simp  if [ -z "$VAL" ]
286211486Simp  then
287211486Simp    exit_err "ERROR: Install medium was set to ftp, but no ftpHost was provided!" 
288211486Simp  fi
289211486Simp  FTPHOST="${VAL}"
290211486Simp
291211730Simp  get_ftpDir
292211486Simp  if [ -z "$VAL" ]
293211486Simp  then
294211486Simp    exit_err "ERROR: Install medium was set to ftp, but no ftpDir was provided!" 
295211486Simp  fi
296211486Simp  FTPDIR="${VAL}"
297211486Simp
298211486Simp  # Check if we have a /usr partition to save the download
299211486Simp  if [ -d "${FSMNT}/usr" ]
300211486Simp  then
301211486Simp    OUTFILE="${FSMNT}/usr/.fetch-${INSFILE}"
302211486Simp  else
303211486Simp    OUTFILE="${FSMNT}/.fetch-${INSFILE}"
304211486Simp  fi
305211486Simp
306211730Simp  DIRS="base catpages dict doc games info manpages proflibs kernels src"
307211730Simp  if [ "${FBSD_ARCH}" = "amd64" ]
308211730Simp  then
309211730Simp    DIRS="${DIRS} lib32"
310211730Simp  fi
311211730Simp
312211730Simp  for d in ${DIRS}
313211730Simp  do
314211730Simp    mkdir -p "${OUTFILE}/${d}"
315211730Simp  done
316211730Simp
317211730Simp
318211486Simp  NETRC="${OUTFILE}/.netrc"
319220059Sjpaetzel  cat <<EOF >"${NETRC}"
320211486Simpmachine ${FTPHOST}
321211486Simplogin anonymous
322211486Simppassword anonymous
323211486Simpmacdef INSTALL
324211486Simpbin
325211486Simpprompt
326211486SimpEOF
327211486Simp
328211486Simp  for d in ${DIRS}
329211486Simp  do
330220059Sjpaetzel    cat <<EOF >>"${NETRC}"
331211486Simpcd ${FTPDIR}/${d}
332211486Simplcd ${OUTFILE}/${d}
333211486Simpmreget *
334211486SimpEOF
335211486Simp  done
336211486Simp
337220059Sjpaetzel  cat <<EOF >>"${NETRC}"
338211486Simpbye
339211486Simp
340211486Simp
341211486SimpEOF
342211486Simp
343211487Simp  # Fetch the files via ftp
344211487Simp  echo "$ INSTALL" | ftp -N "${NETRC}" "${FTPHOST}"
345211486Simp
346211486Simp  # Done fetching, now reset the INSFILE to our downloaded archived
347220059Sjpaetzel  export INSFILE="${OUTFILE}"
348211486Simp}
349211486Simp
350214189Simp# Function which does the rsync download from the server specified in cfg
351209513Simpstart_rsync_copy()
352209513Simp{
353209513Simp  # Load our rsync config values
354209513Simp  get_value_from_cfg rsyncPath
355209513Simp  if [ -z "${VAL}" ]; then
356209513Simp    exit_err "ERROR: rsyncPath is unset! Please check your config and try again."
357209513Simp  fi
358220059Sjpaetzel  export RSYNCPATH="${VAL}"
359209513Simp
360209513Simp  get_value_from_cfg rsyncHost
361209513Simp  if [  -z "${VAL}" ]; then
362209513Simp    exit_err "ERROR: rsyncHost is unset! Please check your config and try again."
363209513Simp  fi
364220059Sjpaetzel  export RSYNCHOST="${VAL}"
365209513Simp
366209513Simp  get_value_from_cfg rsyncUser
367209513Simp  if [ -z "${VAL}" ]; then
368209513Simp    exit_err "ERROR: rsyncUser is unset! Please check your config and try again."
369209513Simp  fi
370220059Sjpaetzel  export RSYNCUSER="${VAL}"
371209513Simp
372209513Simp  get_value_from_cfg rsyncPort
373209513Simp  if [ -z "${VAL}" ]; then
374209513Simp    exit_err "ERROR: rsyncPort is unset! Please check your config and try again."
375209513Simp  fi
376220059Sjpaetzel  export RSYNCPORT="${VAL}"
377209513Simp
378220059Sjpaetzel  COUNT=1
379209513Simp  while
380209513Simp  z=1
381209513Simp  do
382209513Simp    if [ ${COUNT} -gt ${RSYNCTRIES} ]
383209513Simp    then
384209513Simp     exit_err "ERROR: Failed rsync command!"
385209513Simp     break
386209513Simp    fi
387209513Simp
388209513Simp    rsync -avvzHsR \
389209513Simp    --rsync-path="rsync --fake-super" \
390209513Simp    -e "ssh -p ${RSYNCPORT}" \
391209513Simp    ${RSYNCUSER}@${RSYNCHOST}:${RSYNCPATH}/./ ${FSMNT}
392220059Sjpaetzel    if [ $? -ne 0 ]
393209513Simp    then
394209513Simp      echo "Rsync failed! Tries: ${COUNT}"
395209513Simp    else
396209513Simp      break
397209513Simp    fi
398209513Simp
399220059Sjpaetzel    COUNT=$((COUNT+1))
400209513Simp  done 
401209513Simp
402209513Simp};
403209513Simp
404213650Simpstart_image_install()
405213650Simp{
406213650Simp  if [ -z "${IMAGE_FILE}" ]
407213650Simp  then
408213650Simp    exit_err "ERROR: installMedium set to image but no image file specified!"
409213650Simp  fi
410209513Simp
411213650Simp  # We are ready to start mounting, lets read the config and do it
412213650Simp  while read line
413213650Simp  do
414220059Sjpaetzel    echo $line | grep -q "^disk0=" 2>/dev/null
415220059Sjpaetzel    if [ $? -eq 0 ]
416213650Simp    then
417213650Simp      # Found a disk= entry, lets get the disk we are working on
418213650Simp      get_value_from_string "${line}"
419213650Simp      strip_white_space "$VAL"
420213650Simp      DISK="$VAL"
421213650Simp    fi
422213650Simp
423220059Sjpaetzel    echo $line | grep -q "^commitDiskPart" 2>/dev/null
424220059Sjpaetzel    if [ $? -eq 0 ]
425213650Simp    then
426213650Simp      # Found our flag to commit this disk setup / lets do sanity check and do it
427220059Sjpaetzel      if [ -n "${DISK}" ]
428213650Simp      then
429213650Simp
430213650Simp        # Write the image
431213650Simp        write_image "${IMAGE_FILE}" "${DISK}"
432213650Simp
433213650Simp        # Increment our disk counter to look for next disk and unset
434213650Simp        unset DISK
435213650Simp        break
436213650Simp
437213650Simp      else
438213650Simp        exit_err "ERROR: commitDiskPart was called without procceding disk<num>= and partition= entries!!!"
439213650Simp      fi
440213650Simp    fi
441213650Simp
442213650Simp  done <${CFGF}
443213650Simp};
444213650Simp
445209513Simp# Entrance function, which starts the installation process
446209513Simpinit_extraction()
447209513Simp{
448209513Simp  # Figure out what file we are using to install from via the config
449209513Simp  get_value_from_cfg installFile
450209513Simp
451220059Sjpaetzel  if [ -n "${VAL}" ]
452209513Simp  then
453220059Sjpaetzel    export INSFILE="${VAL}"
454209513Simp  else
455209513Simp    # If no installFile specified, try our defaults
456209513Simp    if [ "$INSTALLTYPE" = "FreeBSD" ]
457209513Simp    then
458209513Simp      case $PACKAGETYPE in
459211730Simp        uzip) INSFILE="${FBSD_UZIP_FILE}" ;;
460211730Simp        tar) INSFILE="${FBSD_TAR_FILE}" ;;
461247705Sjpaetzel        dist) 
462247705Sjpaetzel	  get_value_from_cfg_with_spaces distFiles
463247705Sjpaetzel	  if [ -z "$VAL" ] ; then
464247705Sjpaetzel	     exit_err "No dist files specified!"
465247705Sjpaetzel	  fi
466247705Sjpaetzel	  INSFILE="${VAL}" 
467247705Sjpaetzel  	  ;;
468211730Simp        split)
469211730Simp          INSDIR="${FBSD_BRANCH_DIR}"
470209513Simp
471211730Simp          # This is to trick opt_mount into not failing
472211730Simp          INSFILE="${INSDIR}"
473211730Simp          ;;
474209513Simp      esac
475209513Simp    else
476209513Simp      case $PACKAGETYPE in
477211730Simp        uzip) INSFILE="${UZIP_FILE}" ;;
478211730Simp        tar) INSFILE="${TAR_FILE}" ;;
479247705Sjpaetzel        dist) 
480247705Sjpaetzel	  get_value_from_cfg_with_spaces distFiles
481247705Sjpaetzel	  if [ -z "$VAL" ] ; then
482247705Sjpaetzel	     exit_err "No dist files specified!"
483247705Sjpaetzel	  fi
484247705Sjpaetzel	  INSFILE="${VAL}" 
485247705Sjpaetzel  	  ;;
486209513Simp      esac
487209513Simp    fi
488209513Simp    export INSFILE
489209513Simp  fi
490209513Simp
491209513Simp  # Lets start by figuring out what medium we are using
492209513Simp  case ${INSTALLMEDIUM} in
493211730Simp    dvd|usb)
494211730Simp      # Lets start by mounting the disk 
495211730Simp      opt_mount 
496220059Sjpaetzel      if [ -n "${INSDIR}" ]
497211730Simp      then
498211730Simp        INSDIR="${CDMNT}/${INSDIR}" ; export INSDIR
499211730Simp	    start_extract_split
500209513Simp
501211730Simp      else
502247705Sjpaetzel	if [ "$PACKAGETYPE" = "dist" ] ; then
503247705Sjpaetzel          start_extract_dist "${CDMNT}/usr/freebsd-dist"
504247705Sjpaetzel	else
505247705Sjpaetzel          INSFILE="${CDMNT}/${INSFILE}" ; export INSFILE
506247705Sjpaetzel          start_extract_uzip_tar
507247705Sjpaetzel	fi
508211730Simp      fi
509211730Simp      ;;
510211486Simp
511212337Simp    ftp)
512247705Sjpaetzel      case $PACKAGETYPE in
513247705Sjpaetzel	 split)
514247705Sjpaetzel           fetch_split_files
515211730Simp
516247705Sjpaetzel           INSDIR="${INSFILE}" ; export INSDIR
517247705Sjpaetzel           start_extract_split
518247705Sjpaetzel	   ;;
519247705Sjpaetzel	  dist)
520247705Sjpaetzel           fetch_dist_file
521247705Sjpaetzel           start_extract_dist "$DLDIR"
522247705Sjpaetzel	   ;;
523247705Sjpaetzel	     *)
524247705Sjpaetzel           fetch_install_file
525247705Sjpaetzel           start_extract_uzip_tar 
526247705Sjpaetzel	   ;;
527247705Sjpaetzel       esac
528211730Simp      ;;
529211730Simp
530212337Simp    sftp) ;;
531212337Simp
532212337Simp    rsync) start_rsync_copy ;;
533213650Simp    image) start_image_install ;;
534225657Sjpaetzel    local)
535225657Sjpaetzel      get_value_from_cfg localPath
536225657Sjpaetzel      if [ -z "$VAL" ]
537225657Sjpaetzel      then
538225657Sjpaetzel        exit_err "Install medium was set to local, but no localPath was provided!"
539225657Sjpaetzel      fi
540225657Sjpaetzel      LOCALPATH=$VAL
541247705Sjpaetzel      if [ "$PACKAGETYPE" = "dist" ] ; then
542247705Sjpaetzel        INSFILE="${INSFILE}" ; export INSFILE
543247705Sjpaetzel        start_extract_dist "$LOCALPATH"
544247705Sjpaetzel      else
545247705Sjpaetzel        INSFILE="${LOCALPATH}/${INSFILE}" ; export INSFILE
546247705Sjpaetzel        start_extract_uzip_tar
547247705Sjpaetzel      fi
548225657Sjpaetzel      ;;
549211730Simp    *) exit_err "ERROR: Unknown install medium" ;;
550209513Simp  esac
551209513Simp
552209513Simp};
553