#!/bin/bash

TARGET=/dev/hda

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

ARCH=amd64

echo ,${IMAGESIZE}$',L,*\n,,S\n;\n;' | sfdisk -uM -H 255 -S 63 $TARGET

xen-create-image --image-dev ${TARGET}1 --swap-dev ${TARGET}2 --fs ext3 --ide --arch $ARCH --dist $DIST --hostname $HOSTNAME --mirror $MIRROR --ip=$IP --netmask=255.255.0.0 --gateway=18.181.0.1 --cache=yes
