%include /tmp/part-include

%pre

#!/bin/bash

set $(list-harddrives)

#    $1 = 1st disk name
#    $2 = 1st disk size
#    $3 = 2nd disk name
#    $4 = 2nd disk size
#    so on

let numhd=$#/2

drive1=$1
drive2=$3

# calculate swap
mem=$(grep MemTotal /proc/meminfo | awk '{print $2}')
swap=$(( $mem / 1000 * 2 ))

#Write out partition scheme based on whether there are 1 or 2 hard drives

if [ $numhd == "2" ] ; then
        #2 drives
        echo "# partitioning scheme generated in %pre for 2 drives"             > /tmp/part-include
        echo "bootloader --location=mbr --driveorder=$drive1,$drive2"           >> /tmp/part-include
        echo "clearpart --all --initlabel"                                      >> /tmp/part-include
        echo "part raid.11 --size=100 --ondisk=$drive1"                         >> /tmp/part-include
        echo "part raid.21 --size=100 --ondisk=$drive2"                         >> /tmp/part-include
        echo "part raid.13 --size=100 --ondisk=$drive1 --grow"                  >> /tmp/part-include
        echo "part raid.23 --size=100 --ondisk=$drive2 --grow"                  >> /tmp/part-include

        echo "raid /boot --fstype ext3 --level=RAID1 --device=md0 raid.11 raid.21"      >> /tmp/part-include
        echo "raid pv.01 --level=RAID1 --device=md2 raid.13 raid.23"                    >> /tmp/part-include

        echo "volgroup vg0 pv.01"                                                       >> /tmp/part-include

        echo "logvol swap --fstype swap --name=swap --vgname=vg0 --size=$swap"           >> /tmp/part-include
        echo "logvol / --fstype ext3 --name=root --vgname=vg0 --size=300 --grow"        >> /tmp/part-include
else
        #1 drive
        echo "# partitioning scheme generated in %pre for 1 drives"                     > /tmp/part-include
        echo "bootloader --location=mbr --driveorder=$drive1"                           >> /tmp/part-include
        echo "clearpart --all --initlabel"                                              >> /tmp/part-include
        echo "part /boot --fstype ext3 --size=100   --ondisk=$drive1"                   >> /tmp/part-include
        echo "part swap  --fstype ext3 --size=$swap --ondisk=$drive1"                   >> /tmp/part-include
        echo "part /     --fstype ext3 --size=300   --ondisk=$drive1  --grow"           >> /tmp/part-include
fi

[ -f /tmp/part-include ] || touch /tmp/part-include
