You need to use GNU parted utility - a partition manipulation program. It is perfect tool and works from a shell script. Here is a sample shell script. Make changes as per your setup and test script in a dummy environment.
Read parted and mke2fs man pages.
if [ $# -eq 0 ]
echo "$0 partition-name
echo "$0 /dev/sda1"
echo "* Creating partition."
parted -s -- $PART mkpart primary ext3 0 -1
echo "* Formatting the partition."
mke2fs -j -m 0 -O dir_index $PART