From nobody@FreeBSD.org  Tue Aug 31 00:33:19 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 6843D10656B1
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 31 Aug 2010 00:33:19 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 563EF8FC1D
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 31 Aug 2010 00:33:19 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o7V0XJ4D008379
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 31 Aug 2010 00:33:19 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o7V0XJO4008378;
	Tue, 31 Aug 2010 00:33:19 GMT
	(envelope-from nobody)
Message-Id: <201008310033.o7V0XJO4008378@www.freebsd.org>
Date: Tue, 31 Aug 2010 00:33:19 GMT
From: John Hixson <john@ixsystems.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: pc-sysinstall patch that allows images to be written to disks
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         150137
>Category:       bin
>Synopsis:       [patch] pc-sysinstall(8) patch that allows images to be written to disks
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    imp
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Tue Aug 31 00:40:03 UTC 2010
>Closed-Date:    Sat Oct 09 01:36:20 MDT 2010
>Last-Modified:  Sat Oct 09 01:36:20 MDT 2010
>Originator:     John Hixson
>Release:        9.0-CURRENT
>Organization:
iXsystems
>Environment:
FreeBSD thinkbsd 9.0-CURRENT FreeBSD 9.0-CURRENT #4: Fri Aug 20 05:23:56 PDT 2010     john@thinkbsd:/usr/obj/usr/src/sys/THINKBSD  amd64
>Description:
This patch creates the "image" directive for the pc-sysinstall config file. This allows disks to be configured with an image instead of partitioning. 
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

diff -urN /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/backend/Makefile usr.sbin/pc-sysinstall/backend/Makefile
--- /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/backend/Makefile	2010-08-19 12:22:59.000000000 -0700
+++ usr.sbin/pc-sysinstall/backend/Makefile	2010-08-26 14:15:33.000000000 -0700
@@ -7,7 +7,7 @@
 	functions-newfs.sh functions-packages.sh functions-parse.sh \
 	functions-runcommands.sh functions-unmount.sh \
 	functions-upgrade.sh functions-users.sh \
-	functions.sh parseconfig.sh startautoinstall.sh
+	functions.sh parseconfig.sh startautoinstall.sh installimage.sh
 FILESMODE=	${BINMODE}
 FILESDIR=${SHAREDIR}/pc-sysinstall/backend
 NO_OBJ=
diff -urN /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh
--- /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh	2010-08-24 16:07:50.000000000 -0700
+++ usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh	2010-08-30 17:21:59.000000000 -0700
@@ -566,9 +566,8 @@
 setup_disk_label()
 {
   # We are ready to start setting up the label, lets read the config and do the actions
-
   # First confirm that we have a valid WORKINGSLICES
-  if [ -z "${WORKINGSLICES}" ]; then
+  if [ -z "${WORKINGSLICES}" -a -z "${WORKINGIMAGES}" ]; then
     exit_err "ERROR: No slices were setup! Please report this to the maintainers"
   fi
 
@@ -613,6 +612,12 @@
     populate_disk_label "${i}"
   done
 
+  for i in $WORKINGIMAGES
+  do
+    image=`echo "${i}"|cut -f2 -d:`
+    check_image_layout "${image}" 
+  done
+
   # Check if we made a root partition
   if [ "$FOUNDROOT" = "-1" ]
   then
@@ -631,3 +636,166 @@
   fi
 };
 
+check_fstab_mbr()
+{
+  local SLICE
+  local FSTAB
+
+  if [ -z "$2" ]
+  then
+	return 1
+  fi
+
+  SLICE="$1"
+  FSTAB="$2/etc/fstab"
+
+  if [ -f "${FSTAB}" ]
+  then
+    PARTLETTER=`echo "$SLICE" | sed -E 's|^.+([a-h])$|\1|'`
+
+    grep -E '^.+ +/ +' "${FSTAB}" >/dev/null 2>&1
+    if [ "$?" = "0" ]
+    then
+      if [ "${PARTLETTER}" = "a" ]
+      then
+        FOUNDROOT="0"
+      else
+        FOUNDROOT="1"
+      fi
+      export FOUNDROOT
+    fi
+
+    grep -E '^.+ +/boot +' "${FSTAB}" >/dev/null 2>&1
+    if [ "$?" = "0" ]
+    then
+      if [ "${PARTLETTER}" = "a" ]
+      then
+        USINGBOOTPART="0"
+      else 
+        exit_err "/boot partition must be first partition"
+      fi 
+      export USINGBOOTPART
+    fi
+
+    return 0
+  fi
+
+  return 1
+};
+
+check_fstab_gpt()
+{
+  local SLICE
+  local FSTAB
+
+  if [ -z "$2" ]
+  then
+	return 1
+  fi
+
+  SLICE="$1"
+  FSTAB="$2/etc/fstab"
+
+  if [ -f "${FSTAB}" ]
+  then
+    PARTNUMBER=`echo "${SLICE}" | sed -E 's|^.+p([0-9]*)$|\1|'`
+
+    grep -E '^.+ +/ +' "${FSTAB}" >/dev/null 2>&1
+    if [ "$?" = "0" ]
+    then
+      if [ "${PARTNUMBER}" = "2" ]
+      then
+        FOUNDROOT="0"
+      else
+        FOUNDROOT="1"
+      fi
+      export FOUNDROOT
+    fi
+
+    grep -E '^.+ +/boot +' "${FSTAB}" >/dev/null 2>&1
+    if [ "$?" = "0" ]
+    then
+      if [ "${PARTNUMBER}" = "2" ]
+      then
+        USINGBOOTPART="0"
+      else 
+        exit_err "/boot partition must be first partition"
+      fi 
+      export USINGBOOTPART
+    fi
+
+    return 0
+  fi
+
+
+  return 1
+};
+
+check_image_layout()
+{
+  local SLICES
+  local IMAGE
+  local TYPE
+  local RES
+  local MD
+  local F
+
+  IMAGE="$1"
+  TYPE="MBR"
+
+  if [ -z "${IMAGE}" ]
+  then
+	return 1
+  fi
+
+  MD=`mdconfig -af "${IMAGE}"`
+  if [ "$?" != "0" ]
+  then
+	return 1
+  fi
+
+  SLICES=`ls /dev/${MD}s[1-4]*[a-h]* 2>/dev/null`
+  if [ "$?" != "0" ]
+  then
+    SLICES=`ls /dev/${MD}p[0-9]* 2>/dev/null`
+    if [ -n "${SLICES}" ]
+    then
+      TYPE="GPT"
+      RES=0
+    fi
+  else
+    RES=0
+  fi
+
+  for slice in ${SLICES}
+  do
+    F=1
+    mount ${slice} /mnt 2>/dev/null
+    if [ "$?" != "0" ]
+    then
+      continue
+    fi 
+
+    if [ "${TYPE}" = "MBR" ]
+    then
+	  check_fstab_mbr "${slice}" "/mnt"
+      F="$?"
+
+    elif [ "${TYPE}" = "GPT" ]
+    then
+	  check_fstab_gpt "${slice}" "/mnt"
+      F="$?"
+    fi 
+
+    if [ "${F}" = "0" ]
+    then
+      umount /mnt
+      break 
+    fi
+
+    umount /mnt
+  done
+
+  mdconfig -d -u "${MD}"
+  return ${RES}
+};
diff -urN /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/backend/functions-disk.sh usr.sbin/pc-sysinstall/backend/functions-disk.sh
--- /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/backend/functions-disk.sh	2010-08-24 16:07:50.000000000 -0700
+++ usr.sbin/pc-sysinstall/backend/functions-disk.sh	2010-08-30 17:23:26.000000000 -0700
@@ -231,9 +231,6 @@
 get_disk_mediasize()
 {
   mediasize=`diskinfo -v ${1} | grep "# mediasize in sectors" | tr -s ' ' | cut -f 2`
-
-  # Not sure why this is, memory disks need it though.
-  mediasize=`expr ${mediasize} - 10`
   VAL="${mediasize}" ; export VAL
 };
 
@@ -336,164 +333,205 @@
   # We are ready to start setting up the disks, lets read the config and do the actions
   while read line
   do
-     echo $line | grep "^disk${disknum}=" >/dev/null 2>/dev/null
-     if [ "$?" = "0" ]
-     then
-
-       # Found a disk= entry, lets get the disk we are working on
-       get_value_from_string "${line}"
-       strip_white_space "$VAL"
-       DISK="$VAL"
+    echo $line | grep "^disk${disknum}=" >/dev/null 2>/dev/null
+    if [ "$?" = "0" ]
+    then
+
+      # Found a disk= entry, lets get the disk we are working on
+      get_value_from_string "${line}"
+      strip_white_space "$VAL"
+      DISK="$VAL"
      
