fi
}
+# Global variable for storing the partition option parameters;
+params=
+
+function msdos_partition_options {
+ # the partition number
+ local i=$1
+ # used for storing the per-part variables,
+ # accessed via indirect referencing
+ local tmp=""
+
+ tmp="INSTALLERFW_PART${i}_SIZE"
+ local size=${!tmp}
+ [ -z "$size" ] && size="1024"
+ if [[ "$INSTALLERFW_PART_COUNT" = "$((i+1))" ]]; then
+ # an 'empty' value means that sfdisk will use
+ # the defaults, in this case expanding to the
+ # end of the disk
+ size=""
+ fi
+ params=$(printf "${params}\n%s" ",${size}")
+
+ tmp="INSTALLERFW_PART${i}_FSTYPE"
+ local fstype=${!tmp}
+ local typeid='83'
+ [ "$fstype" = "swap" ] && typeid='82'
+ params=$(printf "${params}%s" ",${typeid}")
+
+ # handle bootflag last
+ tmp="INSTALLERFW_PART${i}_BOOTFLAG"
+ local bootflag=${!tmp}
+ if [ "$bootflag" = "True" ]; then
+ params=$(printf "${params}%s" ',*')
+ else
+ params=$(printf "${params}\n")
+ fi
+}
+
+function gpt_partition_options {
+ # the partition number
+ local i=$1
+ # used for storing the per-part variables,
+ # accessed via indirect referencing
+ local tmp=""
+
+ tmp="INSTALLERFW_PART${i}_ALIGN"
+ local align=${!tmp}
+ [ -n "$align" ] && params=$(printf "${params}%s" " --set-alignment=${align}")
+
+ # sgdisk uses '0' to mean 'default value'
+ params=$(printf "$params%s" " --new=0:0")
+
+ tmp="INSTALLERFW_PART${i}_SIZE"
+ local size=${!tmp}
+ if [[ "$INSTALLERFW_PART_COUNT" = "$((i+1))" ]]; then
+ size="0"
+ fi
+ [ -z "$size" ] && size="1024"
+ [ -n "$size" ] && params=$(printf "${params}%s" ":${size}M")
+
+ # TODO: need to handle swap partition types if encountered
+
+ # the following GUID option does not accept default partition values,
+ # so partition numbering must start at index 1, not 0
+ local partnum="$((i+1))"
+
+ tmp="INSTALLERFW_PART${i}_TYPE_ID"
+ local typeid=${!tmp}
+ [ -n "$typeid" ] && params=$(printf "${params}%s" " --typecode=${partnum}:${typeid}")
+}
+
function partition_device {
/usr/sbin/sfdisk -uM $TARGET_DEV << EOF
,2000,82
set_mounts
find_devices
message "Installing on to the hard disk now, this will take a few minutes..."
+
+pnum=0
+while [ "$pnum" -lt "$INSTALLERFW_PART_COUNT" ]; do
+ if [ "$INSTALLERFW_PTABLE_FORMAT" = "msdos" ]; then
+ msdos_partition_options $pnum
+ elif [ "$INSTALLERFW_PTABLE_FORMAT" = "gpt" ]; then
+ gpt_partition_options $pnum
+ fi
+ pnum="$((pnum+1))"
+done
+
partition_device
format_device
mount_devices