#!/bin/bash

TARGET=/dev/hda

#For some strange reason, . $TARGET doesn't work reliably.
eval `grep -a -m1 -B 100 ^return$ $TARGET | grep -v return`


#HOSTNAME=foobar
#DIST=etch
#MIRROR=http://debian.lcs.mit.edu/debian
#IMAGESIZE=3800

ARCH=amd64

#LVSIZE=`lvs --noheadings --units M --nosuffix -o Size /dev/xenvg/d_foobar_hda | sed 's/\..*//'`

# If this script is interrupted, it may not clean up after itself.
# In particular, it may leave ${VOLUME}1 mounted somewhere in tmp.
# Unmount it, then kpartx -d $VOLUME to clean up.

###
###  Create the device for SIPB-Xen purposes
###
echo ,${IMAGESIZE}$',L,*\n,,S\n;\n;' | sfdisk -uM -H 255 -S 63 $TARGET
#kpartx -a $TARGET

xen-create-image --image-dev ${TARGET}1 --swap-dev ${TARGET}2 --fs ext3 --ide --arch $ARCH --dist $DIST --hostname $HOSTNAME --mirror $MIRROR --dhcp --cache=yes

#kpartx -d $TARGET