-       # Before we go further, lets confirm this disk really exists
-       if [ ! -e "/dev/${DISK}" ]
-       then
-         exit_err "ERROR: The disk ${DISK} does not exist!"
-       fi
-
-       # Make sure we stop any gmirrors on this disk
-       stop_all_gmirror ${DISK}
-
-       # Make sure we stop any geli stuff on this disk
-       stop_all_geli ${DISK}
-
-       # Make sure we don't have any zpools loaded
-       stop_all_zfs
-
-     fi
-
-     # Lets look if this device will be mirrored on another disk
-     echo $line | grep "^mirror=" >/dev/null 2>/dev/null
-     if [ "$?" = "0" ]
-     then
-
-       # Found a disk= entry, lets get the disk we are working on
-       get_value_from_string "${line}"
-       strip_white_space "$VAL"
-       MIRRORDISK="$VAL"
+      # Before we go further, lets confirm this disk really exists
+      if [ ! -e "/dev/${DISK}" ]
+      then
+        exit_err "ERROR: The disk ${DISK} does not exist!"
+      fi
+
+      # Make sure we stop any gmirrors on this disk
+      stop_all_gmirror ${DISK}
+
+      # Make sure we stop any geli stuff on this disk
+      stop_all_geli ${DISK}
+
+      # Make sure we don't have any zpools loaded
+      stop_all_zfs
+
+    fi
+
+    # Lets look if this device will be mirrored on another disk
+    echo $line | grep "^mirror=" >/dev/null 2>/dev/null
+    if [ "$?" = "0" ]
+    then
+
+      # Found a disk= entry, lets get the disk we are working on
+      get_value_from_string "${line}"
+      strip_white_space "$VAL"
+      MIRRORDISK="$VAL"
      
-       # Before we go further, lets confirm this disk really exists
-       if [ ! -e "/dev/${MIRRORDISK}" ]
-       then
-         exit_err "ERROR: The mirror disk ${MIRRORDISK} does not exist!"
-       fi
-     fi
-
-     # Lets see if we have been given a mirror balance choice
-     echo $line | grep "^mirrorbal=" >/dev/null 2>/dev/null
-     if [ "$?" = "0" ]
-     then
-
-       # Found a disk= entry, lets get the disk we are working on
-       get_value_from_string "${line}"
-       strip_white_space "$VAL"
-       MIRRORBAL="$VAL"
-     fi
-
-     echo $line | grep "^partition=" >/dev/null 2>/dev/null
-     if [ "$?" = "0" ]
-     then
-       # Found a partition= entry, lets read / set it 
-       get_value_from_string "${line}"
-       strip_white_space "$VAL"
-       PTYPE="$VAL"
-
-       # We are using free space, figure out the slice number
-       if [ "${PTYPE}" = "free" -o "${PTYPE}" = "FREE" ]
-       then
-         # Lets figure out what number this slice will be
-         LASTSLICE="`gpart show ${DISK} | grep -v ${DISK} | grep -v ' free' |tr -s '\t' ' ' | cut -d ' ' -f 4 | sed '/^$/d' | tail -n 1`"
-         if [ -z "${LASTSLICE}" ]
-         then
-           LASTSLICE="1"
-         else
-           LASTSLICE="`expr $LASTSLICE + 1`"
-         fi
-
-         if [ $LASTSLICE -gt 4 ]
-         then
-           exit_err "ERROR: BSD only supports primary partitions, and there are none availble on $DISK"
-         fi
-
-       fi
-     fi
-
-     # Check if we have a partscheme specified
-     echo $line | grep "^partscheme=" >/dev/null 2>/dev/null
-     if [ "$?" = "0" ] ; then
-       # Found a partscheme= entry, lets read / set it 
-       get_value_from_string "${line}"
-       strip_white_space "$VAL"
-       PSCHEME="$VAL"
-       if [ "$PSCHEME" != "GPT" -a "$PSCHEME" != "MBR" ] ; then
-	 exit_err "Unknown partition scheme: $PSCHEME" 
-       fi
-     fi
-
-     echo $line | grep "^bootManager=" >/dev/null 2>/dev/null
-     if [ "$?" = "0" ]
-     then
-       # Found a bootManager= entry, lets read /set it
-       get_value_from_string "${line}"
-       strip_white_space "$VAL"
-       BMANAGER="$VAL"
-     fi
-
-     echo $line | grep "^commitDiskPart" >/dev/null 2>/dev/null
-     if [ "$?" = "0" ]
-     then
-       # Found our flag to commit this disk setup / lets do sanity check and do it
-       if [ ! -z "${DISK}" -a ! -z "${PTYPE}" ]
-       then
-         case ${PTYPE} in
-           all|ALL)
-		     if [ "$PSCHEME" = "MBR" -o -z "$PSCHEME" ] ; then
-               PSCHEME="MBR"
-               tmpSLICE="${DISK}s1"  
-			 else
-               tmpSLICE="${DISK}p1"  
-			 fi
-
-             run_gpart_full "${DISK}" "${BMANAGER}" "${PSCHEME}"
-			 ;;
-
-           s1|s2|s3|s4)
-			 tmpSLICE="${DISK}${PTYPE}" 
-             # Get the number of the slice we are working on
-             s="`echo ${PTYPE} | awk '{print substr($0,length,1)}'`" 
-             run_gpart_slice "${DISK}" "${BMANAGER}" "${s}"
-			 ;;
-
-           free|FREE)
-			 tmpSLICE="${DISK}s${LASTSLICE}"
-             run_gpart_free "${DISK}" "${LASTSLICE}" "${BMANAGER}"
-			 ;;
-
-           *) exit_err "ERROR: Unknown PTYPE: $PTYPE" ;;
-         esac
-
-         # Now save which disk<num> this is, so we can parse it later during slice partition setup
-         echo "disk${disknum}" >${SLICECFGDIR}/$tmpSLICE
-
-         # Save any mirror config
-         if [ ! -z "$MIRRORDISK" ]
-         then
-           # Default to round-robin if the user didn't specify
-           if [ -z "$MIRRORBAL" ]
-           then
-             MIRRORBAL="round-robin"
-           fi
-           echo "$MIRRORDISK:$MIRRORBAL" >${MIRRORCFGDIR}/$DISK
-         fi
-
-
-         # Increment our disk counter to look for next disk and unset
-         unset BMANAGER PTYPE DISK MIRRORDISK MIRRORBAL PSCHEME
-         disknum="`expr $disknum + 1`"
-       else
-         exit_err "ERROR: commitDiskPart was called without procceding disk<num>= and partition= entries!!!" 
-       fi
-     fi
+      # Before we go further, lets confirm this disk really exists
+      if [ ! -e "/dev/${MIRRORDISK}" ]
+      then
+        exit_err "ERROR: The mirror disk ${MIRRORDISK} does not exist!"
+      fi
+    fi
+
+    # Lets see if we have been given a mirror balance choice
+    echo $line | grep "^mirrorbal=" >/dev/null 2>/dev/null
+    if [ "$?" = "0" ]
+    then
+
+      # Found a disk= entry, lets get the disk we are working on
+      get_value_from_string "${line}"
+      strip_white_space "$VAL"
+      MIRRORBAL="$VAL"
+    fi
+
+    echo $line | grep "^partition=" >/dev/null 2>/dev/null
+    if [ "$?" = "0" ]
+    then
+      # Found a partition= entry, lets read / set it 
+      get_value_from_string "${line}"
+      strip_white_space "$VAL"
+      PTYPE=`echo $VAL|tr A-Z a-z`
+
+      # We are using free space, figure out the slice number
+      if [ "${PTYPE}" = "free" ]
+      then
+        # Lets figure out what number this slice will be
+        LASTSLICE="`gpart show ${DISK} \
+			| grep -v ${DISK} \
+			| grep -v ' free' \
+			| tr -s '\t' ' ' \
+			| cut -d ' ' -f 4 \
+			| sed '/^$/d' \
+			| tail -n 1`"
+
+        if [ -z "${LASTSLICE}" ]
+        then
+          LASTSLICE="1"
+        else
+          LASTSLICE="`expr $LASTSLICE + 1`"
+        fi
+
+        if [ $LASTSLICE -gt 4 ]
+        then
+          exit_err "ERROR: BSD only supports primary partitions, and there are none availble on $DISK"
+        fi
+
+      fi
+    fi
+
+    # Check if we have an image file defined
+    echo $line | grep "^image=" >/dev/null 2>/dev/null
+    if [ "$?" = "0" ] ; then
+      # Found an image= entry, lets read / set it
+      get_value_from_string "${line}"
+      strip_white_space "$VAL"
+      IMAGE="$VAL"
+      if [ ! -f "$IMAGE" ] ; then
+        exit_err "$IMAGE file does not exist"
+      fi
+    fi
+
+    # Check if we have a partscheme specified
+    echo $line | grep "^partscheme=" >/dev/null 2>/dev/null
+    if [ "$?" = "0" ] ; then
+      # Found a partscheme= entry, lets read / set it 
+      get_value_from_string "${line}"
+      strip_white_space "$VAL"
+      PSCHEME="$VAL"
+      if [ "$PSCHEME" != "GPT" -a "$PSCHEME" != "MBR" ] ; then
+        exit_err "Unknown partition scheme: $PSCHEME" 
+      fi
+    fi
+
+    echo $line | grep "^bootManager=" >/dev/null 2>/dev/null
+    if [ "$?" = "0" ]
+    then
+      # Found a bootManager= entry, lets read /set it
+      get_value_from_string "${line}"
+      strip_white_space "$VAL"
+      BMANAGER="$VAL"
+    fi
+
+    echo $line | grep "^commitDiskPart" >/dev/null 2>/dev/null
+    if [ "$?" = "0" ]
+    then
+      # Found our flag to commit this disk setup / lets do sanity check and do it
+      if [ ! -z "${DISK}" -a ! -z "${PTYPE}" ]
+      then
+        case ${PTYPE} in
+          all)
+            if [ "$PSCHEME" = "MBR" -o -z "$PSCHEME" ] ; then
+              PSCHEME="MBR"
+              tmpSLICE="${DISK}s1"  
+			else
+              tmpSLICE="${DISK}p1"  
+            fi
+
+            run_gpart_full "${DISK}" "${BMANAGER}" "${PSCHEME}"
+            ;;
+
+          s1|s2|s3|s4)
+            tmpSLICE="${DISK}${PTYPE}" 
+            # Get the number of the slice we are working on
+            s="`echo ${PTYPE} | awk '{print substr($0,length,1)}'`" 
+            run_gpart_slice "${DISK}" "${BMANAGER}" "${s}"
+            ;;
+
+          free)
+            tmpSLICE="${DISK}s${LASTSLICE}"
+            run_gpart_free "${DISK}" "${LASTSLICE}" "${BMANAGER}"
+            ;;
+
+          image)
+            if [ -n "${IMAGE}" ]
+            then
+              write_image "${IMAGE}" "${DISK}"
+            else 
+			  exit_err "ERROR: partition type image specified with no image!"
+            fi 
+
+            IMAGE="${DISK}:${IMAGE}"
+            if [ -z "${WORKINGIMAGES}" ]
+            then
+			  WORKINGIMAGES="${IMAGE}"
+            else 
+			  WORKINGIMAGES="${WORKINGIMAGES} ${IMAGE}"
+            fi 
+
+            export WORKINGIMAGES
+            ;;
+
+          *) exit_err "ERROR: Unknown PTYPE: $PTYPE" ;;
+        esac
+
+        # Now save which disk<num> this is, so we can parse it later during slice partition setup
+        if [ -n "${tmpSLICE}" ]
+        then
+          echo "disk${disknum}" >${SLICECFGDIR}/$tmpSLICE
+        fi
+
+        # Save any mirror config
+        if [ ! -z "$MIRRORDISK" ]
+        then
+          # Default to round-robin if the user didn't specify
+          if [ -z "$MIRRORBAL" ]
+          then
+            MIRRORBAL="round-robin"
+          fi
+          echo "$MIRRORDISK:$MIRRORBAL" >${MIRRORCFGDIR}/$DISK
+        fi
+
+
+        # Increment our disk counter to look for next disk and unset
+        unset BMANAGER PTYPE DISK MIRRORDISK MIRRORBAL PSCHEME IMAGE
+        disknum="`expr $disknum + 1`"
+      else
+        exit_err "ERROR: commitDiskPart was called without procceding disk<num>= and partition= entries!!!" 
+      fi
+    fi
 
   done <${CFGF}
 
@@ -590,8 +628,7 @@
   totalblocks="`expr ${totalblocks} \* ${sec}`"
   if [ -z "${totalblocks}" ]
   then
-	get_disk_mediasize "${_intDISK}"
-	totalblocks="${VAL}"
+    totalblocks=`gpart show "${_intDISK}"|tail -2|head -1|awk '{ print $2 }'`
   fi
 
   # Now set the ending block to the total disk block size
diff -urN /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/backend/functions-extractimage.sh usr.sbin/pc-sysinstall/backend/functions-extractimage.sh
--- /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/backend/functions-extractimage.sh	2010-08-24 16:07:50.000000000 -0700
+++ usr.sbin/pc-sysinstall/backend/functions-extractimage.sh	2010-08-26 17:15:13.000000000 -0700
@@ -377,7 +377,7 @@
       fi
       ;;
 
-    ftp|sftp)
+    ftp)
       if [ "$PACKAGETYPE" = "split" ]
       then
         fetch_split_files
@@ -390,9 +390,9 @@
       fi
       ;;
 
-      rsync) start_rsync_copy ;;
-    img)
-		;;
+    sftp) ;;
+
+    rsync) start_rsync_copy ;;
     *) exit_err "ERROR: Unknown install medium" ;;
   esac
 
diff -urN /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/backend/functions-installcomponents.sh usr.sbin/pc-sysinstall/backend/functions-installcomponents.sh
--- /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/backend/functions-installcomponents.sh	2010-08-24 16:07:50.000000000 -0700
+++ usr.sbin/pc-sysinstall/backend/functions-installcomponents.sh	2010-08-25 13:06:01.000000000 -0700
@@ -60,7 +60,7 @@
 	    RESULT="$?"
         ;;
 
-      ftp|sftp)
+      ftp)
         get_value_from_cfg ftpPath
         if [ -z "$VAL" ]
         then
@@ -71,6 +71,8 @@
         fetch_file "${FTPPATH}/${COMPFILEDIR}/${SUBDIR}/${CFILE}" "${FSMNT}/${COMPTMPDIR}/${CFILE}" "0"
         RESULT="$?"
        ;;
+
+      sftp) ;;
     esac
 
     if [ "${RESULT}" != "0" ]
diff -urN /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/backend/functions-packages.sh usr.sbin/pc-sysinstall/backend/functions-packages.sh
--- /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/backend/functions-packages.sh	2010-08-24 16:07:51.000000000 -0700
+++ usr.sbin/pc-sysinstall/backend/functions-packages.sh	2010-08-25 13:05:36.000000000 -0700
@@ -113,7 +113,8 @@
 
     case "${INSTALLMEDIUM}" in
       usb|dvd) get_package_index_by_fs ;;
-      ftp|sftp) get_package_index_by_ftp "${FTPPATH}" ;;
+      ftp) get_package_index_by_ftp "${FTPPATH}" ;;
+      sftp) ;;
       *) RES=1 ;;
     esac
 
@@ -369,6 +370,7 @@
 
   case "${INSTALLMEDIUM}" in
     usb|dvd) fetch_package_by_fs "${CATEGORY}" "${PACKAGE}" "${SAVEDIR}" ;;
-    ftp|sftp) fetch_package_by_ftp "${CATEGORY}" "${PACKAGE}" "${SAVEDIR}" ;;
+    ftp) fetch_package_by_ftp "${CATEGORY}" "${PACKAGE}" "${SAVEDIR}" ;;
+    sftp) ;;
   esac
 };
diff -urN /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/backend/functions-parse.sh usr.sbin/pc-sysinstall/backend/functions-parse.sh
--- /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/backend/functions-parse.sh	2010-08-24 16:07:51.000000000 -0700
+++ usr.sbin/pc-sysinstall/backend/functions-parse.sh	2010-08-26 18:12:57.000000000 -0700
@@ -85,6 +85,7 @@
     VALID="1"
     for i in ${2}
     do
+      VAL=`echo "$VAL"|tr A-Z a-z`
       if [ "$VAL" = "${i}" ]
       then 
         VALID="0"
diff -urN /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/backend/functions.sh usr.sbin/pc-sysinstall/backend/functions.sh
--- /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/backend/functions.sh	2010-08-24 16:07:51.000000000 -0700
+++ usr.sbin/pc-sysinstall/backend/functions.sh	2010-08-28 22:18:42.000000000 -0700
@@ -283,3 +283,118 @@
     return
   fi
 };
+
+write_image()
+{
+  IMAGE_FILE="$1"
+  DEVICE_FILE="$2"
+
+  if [ -z "${IMAGE_FILE}" ]
+  then
+    echo "ERROR: Image file not specified!"
+    exit 1
+  fi
+ 
+  if [ -z "${DEVICE_FILE}" ]
+  then
+    echo "ERROR: Device file not specified!"
+    exit 1
+  fi
+ 
+  if [ ! -f "${IMAGE_FILE}" ]
+  then
+    echo "ERROR: '${IMAGE_FILE}' does not exist!"
+    exit 1
+  fi
+
+  DEVICE_FILE="${DEVICE_FILE#/dev/}"
+  DEVICE_FILE="/dev/${DEVICE_FILE}"
+ 
+  if [ ! -c "${DEVICE_FILE}" ]
+  then
+    echo "ERROR: '${DEVICE_FILE}' is not a character device!"
+    exit 1
+  fi
+
+  if [ "${RES}" = "0" ]
+  then
+    rc_halt "dd if=${IMAGE_FILE} of=${DEVICE_FILE} ibs=16k obs=16k"
+  fi
+
+  return 0
+};
+
+install_fresh()
+{
+  # Lets start setting up the disk slices now
+  setup_disk_slice
+  
+  # Disk setup complete, now lets parse WORKINGSLICES and setup the bsdlabels
+  setup_disk_label
+  
+  # Now we've setup the bsdlabels, lets go ahead and run newfs / zfs 
+  # to setup the filesystems
+  setup_filesystems
+
+  # Lets mount the partitions now
+  mount_all_filesystems
+
+  # We are ready to begin extraction, lets start now
+  init_extraction 
+
+  # Check if we have any optional modules to load 
+  install_components
+
+  # Check if we have any packages to install
+  install_packages
+
+  # Do any localization in configuration
+  run_localize
+  
+  # Save any networking config on the installed system
+  save_networking_install
+
+  # Now add any users
+  setup_users
+
+  # Now run any commands specified
+  run_commands
+  
+  # Do any last cleanup / setup before unmounting
+  run_final_cleanup
+
+  # Unmount and finish up
+  unmount_all_filesystems
+
+  echo_log "Installation finished!"
+}
+
+install_upgrade()
+{
+  # We're going to do an upgrade, skip all the disk setup 
+  # and start by mounting the target drive/slices
+  mount_upgrade
+  
+  # Start the extraction process
+  init_extraction
+
+  # Do any localization in configuration
+  run_localize
+
+  # ow run any commands specified
+  run_commands
+  
+  # Merge any old configuration files
+  merge_old_configs
+
+  # Check if we have any optional modules to load 
+  install_components
+
+  # Check if we have any packages to install
+  install_packages
+
+  # All finished, unmount the file-systems
+  unmount_upgrade
+
+  echo_log "Upgrade finished!"
+}
diff -urN /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/backend/installimage.sh usr.sbin/pc-sysinstall/backend/installimage.sh
--- /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/backend/installimage.sh	1969-12-31 16:00:00.000000000 -0800
+++ usr.sbin/pc-sysinstall/backend/installimage.sh	2010-08-26 12:58:04.000000000 -0700
@@ -0,0 +1,34 @@
+#!/bin/sh
+#-
+# Copyright (c) 2010 iXsystems, Inc.  All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+
+# Source our functions scripts
+. ${BACKEND}/functions.sh
+
+IMAGE_FILE="${1}"
+DEVICE_FILE="${2}"
+
+write_image "${IMAGE_FILE}" "${DEVICE_FILE}"
diff -urN /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/backend/parseconfig.sh usr.sbin/pc-sysinstall/backend/parseconfig.sh
--- /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/backend/parseconfig.sh	2010-08-24 16:07:51.000000000 -0700
+++ usr.sbin/pc-sysinstall/backend/parseconfig.sh	2010-08-26 21:55:19.000000000 -0700
@@ -73,9 +73,9 @@
 check_value installMode "fresh upgrade"
 check_value bootManager "bsd none"
 check_value installType "PCBSD FreeBSD"
-check_value installMedium "dvd usb ftp rsync img"
+check_value installMedium "dvd usb ftp rsync"
 check_value packageType "uzip tar rsync split"
-if_check_value_exists partition "all ALL s1 s2 s3 s4 free FREE"
+if_check_value_exists partition "all s1 s2 s3 s4 free image"
 if_check_value_exists mirrorbal "load prefer round-robin split"
 
 # We passed all sanity checks! Yay, lets start the install
@@ -98,79 +98,18 @@
 start_networking
 
 # If we are not doing an upgrade, lets go ahead and setup the disk
-if [ "${INSTALLMODE}" = "fresh" ]
-then
-
-  # Lets start setting up the disk slices now
-  setup_disk_slice
-  
-  # Disk setup complete, now lets parse WORKINGSLICES and setup the bsdlabels
-  setup_disk_label
-  
-  # Now we've setup the bsdlabels, lets go ahead and run newfs / zfs 
-  # to setup the filesystems
-  setup_filesystems
-
-  # Lets mount the partitions now
-  mount_all_filesystems
-
-  # We are ready to begin extraction, lets start now
-  init_extraction
-
-  # Check if we have any optional modules to load 
-  install_components
-
-  # Check if we have any packages to install
-  install_packages
-
-  # Do any localization in configuration
-  run_localize
-  
-  # Save any networking config on the installed system
-  save_networking_install
-
-  # Now add any users
-  setup_users
-
-  # Now run any commands specified
-  run_commands
-  
-  # Do any last cleanup / setup before unmounting
-  run_final_cleanup
-
-  # Unmount and finish up
-  unmount_all_filesystems
-
-  echo_log "Installation finished!"
-  exit 0
-
-else
-  # We're going to do an upgrade, skip all the disk setup 
-  # and start by mounting the target drive/slices
-  mount_upgrade
-  
-  # Start the extraction process
-  init_extraction
-
-  # Do any localization in configuration
-  run_localize
-
-  # Now run any commands specified
-  run_commands
-  
-  # Merge any old configuration files
-  merge_old_configs
-
-  # Check if we have any optional modules to load 
-  install_components
-
-  # Check if we have any packages to install
-  install_packages
-
-  # All finished, unmount the file-systems
-  unmount_upgrade
-
-  echo_log "Upgrade finished!"
-  exit 0
-fi
+case "${INSTALLMODE}" in
+  fresh)
+	install_fresh
+    ;;
+
+  upgrade)
+    install_upgrade
+    ;;
+
+  *)
+	exit 1
+    ;;
+esac
 
+exit 0
diff -urN /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/backend-query/disk-list.sh usr.sbin/pc-sysinstall/backend-query/disk-list.sh
--- /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/backend-query/disk-list.sh	2010-08-24 16:07:51.000000000 -0700
+++ usr.sbin/pc-sysinstall/backend-query/disk-list.sh	2010-08-24 16:15:15.000000000 -0700
@@ -27,6 +27,7 @@
 
 ARGS=$1
 FLAGS_MD=""
+FLAGS_CD=""
 FLAGS_VERBOSE=""
 
 shift
@@ -39,6 +40,9 @@
     -v)
       FLAGS_VERBOSE=1
       ;;
+    -c)
+      FLAGS_CD=1
+      ;;
   esac
   shift
 done
@@ -62,9 +66,12 @@
   DEV="${i}"
 
   # Make sure we don't find any cd devices
-  case "${DEV}" in
-    acd[0-9]*|cd[0-9]*|scd[0-9]*) continue ;;
-  esac
+  if [ -z "${FLAGS_CD}" ]
+  then
+    case "${DEV}" in
+      acd[0-9]*|cd[0-9]*|scd[0-9]*) continue ;;
+    esac
+  fi
 
   # Check the dmesg output for some more info about this device
   NEWLINE=$(dmesg | sed -n "s/^$DEV: .*<\(.*\)>.*$/ <\1>/p" | head -n 1)
diff -urN /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/doc/help-index usr.sbin/pc-sysinstall/doc/help-index
--- /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/doc/help-index	2010-08-19 12:23:00.000000000 -0700
+++ usr.sbin/pc-sysinstall/doc/help-index	2010-08-26 12:59:25.000000000 -0700
@@ -9,6 +9,8 @@
    	Display the help data for the specified command
 
 System Query Commands
+    install-image <image> <device>
+        Installs an image file to a device file
 
     disk-list 
         Provides a listing of the disk drives detected on this system
diff -urN /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/examples/README usr.sbin/pc-sysinstall/examples/README
--- /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/examples/README	2010-08-19 12:23:00.000000000 -0700
+++ usr.sbin/pc-sysinstall/examples/README	2010-08-30 17:32:08.000000000 -0700
@@ -114,7 +114,7 @@
  # disk0=ada0s1a
 
 
-# partition=(all, free, s1, s1, s3, s4)
+# partition=(all, free, s1, s1, s3, s4, image)
 
 After setting disk[0-9], the partition= variable is used to specify which target
 partition we will be working with for this device.
@@ -124,7 +124,9 @@
 Setting this to "free" will allow pc-sysinstall to search for the first available
 primary slice with free space, and create the slice. 
 
-Setting this to "s1, s2, s3 or s4" will use the specified MBR slice
+Setting this to "s1, s2, s3 or s4" will use the specified MBR slice.
+
+Setting this to "image" will use an image to configure the disk.
 
 (This tag is unused for upgrades)
 
@@ -151,6 +153,11 @@
 Setting this option will instruct pc-sysinstall to install the BSD boot Manager,
 or leave it empty
 
+# image=(/path/to/image/file)
+
+Setting this option will instruct pc-sysinstall to write the image file
+specified by the path to the disk.
+
 # commitDiskPart
 
 This command must be placed at the end of the diskX= section, before starting
diff -urN /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh
--- /home/john/src/freebsd/9.0-CURRENT/src/usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh	2010-08-24 16:07:51.000000000 -0700
+++ usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh	2010-08-26 12:39:19.000000000 -0700
@@ -116,6 +116,10 @@
     fi
   ;;
 
+  # Install an image file to a device
+  install-image) ${BACKEND}/installimage.sh "${2}" "${3}"
+  ;;
+
   # Parse an auto-install directive, and begin the installation
   start-autoinstall) ${BACKEND}/startautoinstall.sh ${2}
   ;;


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->imp 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Mon Sep 6 07:06:12 UTC 2010 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=150137 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/150137: commit references a PR
Date: Wed,  8 Sep 2010 20:10:40 +0000 (UTC)

 Author: imp
 Date: Wed Sep  8 20:10:24 2010
 New Revision: 212337
 URL: http://svn.freebsd.org/changeset/base/212337
 
 Log:
   pc-sysinstall(8) patch that allows images to be written to disks
   
   This patch creates the "image" directive for the pc-sysinstall config
   file. This allows disks to be configured with an image instead of
   partitioning.
   
   PR:		150137
   Submitted by:	John Hixson
 
 Modified:
   head/usr.sbin/pc-sysinstall/backend-query/disk-list.sh
   head/usr.sbin/pc-sysinstall/backend/Makefile
   head/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh
   head/usr.sbin/pc-sysinstall/backend/functions-disk.sh
   head/usr.sbin/pc-sysinstall/backend/functions-extractimage.sh
   head/usr.sbin/pc-sysinstall/backend/functions-installcomponents.sh
   head/usr.sbin/pc-sysinstall/backend/functions-packages.sh
   head/usr.sbin/pc-sysinstall/backend/functions-parse.sh
   head/usr.sbin/pc-sysinstall/backend/functions.sh
   head/usr.sbin/pc-sysinstall/backend/parseconfig.sh
   head/usr.sbin/pc-sysinstall/doc/help-index
   head/usr.sbin/pc-sysinstall/examples/README
   head/usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh
 
 Modified: head/usr.sbin/pc-sysinstall/backend-query/disk-list.sh
 ==============================================================================
 --- head/usr.sbin/pc-sysinstall/backend-query/disk-list.sh	Wed Sep  8 20:09:50 2010	(r212336)
 +++ head/usr.sbin/pc-sysinstall/backend-query/disk-list.sh	Wed Sep  8 20:10:24 2010	(r212337)
 @@ -27,6 +27,7 @@
  
  ARGS=$1
  FLAGS_MD=""
 +FLAGS_CD=""
  FLAGS_VERBOSE=""
  
  shift
 @@ -39,6 +40,9 @@ do
      -v)
        FLAGS_VERBOSE=1
        ;;
 +    -c)
 +      FLAGS_CD=1
 +      ;;
    esac
    shift
  done
 @@ -62,9 +66,12 @@ do
    DEV="${i}"
  
    # Make sure we don't find any cd devices
 -  case "${DEV}" in
 -    acd[0-9]*|cd[0-9]*|scd[0-9]*) continue ;;
 -  esac
 +  if [ -z "${FLAGS_CD}" ]
 +  then
 +    case "${DEV}" in
 +      acd[0-9]*|cd[0-9]*|scd[0-9]*) continue ;;
 +    esac
 +  fi
  
    # Check the dmesg output for some more info about this device
    NEWLINE=$(dmesg | sed -n "s/^$DEV: .*<\(.*\)>.*$/ <\1>/p" | head -n 1)
 
 Modified: head/usr.sbin/pc-sysinstall/backend/Makefile
 ==============================================================================
 --- head/usr.sbin/pc-sysinstall/backend/Makefile	Wed Sep  8 20:09:50 2010	(r212336)
 +++ head/usr.sbin/pc-sysinstall/backend/Makefile	Wed Sep  8 20:10:24 2010	(r212337)
 @@ -7,7 +7,7 @@ FILES=	functions-bsdlabel.sh functions-c
  	functions-newfs.sh functions-packages.sh functions-parse.sh \
  	functions-runcommands.sh functions-unmount.sh \
  	functions-upgrade.sh functions-users.sh \
 -	functions.sh parseconfig.sh startautoinstall.sh
 +	functions.sh parseconfig.sh startautoinstall.sh installimage.sh
  FILESMODE=	${BINMODE}
  FILESDIR=${SHAREDIR}/pc-sysinstall/backend
  NO_OBJ=
 
 Modified: head/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh
 ==============================================================================
 --- head/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh	Wed Sep  8 20:09:50 2010	(r212336)
 +++ head/usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh	Wed Sep  8 20:10:24 2010	(r212337)
 @@ -566,9 +566,8 @@ populate_disk_label()
  setup_disk_label()
  {
    # We are ready to start setting up the label, lets read the config and do the actions
 -
    # First confirm that we have a valid WORKINGSLICES
 -  if [ -z "${WORKINGSLICES}" ]; then
 +  if [ -z "${WORKINGSLICES}" -a -z "${WORKINGIMAGES}" ]; then
      exit_err "ERROR: No slices were setup! Please report this to the maintainers"
    fi
  
 @@ -613,6 +612,12 @@ setup_disk_label()
      populate_disk_label "${i}"
    done
  
 +  for i in $WORKINGIMAGES
 +  do
 +    image=`echo "${i}"|cut -f2 -d:`
 +    check_image_layout "${image}" 
 +  done
 +
    # Check if we made a root partition
    if [ "$FOUNDROOT" = "-1" ]
    then
 @@ -631,3 +636,166 @@ setup_disk_label()
    fi
  };
  
 +check_fstab_mbr()
 +{
 +  local SLICE
 +  local FSTAB
 +
 +  if [ -z "$2" ]
 +  then
 +	return 1
 +  fi
 +
 +  SLICE="$1"
 +  FSTAB="$2/etc/fstab"
 +
 +  if [ -f "${FSTAB}" ]
 +  then
 +    PARTLETTER=`echo "$SLICE" | sed -E 's|^.+([a-h])$|\1|'`
 +
 +    grep -E '^.+ +/ +' "${FSTAB}" >/dev/null 2>&1
 +    if [ "$?" = "0" ]
 +    then
 +      if [ "${PARTLETTER}" = "a" ]
 +      then
 +        FOUNDROOT="0"
 +      else
 +        FOUNDROOT="1"
 +      fi
 +      export FOUNDROOT
 +    fi
 +
 +    grep -E '^.+ +/boot +' "${FSTAB}" >/dev/null 2>&1
 +    if [ "$?" = "0" ]
 +    then
 +      if [ "${PARTLETTER}" = "a" ]
 +      then
 +        USINGBOOTPART="0"
 +      else 
 +        exit_err "/boot partition must be first partition"
 +      fi 
 +      export USINGBOOTPART
 +    fi
 +
 +    return 0
 +  fi
 +
 +  return 1
 +};
 +
 +check_fstab_gpt()
 +{
 +  local SLICE
 +  local FSTAB
 +
 +  if [ -z "$2" ]
 +  then
 +	return 1
 +  fi
 +
 +  SLICE="$1"
 +  FSTAB="$2/etc/fstab"
 +
 +  if [ -f "${FSTAB}" ]
 +  then
 +    PARTNUMBER=`echo "${SLICE}" | sed -E 's|^.+p([0-9]*)$|\1|'`
 +
 +    grep -E '^.+ +/ +' "${FSTAB}" >/dev/null 2>&1
 +    if [ "$?" = "0" ]
 +    then
 +      if [ "${PARTNUMBER}" = "2" ]
 +      then
 +        FOUNDROOT="0"
 +      else
 +        FOUNDROOT="1"
 +      fi
 +      export FOUNDROOT
 +    fi
 +
 +    grep -E '^.+ +/boot +' "${FSTAB}" >/dev/null 2>&1
 +    if [ "$?" = "0" ]
 +    then
 +      if [ "${PARTNUMBER}" = "2" ]
 +      then
 +        USINGBOOTPART="0"
 +      else 
 +        exit_err "/boot partition must be first partition"
 +      fi 
 +      export USINGBOOTPART
 +    fi
 +
 +    return 0
 +  fi
 +
 +
 +  return 1
 +};
 +
 +check_image_layout()
 +{
 +  local SLICES
 +  local IMAGE
 +  local TYPE
 +  local RES
 +  local MD
 +  local F
 +
 +  IMAGE="$1"
 +  TYPE="MBR"
 +
 +  if [ -z "${IMAGE}" ]
 +  then
 +	return 1
 +  fi
 +
 +  MD=`mdconfig -af "${IMAGE}"`
 +  if [ "$?" != "0" ]
 +  then
 +	return 1
 +  fi
 +
 +  SLICES=`ls /dev/${MD}s[1-4]*[a-h]* 2>/dev/null`
 +  if [ "$?" != "0" ]
 +  then
 +    SLICES=`ls /dev/${MD}p[0-9]* 2>/dev/null`
 +    if [ -n "${SLICES}" ]
 +    then
 +      TYPE="GPT"
 +      RES=0
 +    fi
 +  else
 +    RES=0
 +  fi
 +
 +  for slice in ${SLICES}
 +  do
 +    F=1
 +    mount ${slice} /mnt 2>/dev/null
 +    if [ "$?" != "0" ]
 +    then
 +      continue
 +    fi 
 +
 +    if [ "${TYPE}" = "MBR" ]
 +    then
 +	  check_fstab_mbr "${slice}" "/mnt"
 +      F="$?"
 +
 +    elif [ "${TYPE}" = "GPT" ]
 +    then
 +	  check_fstab_gpt "${slice}" "/mnt"
 +      F="$?"
 +    fi 
 +
 +    if [ "${F}" = "0" ]
 +    then
 +      umount /mnt
 +      break 
 +    fi
 +
 +    umount /mnt
 +  done
 +
 +  mdconfig -d -u "${MD}"
 +  return ${RES}
 +};
 
 Modified: head/usr.sbin/pc-sysinstall/backend/functions-disk.sh
 ==============================================================================
 --- head/usr.sbin/pc-sysinstall/backend/functions-disk.sh	Wed Sep  8 20:09:50 2010	(r212336)
 +++ head/usr.sbin/pc-sysinstall/backend/functions-disk.sh	Wed Sep  8 20:10:24 2010	(r212337)
 @@ -231,9 +231,6 @@ get_disk_heads()
  get_disk_mediasize()
  {
    mediasize=`diskinfo -v ${1} | grep "# mediasize in sectors" | tr -s ' ' | cut -f 2`
 -
 -  # Not sure why this is, memory disks need it though.
 -  mediasize=`expr ${mediasize} - 10`
    VAL="${mediasize}" ; export VAL
  };
  
 @@ -336,164 +333,205 @@ setup_disk_slice()
    # We are ready to start setting up the disks, lets read the config and do the actions
    while read line
    do
 -     echo $line | grep "^disk${disknum}=" >/dev/null 2>/dev/null
 -     if [ "$?" = "0" ]
 -     then
 -
 -       # Found a disk= entry, lets get the disk we are working on
 -       get_value_from_string "${line}"
 -       strip_white_space "$VAL"
 -       DISK="$VAL"
 +    echo $line | grep "^disk${disknum}=" >/dev/null 2>/dev/null
 +    if [ "$?" = "0" ]
 +    then
 +
 +      # Found a disk= entry, lets get the disk we are working on
 +      get_value_from_string "${line}"
 +      strip_white_space "$VAL"
 +      DISK="$VAL"
       
 -       # Before we go further, lets confirm this disk really exists
 -       if [ ! -e "/dev/${DISK}" ]
 -       then
 -         exit_err "ERROR: The disk ${DISK} does not exist!"
 -       fi
 -
 -       # Make sure we stop any gmirrors on this disk
 -       stop_all_gmirror ${DISK}
 -
 -       # Make sure we stop any geli stuff on this disk
 -       stop_all_geli ${DISK}
 -
 -       # Make sure we don't have any zpools loaded
 -       stop_all_zfs
 -
 -     fi
 -
 -     # Lets look if this device will be mirrored on another disk
 -     echo $line | grep "^mirror=" >/dev/null 2>/dev/null
 -     if [ "$?" = "0" ]
 -     then
 -
 -       # Found a disk= entry, lets get the disk we are working on
 -       get_value_from_string "${line}"
 -       strip_white_space "$VAL"
 -       MIRRORDISK="$VAL"
 +      # Before we go further, lets confirm this disk really exists
 +      if [ ! -e "/dev/${DISK}" ]
 +      then
 +        exit_err "ERROR: The disk ${DISK} does not exist!"
 +      fi
 +
 +      # Make sure we stop any gmirrors on this disk
 +      stop_all_gmirror ${DISK}
 +
 +      # Make sure we stop any geli stuff on this disk
 +      stop_all_geli ${DISK}
 +
 +      # Make sure we don't have any zpools loaded
 +      stop_all_zfs
 +
 +    fi
 +
 +    # Lets look if this device will be mirrored on another disk
 +    echo $line | grep "^mirror=" >/dev/null 2>/dev/null
 +    if [ "$?" = "0" ]
 +    then
 +
 +      # Found a disk= entry, lets get the disk we are working on
 +      get_value_from_string "${line}"
 +      strip_white_space "$VAL"
 +      MIRRORDISK="$VAL"
       
 -       # Before we go further, lets confirm this disk really exists
 -       if [ ! -e "/dev/${MIRRORDISK}" ]
 -       then
 -         exit_err "ERROR: The mirror disk ${MIRRORDISK} does not exist!"
 -       fi
 -     fi
 -
 -     # Lets see if we have been given a mirror balance choice
 -     echo $line | grep "^mirrorbal=" >/dev/null 2>/dev/null
 -     if [ "$?" = "0" ]
 -     then
 -
 -       # Found a disk= entry, lets get the disk we are working on
 -       get_value_from_string "${line}"
 -       strip_white_space "$VAL"
 -       MIRRORBAL="$VAL"
 -     fi
 -
 -     echo $line | grep "^partition=" >/dev/null 2>/dev/null
 -     if [ "$?" = "0" ]
 -     then
 -       # Found a partition= entry, lets read / set it 
 -       get_value_from_string "${line}"
 -       strip_white_space "$VAL"
 -       PTYPE="$VAL"
 -
 -       # We are using free space, figure out the slice number
 -       if [ "${PTYPE}" = "free" -o "${PTYPE}" = "FREE" ]
 -       then
 -         # Lets figure out what number this slice will be
 -         LASTSLICE="`gpart show ${DISK} | grep -v ${DISK} | grep -v ' free' |tr -s '\t' ' ' | cut -d ' ' -f 4 | sed '/^$/d' | tail -n 1`"
 -         if [ -z "${LASTSLICE}" ]
 -         then
 -           LASTSLICE="1"
 -         else
 -           LASTSLICE="`expr $LASTSLICE + 1`"
 -         fi
 -
 -         if [ $LASTSLICE -gt 4 ]
 -         then
 -           exit_err "ERROR: BSD only supports primary partitions, and there are none availble on $DISK"
 -         fi
 -
 -       fi
 -     fi
 -
 -     # Check if we have a partscheme specified
 -     echo $line | grep "^partscheme=" >/dev/null 2>/dev/null
 -     if [ "$?" = "0" ] ; then
 -       # Found a partscheme= entry, lets read / set it 
 -       get_value_from_string "${line}"
 -       strip_white_space "$VAL"
 -       PSCHEME="$VAL"
 -       if [ "$PSCHEME" != "GPT" -a "$PSCHEME" != "MBR" ] ; then
 -	 exit_err "Unknown partition scheme: $PSCHEME" 
 -       fi
 -     fi
 -
 -     echo $line | grep "^bootManager=" >/dev/null 2>/dev/null
 -     if [ "$?" = "0" ]
 -     then
 -       # Found a bootManager= entry, lets read /set it
 -       get_value_from_string "${line}"
 -       strip_white_space "$VAL"
 -       BMANAGER="$VAL"
 -     fi
 -
 -     echo $line | grep "^commitDiskPart" >/dev/null 2>/dev/null
 -     if [ "$?" = "0" ]
 -     then
 -       # Found our flag to commit this disk setup / lets do sanity check and do it
 -       if [ ! -z "${DISK}" -a ! -z "${PTYPE}" ]
 -       then
 -         case ${PTYPE} in
 -           all|ALL)
 -		     if [ "$PSCHEME" = "MBR" -o -z "$PSCHEME" ] ; then
 -               PSCHEME="MBR"
 -               tmpSLICE="${DISK}s1"  
 -			 else
 -               tmpSLICE="${DISK}p1"  
 -			 fi
 -
 -             run_gpart_full "${DISK}" "${BMANAGER}" "${PSCHEME}"
 -			 ;;
 -
 -           s1|s2|s3|s4)
 -			 tmpSLICE="${DISK}${PTYPE}" 
 -             # Get the number of the slice we are working on
 -             s="`echo ${PTYPE} | awk '{print substr($0,length,1)}'`" 
 -             run_gpart_slice "${DISK}" "${BMANAGER}" "${s}"
 -			 ;;
 -
 -           free|FREE)
 -			 tmpSLICE="${DISK}s${LASTSLICE}"
 -             run_gpart_free "${DISK}" "${LASTSLICE}" "${BMANAGER}"
 -			 ;;
 -
 -           *) exit_err "ERROR: Unknown PTYPE: $PTYPE" ;;
 -         esac
 -
 -         # Now save which disk<num> this is, so we can parse it later during slice partition setup
 -         echo "disk${disknum}" >${SLICECFGDIR}/$tmpSLICE
 -
 -         # Save any mirror config
 -         if [ ! -z "$MIRRORDISK" ]
 -         then
 -           # Default to round-robin if the user didn't specify
 -           if [ -z "$MIRRORBAL" ]
 -           then
 -             MIRRORBAL="round-robin"
 -           fi
 -           echo "$MIRRORDISK:$MIRRORBAL" >${MIRRORCFGDIR}/$DISK
 -         fi
 -
 -
 -         # Increment our disk counter to look for next disk and unset
 -         unset BMANAGER PTYPE DISK MIRRORDISK MIRRORBAL PSCHEME
 -         disknum="`expr $disknum + 1`"
 -       else
 -         exit_err "ERROR: commitDiskPart was called without procceding disk<num>= and partition= entries!!!" 
 -       fi
 -     fi
 +      # Before we go further, lets confirm this disk really exists
 +      if [ ! -e "/dev/${MIRRORDISK}" ]
 +      then
 +        exit_err "ERROR: The mirror disk ${MIRRORDISK} does not exist!"
 +      fi
 +    fi
 +
 +    # Lets see if we have been given a mirror balance choice
 +    echo $line | grep "^mirrorbal=" >/dev/null 2>/dev/null
 +    if [ "$?" = "0" ]
 +    then
 +
 +      # Found a disk= entry, lets get the disk we are working on
 +      get_value_from_string "${line}"
 +      strip_white_space "$VAL"
 +      MIRRORBAL="$VAL"
 +    fi
 +
 +    echo $line | grep "^partition=" >/dev/null 2>/dev/null
 +    if [ "$?" = "0" ]
 +    then
 +      # Found a partition= entry, lets read / set it 
 +      get_value_from_string "${line}"
 +      strip_white_space "$VAL"
 +      PTYPE=`echo $VAL|tr A-Z a-z`
 +
 +      # We are using free space, figure out the slice number
 +      if [ "${PTYPE}" = "free" ]
 +      then
 +        # Lets figure out what number this slice will be
 +        LASTSLICE="`gpart show ${DISK} \
 +			| grep -v ${DISK} \
 +			| grep -v ' free' \
 +			| tr -s '\t' ' ' \
 +			| cut -d ' ' -f 4 \
 +			| sed '/^$/d' \
 +			| tail -n 1`"
 +
 +        if [ -z "${LASTSLICE}" ]
 +        then
 +          LASTSLICE="1"
 +        else
 +          LASTSLICE="`expr $LASTSLICE + 1`"
 +        fi
 +
 +        if [ $LASTSLICE -gt 4 ]
 +        then
 +          exit_err "ERROR: BSD only supports primary partitions, and there are none availble on $DISK"
 +        fi
 +
 +      fi
 +    fi
 +
 +    # Check if we have an image file defined
 +    echo $line | grep "^image=" >/dev/null 2>/dev/null
 +    if [ "$?" = "0" ] ; then
 +      # Found an image= entry, lets read / set it
 +      get_value_from_string "${line}"
 +      strip_white_space "$VAL"
 +      IMAGE="$VAL"
 +      if [ ! -f "$IMAGE" ] ; then
 +        exit_err "$IMAGE file does not exist"
 +      fi
 +    fi
 +
 +    # Check if we have a partscheme specified
 +    echo $line | grep "^partscheme=" >/dev/null 2>/dev/null
 +    if [ "$?" = "0" ] ; then
 +      # Found a partscheme= entry, lets read / set it 
 +      get_value_from_string "${line}"
 +      strip_white_space "$VAL"
 +      PSCHEME="$VAL"
 +      if [ "$PSCHEME" != "GPT" -a "$PSCHEME" != "MBR" ] ; then
 +        exit_err "Unknown partition scheme: $PSCHEME" 
 +      fi
 +    fi
 +
 +    echo $line | grep "^bootManager=" >/dev/null 2>/dev/null
 +    if [ "$?" = "0" ]
 +    then
 +      # Found a bootManager= entry, lets read /set it
 +      get_value_from_string "${line}"
 +      strip_white_space "$VAL"
 +      BMANAGER="$VAL"
 +    fi
 +
 +    echo $line | grep "^commitDiskPart" >/dev/null 2>/dev/null
 +    if [ "$?" = "0" ]
 +    then
 +      # Found our flag to commit this disk setup / lets do sanity check and do it
 +      if [ ! -z "${DISK}" -a ! -z "${PTYPE}" ]
 +      then
 +        case ${PTYPE} in
 +          all)
 +            if [ "$PSCHEME" = "MBR" -o -z "$PSCHEME" ] ; then
 +              PSCHEME="MBR"
 +              tmpSLICE="${DISK}s1"  
 +			else
 +              tmpSLICE="${DISK}p1"  
 +            fi
 +
 +            run_gpart_full "${DISK}" "${BMANAGER}" "${PSCHEME}"
 +            ;;
 +
 +          s1|s2|s3|s4)
 +            tmpSLICE="${DISK}${PTYPE}" 
 +            # Get the number of the slice we are working on
 +            s="`echo ${PTYPE} | awk '{print substr($0,length,1)}'`" 
 +            run_gpart_slice "${DISK}" "${BMANAGER}" "${s}"
 +            ;;
 +
 +          free)
 +            tmpSLICE="${DISK}s${LASTSLICE}"
 +            run_gpart_free "${DISK}" "${LASTSLICE}" "${BMANAGER}"
 +            ;;
 +
 +          image)
 +            if [ -n "${IMAGE}" ]
 +            then
 +              write_image "${IMAGE}" "${DISK}"
 +            else 
 +			  exit_err "ERROR: partition type image specified with no image!"
 +            fi 
 +
 +            IMAGE="${DISK}:${IMAGE}"
 +            if [ -z "${WORKINGIMAGES}" ]
 +            then
 +			  WORKINGIMAGES="${IMAGE}"
 +            else 
 +			  WORKINGIMAGES="${WORKINGIMAGES} ${IMAGE}"
 +            fi 
 +
 +            export WORKINGIMAGES
 +            ;;
 +
 +          *) exit_err "ERROR: Unknown PTYPE: $PTYPE" ;;
 +        esac
 +
 +        # Now save which disk<num> this is, so we can parse it later during slice partition setup
 +        if [ -n "${tmpSLICE}" ]
 +        then
 +          echo "disk${disknum}" >${SLICECFGDIR}/$tmpSLICE
 +        fi
 +
 +        # Save any mirror config
 +        if [ ! -z "$MIRRORDISK" ]
 +        then
 +          # Default to round-robin if the user didn't specify
 +          if [ -z "$MIRRORBAL" ]
 +          then
 +            MIRRORBAL="round-robin"
 +          fi
 +          echo "$MIRRORDISK:$MIRRORBAL" >${MIRRORCFGDIR}/$DISK
 +        fi
 +
 +
 +        # Increment our disk counter to look for next disk and unset
 +        unset BMANAGER PTYPE DISK MIRRORDISK MIRRORBAL PSCHEME IMAGE
 +        disknum="`expr $disknum + 1`"
 +      else
 +        exit_err "ERROR: commitDiskPart was called without procceding disk<num>= and partition= entries!!!" 
 +      fi
 +    fi
  
    done <${CFGF}
  
 @@ -590,8 +628,7 @@ init_mbr_full_disk()
    totalblocks="`expr ${totalblocks} \* ${sec}`"
    if [ -z "${totalblocks}" ]
    then
 -	get_disk_mediasize "${_intDISK}"
 -	totalblocks="${VAL}"
 +    totalblocks=`gpart show "${_intDISK}"|tail -2|head -1|awk '{ print $2 }'`
    fi
  
    # Now set the ending block to the total disk block size
 
 Modified: head/usr.sbin/pc-sysinstall/backend/functions-extractimage.sh
 ==============================================================================
 --- head/usr.sbin/pc-sysinstall/backend/functions-extractimage.sh	Wed Sep  8 20:09:50 2010	(r212336)
 +++ head/usr.sbin/pc-sysinstall/backend/functions-extractimage.sh	Wed Sep  8 20:10:24 2010	(r212337)
 @@ -377,7 +377,7 @@ init_extraction()
        fi
        ;;
  
 -    ftp|sftp)
 +    ftp)
        if [ "$PACKAGETYPE" = "split" ]
        then
          fetch_split_files
 @@ -390,9 +390,9 @@ init_extraction()
        fi
        ;;
  
 -      rsync) start_rsync_copy ;;
 -    img)
 -		;;
 +    sftp) ;;
 +
 +    rsync) start_rsync_copy ;;
      *) exit_err "ERROR: Unknown install medium" ;;
    esac
  
 
 Modified: head/usr.sbin/pc-sysinstall/backend/functions-installcomponents.sh
 ==============================================================================
 --- head/usr.sbin/pc-sysinstall/backend/functions-installcomponents.sh	Wed Sep  8 20:09:50 2010	(r212336)
 +++ head/usr.sbin/pc-sysinstall/backend/functions-installcomponents.sh	Wed Sep  8 20:10:24 2010	(r212337)
 @@ -60,7 +60,7 @@ copy_component()
  	    RESULT="$?"
          ;;
  
 -      ftp|sftp)
 +      ftp)
          get_value_from_cfg ftpPath
          if [ -z "$VAL" ]
          then
 @@ -71,6 +71,8 @@ copy_component()
          fetch_file "${FTPPATH}/${COMPFILEDIR}/${SUBDIR}/${CFILE}" "${FSMNT}/${COMPTMPDIR}/${CFILE}" "0"
          RESULT="$?"
         ;;
 +
 +      sftp) ;;
      esac
  
      if [ "${RESULT}" != "0" ]
 
 Modified: head/usr.sbin/pc-sysinstall/backend/functions-packages.sh
 ==============================================================================
 --- head/usr.sbin/pc-sysinstall/backend/functions-packages.sh	Wed Sep  8 20:09:50 2010	(r212336)
 +++ head/usr.sbin/pc-sysinstall/backend/functions-packages.sh	Wed Sep  8 20:10:24 2010	(r212337)
 @@ -113,7 +113,8 @@ get_package_index()
  
      case "${INSTALLMEDIUM}" in
        usb|dvd) get_package_index_by_fs ;;
 -      ftp|sftp) get_package_index_by_ftp "${FTPPATH}" ;;
 +      ftp) get_package_index_by_ftp "${FTPPATH}" ;;
 +      sftp) ;;
        *) RES=1 ;;
      esac
  
 @@ -369,6 +370,7 @@ fetch_package()
  
    case "${INSTALLMEDIUM}" in
      usb|dvd) fetch_package_by_fs "${CATEGORY}" "${PACKAGE}" "${SAVEDIR}" ;;
 -    ftp|sftp) fetch_package_by_ftp "${CATEGORY}" "${PACKAGE}" "${SAVEDIR}" ;;
 +    ftp) fetch_package_by_ftp "${CATEGORY}" "${PACKAGE}" "${SAVEDIR}" ;;
 +    sftp) ;;
    esac
  };
 
 Modified: head/usr.sbin/pc-sysinstall/backend/functions-parse.sh
 ==============================================================================
 --- head/usr.sbin/pc-sysinstall/backend/functions-parse.sh	Wed Sep  8 20:09:50 2010	(r212336)
 +++ head/usr.sbin/pc-sysinstall/backend/functions-parse.sh	Wed Sep  8 20:10:24 2010	(r212337)
 @@ -85,6 +85,7 @@ if_check_value_exists()
      VALID="1"
      for i in ${2}
      do
 +      VAL=`echo "$VAL"|tr A-Z a-z`
        if [ "$VAL" = "${i}" ]
        then 
          VALID="0"
 
 Modified: head/usr.sbin/pc-sysinstall/backend/functions.sh
 ==============================================================================
 --- head/usr.sbin/pc-sysinstall/backend/functions.sh	Wed Sep  8 20:09:50 2010	(r212336)
 +++ head/usr.sbin/pc-sysinstall/backend/functions.sh	Wed Sep  8 20:10:24 2010	(r212337)
 @@ -283,3 +283,118 @@ get_zpool_name()
      return
    fi
  };
 +
 +write_image()
 +{
 +  IMAGE_FILE="$1"
 +  DEVICE_FILE="$2"
 +
 +  if [ -z "${IMAGE_FILE}" ]
 +  then
 +    echo "ERROR: Image file not specified!"
 +    exit 1
 +  fi
 + 
 +  if [ -z "${DEVICE_FILE}" ]
 +  then
 +    echo "ERROR: Device file not specified!"
 +    exit 1
 +  fi
 + 
 +  if [ ! -f "${IMAGE_FILE}" ]
 +  then
 +    echo "ERROR: '${IMAGE_FILE}' does not exist!"
 +    exit 1
 +  fi
 +
 +  DEVICE_FILE="${DEVICE_FILE#/dev/}"
 +  DEVICE_FILE="/dev/${DEVICE_FILE}"
 + 
 +  if [ ! -c "${DEVICE_FILE}" ]
 +  then
 +    echo "ERROR: '${DEVICE_FILE}' is not a character device!"
 +    exit 1
 +  fi
 +
 +  if [ "${RES}" = "0" ]
 +  then
 +    rc_halt "dd if=${IMAGE_FILE} of=${DEVICE_FILE} ibs=16k obs=16k"
 +  fi
 +
 +  return 0
 +};
 +
 +install_fresh()
 +{
 +  # Lets start setting up the disk slices now
 +  setup_disk_slice
 +  
 +  # Disk setup complete, now lets parse WORKINGSLICES and setup the bsdlabels
 +  setup_disk_label
 +  
 +  # Now we've setup the bsdlabels, lets go ahead and run newfs / zfs 
 +  # to setup the filesystems
 +  setup_filesystems
 +
 +  # Lets mount the partitions now
 +  mount_all_filesystems
 +
 +  # We are ready to begin extraction, lets start now
 +  init_extraction 
 +
 +  # Check if we have any optional modules to load 
 +  install_components
 +
 +  # Check if we have any packages to install
 +  install_packages
 +
 +  # Do any localization in configuration
 +  run_localize
 +  
 +  # Save any networking config on the installed system
 +  save_networking_install
 +
 +  # Now add any users
 +  setup_users
 +
 +  # Now run any commands specified
 +  run_commands
 +  
 +  # Do any last cleanup / setup before unmounting
 +  run_final_cleanup
 +
 +  # Unmount and finish up
 +  unmount_all_filesystems
 +
 +  echo_log "Installation finished!"
 +}
 +
 +install_upgrade()
 +{
 +  # We're going to do an upgrade, skip all the disk setup 
 +  # and start by mounting the target drive/slices
 +  mount_upgrade
 +  
 +  # Start the extraction process
 +  init_extraction
 +
 +  # Do any localization in configuration
 +  run_localize
 +
 +  # ow run any commands specified
 +  run_commands
 +  
 +  # Merge any old configuration files
 +  merge_old_configs
 +
 +  # Check if we have any optional modules to load 
 +  install_components
 +
 +  # Check if we have any packages to install
 +  install_packages
 +
 +  # All finished, unmount the file-systems
 +  unmount_upgrade
 +
 +  echo_log "Upgrade finished!"
 +}
 
 Modified: head/usr.sbin/pc-sysinstall/backend/parseconfig.sh
 ==============================================================================
 --- head/usr.sbin/pc-sysinstall/backend/parseconfig.sh	Wed Sep  8 20:09:50 2010	(r212336)
 +++ head/usr.sbin/pc-sysinstall/backend/parseconfig.sh	Wed Sep  8 20:10:24 2010	(r212337)
 @@ -73,9 +73,9 @@ file_sanity_check "installMode disk0 ins
  check_value installMode "fresh upgrade"
  check_value bootManager "bsd none"
  check_value installType "PCBSD FreeBSD"
 -check_value installMedium "dvd usb ftp rsync img"
 +check_value installMedium "dvd usb ftp rsync"
  check_value packageType "uzip tar rsync split"
 -if_check_value_exists partition "all ALL s1 s2 s3 s4 free FREE"
 +if_check_value_exists partition "all s1 s2 s3 s4 free image"
  if_check_value_exists mirrorbal "load prefer round-robin split"
  
  # We passed all sanity checks! Yay, lets start the install
 @@ -98,79 +98,18 @@ PACKAGETYPE="${VAL}" ; export PACKAGETYP
  start_networking
  
  # If we are not doing an upgrade, lets go ahead and setup the disk
 -if [ "${INSTALLMODE}" = "fresh" ]
 -then
 -
 -  # Lets start setting up the disk slices now
 -  setup_disk_slice
 -  
 -  # Disk setup complete, now lets parse WORKINGSLICES and setup the bsdlabels
 -  setup_disk_label
 -  
 -  # Now we've setup the bsdlabels, lets go ahead and run newfs / zfs 
 -  # to setup the filesystems
 -  setup_filesystems
 -
 -  # Lets mount the partitions now
 -  mount_all_filesystems
 -
 -  # We are ready to begin extraction, lets start now
 -  init_extraction
 -
 -  # Check if we have any optional modules to load 
 -  install_components
 -
 -  # Check if we have any packages to install
 -  install_packages
 -
 -  # Do any localization in configuration
 -  run_localize
 -  
 -  # Save any networking config on the installed system
 -  save_networking_install
 -
 -  # Now add any users
 -  setup_users
 -
 -  # Now run any commands specified
 -  run_commands
 -  
 -  # Do any last cleanup / setup before unmounting
 -  run_final_cleanup
 -
 -  # Unmount and finish up
 -  unmount_all_filesystems
 -
 -  echo_log "Installation finished!"
 -  exit 0
 -
 -else
 -  # We're going to do an upgrade, skip all the disk setup 
 -  # and start by mounting the target drive/slices
 -  mount_upgrade
 -  
 -  # Start the extraction process
 -  init_extraction
 -
 -  # Do any localization in configuration
 -  run_localize
 -
 -  # Now run any commands specified
 -  run_commands
 -  
 -  # Merge any old configuration files
 -  merge_old_configs
 -
 -  # Check if we have any optional modules to load 
 -  install_components
 -
 -  # Check if we have any packages to install
 -  install_packages
 -
 -  # All finished, unmount the file-systems
 -  unmount_upgrade
 -
 -  echo_log "Upgrade finished!"
 -  exit 0
 -fi
 +case "${INSTALLMODE}" in
 +  fresh)
 +	install_fresh
 +    ;;
 +
 +  upgrade)
 +    install_upgrade
 +    ;;
 +
 +  *)
 +	exit 1
 +    ;;
 +esac
  
 +exit 0
 
 Modified: head/usr.sbin/pc-sysinstall/doc/help-index
 ==============================================================================
 --- head/usr.sbin/pc-sysinstall/doc/help-index	Wed Sep  8 20:09:50 2010	(r212336)
 +++ head/usr.sbin/pc-sysinstall/doc/help-index	Wed Sep  8 20:10:24 2010	(r212337)
 @@ -9,6 +9,8 @@ Help Commands
     	Display the help data for the specified command
  
  System Query Commands
 +    install-image <image> <device>
 +        Installs an image file to a device file
  
      disk-list 
          Provides a listing of the disk drives detected on this system
 
 Modified: head/usr.sbin/pc-sysinstall/examples/README
 ==============================================================================
 --- head/usr.sbin/pc-sysinstall/examples/README	Wed Sep  8 20:09:50 2010	(r212336)
 +++ head/usr.sbin/pc-sysinstall/examples/README	Wed Sep  8 20:10:24 2010	(r212337)
 @@ -114,7 +114,7 @@ root zpool of the target system to updat
   # disk0=ada0s1a
  
  
 -# partition=(all, free, s1, s1, s3, s4)
 +# partition=(all, free, s1, s1, s3, s4, image)
  
  After setting disk[0-9], the partition= variable is used to specify which target
  partition we will be working with for this device.
 @@ -124,7 +124,9 @@ Setting this to "all" will setup the dis
  Setting this to "free" will allow pc-sysinstall to search for the first available
  primary slice with free space, and create the slice. 
  
 -Setting this to "s1, s2, s3 or s4" will use the specified MBR slice
 +Setting this to "s1, s2, s3 or s4" will use the specified MBR slice.
 +
 +Setting this to "image" will use an image to configure the disk.
  
  (This tag is unused for upgrades)
  
 @@ -151,6 +153,11 @@ specified this defaults to "round-robin"
  Setting this option will instruct pc-sysinstall to install the BSD boot Manager,
  or leave it empty
  
 +# image=(/path/to/image/file)
 +
 +Setting this option will instruct pc-sysinstall to write the image file
 +specified by the path to the disk.
 +
  # commitDiskPart
  
  This command must be placed at the end of the diskX= section, before starting
 
 Modified: head/usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh
 ==============================================================================
 --- head/usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh	Wed Sep  8 20:09:50 2010	(r212336)
 +++ head/usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh	Wed Sep  8 20:10:24 2010	(r212337)
 @@ -116,6 +116,10 @@ case $1 in
      fi
    ;;
  
 +  # Install an image file to a device
 +  install-image) ${BACKEND}/installimage.sh "${2}" "${3}"
 +  ;;
 +
    # Parse an auto-install directive, and begin the installation
    start-autoinstall) ${BACKEND}/startautoinstall.sh ${2}
    ;;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: arundel 
State-Changed-When: Fri Sep 10 02:58:16 UTC 2010 
State-Changed-Why:  
Patched in HEAD (r150137). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=150137 
State-Changed-From-To: patched->closed 
State-Changed-By: imp 
State-Changed-When: Sat Oct 9 01:35:19 MDT 2010 
State-Changed-Why:  
patched isn't appropriate because we've not MFC'd this yet. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=150137 
>Unformatted:
